[WRONG BRANCH] feat: add OpenCode Go quota usage - #1543
Conversation
📝 WalkthroughWalkthroughThe PR adds an end-to-end OpenCode Go quota test. It validates the usage request, quota mappings, reset timestamps, report metadata, API-key redaction, and test-state cleanup. ChangesOpenCode Go quota reporting
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 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 |
|
✅ Deterministic PR hygiene checks passed. |
⏳ DRAFT
What to do
Review readiness checklist
0/4 boxes ticked. Its title has been prefixed with |
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-opencode-go.test.ts`:
- Around line 32-55: Update the fetch mock and assertion in the quota test
around fetchProviderQuotaReports and the seen request records to capture
init?.method, then require the recorded usage request method to equal "GET"
alongside the existing URL, authorization, and redirect expectations.
🪄 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: 0ec2000b-a7c0-44b4-8374-5206a96e828e
📒 Files selected for processing (1)
tests/provider-quota-opencode-go.test.ts
| const seen: Array<{ url: string; authorization: string | null; redirect?: RequestRedirect }> = []; | ||
| globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => { | ||
| const url = String(input); | ||
| const headers = new Headers(init?.headers); | ||
| seen.push({ url, authorization: headers.get("authorization"), redirect: init?.redirect }); | ||
| if (url !== "https://opencode.ai/zen/go/v1/usage") { | ||
| return new Response("not found", { status: 404 }); | ||
| } | ||
| return new Response(JSON.stringify({ | ||
| usage: { | ||
| rolling: { percent: 12, resetsAt: "2026-08-12T18:00:00Z" }, | ||
| weekly: { percent: 8, resetsAt: "2026-08-17T00:00:00Z" }, | ||
| monthly: { percent: 35, resetsAt: "2026-09-01T00:00:00Z" }, | ||
| }, | ||
| }), { status: 200, headers: { "content-type": "application/json" } }); | ||
| }) as typeof fetch; | ||
|
|
||
| const result = await fetchProviderQuotaReports(openCodeGoConfig(), true); | ||
|
|
||
| expect(seen).toEqual([{ | ||
| url: "https://opencode.ai/zen/go/v1/usage", | ||
| authorization: "Bearer opencode-go-secret", | ||
| redirect: "error", | ||
| }]); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Assert the HTTP method for the usage request.
The mock does not capture init?.method. A POST or another non-GET request to the correct URL would pass this test. Capture method and assert "GET" in seen.
Proposed test update
- const seen: Array<{ url: string; authorization: string | null; redirect?: RequestRedirect }> = [];
+ const seen: Array<{ url: string; method: string; authorization: string | null; redirect?: RequestRedirect }> = [];
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
const url = String(input);
const headers = new Headers(init?.headers);
- seen.push({ url, authorization: headers.get("authorization"), redirect: init?.redirect });
+ seen.push({
+ url,
+ method: init?.method ?? "GET",
+ authorization: headers.get("authorization"),
+ redirect: init?.redirect,
+ });
...
url: "https://opencode.ai/zen/go/v1/usage",
+ method: "GET",
authorization: "Bearer opencode-go-secret",📝 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.
| const seen: Array<{ url: string; authorization: string | null; redirect?: RequestRedirect }> = []; | |
| globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => { | |
| const url = String(input); | |
| const headers = new Headers(init?.headers); | |
| seen.push({ url, authorization: headers.get("authorization"), redirect: init?.redirect }); | |
| if (url !== "https://opencode.ai/zen/go/v1/usage") { | |
| return new Response("not found", { status: 404 }); | |
| } | |
| return new Response(JSON.stringify({ | |
| usage: { | |
| rolling: { percent: 12, resetsAt: "2026-08-12T18:00:00Z" }, | |
| weekly: { percent: 8, resetsAt: "2026-08-17T00:00:00Z" }, | |
| monthly: { percent: 35, resetsAt: "2026-09-01T00:00:00Z" }, | |
| }, | |
| }), { status: 200, headers: { "content-type": "application/json" } }); | |
| }) as typeof fetch; | |
| const result = await fetchProviderQuotaReports(openCodeGoConfig(), true); | |
| expect(seen).toEqual([{ | |
| url: "https://opencode.ai/zen/go/v1/usage", | |
| authorization: "Bearer opencode-go-secret", | |
| redirect: "error", | |
| }]); | |
| const seen: Array<{ url: string; method: string; authorization: string | null; redirect?: RequestRedirect }> = []; | |
| globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => { | |
| const url = String(input); | |
| const headers = new Headers(init?.headers); | |
| seen.push({ | |
| url, | |
| method: init?.method ?? "GET", | |
| authorization: headers.get("authorization"), | |
| redirect: init?.redirect, | |
| }); | |
| if (url !== "https://opencode.ai/zen/go/v1/usage") { | |
| return new Response("not found", { status: 404 }); | |
| } | |
| return new Response(JSON.stringify({ | |
| usage: { | |
| rolling: { percent: 12, resetsAt: "2026-08-12T18:00:00Z" }, | |
| weekly: { percent: 8, resetsAt: "2026-08-17T00:00:00Z" }, | |
| monthly: { percent: 35, resetsAt: "2026-09-01T00:00:00Z" }, | |
| }, | |
| }), { status: 200, headers: { "content-type": "application/json" } }); | |
| }) as typeof fetch; | |
| const result = await fetchProviderQuotaReports(openCodeGoConfig(), true); | |
| expect(seen).toEqual([{ | |
| url: "https://opencode.ai/zen/go/v1/usage", | |
| method: "GET", | |
| authorization: "Bearer opencode-go-secret", | |
| redirect: "error", | |
| }]); |
🤖 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-opencode-go.test.ts` around lines 32 - 55, Update the
fetch mock and assertion in the quota test around fetchProviderQuotaReports and
the seen request records to capture init?.method, then require the recorded
usage request method to equal "GET" alongside the existing URL, authorization,
and redirect expectations.
|
Superseded by #1545, which is based on and targets |
Summary
GET /zen/go/v1/usageOPENCODE_API_KEYbearer without exposing it in quota responsesTest plan
Summary by CodeRabbit
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.