Skip to content

refactor(daemon): relocate the handler tests by what they assert - #3666

Merged
thymikee merged 18 commits into
refactor/daemon-server-testsfrom
refactor/daemon-handlers-tests
Oct 15, 2026
Merged

thymikee merged 18 commits into
refactor/daemon-server-testsfrom
refactor/daemon-handlers-tests

Conversation

@thymikee

@thymikee thymikee commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Summary

Batch handlers of the daemon test redesign (no test exports of any kind). The 13 root tests under src/__tests__/daemon-composition/handlers/ are placed by what they assert; the directory is gone. Stacked on #3652 for its runtime-deps fixture and the backend-forwarding command surface fake; it retargets to main when #3652 merges.

Daemon halves (a) run against the package fakes (hostDiagnosticsFixture, providerCredentialsFixture, platformResourceCleanupFixture, the forwarding surface, the services port). Assertions about what real adapters or command-family code do (c) moved to tests beside that code. The snapshot-interactor-capture, device-ready and provider-device-runtime mocks are all gone: handler tests go through the bound captureSnapshot operation and DaemonPlatformServices.ensureLocalDeviceReady.

a / c split and test-count parity

Before = exact count on the source file at its old path (vitest JSON reporter); after = run count per destination on this head.

Source (before) Daemon half (a) Root / package half (c)
lease-provider-credentials (10) sessions/handlers/lease-provider-credentials.test.ts (13) src/provider-credential-fingerprint.test.ts (+1: bundled TestMu manifest; Limrun cases were already there)
session-doctor-warmup (9) sessions/handlers/session-doctor-warmup.test.ts (8) src/platform-runtime-host-diagnostics.test.ts (2)
session-relaunch-guards (5) sessions/handlers/__tests__/session-relaunch-guards.test.ts (3 → 6) src/platform-runtime-open-target-relaunch.test.ts (4)
session-device-claims-cancellation (1) sessions/handlers/__tests__/session-device-claims.test.ts (10 → 11) packages/platform-android/src/lifecycle.test.ts (+1: IME activated after launch dispatch)
session-close-runner-retention (3) session-lifecycle/internal/session-close-lifecycle-teardown.test.ts (7, shared) src/platform-runtime-resource-cleanup-retention.test.ts (5)
session-relaunch-close (15) session-lifecycle/internal/session-open-execution-relaunch.test.ts (6) packages/platform-apple/src/lifecycle-relaunch-close.test.ts (9), src/platform-runtime-apple-application-tools-close-alerts.test.ts (4)
snapshot-alert-android-occlusion (2) none src/core/interactors/android-alert-occlusion.test.ts (2), pure git mv (97% similarity)
snapshot-handler (13) sessions/handlers/snapshot-handler.test.ts (13), git mv (78%) none
snapshot-handler-freshness (9) sessions/handlers/snapshot-handler-freshness.test.ts (4), core/__tests__/snapshot-capture.test.ts (6 → 8) src/commands/capture/runtime/snapshot-freshness.test.ts (6), src/commands/capture/output.test.ts (5 → 6)
snapshot-handler-wait (8) sessions/handlers/snapshot-handler-wait.test.ts (5), execution/wait-current-surface.test.ts (4 → 6) src/commands/interaction/runtime/wait-capture-options.test.ts (2)
snapshot-scoped-refs (3) sessions/handlers/snapshot-scoped-refs.test.ts (3), git mv (89%) none
snapshot-session-cleanup (3) core/snapshot-session.test.ts (5) src/platform-runtime-resource-cleanup-sessionless-host.test.ts (3)
wait-landmark-recording (5) execution/wait-runtime-landmark.test.ts (6), git mv (53%) none

86 tests before; 118 declared across the destinations including tests added to existing twins. No test disappeared without a named owner. The assertions that were dropped because an existing test already pins them:

  • session-relaunch-close: totalDurationMs (asserted in server/__tests__/request-router-open.test.ts); Android relaunch sequencing (platform-android/lifecycle.test.ts); physical-iOS ordering (platform-apple/lifecycle.test.ts); runner release on close (platform-apple/lifecycle.test.ts).
  • session-doctor-warmup: the non-macOS skip and the non-simulator/provider skips (platform-apple/src/__tests__/doctor.test.ts).
  • snapshot-handler: filtered-to-zero guidance text (src/commands/capture/runtime/snapshot.test.ts).
  • wait-landmark-recording: polling-loop landmark semantics (runtime/wait-selector.test.ts, two named tests).

