Thanks to visit codestin.com
Credit goes to github.com

Skip to content

test: cover login-menu data layer targeting, view model, and drift sync - #563

Merged
ndycode merged 2 commits into
mainfrom
claude/audit-44-login-menu-data-tests
Jun 11, 2026
Merged

ndycode merged 2 commits into
mainfrom
claude/audit-44-login-menu-data-tests

Conversation

@ndycode

@ndycode ndycode commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Summary

Fourth suite in the direct-coverage push for the login machinery (siblings: #559, #560, #561; all independent, based on main). lib/codex-manager/login-menu-data.ts had direct tests only for refreshQuotaCacheForMenu; its other three exports — the quota probe targeting, the dashboard view model, and the Codex CLI drift sync — were exercised only through the interactive menu. This adds test/login-menu-data.test.ts (15 tests).

countMenuQuotaRefreshTargets and toExistingAccountInfo run with no mocks at all (pure given storage/cache/settings fixtures); only loadCodexCliState and setCodexCliActiveSelection are mocked for the drift-sync tests.

What the tests pin

countMenuQuotaRefreshTargets (decides which accounts the menu probes):

  • Counts enabled accounts with usable tokens and stale/missing cache entries.
  • Skips disabled accounts, tokens inside the 5-minute freshness window, and cache entries younger than the TTL.
  • Skips accounts whose probe result could not be stored behind a safe lookup key (duplicate accountIds with no email fallback) — probing them would waste requests on unattributable snapshots.

toExistingAccountInfo (the dashboard row view model):

  • Status mapping: active (current row), disabled, cooldown, quota-exhausted (0% remaining with a future reset), rate-limited (429 entry), and plain ok.
  • Ready-first ordering: most quota headroom first, exhausted accounts last; index becomes the display position while sourceIndex still points into storage; isDefaultAccount survives reordering.
  • Quick-switch numbering in both modes: visible-row (default) and storage-position (menuSortQuickSwitchVisibleRow: false).
  • Source order preserved when sorting is disabled.

syncCodexCliActiveSelectionIfDrifted (repairs auth.json drift):

  • No-ops when the CLI state matches by accountId, when there is no CLI state, when the match is by sanitized email (case/whitespace-insensitive) with accountIds absent, when the state read throws, and for an empty pool (no read at all).
  • On real drift, rewrites the CLI selection with exactly the active account's credentials and reports the writer's result. Also pins the { forceRefresh: true } read.

Validation

  • vitest run test/login-menu-data.test.ts — 15/15 passing
  • npm run typecheck — clean
  • npx eslint test/login-menu-data.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/login-menu-data.test.ts, providing direct vitest coverage for four of the five exports in lib/codex-manager/login-menu-data.ts. the previous review feedback was addressed in this revision: both the writer-false propagation path and the loadRuntimeCurrentSelectionForStorage describe block are now included.

  • countMenuQuotaRefreshTargets (5 tests): verifies disabled-account skipping, token-freshness window, stale-cache counting, and the duplicate-accountId / no-email-fallback safety gate that prevents unattributable probe snapshots.
  • toExistingAccountInfo (4 tests): pins status mapping for all six states, ready-first sort + display/storage index renumbering, quick-switch numbering in both visible-row and storage-position modes, and sort-disabled source-order preservation.
  • syncCodexCliActiveSelectionIfDrifted (7 tests): covers match-by-id no-op, null-state no-op, accountId drift rewrite, writer-false propagation (windows EBUSY path), sanitized-email match, read-throws no-op, and empty-pool early exit.
  • loadRuntimeCurrentSelectionForStorage (3 tests): verifies all three runtime signals are threaded to the resolver, app-bind null-passthrough when router is not running, and Promise.all error swallowing to null for both signal sources.

Confidence Score: 5/5

test-only addition with no production code changes; safe to merge

the suite is a pure test addition with no changes to production code. all assertions were verified against the source: status ordering, index/sourceIndex renumbering, quick-switch numbering, drift-sync branching, and the Promise.all error-swallowing paths all match the implementation. both concerns from the previous review round are addressed — the writer-false propagation test and the loadRuntimeCurrentSelectionForStorage describe block are present.

no files require special attention

Important Files Changed

Filename Overview
test/login-menu-data.test.ts new test suite covering 4/5 exports of login-menu-data.ts with 19 tests; no logic errors found, all assertions match production code paths including the writer-false propagation and loadRuntimeCurrentSelectionForStorage error-swallowing paths added in response to prior review feedback

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[syncCodexCliActiveSelectionIfDrifted] --> B{activeIndex valid\nand accounts non-empty?}
    B -- no --> C[return false]
    B -- yes --> D[loadCodexCliState\nforceRefresh: true]
    D -- throws --> C
    D -- null --> C
    D -- state --> E{accountId present\non both sides?}
    E -- yes --> F{accountIds match?}
    F -- yes --> C
    F -- no --> I[setCodexCliActiveSelection\nwith active account creds]
    E -- no --> G{emails present\non both sides?}
    G -- yes --> H{sanitized emails match?}
    H -- yes --> C
    H -- no --> I
    G -- no --> I
    I --> J[return writer result\ntrue = written, false = skipped/EBUSY]
Loading

Reviews (2): Last reviewed commit: "test: cover runtime selection loading an..." | Re-trigger Greptile

Direct coverage for the three untested login-menu-data.ts exports
(refreshQuotaCacheForMenu already has its own suite):

- countMenuQuotaRefreshTargets: counts enabled accounts with usable
  tokens and stale/missing cache entries; skips disabled accounts,
  soon-to-expire tokens, fresh entries, and accounts whose probe
  result could not be stored behind a safe lookup key (duplicate
  accountIds without an email fallback)
- toExistingAccountInfo: status mapping (active/disabled/cooldown/
  quota-exhausted/rate-limited/ok), ready-first ordering with display
  reindexing and sourceIndex preservation, quick-switch numbering in
  both visible-row and storage-position modes, and source order when
  sorting is disabled
- syncCodexCliActiveSelectionIfDrifted: no-ops on matching accountId,
  missing CLI state, sanitized-email match, read failures, and empty
  pools; rewrites the CLI selection with the active account's
  credentials on real drift

https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@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 11 minutes and 42 seconds. 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: ef8e1b23-0aed-4b34-a6c2-b1e86a1b3186

📥 Commits

Reviewing files that changed from the base of the PR and between 6ede089 and f80a899.

📒 Files selected for processing (1)
  • test/login-menu-data.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/audit-44-login-menu-data-tests
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch claude/audit-44-login-menu-data-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/login-menu-data.test.ts
Comment thread test/login-menu-data.test.ts
Add the loadRuntimeCurrentSelectionForStorage describe block (all
three signals threaded into resolveRuntimeCurrentAccount, the
non-running router dropped to null, and failing signal sources
degraded to absent instead of throwing) plus the writer-false case so
a skipped CLI write propagates as false from
syncCodexCliActiveSelectionIfDrifted.

https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
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