Skip to content

feat(audit): report controls that share one accessible name - #4771

Merged
thymikee merged 4 commits into
mainfrom
feat/audit-ambiguous-name
Nov 19, 2026
Merged

thymikee merged 4 commits into
mainfrom
feat/audit-ambiguous-name

Conversation

@thymikee

@thymikee thymikee commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Summary

audit treated any nonempty name as valid. Three buttons named "Save" looked fine, so a screen-reader user and an agent could not tell them apart.

This adds the ambiguous-name finding kind. Two or more evaluated controls of one role that share one accessible name on the captured screen each report a warning. The detail gives the shared label and the count. Names that differ only by case or surrounding whitespace count as one name. Controls of different roles may still share a name. System bars and keyboard keys stay excluded, and the existing wrapper collapse keeps a duplicated control silent.

Touched files: 10. Scope stayed in the audit owner plus its contracts, output, help, and docs. No device-facing behavior changed, so no device run was needed.

agent-device audit
# @e4  ambiguous-name  button "Save"  Name shared by 3 controls of this role

--json adds the kind to findings[].kind and guidance, with detail: { name, count }.

Closes #4762

Validation

Tested SHA: c5878c8

pnpm check:affected --run passed with exactCommit=true: format, lint, typecheck, layering, fallow, build, vitest-related, unit, command-docs, docs-links, docs-prose. Web smoke, replay and Linux lanes stay GitHub-authoritative.

The new capture-kit and command-output tests fail on the base and pass at this head. Provider integration for ios-audit and android-audit passes locally; the iOS clean-screen fixture now names its two buttons differently, since it must prove "no findings".

No unresolved risks.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff Turn on auto-fix

Add the ambiguous-name finding kind: two or more evaluated controls of one
role that carry one accessible name on the captured screen. Names that differ
only by case or surrounding whitespace count as one name. Each affected
control reports a warning with the shared label and the count, and the
guidance asks for a unique label that names its target.
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.41 MB 6.41 MB +2.1 kB
Package (unpacked) 6.41 MB 6.41 MB +2.1 kB
Package (download) 1.95 MB 1.95 MB +646 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 29.9 ms 32.8 ms +2.8 ms
CLI --help 63.5 ms 64.4 ms +1.0 ms

@thymikee

Copy link
Copy Markdown
Member Author

The audit check has one false positive at c5878c8: a single control can be reported as ambiguous with itself. The sharedNames pre-pass at snapshot-audit.ts:85 counts every evaluated control node, including the sole child of a same-role control. The audit already treats that pair as one control exposed twice (collapseIntoParent, :165-177). A screen with one "Save" button captured as Button > Button therefore counts 2. collapseIntoParent drops only the child's finding, so the parent reports "Name shared by 2 controls". Three wrapped Save buttons report a count of 6. The new test at snapshot-audit.test.ts:249-255 expects this result. On screens where controls are exposed as wrapper pairs (the shape #4592 added the collapse rule for), agents following help accessibility would ask the app to rename a control that is already unique. A name group should count logical controls, so please put the wrapped-duplicate identity rule (same controlRole as the parent and the parent's only child) in one predicate that both evaluatedNameGroup and collapseIntoParent use. Then change the test at :249 to expect no finding for one wrapped "Save", and add a test that three wrapped Save buttons report a count of 3.

The help text promises behavior the code does not have until that is fixed. cliDetail in snapshot.ts:192 and commands.md:435 say a name shared by "two or more controls" is reported once per control, and the PR body says the wrapper collapse keeps a duplicated control silent. The fix above makes both true, so no separate text change is needed.

Not blocking, take or leave: sharedNameText in audit-output.ts:69 prints only the count, and elementText prints finding.label, so a control named by contentDescription, text or a child shows "Name shared by 2 controls of this role" with no name (render detail.name and add a test for that case); the "Checks audit cannot do" section in cli-help-workflows.ts:236 still lists "A label must be specific and unique" as manual, so it could narrow to labels that are unique but not specific and names shared across roles; and the doc block on sharedNames (snapshot-audit.ts:60) repeats the NUL key encoding that nameGroupKey already shows, while accessibleName and controlOwnership now run twice per control.