The macOS close claim in test/integration/command-coverage/declarations.ts named the deleted session-relaunch-close test; it now names platform-apple/lifecycle-relaunch-close.test.ts "close finalization releases the runner before it dismisses close alerts" (the ordering owner), and its note says the daemon close tests own session deletion. smoke-macos-coverage passes.

Selection

All destinations are 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, so no test changes project. check:affected --run runs the vitest related leg over them and passes.

vi.mock (all target an external package or the exact module the code imports)

  • session-open-execution-relaunch.test.ts, device-selection/dispatch-resolve: "relaunches without a session…" and "ambient provider claim…" get a non-empty opened list only because the mocked device resolves.
  • snapshot-handler.test.ts, core/ios-app-session-hint.ts: the hint test asserts the response hint equals the mocked value and toHaveBeenCalledWith(iosSimulatorDevice, platformServices).
  • platform-runtime-host-diagnostics.test.ts, platform-apple/doctor: toEqual(check) and toHaveBeenCalledWith(IOS_SIMULATOR, context).
  • platform-runtime-apple-application-tools-close-alerts.test.ts, platform-apple/macos: runMacOsAlertAction called with 'dismiss' in three tests, not called in the fourth.
  • platform-runtime-resource-cleanup-sessionless-host.test.ts, runner/operations and app-lifecycle: stopIosRunnerSession / closeIosApp asserted called and not called.
  • android-alert-occlusion.test.ts, platform-android/mechanics: snapshotAndroid resolves the covered capture, the alert is null, pressAndroid is not called.
  • Existing twin session-device-claims.test.ts keeps its own mocks unchanged.

Subpath exports

