fix(provider-webdriver): never resend a mutating WebDriver request

Merged
TH
2mo ago
+960-125

Summary

Part of #3069.

Twelve mutating WebDriver routes were sent again after a timeout or a 5xx (actions, keys, back, rotation, orientation, installApp, activateApp, terminateApp, deleteSession, and the mobile: scripts deepLink, activateApp, pressButton, setClipboard). A slow tap, type, or back could run twice. The first commit proves it on main through the real client and transport.

  • Retry follows the HTTP method: GET and HEAD keep the policy's retry budget; every other method gets one attempt unless the request is marked idempotent (mobile: getClipboard, a POST read, is the one opt-in). No per-call opt-out to forget.
  • The transport says what it knows, typed as 'no' | 'unknown': dispatched: "no" only when the failure proves the request never reached the driver (cause code in ECONNREFUSED, ENOTFOUND, EAI_AGAIN, EHOSTUNREACH, ENETUNREACH, UND_ERR_CONNECT_TIMEOUT, through cause chains and AggregateError members); any other TypeError, a post-body socket reset, a body-read failure, a timeout, or a 5xx is "unknown" with reason: webdriver_request_interrupted.
  • One classifier for "route unsupported", in the transport: a W3C error code decides when present (unknown command / unknown method; invalid session id is not unsupported); with no code, a bare 404, 405, or 501. It sets reason: webdriver_route_unsupported; the activateApp/terminateApp sibling fallback, orientation, and the keyboard/active-element probes all read that reason. Two --debug diagnostics: webdriver_route_unsupported (method, path, status, W3C code) and webdriver_route_fallback (from, to, status) after the sibling succeeds; both loaded on demand so the eager closure holds.

11 files. Web sessions only.

Validation

Tested commit e307316606. pnpm check:affected --run: all runnable checks passed.

  • webdriver-mutation-resend.test.ts: table over all 17 mutating routes (enumerated from the client source), one send and dispatched: "unknown" per row on a timeout; GET /source and mobile: getClipboard still retried; POST 5xx one call.
  • webdriver-transport.test.ts: real sockets, no doubles: a released port → no; a server that resets after reading the body → unknown, one request; headers then reset → unknown. Ten-row unsupported-route table through the real transport.
  • Live, two current drivers, open then close with --debug: AWS Device Farm iPhone Air / iOS 26.3.1 (XCUITest), and BrowserStack Google Pixel 8 / Android 14.0 on Appium v3.2.0 with UiAutomator2 driver v7.0.0 (its Appium log: POST .../appium/device/activate_app 200 98 ms, .../terminate_app 200 209 ms, one send each, no /execute/sync). Both still serve the legacy route, so open/close are unchanged there and the sibling fallback is dormant; it is proven through the real transport against a 404 answer and covered by the typed reason and the two diagnostics.
  • Behavior change to note: a bare 404 from the keyboard or active-element probe now reads as unsupported, by the one rule (before: 405/501 only).