The finding rests on the PR's own test shape, not a measured live capture. CI is still finishing, and nothing has failed. There are no conflicts. Before merge, the count has to cover logical controls only, with the shared predicate and the flipped test.

@thymikee

Copy link
Copy Markdown
Member Author

Thanks for the update. The earlier findings are addressed, but one false negative remains in the audit at 1b9a951.

evaluatedNameGroup drops every only-child of a same-role control from the shared-name count, even when the parent is not evaluated. If the parent is disabled, non-hittable, zero-rect, system-owned or ref-less, it is excluded at line 111, and its child is excluded at line 114, so that control is counted zero times. For example, Button(enabled:false, "Save") > Button("Save") plus a plain Button("Save") gives count 1 and no finding. Two such wrapped pairs also give no finding. The old code reported both children. This hides two controls an agent cannot tell apart by name, and the "reported once per control" text in help/commands.md is wrong for this shape. collapseIntoParent already keeps the child when the parent does not report that kind (tests at lines 302-320), so the two sites share a predicate but disagree on the outcome. Please make a child count as the same control as its parent only when the parent speaks for it: the parent is itself evaluated (has a ref and passes isActionable), has the same role, and has exactly one child. Putting the parent-evaluated condition inside isDuplicateExposure should do it, and it does not change collapseIntoParent. Please add a test where a disabled or ref-less wrapper over a "Save" child, plus a plain "Save" button, reports two findings with count 2.

Not blocking, take or leave: the multi-wrapped test at snapshot-audit.test.ts:264 asserts only kind and ref, and the old code gives the same summary (count 4), so asserting detail { name: "Save", count: 2 } on both findings would pin the logical count.

Checks are still running, with Smoke Tests in progress and nothing failed so far. The change only touches the pure audit function and its unit test. Before merge, the wrapped-child count needs the single predicate and the new test.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on 1b9a951. The verdict and the full list are in the summary comment.

@thymikee

Copy link
Copy Markdown
Member Author

Fixed at 9bce6b6.

  • Blocking: isDuplicateExposure now requires the parent to be an evaluated control of the same role with exactly one child. A disabled, unhittable, system-owned or ref-less wrapper no longer absorbs its child. The count and collapseIntoParent share this one predicate.
  • New test: a disabled wrapper, and a ref-less wrapper, over "Save" plus a plain "Save" each give two findings with {name: "Save", count: 2}.
  • Three wrapped Save buttons report three findings with count: 3. That test fails on the double-count code.
  • Each control is now resolved once (evaluated map). accessibleName and controlOwnership no longer run twice per control. The duplicated NUL-key doc is gone.
  • A role-only line now shows the shared name, for example button "Add to cart" Name shared by 2 controls of this role, with a test. A line with a label is unchanged, so the name is not printed twice.
  • help accessibility now leaves only labels that are unique but not specific, and names shared across roles, as manual checks.
  • check:affected --run passed with exactCommit=true. An earlier run failed only on snapshot-producer-emitters.test.ts timing out at 5 s under host load; it passes alone.

@thymikee

Copy link
Copy Markdown
Member Author

The PR is ready at 9bce6b6. The earlier findings from #4771 (comment) are fixed in the code. Not blocking: the relocated doc comment in https://github.com/callstack/agent-device/blob/9bce6b6/packages/capture-kit/src/snapshot/snapshot-audit.ts#L67 has a blank line between it and nameGroupKey, so it reads as detached; drop the blank line if you like, or leave it.