Package Before (#3652) After
daemon 96 89

Deleted: __tests__/support/provider-device-admission-fixture, handlers/session-doctor, handlers/session-doctor-app, handlers/session-doctor-metro, session-lifecycle/index, snapshot-capture, snapshot-session. No other package changed; no new subpath, barrel or export *.

Notes

  • Fixtures: no new fake family. The shared forwardingCreateCommandSurface (refactor(daemon): relocate the server runtime tests by what they assert #3652) now stores the backend's snapshot (flat-nodes fallback) and forwards diffSnapshot the same way; command-surface-fake.test.ts pins both.
  • Edits outside packages/daemon and the daemon-composition tree (c halves, additive): platform-android/lifecycle.test.ts, new platform-apple/lifecycle-relaunch-close.test.ts, src/commands/** tests, src/provider-credential-fingerprint.test.ts, test/integration/command-coverage/declarations.ts.
  • Aspect suffixes (-relaunch, -retention, -sessionless-host, -landmark) keep the new files from colliding with parallel moves of wait-runtime, platform-runtime-resource-cleanup and platform-runtime-open-target tests.

Validation

check:quick, check:layering, check:fallow, check:gate-manifest and check:affected --run passed on the first head (the run caught the stale coverage claim above). After the review fixes, check:quick and the touched suites pass; the full gates rerun on the final head are recorded in the thread.

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 39 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread packages/daemon/src/core/snapshot-session.test.ts
Comment thread packages/daemon/src/sessions/handlers/__tests__/session-device-claims.test.ts Outdated
Comment thread packages/daemon/src/__tests__/support/snapshot-command-surface-fakes.ts Outdated
Comment thread packages/platform-apple/src/lifecycle-relaunch-close.test.ts
Comment thread src/platform-runtime-resource-cleanup-sessionless-host.test.ts Outdated
Comment thread packages/daemon/src/sessions/handlers/snapshot-handler.test.ts
Comment thread src/platform-runtime-resource-cleanup-sessionless-host.test.ts Outdated
@thymikee

Copy link
Copy Markdown
Member Author

The 615c162 head has one test that no longer guards what it claims. The ADR 0014 case "snapshot re-activates a complete frame; diff preserves it" in snapshot-handler.test.ts runs its diff step with forwardingCreateCommandSurface. That surface inherits the inert diffSnapshot, which never reads the backend and never writes the session. The old test used the real surface, where diff replaced the stored tree. Now the frame is already active from the earlier snapshot, so refFrameState === 'active' holds trivially. A daemon change that expires the frame when diff replaces the observation would still pass, and the only daemon-side check of this invariant is gone. Please use diffForwardingCreateCommandSurface for that diff step, as the tests near lines 284 and 351 already do. Then show by mutation that expiring the frame on diff replacement turns it red. The rule: every relocated test whose assertion depends on a session write must run a surface that performs that write.

Could one fake do the whole job? If forwardingCreateCommandSurface stored captured.snapshot (with a nodes fallback) and forwarded diffSnapshot the same way, storingCreateCommandSurface and diffForwardingCreateCommandSurface could go. Then snapshot-command-surface-fakes.ts would disappear, and no test could pick the inert diff by mistake. That fake lives in the stacked #3652, so it needs a change there first, or a follow-up after it merges. This PR should not add a second fake family.

Not blocking: diffForwardingCreateCommandSurface delegates to a fake that stores captured.nodes (empty), not captured.snapshot, although its doc says it stores the tree it observed. It passes today only because the diff assertions check generation and call counts. Take or leave the ordering, order-of-cleanup and strengthening asks in the threads below.

The open cubic-dev-ai threads still apply. The two that matter most are the diff fake storing an empty tree and the ADR 0014 diff step, whose anchor is on line 64 but whose substance is the line 263 test above. Seven lower-priority threads also still apply, and the old tests had the same gaps in those cases. None of the threads can be resolved yet.

I read the Cubic-flagged files, the guards, claims, cleanup and snapshot-handler pairs, and the Android IME and declarations diffs. I did not compare the wait-landmark, doctor-warmup, lease-provider-credentials and close-lifecycle-teardown moves against their originals. I did not recount the test-count table, run any tests, or mutation-check the new daemon-side tests. All 14 checks are still queued on this head, so there is no CI result to attribute yet. There are no conflicts. Before merge, fix the diff step, show the mutation going red, and let the queued checks finish.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 5.24 MB 5.24 MB 0 B
Package (unpacked) 5.24 MB 5.24 MB 0 B
Package (download) 1.57 MB 1.57 MB -10 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 21.6 ms 21.7 ms +0.1 ms
CLI --help 59.9 ms 59.5 ms -0.4 ms

@thymikee
thymikee force-pushed the refactor/daemon-handlers-tests branch from 615c162 to 488ccd9 Compare October 15, 2026 14:17
@thymikee

Copy link
Copy Markdown
Member Author

Re the ADR 0014 case: fixed in 488ccd9. The shared forwarding surface (#3652) now forwards diffSnapshot through the session seam, so every snapshot-handler diff step writes the session. Mutation: expiring the ref frame when the diff replaces the observation (inside the daemon's setRecord for req.command === 'diff') turns 'snapshot re-activates a complete frame; diff preserves it (ADR 0014)' red with expected 'expired' to be 'active'; reverted, green. One fake now does the whole job: snapshot-command-surface-fakes.ts (storingCreateCommandSurface, diffForwardingCreateCommandSurface) is deleted. The other review threads are answered and resolved.

thymikee and others added 18 commits October 15, 2026 16:36
…sal (a) and root TestMu fingerprint (c)

lease-provider-credentials: (a) lease.ts refusal/passthrough against providerCredentialsFixture in
sessions/handlers; (c) bundled TestMu manifest fingerprints in src/provider-credential-fingerprint.test.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ost diagnostics wiring (c)

session-doctor-warmup: (a) handleDoctorCommand warmup routing against hostDiagnosticsFixture in
sessions/handlers; (c) createHostDiagnostics warmup delegation in src/platform-runtime-host-diagnostics.test.ts.
Runner skip rules stay pinned by packages/platform-apple doctor.test.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…open-target validator (c)

session-relaunch-guards: (a) extend sessions/handlers/__tests__/session-relaunch-guards.test.ts with
the platform-services port refusal routing; (c) real validateOpenRelaunchTarget rules in
src/platform-runtime-open-target-relaunch.test.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (a) plus Android IME sequencing (c)

session-device-claims-cancellation: (a) cancellation retains the claim, in
sessions/handlers/__tests__/session-device-claims.test.ts; (c) activate-test-ime after launch dispatch in
packages/platform-android/src/lifecycle.test.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…a) and cleanup rule (c)

session-close-runner-retention: (a) close hands the platform retention decision to
finalizeApplicationClose in session-close-lifecycle-teardown.test.ts; (c) retainExecutionHostAfterClose rule in
src/platform-runtime-resource-cleanup-retention.test.ts. releaseRunnerOnClose({retain}) stays pinned by
packages/platform-apple lifecycle.test.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pple lifecycle/tools behavior (c)

session-relaunch-close (15): (a) session-open-execution-relaunch.test.ts and
session-close-lifecycle-teardown.test.ts drive the daemon against the port fixtures; (c) Apple relaunch/close
sequencing in packages/platform-apple/src/lifecycle-relaunch-close.test.ts and macOS close-alert dismissal
in src/platform-runtime-apple-application-tools-close-alerts.test.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… routing (a) and command-family output (c)

snapshot-handler (13): (a) sessions/handlers/snapshot-handler.test.ts on forwardingCreateCommandSurface; the
filtered-to-zero guidance assertion is (c) already pinned by runtime/snapshot.test.ts.
snapshot-handler-freshness (9): (a) sessions/handlers/snapshot-handler-freshness.test.ts and
core/__tests__/snapshot-capture.test.ts; (c) src/commands/capture/runtime/snapshot-freshness.test.ts and
output.test.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (a) and wait command options (c)

snapshot-handler-wait (8): (a) sessions/handlers/snapshot-handler-wait.test.ts (backend capture freshness,
forced fresh capture, current-surface decoration wiring, stalled-capture non-decoration) and
execution/wait-current-surface.test.ts (surface summary shaping); (c)
src/commands/interaction/runtime/wait-capture-options.test.ts (hidden-content hints off on every poll).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
snapshot-scoped-refs (3): (a) sessions/handlers/snapshot-scoped-refs.test.ts on a storing command surface
fake; support/snapshot-command-surface-fakes.ts (new, additive) also hosts the diff variant.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and runner-host teardown (c)

snapshot-session-cleanup (3): (a) core/snapshot-session.test.ts against platformResourceCleanupFixture; (c)
src/platform-runtime-resource-cleanup-sessionless-host.test.ts for the real runner-host teardown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…actor (c)

snapshot-alert-android-occlusion (2): pure move to src/core/interactors/android-alert-occlusion.test.ts
(only the module specifier changes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ime (a)

wait-landmark-recording (5): (a) execution/wait-runtime-landmark.test.ts with a wait command surface
double; the polling-loop landmark semantics stay pinned by runtime/wait-selector.test.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…test typing

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…aunch/close suite

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…es it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… without importers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ce and tighten the order and claim assertions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee
thymikee force-pushed the refactor/daemon-handlers-tests branch from e3e3137 to 4b07e86 Compare October 15, 2026 14:36
@thymikee

Copy link
Copy Markdown
Member Author

The code in 4b07e86 looks good. The new commit fixes the earlier concerns: the diff step now writes the session, the empty-tree diff fake is gone, and the ordering and typed assertions are in place.

The change is test-only apart from a small production edit (+4/-4), and I found no production route that the queued jobs exercise differently. All 14 checks are still queued and none has failed, so there is no CI result to read yet. I did not run the expire-the-frame mutation myself, so that result is your claim. I also did not recount the 86-to-118 test table or re-diff the earlier moves, since this commit does not touch them.

The inline threads from cubic-dev-ai are all handled at this head, so you can resolve them. These cover the ADR 0014 diff step (#3666 (comment)), the empty-tree diff fake (#3666 (comment)), the task and cleanup order (#3666 (comment)), the runner stop ordering (#3666 (comment)), the abandoned claim timestamp (#3666 (comment)), the sessionless-host call order (#3666 (comment)), the bundle id mock (#3666 (comment)) and the bound devices check (#3666 (comment)). The active-session platform thread (#3666 (comment)) was resolved with a reply and the gap it names is not new, so it can stay resolved.

Once the queued checks pass and #3652 lands so the base retargets to main, this can merge. It needs no further code change.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Oct 15, 2026
@thymikee
thymikee added this pull request to stack #3681 October 15, 2026 15:46
@thymikee
thymikee merged commit 282643e into main Oct 15, 2026
22 checks passed
@thymikee
thymikee deleted the refactor/daemon-handlers-tests branch October 15, 2026 16:50
thymikee added a commit that referenced this pull request Oct 15, 2026
…hots (#3684)

#3642 made BackendSnapshotResult carry a required snapshot and dropped the
flat nodes fields; the daemon test relocations (#3652, #3666) landed after it
with the old shape, so main fails tsc -b.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant