Skip to content
Source
Sign inSign up
pingdotgg/t3code

test: run clock-free live tests on TestClock #35868

Mergedjuliusmarmingemerged 11 commits intomain fromrefs/pull/35868/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Many it.live tests used the wall clock for no reason. Three things went wrong because of it:

  • Date drift. The storageCleanup fixtures are pinned to NOW_MS (2026-06-10), but the tests compared those dates against today's clock. The "usage-limited checkout" test reported "Inactive for 185 days" where it means 30 days, and the usage reset it describes was months overdue.
  • Real waits. A few tests sat through real timeouts (a 1s invalidation timeout, a 1ms host yield).
  • Clock-free tests on it.live. These lost the deterministic TestClock for nothing.

This moves them to it.effect. Real FileSystem, sqlite and temp dirs still work there. Tests that compare at(...) dates now TestClock.setTime(NOW_MS). Where a timer is part of the behavior, the test forks the work, waits on a Deferred, then adjusts the clock.

A correction to the audit that started this: the usage-limited checkout test was not passing vacuously. Even under TestClock, breaking the usage-limit hold doesn't fail it, because both preferences are off at the first check. The test is kept by the "settings changed since check" recheck, and breaking that recheck fails it under both clocks. It now asserts that keep reason, so it pins the mechanism it really covers.

Converted (per file)

FileConvertedNotes
apps/server/src/storageCleanup.test.ts8setTime(NOW_MS); one date written relative to DateTime.now became at(-DAY_MS)
apps/server/src/usage/UsageService.test.ts42The 5 that wrapped it.live in TestClock.layer() are now plain it.effect. The v4–v14 cache upgrades and "absent directory diagnostics" set a realistic time: at epoch 0 the stale-temp and retention cutoffs go negative
apps/server/src/preview/ServerBrowser.test.ts45No adjusts needed
packages/shared (KeyedCoalescingWorker 4, DrainableWorker 1)5
packages/client-runtime/src/state/pullRequests.test.ts3The stall case forks, awaits a Deferred from the stalled invalidate, then adjusts 1s; at 999ms it times out. The for loop became it.effect.each (lint)
apps/server/src/orchestration-v2/Adapters/ClaudeTaskOutputTail.test.ts1The stop-driven test
ModelManifest 4, ProviderInstanceRegistry 3, McpOAuth 3, OrchestratorMcpService 111
apps/server/src/ws.test.ts1.each split: thread case on TestClock
apps/mobile/src/connection/environment-cache-store.test.ts2Fork loadPullRequests, adjust 1ms past its host yield, join

Left live

  • storageCleanup orphan-worktree and artifact-log aging tests. They compare real file mtimes.
  • ws.test.ts shell resume. Shell updates batch through Stream.groupedWithin(512, 50ms), and there is no signal to adjust after each window opens.
  • PeerLinks.test.ts "one dropped descriptor request". The middleware can only signal when it serves the 503. The client registers its 1s retry sleep only after it reads that response over a real socket. TestClock's adjust does not wait for I/O, so the adjust can land before the sleep exists. A Deferred version passed 11 of 11 runs, including under load, but that ordering isn't guaranteed. I didn't want a latent flake.
  • ClaudeTaskOutputTail "follows a file that appears…" and "skips ahead…". They have the same I/O ordering problem: the tail stats the file before registering its 250ms poll. The file's existing comment already says this.

Verification

  • Each touched file ran 2–5 times, and the full set ran again under a 16-core yes load. Server tests ran in unshare -U -p with TMPDIR under $HOME.
  • Timer adjusts are load-bearing. The pull-request stall test times out at 999ms, and the converted PeerLinks test hung without its adjust.
  • vp run check:changed: format, lint, knip, typecheck (35 packages) and the 14 changed test files (581 tests) all pass.

Done by Claude Opus 5.5 in Claude Code.

🤖 Generated with Claude Code

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved at d092a33

      Macroscope's review found this PR approvable — The PR is described as moving clock-free live tests onto TestClock, with all changes confined to repository-ignored paths. Within that prescribed scope, no material risk requiring human judgment is identified.

      Notes:

      • No code objects were reviewed. Approvability was decided on eligibility alone.
      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      Tests across mobile, server, client runtime, and shared packages now use effect-based runners. Selected asynchronous tests control time explicitly. Browser preview tests add assertions for downloads, tab ownership, profile persistence, and tab limits.

      Changes: Effect-based test updates

      Layer / File(s)Summary
      Clock-controlled async tests
      apps/mobile/src/connection/environment-cache-store.test.ts, packages/client-runtime/src/state/pullRequests.test.ts
      Selected asynchronous tests use it.effect and advance the test clock to exercise deferred link loading and stalled invalidation.
      Browser preview test coverage
      apps/server/src/preview/ServerBrowser.test.ts
      Tests use effect-based runners and cover downloads, human control of tabs, profile persistence across restart, and tab limits.
      Storage cleanup timing and assertions
      apps/server/src/storageCleanup.test.ts
      Tests use effect-based runners, set fixed clock values, and assert that an entry is kept when settings change during measurement.
      Usage service effect tests
      apps/server/src/usage/UsageService.test.ts
      Tests switch to effect-based runners. Selected cases set clock values explicitly or remove TestClock.layer().
      Other server and shared effect tests
      apps/server/src/auth/McpOAuth.test.ts, apps/server/src/mcp/OrchestratorMcpService.test.ts, apps/server/src/orchestration-v2/Adapters/ClaudeTaskOutputTail.test.ts, apps/server/src/provider/*test.ts, apps/server/src/ws.test.ts, packages/shared/src/*Worker.test.ts
      Tests switch to effect-based runners. Websocket replay setup is shared by thread and shell cases.

      Estimated code review effort: 3 (Moderate) | ~25 minutes

      Change: Other

      Suggested reviewers: t3dotgg, maria-rcks

      Merge Risk: Minimal · up to d092a

      This change only affects how tests run and does not alter production behavior. No concrete merge-blocking risk remains after review.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title "test: run clock-free live tests on TestClock" matches the main change: tests that did not need wall-clock time moved from it.live to it.effect on TestClock. It is a conventional-commit styl…
      Description checkPassedThe description follows the template's main ideas. It states the problem (wall-clock use in it.live tests, date drift, real waits) and the change (move to it.effect, set TestClock to NOW_MS, fork and …
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Title check

      Explanation

      The title "test: run clock-free live tests on TestClock" matches the main change: tests that did not need wall-clock time moved from it.live to it.effect on TestClock. It is a conventional-commit style title, short and specific. Some details (date fixes, timer adjustments, kept-live tests) are not in the title, which is expected.

      Full details: Description check

      Explanation

      The description follows the template's main ideas. It states the problem (wall-clock use in it.live tests, date drift, real waits) and the change (move to it.effect, set TestClock to NOW_MS, fork and adjust for timers). It lists the scope per file, explains which tests stay live and why, and gives verification steps with observed results. The template's Scope section asks for a linked issue or a reason for no issue. The description does not link an issue or explain why none is needed, and the Problem section is not headed in the template's terms. The template's agent-attribution line is present in the form of "Done by Claude Opus 5.5 in Claude Code." Overall the description is mostly complete with one notable gap.

      Finishing Touches

      Generate unit tests (beta)

      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Usage-based review receipt

      Note

      This review was completed with usage-based billing: files reviewed beyond your plan's included limits are billed at $0.25/file. View usage-based billing.

      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between 6d16375ff36fd3326bd695220598472366dad7fc and d092a336f83f6281292977659ab874775762547f.

      Files selected for processing: 3

      • apps/server/src/preview/ServerBrowser.test.ts
      • apps/server/src/storageCleanup.test.ts
      • apps/server/src/usage/UsageService.test.ts

      Limit details: You’ve used all 10 included reviews currently available.

    4. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded21.5 KiB21.5 KiB0 B (0.0%)24.4 KiB✅
      CodexLive turn messages110 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.9 KiB21.9 KiB0 B (0.0%)24.4 KiB✅
      ClaudeLive turn messages110 (0.0%)8✅

      Other scenarios

      All 64 scenario measurements match main.

      All 64 scenario measurements
      ProviderScenarioMetricMain baselineThis PRImpactPR ceiling
      Codexshort turn resumeWebSocket decoded10.5 KiB10.5 KiB0 B (0.0%)12.7 KiB✅
      Codexshort turn resumeWebSocket messages220 (0.0%)2✅
      Codexlong turn running, cold openHTTP decoded281.7 KiB281.7 KiB0 B (0.0%)302.7 KiB✅
      Codexlong turn running, cold openrows75750 (0.0%)75✅
      Codexlong turn running, history pageHTTP decoded92.4 KiB92.4 KiB0 B (0.0%)107.4 KiB✅
      Codexlong turn running, history pagerows75750 (0.0%)75✅
      Codexlong turn finished, cold openHTTP decoded381.5 KiB381.5 KiB0 B (0.0%)410.2 KiB✅
      Codexlong turn finished, cold openrows1511510 (0.0%)151✅
      Codexlong turn finished, socket cold openWebSocket decoded381.6 KiB381.6 KiB0 B (0.0%)410.2 KiB✅
      Codexlong turn finished, socket cold openWebSocket messages220 (0.0%)2✅
      Codexlong turn finished, socket cold openrows1511510 (0.0%)151✅
      Codexlong turn finished, work pageHTTP decoded186.2 KiB186.2 KiB0 B (0.0%)200.2 KiB✅
      Codexlong turn finished, work pagerows1501500 (0.0%)150✅
      Codexidle thread resumeWebSocket decoded65 B65 B0 B (0.0%)200 B✅
      Codexidle thread resumeWebSocket messages110 (0.0%)1✅
      Codexfleet shell snapshotHTTP decoded42.4 KiB42.4 KiB0 B (0.0%)53.7 KiB✅
      Codexfleet shell snapshotrows27270 (0.0%)27✅
      Codexfleet shell subscribeWebSocket decoded65 B65 B0 B (0.0%)200 B✅
      Codexfleet shell subscribeWebSocket messages110 (0.0%)1✅
      Codexfleet shell resume checkHTTP decoded18 B18 B0 B (0.0%)100 B✅
      Codexfleet shell resume checkrows0000✅
      Codexstale shell reloadHTTP decoded42.4 KiB42.4 KiB0 B (0.0%)53.7 KiB✅
      Codexstale shell reloadrows27270 (0.0%)27✅
      Codexstale shell resumeWebSocket decoded140 B140 B0 B (0.0%)400 B✅
      Codexstale shell resumeWebSocket messages220 (0.0%)2✅
      Codexstale todo list cold openHTTP decoded72.4 KiB72.4 KiB0 B (0.0%)83.0 KiB✅
      Codexstale todo list cold openrows75750 (0.0%)75✅
      Codexstale todo list cold opennodes220 (0.0%)4✅
      Codexstale todo list cold opensubagents220 (0.0%)4✅
      Codexstale todo list cold openplans110 (0.0%)2✅
      Codexstale todo list cold openproviderTurns110 (0.0%)2✅
      Codexstale todo list cold opencheckpoints110 (0.0%)2✅
      Claudeshort turn resumeWebSocket decoded10.6 KiB10.6 KiB0 B (0.0%)12.7 KiB✅
      Claudeshort turn resumeWebSocket messages220 (0.0%)2✅
      Claudelong turn running, cold openHTTP decoded283.3 KiB283.3 KiB0 B (0.0%)302.7 KiB✅
      Claudelong turn running, cold openrows75750 (0.0%)75✅
      Claudelong turn running, history pageHTTP decoded93.4 KiB93.4 KiB0 B (0.0%)107.4 KiB✅
      Claudelong turn running, history pagerows75750 (0.0%)75✅
      Claudelong turn finished, cold openHTTP decoded384.2 KiB384.2 KiB0 B (0.0%)410.2 KiB✅
      Claudelong turn finished, cold openrows1511510 (0.0%)151✅
      Claudelong turn finished, socket cold openWebSocket decoded384.3 KiB384.3 KiB0 B (0.0%)410.2 KiB✅
      Claudelong turn finished, socket cold openWebSocket messages220 (0.0%)2✅
      Claudelong turn finished, socket cold openrows1511510 (0.0%)151✅
      Claudelong turn finished, work pageHTTP decoded188.1 KiB188.1 KiB0 B (0.0%)200.2 KiB✅
      Claudelong turn finished, work pagerows1501500 (0.0%)150✅
      Claudeidle thread resumeWebSocket decoded66 B66 B0 B (0.0%)200 B✅
      Claudeidle thread resumeWebSocket messages110 (0.0%)1✅
      Claudefleet shell snapshotHTTP decoded43.0 KiB43.0 KiB0 B (0.0%)53.7 KiB✅
      Claudefleet shell snapshotrows27270 (0.0%)27✅
      Claudefleet shell subscribeWebSocket decoded66 B66 B0 B (0.0%)200 B✅
      Claudefleet shell subscribeWebSocket messages110 (0.0%)1✅
      Claudefleet shell resume checkHTTP decoded18 B18 B0 B (0.0%)100 B✅
      Claudefleet shell resume checkrows0000✅
      Claudestale shell reloadHTTP decoded43.0 KiB43.0 KiB0 B (0.0%)53.7 KiB✅
      Claudestale shell reloadrows27270 (0.0%)27✅
      Claudestale shell resumeWebSocket decoded140 B140 B0 B (0.0%)400 B✅
      Claudestale shell resumeWebSocket messages220 (0.0%)2✅
      Claudestale todo list cold openHTTP decoded73.4 KiB73.4 KiB0 B (0.0%)83.0 KiB✅
      Claudestale todo list cold openrows75750 (0.0%)75✅
      Claudestale todo list cold opennodes220 (0.0%)4✅
      Claudestale todo list cold opensubagents220 (0.0%)4✅
      Claudestale todo list cold openplans110 (0.0%)2✅
      Claudestale todo list cold openproviderTurns110 (0.0%)2✅
      Claudestale todo list cold opencheckpoints110 (0.0%)2✅

      Baseline: b7a224c · PR result: d092a33 · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 108.5 KiB
      • Claude decoded thread snapshot: 108.8 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    5. juliusmarminge added labelstakeover

    6. juliusmarminge merged this43ce395

    7. juliusmarminge closed this

    8. Evidence

      Created identical synthetic demo projects, sent “Give me a short tour” through the replay provider, observed streaming and tool activity, then waited for the final reply and Done state. Both real-app runs behaved alike. Environment: Chromium, 1280×800, light theme, fresh isolated data. Generated workspace paths are redacted.

      BeforeAfter
      b7a224c7ddd092a336f8
      Before: streaming replay turnAfter: streaming replay turn
      Before: completed replay turnAfter: completed replay turn
      Before recordingAfter recording

      Scenario driver

      The scenario passes on both commits. These captures establish parity for this replay-thread flow only; they do not prove deterministic fixture dates or simulated timer advances.

      Not shown:

      • Deterministic fixture dates, simulated timeout advances, and retention of live tests for real I/O are test-runner properties with no production-app manifestation; app captures cannot demonstrate them.
      • Complete path coverage was not established: OAuth/MCP, preview automation, usage refresh, storage cleanup, provider manifests and registries, Claude task-output tailing, pull-request state, shared workers, and mobile environment-cache behavior were not individually exercised.
      • Desktop, mobile, remote/relay, and real-provider behavior were not captured. passesOnHead describes only the captured web replay flow.

Sign in to join this conversation.