refactor(daemon): package-local runtime fakes for the remaining daemon ports [11a-4]
What
Daemon-extraction slice 11a-4: eliminates every edge where a file under src/daemon/ imports (or vi.mocks) a non-package module outside src/daemon/. Residue scan: 0 edges (node scripts/daemon-edge-residue-scan.mjs, committed in this PR; definition below).
Stacked on refactor/daemon-test-data-fakes (#3517).
How
Daemon suites now answer platform questions at the daemon's own ports, and every port member is a plain vi.fn spy with a canned default answer that carries no platform rule (owner decision on review):
- platform-services port (
src/daemon/__tests__/platform-services-fixture.ts) — all six members (appleSessionObservation,deviceBootObservation,ensureLocalDeviceReady,resolveRequestedOpenSurface,validateOpenRelaunchTarget,resolveSessionAppBundleIdForTarget) are spies; the former near-verbatim copies ofplatform-runtime-open-target.ts,platform-runtime-device-boot.tsandplatform-runtime-device-ready.tsare deleted, and so is the sharedfixtureResolveSessionAppBundleIdForTargetthe lifecycle fixture imported. - application-lifecycle runtime binding —
resolveOpenTarget,prepareApplicationOpenandopenApplicationare spies whose canned answers delegate to the contracts' canonical direct-lifecycle members (identity pass-through, readiness pause, admitted-hint apply). The macOS frontmost-surface rule and the android stopped-AVD discovery branch are gone. The real composed fixture lives root-side (src/__tests__/daemon-composition/application-lifecycle-runtime-fixture.ts) and is built on the same seam set, so both lanes observe one spy family; the gateway and session-command harness take an injectable lifecycle-operations loader. - runtime-hints — hint apply/clear are observed at the fixture's port spies; assertion bodies unchanged.
- root-module mocks — the four replay-repair
platform-runtime-runtime-hints.tsmocks and thesession-open-runtimeplatform-runtime-apple-application-tools.tsmock were dead (no daemon file loads either module; hint apply/clear reach the device through the admitted binding's operations) and are deleted, not retargeted.
Tests that assert what the REAL composed rules answer do not stay in the daemon lane: they move to the composition lane (src/__tests__/daemon-composition/), where the lane's own fixture hands them the root-composed services and the real composed lifecycle. Assertion bodies are copied verbatim; no assertion was edited to fit a fake. The device-ready suite (it pins what the composed readiness port does per device family) whole-file-moves to the composition lane; 19 composition-lane suites that imported the daemon's services fixture now import the composition lane's own real one.
Rule-ownership relocation (this revision, per review)
Sorted with the throwing-fake / canned-success probes against the spy fixture:
- Relocated to the composition lane (18 tests, names unchanged):
session-open-existingopen-target/surface cases ×8 →session-lifecycle/session-open-existing.test.ts;open --relaunchtarget-validation cases ×5 →handlers/session-relaunch-guards.test.ts;device-readyTTL-plus-real-readiness cases ×5 →device/device-ready.test.ts. - Kept in the daemon lane, retargeted to the port spies (assertion bodies unchanged): boot-probe answers in
request-router-open/request-router-open-claim×3 now armobserveBootTimeMsFixture; open-target identity ×2 (session-open-runtime,session-open-execution-runtime) answerresolveOpenTargetFixtureper case; the app-event lifetime case answersresolveSessionAppBundleIdForTargetFixture; the claim-rollback case injects its failure atprepareApplicationOpenFixture. - Dead mocks deleted: 5 (fix for the five remaining root-module mocks).
Per-file test-name parity vs the previous head holds: 2671 names, identical multiset; 18 relocated with their names, 0 renamed, 0 added, 0 dropped.
Residue scan (definition, as requested)
scripts/daemon-edge-residue-scan.mjs walks every .ts/.tsx/.mjs under src/daemon/ and matches each specifier form independently (the earlier ad-hoc scan used one alternation bridging import|export … [\s\S]*? from, which swallowed a vi.mock() specifier sitting between an earlier importOriginal<typeof import(...)> and the file's next static from — that is how five mocks hid under its "0"):
- static
import/export … fromwith the keyword anchored at a statement start (line start or;), so no match ever spans statements (coversimport type, multi-line specifier clauses); - side-effect
import '…'; - dynamic
import('…')andrequire('…')with string or no-substitution template-literal arguments (this also catchesimportOriginal<typeof import('…')>); vi.mock/vi.doMock/vi.unmock/vi.importMock/vi.importActual/vi.importOriginalfirst argument, any position in the file, string or template literal.
A relative specifier that normalizes outside src/daemon/ is an edge; bare specifiers (workspace packages, externals) are allowed. Exit 1 on any edge. Verified: 5 edges on 855bd0f, 0 on this head. Once the daemon is its own package, 11b's R11 package-boundary rule (#3546) enforces this permanently in check:layering; until then this committed scan is the measurement.
Gates
- unit-core lane (
vitest run --project unit-core, full): 1591 files / 13447 passed, 1 skipped, 0 failures; within it daemon lane 316 files / 2306 tests, composition lane 97 files / 638 tests, both 0 failures check:quick,check:layering,check:di-seams,check:gate-manifest,check:fallow,check:affected --run, eager-closure-budgets + test-file-size ratchets,pnpm format: OK
Pure moves / renames dominate the diff; hand-written additions are the port fixtures, the install seam, the composition siblings, and the committed scan.