fix(web): re-resolve a locator that turns ambiguous before its action runs

Merged
OK
2mo ago
+70-13

A tap whose locator gained a second match between locate and perform failed with a raw Playwright ENGINE_FAILURE (infrastructure) instead of LOCATOR_AMBIGUOUS.

  • A single-match locate keeps Playwright's strict locator for the action (packages/web/src/surface.ts:756), so a duplicate that appears in between makes Playwright throw strict mode violation.
  • classifyActionError mapped that to non-retryable ENGINE_FAILURE. It is now retryable NODE_STALE, like a detached element (packages/web/src/actions.ts:247).
  • The runner's existing stale retry in performUntil (packages/e2e/src/locator/engine.ts:450) locates again: still two matches is LOCATOR_AMBIGUOUS, a duplicate that went away lets the action run on the one match. The action never runs on either element of a pair.
  • A violation whose call log shows input already went out (a dragTo resolves its drop target after the press) is ACTION_MAY_HAVE_COMMITTED, never retried, same split the timeout path uses (POST_DISPATCH_PATTERN).
  • POST_DISPATCH_PATTERN now matches only whole - call log lines, so a locator or element text quoting performing click action cannot pass as a dispatch (affected the timeout path too).
  • Real-world trigger: a screen transition that briefly renders the old and new page together.

Verified

Ran it locally: yes

  • testbed, built CLI, a page whose duplicate Go button appears and disappears every 3 ms, 300 screen.getByRole('button', 'Go').tap() calls, result codes counted:
mainthis branch
ENGINE_FAILURE: locator.click: Error: strict mode violation ... x4
LOCATOR_AMBIGUOUS x251
ok x45
ENGINE_FAILURE x0
LOCATOR_AMBIGUOUS x265
ok x35
  • New integration tests in lifecycle.test.ts: locate one button, add a twin, tap (fails on main with ENGINE_FAILURE, here NODE_STALE and no click); a drop target that gains a twin on mousedown (here ACTION_MAY_HAVE_COMMITTED, exactly one mousedown).