The open thread on a wrapper with a differing child name (#4771 (comment)) is half fixed. The unevaluated-parent case is fixed, because isDuplicateExposure now requires the evaluated parent to have the same role. An evaluated 'Save' wrapper over a sole 'Delete' child still drops the child from the count, which is low impact and not blocking. No live capture checked how often real iOS or Android trees expose such wrappers.

The Runner Build (tvOS + visionOS + watchOS) check failed. This diff touches only TypeScript, not the runner sources or the Xcode project, so the failure looks unrelated. It failed during action setup with a cache-download race, so a rerun should clear it. No conflicts are known.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 19, 2026
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 9bce6b6

Since the review of 1b9a951: 0 new · 1 still open · 0 no longer raised

1 finding(s): 1 minor.

🟡 Minor (1)

Where Finding
packages/capture-kit/src/snapshot/snapshot-audit.ts:122 Shared-name count drops sole-child controls even when their names differ

Reviewed with this repository's own Sentinel configuration (96a2813c555e).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 finding moved to a new line on 9bce6b6. The verdict and the full list are in the summary comment.

Comment on lines +122 to +127
for (const node of nodes) {
const control = evaluated.get(node.index);
if (control?.name === undefined || isDuplicateExposure(node, control.role, facts, evaluated))
continue;
const group = nameGroupKey(control.role, control.name);
counts.set(group, (counts.get(group) ?? 0) + 1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Minor · Shared-name count drops sole-child controls even when their names differ

Node 2 button "Continue" (sole child of node 1 button "Save") is skipped by countSharedNames, so the button\0continue group holds only node 3 and is filtered as count 1, reporting no ambiguity even though two buttons share the name "Continue". isDuplicateExposure compares only roles and child counts, never the parent's resolved name with the child's, so the dedup meant for one control exposed twice also silences two distinct controls.

Suggested change
for (const node of nodes) {
const control = evaluated.get(node.index);
if (control?.name === undefined || isDuplicateExposure(node, control.role, facts, evaluated))
continue;
const group = nameGroupKey(control.role, control.name);
counts.set(group, (counts.get(group) ?? 0) + 1);
for (const node of nodes) {
const control = evaluated.get(node.index);
if (control?.name === undefined) continue;
const parent = evaluated.get(node.parentIndex ?? -1);
const onlyChild = facts.children.get(node.parentIndex ?? -1)?.length === 1;
if (parent?.role === control.role && onlyChild && parent.name === control.name) continue;
const group = nameGroupKey(control.role, control.name);
counts.set(group, (counts.get(group) ?? 0) + 1);
}
Details

persona: senior-developer, maintainability, javascript

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.

@thymikee
thymikee merged commit 0b91864 into main Nov 19, 2026
22 of 23 checks passed
@thymikee
thymikee deleted the feat/audit-ambiguous-name branch November 19, 2026 19:05
thymikee added a commit to pcbeingused333/agent-device that referenced this pull request Nov 20, 2026
* origin/main: (70 commits)
  refactor(apple-runner): one RUNNER_ERROR_CODES row per runner error code with parity/docs gates (callstack#4774)
  fix(android): require acknowledgements for test IME typing (callstack#4722)
  feat(scroll): add scroll refresh for pull-to-refresh (callstack#4770)
  refactor(host-kit): add request Scope and use it for the wait capture deadline (callstack#4794)
  fix(android): let permission all change nothing on an app that declares no permissions (callstack#4796)
  fix(cli): replace the CLI session and generated remote config instead of rewriting them in place (callstack#4797)
  fix(host-kit): accept a group-writable script directory the user owns (callstack#4799)
  fix(cli): escape control characters at the CLI's stdout and stderr writes (callstack#4778)
  fix(audit): do not report rows under a persistent bar that scrolling reveals (callstack#4775)
  fix(daemon): refuse an unsafe state directory before first use (callstack#4783)
  refactor: settle remaining single-deadline races through settleWithin (callstack#4788)
  refactor(host-kit): settle deadline races via settleWithin with R87 race ratchet (callstack#4766)
  fix(android): authenticate and bound persistent snapshot helper sessions (callstack#4729)
  fix(daemon): bound upload ingress and finalization (callstack#4721)
  chore(gates): ratchet wire-published reason literals by value (R89) (callstack#4779)
  feat(audit): evaluate role-less clickable views on Android (callstack#4780)
  fix(mutation): keep umask-setting tests out of Stryker's thread pool (callstack#4785)
  feat(audit): report controls that share one accessible name (callstack#4771)
  fix(contracts): pair open runtime hints with their apply operation (callstack#4754)
  refactor(daemon): report startup progress over the launch channel instead of marker files (callstack#4777)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

audit: report controls that share one accessible name

1 participant