fix(quota): report unlimited A6API keys - #1171
Conversation
|
✅ Deterministic PR hygiene checks passed. |
⏳ DRAFT
What to do
Review readiness checklist
2/4 boxes ticked. This PR stays in draft until every box above is ticked. |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe quota model now supports structured USD credits. A6API parsing reports metered usage, unlimited status, expiration timestamps, and custom quota windows. Tests cover metered and unlimited accounts. ChangesA6API credit quota reporting
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/provider-quota.test.ts`:
- Around line 300-327: Update the test around fetchProviderQuotaReports to use a
valid nonzero expires_at timestamp in the mocked unlimited-quota response, then
assert that the returned creditsUsd object includes the same expiresAt value
alongside its existing fields. Keep the test focused on propagating expiry for
unlimited accounts.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 1f1dc15e-b69d-4902-9f2a-c5377732ec6c
📒 Files selected for processing (2)
src/providers/quota.tstests/provider-quota.test.ts
| test("A6API unlimited keys remain visible even when all finite credit totals are zero", async () => { | ||
| globalThis.fetch = (async (input: RequestInfo | URL) => new Response(JSON.stringify( | ||
| String(input).includes("subscription") | ||
| ? { data: { hard_limit_usd: 100_000_000 } } | ||
| : { data: { | ||
| total_granted: 0, | ||
| total_used: 0, | ||
| total_available: 0, | ||
| unlimited_quota: true, | ||
| expires_at: 0, | ||
| } }, | ||
| ), { status: 200 })) as typeof fetch; | ||
|
|
||
| const result = await fetchProviderQuotaReports(a6apiOnlyConfig(), true); | ||
|
|
||
| expect(result.reports).toHaveLength(1); | ||
| expect(result.reports[0]?.quota.creditsUsd).toEqual({ | ||
| used: 0, | ||
| limit: 0, | ||
| remaining: 0, | ||
| percent: 0, | ||
| unlimited: true, | ||
| }); | ||
| expect(result.reports[0]?.quota.customWindows).toEqual([{ | ||
| label: "Unlimited API credits", | ||
| percent: 0, | ||
| }]); | ||
| }); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Test expiry propagation for unlimited accounts.
Line 309 sets expires_at to 0. The test cannot detect a regression that drops expiresAt from the unlimited creditsUsd branch.
Set a valid timestamp and assert expiresAt in the expected quota object.
Proposed test update
- expires_at: 0,
+ expires_at: "2027-01-01T00:00:00Z",
...
percent: 0,
unlimited: true,
+ expiresAt: Date.parse("2027-01-01T00:00:00Z"),As per path instructions, a src/ behavior change must have a focused regression test under tests/.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| test("A6API unlimited keys remain visible even when all finite credit totals are zero", async () => { | |
| globalThis.fetch = (async (input: RequestInfo | URL) => new Response(JSON.stringify( | |
| String(input).includes("subscription") | |
| ? { data: { hard_limit_usd: 100_000_000 } } | |
| : { data: { | |
| total_granted: 0, | |
| total_used: 0, | |
| total_available: 0, | |
| unlimited_quota: true, | |
| expires_at: 0, | |
| } }, | |
| ), { status: 200 })) as typeof fetch; | |
| const result = await fetchProviderQuotaReports(a6apiOnlyConfig(), true); | |
| expect(result.reports).toHaveLength(1); | |
| expect(result.reports[0]?.quota.creditsUsd).toEqual({ | |
| used: 0, | |
| limit: 0, | |
| remaining: 0, | |
| percent: 0, | |
| unlimited: true, | |
| }); | |
| expect(result.reports[0]?.quota.customWindows).toEqual([{ | |
| label: "Unlimited API credits", | |
| percent: 0, | |
| }]); | |
| }); | |
| test("A6API unlimited keys remain visible even when all finite credit totals are zero", async () => { | |
| globalThis.fetch = (async (input: RequestInfo | URL) => new Response(JSON.stringify( | |
| String(input).includes("subscription") | |
| ? { data: { hard_limit_usd: 100_000_000 } } | |
| : { data: { | |
| total_granted: 0, | |
| total_used: 0, | |
| total_available: 0, | |
| unlimited_quota: true, | |
| expires_at: "2027-01-01T00:00:00Z", | |
| } }, | |
| ), { status: 200 })) as typeof fetch; | |
| const result = await fetchProviderQuotaReports(a6apiOnlyConfig(), true); | |
| expect(result.reports).toHaveLength(1); | |
| expect(result.reports[0]?.quota.creditsUsd).toEqual({ | |
| used: 0, | |
| limit: 0, | |
| remaining: 0, | |
| percent: 0, | |
| unlimited: true, | |
| expiresAt: Date.parse("2027-01-01T00:00:00Z"), | |
| }); | |
| expect(result.reports[0]?.quota.customWindows).toEqual([{ | |
| label: "Unlimited API credits", | |
| percent: 0, | |
| }]); | |
| }); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/provider-quota.test.ts` around lines 300 - 327, Update the test around
fetchProviderQuotaReports to use a valid nonzero expires_at timestamp in the
mocked unlimited-quota response, then assert that the returned creditsUsd object
includes the same expiresAt value alongside its existing fields. Keep the test
focused on propagating expiry for unlimited accounts.
Source: Path instructions
e646862 to
d2f4991
Compare
Co-Authored-By: Codex <codex@openai.com>
d2f4991 to
162be68
Compare
|
Closing in favor of #1208, which adopts this change as-is. This PR needed no changes. It was independently re-audited against current Why it sat: 524 workflow runs were queued awaiting maintainer approval, 39 on open-PR branches including this one. The readiness gate verifies the Two observations recorded in #1208, neither blocking: Thanks for catching this — a working key showing as dead is exactly the kind of bug that erodes trust in the dashboard. |
Adopted from PR #1171 by @byongshintv, rebuilt on the current stack. Original closed in favor of this commit. An unlimited A6API key reports zero finite credit totals. Finite-total validation then treated that as a terminal failure and returned before the key could be represented at all, so a perfectly working key looked dead in the dashboard. The unlimited branch now runs ahead of that validation and emits the generic `customWindows` row the GUI and CLI already consume, preserving expiry. It accepts `true`, `1`, and `"true"` for the upstream flag. Two known limitations, stated rather than discovered later: `creditsUsd` and its expiry are not yet surfaced by the GUI — visibility comes from `customWindows` — and neither changes existing behavior for finite keys. Confirmed to fail with the unlimited branch disabled.
…-jun#1171) Adopted from PR lidge-jun#1171 by @byongshintv, rebuilt on the current stack. Original closed in favor of this commit. An unlimited A6API key reports zero finite credit totals. Finite-total validation then treated that as a terminal failure and returned before the key could be represented at all, so a perfectly working key looked dead in the dashboard. The unlimited branch now runs ahead of that validation and emits the generic `customWindows` row the GUI and CLI already consume, preserving expiry. It accepts `true`, `1`, and `"true"` for the upstream flag. Two known limitations, stated rather than discovered later: `creditsUsd` and its expiry are not yet surfaced by the GUI — visibility comes from `customWindows` — and neither changes existing behavior for finite keys. Confirmed to fail with the unlimited branch disabled.
Summary
Verification
bun run typecheckbun test tests/provider-quota.test.ts(86 pass, 0 fail)bun run privacy:scangit diff --check upstream/dev...HEADThe earlier full-suite run had one unrelated
tests/codex-sync-api.test.tsfailure, reproduced unchanged on a cleanupstream/devworktree. The focused quota suite and all static/privacy checks pass after rebasing onto the latestdev.Review readiness checklist
This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:
All CI tests are green on my local testing.
I pushed my PR to the latest dev commit.
I resolved all correct Codex and CodeRabbit findings.
My PR is ready for review.
Summary by CodeRabbit