test: cover runHealthCheck quick and live probe paths - #565
Conversation
Direct coverage for the check command body (also the dashboard's quick/deep check), previously exercised only via the CLI suites: Quick check: - empty pool short-circuits with a message - fresh sessions are trusted without a refresh, the active account is synced to the Codex CLI, and an unchanged pool is not re-saved - a disabled-but-healthy account is re-enabled and persisted - stale sessions refresh through the queue and the rotated credentials are written back and carried into the CLI sync - an expired account with a failed refresh counts as need-re-login with no save and no CLI sync - a failed forced refresh on a still-valid session downgrades to a warning instead of a failure Live probe: - quota snapshots update and persist the cache and count toward Codex availability; the probe model resolves through inspectRequestedModel - probe failures count as signed-in-only without touching the cache - accounts without a resolvable id skip the probe with a warning - a quota cache save failure warns but never aborts the check https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
|
Warning Review limit reached
More reviews will be available in 5 minutes. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
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 |
A stale session renewed by the validation refresh must be probed with the rotated access token, with the snapshot applied to the cache and counted toward Codex availability. https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
Summary
Sixth suite in the direct-coverage push (siblings: #559, #560, #561, #563, #564; all independent, based on
main).lib/codex-manager/health-check.tsis the body of thecheckcommand and the dashboard's quick/deep check actions — 375 lines of refresh, probe, and persistence logic with no direct tests. This addstest/health-check.test.ts(10 tests).Mocked seams:
loadAccounts/saveAccounts,queuedRefresh, the Codex CLI writer, the quota cache loader/saver, andfetchCodexQuotaSnapshot. The real freshness check, the real quota-cache update/attribution helpers, and the real summary formatting all run. Fixtures are clock-relative because the check decides token freshness againstDate.now().What the tests pin
Quick check:
No accounts configured.and never touches the refresh queue.need re-login, with no save and no CLI sync.forceRefreshwith a failed refresh on a still-valid session downgrades to a warning (still works right now) instead of a failure — the account is not falsely flagged for re-login.Live probe:
Codex available.signed in onlyand leaves the cache untouched.live check skipped: missing account ID.Validation
vitest run test/health-check.test.ts— 10/10 passingnpm run typecheck— cleannpx eslint test/health-check.test.ts --max-warnings=0— cleanhttps://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
Generated by Claude Code
note: greptile review for oc-chatgpt-multi-auth. cite files like
lib/foo.ts:123. confirm regression tests + windows concurrency/token redaction coverage.Greptile Summary
adds
test/health-check.test.ts— the first direct coverage forlib/codex-manager/health-check.ts, which was previously untested. all mock seams (storage, refresh queue, codex-cli writer, quota cache, quota probe) are correctly hoisted; the real freshness, cache-update, and summary helpers run unmodified.REAL_NOW + 60_000for stale,REAL_NOW + 3_600_000for fresh) are correct given the 5-minuteACCESS_TOKEN_FRESH_WINDOW_MSthreshold inaccount-credentials.ts.Confidence Score: 5/5
test-only change adding coverage for a previously untested 375-line module; no production logic is modified
mock seams are correct, the stale+liveProbe path previously flagged is now covered, and clock-relative fixtures are sound against the real 5-minute freshness threshold; remaining gaps are minor branches with no production risk
no files require special attention; the three uncovered branches are low-risk gaps worth a follow-up but not blocking
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[runHealthCheck] --> B{storage empty?} B -- yes --> C[log No accounts configured. / return] B -- no --> D[for each account] D --> E{forceRefresh=false AND sessionLikelyValid?} E -- yes --> F[re-enable if disabled] F --> G{liveProbe?} G -- no --> H[ok++] G -- yes --> I{probeAccountId resolved?} I -- no --> J[signedInOnly++ / warnings++] I -- yes --> K[fetchCodexQuotaSnapshot] K -- success --> L[updateQuotaCache / codexAvailable++] K -- failure --> M{isCodexUnavailableError?} M -- yes --> N[CODEX_UNAVAILABLE_PROBE_NOTE untested] M -- no --> O[signedInOnly++ / warnings++] E -- no --> P[queuedRefresh] P -- success --> Q{liveProbe?} Q -- yes --> R[fetchCodexQuotaSnapshot with rotated token] Q -- no --> S[ok++] P -- failure --> T{sessionLikelyValid?} T -- yes --> U[warnings++ signedInOnly if liveProbe untested combo] T -- no --> V[failed++] R -- success --> W[updateQuotaCache / codexAvailable++] P -- success --> X{accountIdentityChanged AND liveProbe?} X -- yes --> Y[pruneUnsafeQuotaEmailCacheEntry untested] D --> Z[save quota cache if changed] Z --> AA[saveAccountsWithRetry if changed] AA --> AB[setCodexCliActiveSelection if active refreshed] AB --> AC[formatResultSummary]Prompt To Fix All With AI
Reviews (2): Last reviewed commit: "test: cover the refresh-then-probe live ..." | Re-trigger Greptile