refactor(daemon): cut daemon test edges into root data fixtures and fakes [11a-3]

Merged
TH
2mo ago
+1184-847

Plan step 11a-3: daemon test files stop importing the root src/__tests__/test-utils/ data fixtures, and the review's copied-fake findings are resolved with one owner each.

Targeted root modules (scan edges now 0): device-inventory-gateways, replay-script-source, android-ui-hierarchy-fixtures, android-snapshot-capture, plugin.fixtures. Total daemon→root scan residue after the cut: 23 edges, all into the platform-runtime cluster owned by step 11a-2 (the only remaining 11a-1 residue).

Review resolutions:

  1. Inventory fake — one owner: packages/device-selection/src/inventory-gateways.fixtures.ts, exported as @agent-device/device-selection/inventory-gateways-fixtures, with findInstalledApp in options, createTestDeviceInventoryGateways exported, and the nullable-provider bridge (withTestDeviceInventoryProvider) extracted once. Daemon (37 files under src/daemon), root composition, device-selection's own tests, and test/integration all import it. The root wrapper and its pin are deleted: the wrapper's fail-closed pin duplicated the real composer's pin already at src/platform-runtime-device-inventory.test.ts, and the real adapter has its own direct tests. test-kit was not viable: the fake needs the root composition's createDeviceInventoryContext (device-selection's production entry), which would make test-kit→device-selection while device-selection's tests need test-kit — a tsc -b project-reference cycle — so the package's own test-only subpath (the fallback) is the one owner.
  2. Replay collector — no second implementation: the real client collector moved into replay-port (script-source-bundle, source-discovery, byte-pure moves with their own test suites), and the bundle helpers live once in replay-port/src/daemon-port/replay-script-source.fixtures.ts (./replay-script-source-fixtures), typed on DaemonWireRequest so it serves both trees without a production seam. Both test trees exercise the same globs, size cap, not-found AppErrors and ranking through it. The root src/__tests__/test-utils/replay-script-source.ts is deleted (its exports move with it; nothing suppressed via .fallowrc).
  3. Android captures: snapshot-capture-fixtures and ui-hierarchy-fixtures are test-only entries on @agent-device/platform-android (the Apple runner requests-fixtures pattern), with the archived raw JSONs under packages/platform-android/src/fixtures/ where own:package-capture owns them. Contract comments kept to one line.
  4. plugin.fixtures stays in @agent-device/test-kit/plugin.fixtures (package vocabulary over the filesystem install, no platform adapters).
  5. createTestDeviceInventoryGatewaysFromProvider is used (lock-policy test + integration harness), so it stays exported; the daemon-side copy that fallow flagged is deleted. pnpm format run repo-wide.
  6. Base delta is test-side only: the moved collector modules are byte-identical and the only production root edit is the two import lines in src/commands/replay/index.ts; everything else is test/fixture moves, import retargets, and gate wiring. No limrun/CONTRIBUTING/coverage/website files in the delta against the current base.

Gates (on the pushed commit, under the host gate lock): check:affected --run clean across all selected lanes; check:quick, check:layering, check:di-seams, check:gate-manifest, check:fallow, the eager-closure budgets table (three APPROVED_OVER_CEILING rows + the mechanics-facet exception for the Android fixture entries), the R13 export-pin tests, and the test-file-size ratchet green. Targeted full runs: src/daemon, src/__tests__, packages, scripts with zero failures; vitest list src parity vs base is exact modulo the moved test files' path keys and one intentionally deleted duplicate pin (the root inventory wrapper's fail-closed case, already owned root-side).

Risk: no production behavior change (CLI startup import-closure guard green through the replay move). Eager-require weight: daemon suites now pull replay-port's real collector instead of the local test twin.

NO DOCS — test topology and fixture ownership only; no user-facing behavior or CLI surface changes.

Follow-up commit (bd49bf829, second review round): assertProviderOutcome/assertSourceFamily moved from the root composer into @agent-device/contracts/device; the fake now calls the shared assertProviderOutcome instead of restating the flow (a malformed provider outcome fails closed with provider_inventory_contract_violation in both paths, pinned by a new fixture test). The fake's local path keeps its per-family filter because the local option is a flat whole-inventory discoverer fanned out per family — that filter is the adapter to the per-family source contract, not a restated assertion site.

Design answers at e4eee6b (review follow-up round):

  1. Composer home (Q1): yes, moved. The composed-gateways flow now lives in @agent-device/device-selection/composed-inventory-gateways with the installed-app probe injected instead of hardcoded; src/platform-runtime-device-inventory.ts stays as the production wiring that attaches the Apple probe (function-scoped import keeps the composition root's eager closure flat; the hub no-growth gate is green). The test fake composes through the real composer with fake registry sources — the root, daemon-composition, and integration consumers exercise the production flow, not a restatement. No root-side wrapper is needed anymore: the one owner is the package entry both trees build on.
  2. Collector home (Q2): moved out of the daemon port. script-source-bundle, source-discovery, and the request fixture now sit at packages/replay-port/src/ (client-side replay vocabulary, like session-replay-vars), outside the daemon-port/ engine-prefix zone; the ./script-source-bundle, ./source-discovery, and ./replay-script-source-fixtures subpaths keep their names. Caller filesystem reads stay out of the daemon's dispatch vocabulary.