Skip to content

test: cover runHealthCheck quick and live probe paths - #565

Merged
ndycode merged 2 commits into
mainfrom
claude/audit-46-health-check-tests
Jun 11, 2026
Merged

test: cover runHealthCheck quick and live probe paths#565
ndycode merged 2 commits into
mainfrom
claude/audit-46-health-check-tests

Conversation

@ndycode

@ndycode ndycode commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Summary

Sixth suite in the direct-coverage push (siblings: #559, #560, #561, #563, #564; all independent, based on main). lib/codex-manager/health-check.ts is the body of the check command and the dashboard's quick/deep check actions — 375 lines of refresh, probe, and persistence logic with no direct tests. This adds test/health-check.test.ts (10 tests).

Mocked seams: loadAccounts/saveAccounts, queuedRefresh, the Codex CLI writer, the quota cache loader/saver, and fetchCodexQuotaSnapshot. 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 against Date.now().

What the tests pin

Quick check:

  • Empty pool short-circuits with No accounts configured. and never touches the refresh queue.
  • Fresh sessions are trusted without a refresh, the summary reports them working, 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 that change is persisted.
  • Stale sessions refresh through the queue; rotated credentials are written back to storage and carried into the CLI sync.
  • An expired account whose refresh fails counts as need re-login, with no save and no CLI sync.
  • forceRefresh with 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:

  • Quota snapshots are fetched with the account id/token and the normalized default probe model, applied to the cache, persisted, and counted as Codex available.
  • A probe failure counts as signed in only and leaves the cache untouched.
  • An account with no resolvable id skips the probe with live check skipped: missing account ID.
  • A quota-cache save failure (Windows EBUSY class) warns but never aborts the check — account fixes still commit and the summary still prints.

Validation

  • vitest run test/health-check.test.ts — 10/10 passing
  • npm run typecheck — clean
  • npx eslint test/health-check.test.ts --max-warnings=0 — clean

https://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 for lib/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.

  • quick-check paths (6 tests): empty pool short-circuit, fresh-session trust + cli sync, disabled-but-healthy re-enable, stale refresh success, stale refresh failure, and forceRefresh downgrade to warning — all covered with precise counter and save/sync assertions.
  • live-probe paths (4 tests): fresh account + successful probe (cache persisted), stale-then-refresh-then-probe using rotated token (addresses the gap flagged in the previous review thread), probe failure as signed-in-only, missing account id skip, and EBUSY cache-save resilience.
  • clock-relative fixtures (REAL_NOW + 60_000 for stale, REAL_NOW + 3_600_000 for fresh) are correct given the 5-minute ACCESS_TOKEN_FRESH_WINDOW_MS threshold in account-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

Filename Overview
test/health-check.test.ts new 10-test suite covering quick-check and live-probe paths with correct mock seams; stale+liveProbe combined path (previously flagged) is now covered; three minor branch gaps remain (isCodexUnavailableError, forceRefresh+liveProbe+failed, accountIdentityChanged pruning)

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]
Loading

Fix All in Codex

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
test/health-check.test.ts:157-190
**three untested branches in health-check.ts**

the live probe tests cover generic errors but miss the `isCodexUnavailableError` branch (health-check.ts lines 153–155 and 261–263), which produces a distinct `CODEX_UNAVAILABLE_PROBE_NOTE` message. a regression there (e.g. wrong import or message change) would go undetected. two other gaps: (1) `forceRefresh: true` + `liveProbe: true` + failed refresh on a still-valid session — the `signedInOnly += 1` at line 285 is never exercised; (2) the `accountIdentityChanged && liveProbe` branch (lines 211–221) that calls `pruneUnsafeQuotaEmailCacheEntry` is never reached because the fake tokens don't produce a real JWT, so `extractAccountId` always returns `undefined` and `applyTokenAccountIdentity` never signals a change. none of these are blocking, but the pruning path in particular hides a windows-relevant cache-file mutation that's worth at least a smoke test.

Reviews (2): Last reviewed commit: "test: cover the refresh-then-probe live ..." | Re-trigger Greptile

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
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@ndycode, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: c09af307-55e5-4de6-b7c2-752efdc61092

📥 Commits

Reviewing files that changed from the base of the PR and between 2e7cfb5 and 92825bc.

📒 Files selected for processing (1)
  • test/health-check.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/audit-46-health-check-tests
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch claude/audit-46-health-check-tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread test/health-check.test.ts
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
@ndycode
ndycode merged commit 3b29251 into main Jun 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants