test(chat): make durable-cron scheduled-wake tests wait robustly#847
Conversation
Two hasActiveWorkloads cron tests polled for an async scheduled-wake user_message by advancing fake timers only 100×1ms. The durable- scheduling pipeline needs more timer+microtask cycles than that to emit the event, so the tests passed only on fast/unloaded runners and failed deterministically elsewhere (surfaced when an unrelated merge reshuffled the 8-way shard split). Replace the fragile fixed-iteration loops with a waitForFakeTimerCondition helper that advances fake time up to 10s while flushing microtasks until the predicate holds. Test-only; no assertions weakened, no product code changed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
@copilot review but do not make fixes Test-only fix unblocking the v1.2.30 release gate (green ci-pass on the tagged commit). Robustifies two fake-timer cron-scheduling waits; verified 10× green + typecheck. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughChangesThe test suite adds deterministic fake-timer helpers and applies them to Claude foreground sends, ambiguous cron handling, idle activity, and scheduled-wake assertions. Agent chat test timing
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
test-desktop (8)was failing deterministically onmain(blocking the v1.2.30 release gate, which requires a greenci-passon the tagged commit). TwoagentChatService.test.tscron tests underhasActiveWorkloadsfailed:does not create task-id scheduled rows for ambiguous parentless cron runsclaims a native cron when unrelated idle output already opened the turnRoot cause
Both tests polled for an async scheduled-wake
user_messageby advancing fake timers only100 × 1ms. The durable-scheduling pipeline (#844) needs more timer+microtask cycles than that to emit the event, so the tests passed only on fast/unloaded runners. They began failing deterministically once an unrelated merge (#846) reshuffled the 8-way shard split onto a slower shard. Verified: running the whole file in isolation reproduced2 failed / 671 passedevery time; same test+impl was green onmainbefore the shard reshuffle.Fix
Replace the fragile fixed-iteration loops with a
waitForFakeTimerConditionhelper that advances fake time up to 10s while flushing microtasks until the predicate holds. Test-only — no product code changed, no assertions weakened or skipped.Verification
673 passed (673)every time.npm --prefix apps/desktop run typecheck: pass.🤖 Generated with Claude Code
Summary by CodeRabbit
Greptile Summary
This PR makes durable-cron scheduled-wake tests wait more reliably. The main changes are:
Confidence Score: 5/5
Safe to merge with minimal risk.
The change is confined to tests and preserves the existing assertions while replacing fragile fixed polling with bounded fake-timer waits.
No files require special attention.
What T-Rex did
Important Files Changed
Sequence Diagram
%%{init: {'theme': 'neutral'}}%% sequenceDiagram participant Test as Durable-cron test participant Helper as waitForFakeTimerCondition participant Timers as Vitest fake timers participant Service as AgentChatService events Test->>Service: start session turn / release cron gate Test->>Helper: wait for expected event predicate loop until predicate true or 10s fake time Helper->>Service: evaluate emitted events alt event not emitted yet Helper->>Timers: advanceTimersByTimeAsync(1) Helper->>Helper: flush microtasks else event emitted Helper-->>Test: return end end Test->>Service: assert scheduled-work / scheduled-wake behavior%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% sequenceDiagram participant Test as Durable-cron test participant Helper as waitForFakeTimerCondition participant Timers as Vitest fake timers participant Service as AgentChatService events Test->>Service: start session turn / release cron gate Test->>Helper: wait for expected event predicate loop until predicate true or 10s fake time Helper->>Service: evaluate emitted events alt event not emitted yet Helper->>Timers: advanceTimersByTimeAsync(1) Helper->>Helper: flush microtasks else event emitted Helper-->>Test: return end end Test->>Service: assert scheduled-work / scheduled-wake behaviorReviews (1): Last reviewed commit: "test(chat): make durable-cron scheduled-..." | Re-trigger Greptile