test: run clock-free live tests on TestClock #35868
main fromrefs/pull/35868/head·merged by juliusmarminge View on GitHubMany it.live tests used the wall clock for no reason. Three things went wrong because of it:
- Date drift. The
storageCleanupfixtures are pinned toNOW_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)#
| File | Converted | Notes |
|---|---|---|
apps/server/src/storageCleanup.test.ts | 8 | setTime(NOW_MS); one date written relative to DateTime.now became at(-DAY_MS) |
apps/server/src/usage/UsageService.test.ts | 42 | The 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.ts | 45 | No adjusts needed |
packages/shared (KeyedCoalescingWorker 4, DrainableWorker 1) | 5 | |
packages/client-runtime/src/state/pullRequests.test.ts | 3 | The 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.ts | 1 | The stop-driven test |
ModelManifest 4, ProviderInstanceRegistry 3, McpOAuth 3, OrchestratorMcpService 1 | 11 | |
apps/server/src/ws.test.ts | 1 | .each split: thread case on TestClock |
apps/mobile/src/connection/environment-cache-store.test.ts | 2 | Fork loadPullRequests, adjust 1ms past its host yield, join |
Left live#
storageCleanuporphan-worktree and artifact-log aging tests. They compare real file mtimes.ws.test.tsshell resume. Shell updates batch throughStream.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'sadjustdoes 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
yesload. Server tests ran inunshare -U -pwithTMPDIRunder$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
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Approvability#
Verdict: Approved at
d092a33Macroscope'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.
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.tsSelected asynchronous tests use it.effectand advance the test clock to exercise deferred link loading and stalled invalidation.Browser preview test coverage
apps/server/src/preview/ServerBrowser.test.tsTests 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.tsTests 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.tsTests 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.tsTests 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 tod092a-
This change only affects how tests run and does not alter production behavior. No concrete merge-blocking risk remains after review.
Pre-merge checks:
4-
Check name Status Explanation Title check 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 styl… Description check 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 … Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check 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#
- Mode: Continue automatically
- Reviewed files: 3
- Charged: $0.75
- View usage details
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-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: test/live-to-testclock
- File: .coderabbit.config.ts
- Commit: d092a33
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Team
- Run ID:
494ee624-54a0-494d-9701-47fce27d82a2
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.tsapps/server/src/storageCleanup.test.tsapps/server/src/usage/UsageService.test.ts
Limit details: You’ve used all 10 included reviews currently available.
-
-
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅ Codex Live turn messages 1 1 0 (0.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅ Claude Live turn messages 1 1 0 (0.0%) 8 ✅ Other scenarios#
All 64 scenario measurements match
main.All 64 scenario measurements
Provider Scenario Metric Main baseline This PR Impact PR ceiling Codex short turn resumeWebSocket decoded10.5 KiB 10.5 KiB 0 B (0.0%) 12.7 KiB ✅ Codex short turn resumeWebSocket messages2 2 0 (0.0%) 2 ✅ Codex long turn running, cold openHTTP decoded281.7 KiB 281.7 KiB 0 B (0.0%) 302.7 KiB ✅ Codex long turn running, cold openrows75 75 0 (0.0%) 75 ✅ Codex long turn running, history pageHTTP decoded92.4 KiB 92.4 KiB 0 B (0.0%) 107.4 KiB ✅ Codex long turn running, history pagerows75 75 0 (0.0%) 75 ✅ Codex long turn finished, cold openHTTP decoded381.5 KiB 381.5 KiB 0 B (0.0%) 410.2 KiB ✅ Codex long turn finished, cold openrows151 151 0 (0.0%) 151 ✅ Codex long turn finished, socket cold openWebSocket decoded381.6 KiB 381.6 KiB 0 B (0.0%) 410.2 KiB ✅ Codex long turn finished, socket cold openWebSocket messages2 2 0 (0.0%) 2 ✅ Codex long turn finished, socket cold openrows151 151 0 (0.0%) 151 ✅ Codex long turn finished, work pageHTTP decoded186.2 KiB 186.2 KiB 0 B (0.0%) 200.2 KiB ✅ Codex long turn finished, work pagerows150 150 0 (0.0%) 150 ✅ Codex idle thread resumeWebSocket decoded65 B 65 B 0 B (0.0%) 200 B ✅ Codex idle thread resumeWebSocket messages1 1 0 (0.0%) 1 ✅ Codex fleet shell snapshotHTTP decoded42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅ Codex fleet shell snapshotrows27 27 0 (0.0%) 27 ✅ Codex fleet shell subscribeWebSocket decoded65 B 65 B 0 B (0.0%) 200 B ✅ Codex fleet shell subscribeWebSocket messages1 1 0 (0.0%) 1 ✅ Codex fleet shell resume checkHTTP decoded18 B 18 B 0 B (0.0%) 100 B ✅ Codex fleet shell resume checkrows0 0 0 0 ✅ Codex stale shell reloadHTTP decoded42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅ Codex stale shell reloadrows27 27 0 (0.0%) 27 ✅ Codex stale shell resumeWebSocket decoded140 B 140 B 0 B (0.0%) 400 B ✅ Codex stale shell resumeWebSocket messages2 2 0 (0.0%) 2 ✅ Codex stale todo list cold openHTTP decoded72.4 KiB 72.4 KiB 0 B (0.0%) 83.0 KiB ✅ Codex stale todo list cold openrows75 75 0 (0.0%) 75 ✅ Codex stale todo list cold opennodes2 2 0 (0.0%) 4 ✅ Codex stale todo list cold opensubagents2 2 0 (0.0%) 4 ✅ Codex stale todo list cold openplans1 1 0 (0.0%) 2 ✅ Codex stale todo list cold openproviderTurns1 1 0 (0.0%) 2 ✅ Codex stale todo list cold opencheckpoints1 1 0 (0.0%) 2 ✅ Claude short turn resumeWebSocket decoded10.6 KiB 10.6 KiB 0 B (0.0%) 12.7 KiB ✅ Claude short turn resumeWebSocket messages2 2 0 (0.0%) 2 ✅ Claude long turn running, cold openHTTP decoded283.3 KiB 283.3 KiB 0 B (0.0%) 302.7 KiB ✅ Claude long turn running, cold openrows75 75 0 (0.0%) 75 ✅ Claude long turn running, history pageHTTP decoded93.4 KiB 93.4 KiB 0 B (0.0%) 107.4 KiB ✅ Claude long turn running, history pagerows75 75 0 (0.0%) 75 ✅ Claude long turn finished, cold openHTTP decoded384.2 KiB 384.2 KiB 0 B (0.0%) 410.2 KiB ✅ Claude long turn finished, cold openrows151 151 0 (0.0%) 151 ✅ Claude long turn finished, socket cold openWebSocket decoded384.3 KiB 384.3 KiB 0 B (0.0%) 410.2 KiB ✅ Claude long turn finished, socket cold openWebSocket messages2 2 0 (0.0%) 2 ✅ Claude long turn finished, socket cold openrows151 151 0 (0.0%) 151 ✅ Claude long turn finished, work pageHTTP decoded188.1 KiB 188.1 KiB 0 B (0.0%) 200.2 KiB ✅ Claude long turn finished, work pagerows150 150 0 (0.0%) 150 ✅ Claude idle thread resumeWebSocket decoded66 B 66 B 0 B (0.0%) 200 B ✅ Claude idle thread resumeWebSocket messages1 1 0 (0.0%) 1 ✅ Claude fleet shell snapshotHTTP decoded43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅ Claude fleet shell snapshotrows27 27 0 (0.0%) 27 ✅ Claude fleet shell subscribeWebSocket decoded66 B 66 B 0 B (0.0%) 200 B ✅ Claude fleet shell subscribeWebSocket messages1 1 0 (0.0%) 1 ✅ Claude fleet shell resume checkHTTP decoded18 B 18 B 0 B (0.0%) 100 B ✅ Claude fleet shell resume checkrows0 0 0 0 ✅ Claude stale shell reloadHTTP decoded43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅ Claude stale shell reloadrows27 27 0 (0.0%) 27 ✅ Claude stale shell resumeWebSocket decoded140 B 140 B 0 B (0.0%) 400 B ✅ Claude stale shell resumeWebSocket messages2 2 0 (0.0%) 2 ✅ Claude stale todo list cold openHTTP decoded73.4 KiB 73.4 KiB 0 B (0.0%) 83.0 KiB ✅ Claude stale todo list cold openrows75 75 0 (0.0%) 75 ✅ Claude stale todo list cold opennodes2 2 0 (0.0%) 4 ✅ Claude stale todo list cold opensubagents2 2 0 (0.0%) 4 ✅ Claude stale todo list cold openplans1 1 0 (0.0%) 2 ✅ Claude stale todo list cold openproviderTurns1 1 0 (0.0%) 2 ✅ Claude stale todo list cold opencheckpoints1 1 0 (0.0%) 2 ✅ Baseline:
b7a224c· PR result:d092a33· Source CI: successScenario 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.
juliusmarminge added labelstakeover
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge merged this43ce395
juliusmarminge closed this
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.
Before After b7a224c7dd d092a336f8 



Before recording After recording 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.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes