refactor(daemon): relocate the find tests by what they assert

Merged
TH
8h ago
+532-252

Summary

Part 1 of 3 of the find/settle batch of the daemon test redesign (no test exports of any kind): the three find-* root tests under src/__tests__/daemon-composition/interaction/ that drove the find handler with the real command surface. Daemon halves (a) run against two new unexported package fakes; assertions about what the real src/commands/interaction/** code does (c) moved beside that code. Parts 2 (settle, disclosure, capture) and 3 (target evidence) follow one at a time. The original 15-commit branch is about 1,970 added lines, so it is split by dependency to stay reviewable (this part: ~510 added).

New package fixtures, both new files, nothing shared edited: support/command-surface-override-fake.ts (a surface whose named members are replaced per case) and support/legacy-capture-interactor-resolution.ts (installs an InteractorResolution that routes legacy snapshot capture through the shared capture double).

a / c split and test-count parity

Before = exact count at the old path (vitest JSON reporter, origin/main); after = run count per destination on this head.

Source (before)Daemon half (a)Command half (c)
find-ambiguous-match (6)execution/interaction/internal/find-ambiguous-match.test.ts (6; the two list cases run on a listing member and keep ref issuance and the partial ref frame)src/commands/interaction/runtime/selector-read-find-list.test.ts (2: "list returns every match", "unique match still lists")
find-production-route (4)execution/interaction/internal/find-production-route.test.ts (2: the surface receives preresolvedTarget for click and for fill)src/commands/interaction/runtime/interactions-find-carried-target.test.ts (4: press/fill act on the carried node; a diverged stored tree cannot retarget)
find-read-only (4)execution/selector-runtime-find-read-only.test.ts (4)covered by selector-read.test.ts (below)

14 tests before; 18 after (+4: the command halves of the two splits).

One assertion had been dropped and is restored: the sparse find-wait hint. The old root test checked details.hint against /snapshot quality verdict is sparse/; the hint is command-authored (sparseSelectorSnapshotError in selector-read-utils.ts), and the daemon test now runs on a fake surface that writes its own error. The command-side test selector-read.test.ts "runtime find wait reports sparse snapshot verdicts on the selector-read route" now asserts the message, details.reason and details.hint. Mutation: deleting the hint line from sparseSelectorSnapshotError fails exactly that test (1/20 across the file). The daemon-side sparse test no longer asserts command-authored message or reason (its fake wrote them); it keeps the daemon-owned part: the refusal passes through as COMMAND_FAILED and the stored tree is untouched.

One assertion was strengthened: "handleFindCommands wait captures fresh snapshots while polling" asserted >= 2 dispatches because the real surface owned the poll count; the fake owns it now, so it asserts exactly 3. The other command-authored assertions of the three source files are accounted for: the ambiguous-match details.matches/candidates stay in the daemon test (daemon-authored in selector-match-errors.ts), the list data and ref-frame assertions moved with the split to the daemon test and selector-read-find-list.test.ts, and the dispatched point (310, 510) is asserted command-side in interactions-find-carried-target.test.ts (SAVE_CENTER).

vi.mock

No vi.mock in any destination file; the only vi.fn spies are local to the production-route test's fake surface members, whose recorded calls are asserted (preresolvedTarget forwarding).

Mutation checks

  • Replacing find's internal: { findResolvedTarget: preresolvedTarget(match) } with internal: {} fails find-production-route "#1654 production route: find click carries its resolved node" (1/2).
  • Replacing forceFresh: needsFreshSnapshot with forceFresh: false in selector-runtime-backend.ts fails "handleFindCommands wait captures fresh snapshots while polling" (1/10 across the find tests).

Selection

All destinations match packages/*/src/**/*.test.ts or src/**/*.test.ts, so unit-core selects them (pnpm test:unit, test:coverage); the sources were already in unit-core. check:affected --run ran the vitest related leg and passes.

Subpath exports

PackageBeforeAfter
daemon8181

No subpath is freed here: the ./testing/* entries these tests used are still imported by parts 2 and 3, which delete them. No new subpath, barrel or export *.

Notes

  • Colocation (R84): the command tests are named for modules in src/commands/interaction/runtime/ (interactions-find-carried-target for interactions.ts, selector-read-find-list for selector-read.ts).
  • The command halves are new files, not appends to another worker's tests.

Validation

check:quick, check:layering, check:fallow, check:gate-manifest and check:affected --run pass on this head.

🤖 Generated with Claude Code