Skip to content

[WRONG BRANCH] feat: add OpenCode Go quota usage - #1543

Closed
Wibias wants to merge 1 commit into
mainfrom
feat/opencode-go-quota-usage
Closed

[WRONG BRANCH] feat: add OpenCode Go quota usage#1543
Wibias wants to merge 1 commit into
mainfrom
feat/opencode-go-quota-usage

Conversation

@Wibias

@Wibias Wibias commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • query OpenCode Go usage from GET /zen/go/v1/usage
  • map the rolling 5-hour, weekly, and monthly percentages and reset times into provider quota
  • authenticate with the configured OPENCODE_API_KEY bearer without exposing it in quota responses

Test plan

  • provider quota test for the Go usage endpoint, bearer auth, all three windows, reset timestamps, and credential redaction

Summary by CodeRabbit

  • Tests
    • Added coverage for OpenCode Go quota reporting.
    • Verified quota periods, reset times, report metadata, request authorization, endpoint behavior, and secret redaction.
    • Ensured test isolation by resetting cached quota state and network mocks between tests.

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.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

OpenCode Go quota reporting

Layer / File(s) Summary
Quota request and report validation
tests/provider-quota-opencode-go.test.ts
The test configures the provider, mocks the usage endpoint, checks the request URL, bearer authorization, and redirect mode, and verifies rolling, weekly, and monthly quota mappings, reset timestamps, report metadata, and API-key redaction. It resets quota cache state and the global fetch implementation between tests.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: ingwannu, lidge-jun

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding OpenCode Go quota usage support.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/opencode-go-quota-usage

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.

@github-actions

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the enhancement New feature or request label Aug 12, 2026
@Wibias
Wibias marked this pull request as ready for review August 12, 2026 15:58
@github-actions github-actions Bot changed the title feat: add OpenCode Go quota usage [WRONG BRANCH] feat: add OpenCode Go quota usage Aug 12, 2026
@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • wrong target branch (main); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.
  • Tick all four boxes in the PR description once you're done (currently 0/4).

Review readiness checklist

  • ⬜ 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.

0/4 boxes ticked.

Its title has been prefixed with [WRONG BRANCH].
This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.
@Wibias Tick the boxes once your local CI is green, your branch is on the latest dev commit, and every correct Codex and CodeRabbit finding is resolved.

@github-actions
github-actions Bot marked this pull request as draft August 12, 2026 15:59
@github-actions github-actions Bot added chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature). and removed enhancement New feature or request labels Aug 12, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4e0ffb2 and 784ba1f.

📒 Files selected for processing (1)
  • tests/provider-quota-opencode-go.test.ts

Comment on lines +32 to +55
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",
}]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

Suggested change
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.

@coderabbitai coderabbitai Bot mentioned this pull request Aug 12, 2026
4 tasks

Wibias commented Aug 12, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #1545, which is based on and targets dev.

@Wibias Wibias closed this Aug 12, 2026
@Wibias
Wibias deleted the feat/opencode-go-quota-usage branch August 12, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant