fix(is): report ambiguous selector matches as ambiguity, not absence (#2870)

Merged
TH
2mo ago
+1335-202

Summary

Closes #2870. Two coupled fixes for is on a selector that matches more than one node.

  1. Ambiguity is no longer reported as absence. The strict reads (is predicates other than exists/absent, and get attrs — both readUnique rows) turned a multi-node match into COMMAND_FAILED/selector_not_found with an empty candidate list — which to an agent reads as "the element does not exist" on a screen where it is plainly on display. A new shared door keys on the pipeline outcome kind, never message text: none stays selector_not_found; ambiguous now answers with the existing AMBIGUOUS_MATCH code plus matches and up to five formatSnapshotLine candidates — ADR 0011's bounded-disclosure shape and the acting path's exact shape (selector-action-resolution.ts), so no new machine vocabulary is introduced and CLI/MCP/replay render candidates through the one existing reader. screenshot --crop-on already had its own typed refusal (CROP_TARGET_AMBIGUOUS) and keeps it. Out of scope by declared policy: get text, is exists, wait.

  2. RN text reads as one node. React Native reports one authored <Text> twice on a regular capture (paragraph view + accessibility-element mirror; measured live via snapshot --raw: identical label, byte-identical rects, both hittable: true). resolveElementReportedTwice extends the read door's EXISTING structural collapse rule (#2498 wrapper control: one ancestor-descendant chain) with a text-echo branch keyed on label identity + wrapper-slack rects + no semantic touch target, keeping the outer reporter — the node whose testID the app authored and the row snapshot -i publishes. Nothing in snapshot presentation changed: the client-serialization dedup invariant stays untouched, refs and find list/snapshot --json counts are unchanged; only fail-closed rows collapse. The replay gate consumes the same function, so live and replay resolve identically.

Validation

  • pnpm check:affected --run (one run per pushed head, recorded in comments): all checks pass at head c6acd1e5e (1,441 unit files, layering, eager-closure ratchet, fallow, wire-compat, command-docs).
  • Live on iPhone Duo / iOS 27.1 at head e04e85be2: is visible|text 'label="Catalog scroll: top"' pass; is visible 'role=text' → AMBIGUOUS_MATCH matches=22 + 5 candidates + +17 more, no reason field; a true miss → selector_not_found with no matches/candidates. Not re-run at the issuance heads — the daemon test below is the verification for those; a live Catalog re-run at this head is left to a human.
  • Reviewer-pinned sequence as a daemon test (selector-runtime-ambiguity-issuance.test.ts): snapshot -i frame → ambiguous is → press <printed candidate ref> acts on the listed node's point, not the earlier tree's positional twin; the unpinned body is refused, never retargeted; the sparse-capture twin prints no candidates and issues nothing. Unit door pins stored / retired-ref / sessionless / no-generation / unstored-capture branches separately.
  • Tests pair each positive with its closest negative: collapse vs. distinct subtrees vs. offset rect (>1 pt stays ambiguous, at both pipeline and command surface); ambiguity carries matches: 2; zero matches carries no count and no candidates.

Known risk

test/integration/android-emulator-e2e/live-assertions.ts accepts only selector_not_found/predicate_failed details reasons, so an ambiguous Android selector now fails loudly instead of scrolling. Lane unrun here.