refactor(provider-webdriver): give BrowserStack and AWS Device Farm the plugin factory shape

Merged
TH
2mo ago
+1751-1320

Summary

Prepares the 0.22 plan to unbundle hosted device providers (#3309 BrowserStack, #3310 AWS Device Farm, #3311 Limrun) by giving BrowserStack and AWS Device Farm the exact shape an installed WebDriver plugin has, so the extraction becomes a packaging change.

  • Each bundled provider is a BundledCloudWebDriverProvider: a manifest-shaped declaration (provider id, connection capabilities, credentialVariables) plus create(host) -> { webDriver, connection }, the shape TestMu returns from its factory. Connect policy and the credential fingerprint read the declaration the way they read a plugin manifest; no provider-name branch is left in src/.
  • Core composes bundled and installed providers through one connect route (resolveProviderConnectionProfile) and one runtime factory. The bundled definition table, the ProviderWebDriver facade with its test-only listArtifactsFromEnv, cloud-webdriver-profile.ts, and the per-provider verify adapters are gone. The CLI now fills leaseBackend from the platform for every provider connection, so TestMu and the Doublespeed plugin no longer each spell the mapping.
  • Connect-time flag readers (requireConnectPlatform, requireConnectFlag, resolveLocalAppArtifact) and resolved-profile checks (requireResolvedProfileValue, requireResolvedProfilePlatform in contracts) are shared with TestMu, whose connection module drops its private copies.
  • Connect callbacks load behind a function-scoped await import, so a daemon never evaluates connect code; the eager-closure gate stays at the merge-base count with no approval row. @agent-device/provider-webdriver/connection-verification is the subpath core tests substitute, mirroring the TestMu package.

Behaviour notes: generated BrowserStack/AWS profiles now carry stateDir like every other provider profile; a whitespace-only BrowserStack credential is treated as unset by the fingerprint (it was already refused as missing); the lease-time AWS message now also names <arn>, matching connect; TestMu's hand-authored-profile verify errors use the shared COMMAND_FAILED reconnect hint.

46 files. Gross diff is above the 1,000-line budget because every test that built the bundled runtimes or mocked the facade had to be retargeted; production is net +19 lines with the superseded paths deleted, and test coverage moved with the code (new *-connection.test.ts, *-provider.test.ts).

Validation

Tested commit: 586aa86bb1 (rebased onto d994d1f7e1; the only conflict was the aws-device-farm.ts import block after #3303 removed LeaseValue). The pre-rebase head 172607744c passed pnpm check:affected --run in full.

  • On the rebased head every locally runnable gate passes individually (pnpm gate …: format, lint, typecheck, layering, di-seams, fallow, build, package, integration-node, macos-coverage, unit, wire-compat, production-exports, eager-closure budgets, depgraph, gate-manifest, replay-compat, maestro-conformance, …).
  • provider-integration is 230/231: the one failure is android-lifecycle.test.ts › "Android Settings flow uses scripted ADB provider", whose waitForFileContent has a 1 s budget. It fails 2/3 runs at the merge-base commit d994d1f7e1 under the same host load and 1/3 runs on this head, so it is a pre-existing contention flake, not a regression; it is unrelated to this change (scripted ADB app-log path).
  • Cloud WebDriver provider scenarios (6 files, 30 tests) build the bundled runtimes through the new factory; fallow audit --base origin/main reports no dead code (one 6-line warn-level clone: the lazy connect wrapper in both providers).
  • No live provider run: the WebDriver engine, hub requests, and capabilities are untouched; the change is composition and connect routing, covered by the connect tests and provider scenarios above. CI provider-integration and coverage remain GitHub-authoritative.