From fa11eaef5f4da66c2064cf1fda0e87154930bdda Mon Sep 17 00:00:00 2001 From: SB Yoon <44089734+yansigit@users.noreply.github.com> Date: Fri, 4 Sep 2026 22:08:26 -0600 Subject: [PATCH] fix(ci): restore quota reset route coverage --- .../ocx/references/01_management_surface.md | 19 ++++++++++++++++++- src/cli/capabilities.ts | 12 ++++++++++++ src/server/management-api.ts | 2 +- src/server/management/route-registry.ts | 2 ++ tests/gui/rate-limit-reset-credits.test.ts | 1 + tests/usage/quota-reset-notify.test.ts | 17 +++++++---------- 6 files changed, 41 insertions(+), 12 deletions(-) diff --git a/skills/ocx/references/01_management_surface.md b/skills/ocx/references/01_management_surface.md index 36438d2f68..1e08569b69 100644 --- a/skills/ocx/references/01_management_surface.md +++ b/skills/ocx/references/01_management_surface.md @@ -72,6 +72,23 @@ JSON mode: `envelope`. - Reads local config; drives no management API route. +### `ocx provider resets` + +Show recently detected quota resets. + +| Method | Route | +|---|---| +| GET | `/api/quota-resets` | + +| Flag | Value | Meaning | +|---|---|---| +| `--limit` | number | Maximum number of reset events to return. | +| `--json` | boolean | Emit the reset-event payload as JSON. | + +JSON mode: `payload`. + +- An empty result distinguishes notifications being disabled from no reset having been detected yet. + ### `ocx account list` Codex OAuth accounts with pool priority and pause state. @@ -587,6 +604,6 @@ JSON mode: `payload`. ## Counts -- declared capabilities: 32 +- declared capabilities: 33 - of those, state-changing: 13 - head-resolved invocations: 2 diff --git a/src/cli/capabilities.ts b/src/cli/capabilities.ts index 6fcdd7cb16..432af28f29 100644 --- a/src/cli/capabilities.ts +++ b/src/cli/capabilities.ts @@ -153,6 +153,18 @@ export const CAPABILITIES: readonly Capability[] = [ json: "envelope", details: ["Reads local config; drives no management API route."], }, + { + command: ["provider", "resets"], + summary: "Show recently detected quota resets.", + routes: [{ method: "GET", path: "/api/quota-resets" }], + flags: [ + { name: "--limit", value: "number", summary: "Maximum number of reset events to return." }, + { name: "--json", value: "boolean", summary: "Emit the reset-event payload as JSON." }, + ], + mutates: false, + json: "payload", + details: ["An empty result distinguishes notifications being disabled from no reset having been detected yet."], + }, { command: ["provider", "keychain"], summary: "Move a provider's API key into the OS keychain, restore it, or report where it lives.", diff --git a/src/server/management-api.ts b/src/server/management-api.ts index f5478a8077..f1749bc78e 100644 --- a/src/server/management-api.ts +++ b/src/server/management-api.ts @@ -138,7 +138,7 @@ async function handleLabRoutesOnDemand(ctx: ManagementContext): Promise { - if (ctx.url.pathname !== "/api/quota-resets") return null; + if (!pathInManagementNamespace(ctx.url.pathname, "/api/quota-resets")) return null; const { handleQuotaResetRoutes } = await import("./management/quota-reset-routes"); return handleQuotaResetRoutes(ctx); } diff --git a/src/server/management/route-registry.ts b/src/server/management/route-registry.ts index 8add87803d..db2c011a06 100644 --- a/src/server/management/route-registry.ts +++ b/src/server/management/route-registry.ts @@ -81,6 +81,8 @@ export interface ManagementRoute { export const MANAGEMENT_ROUTES: readonly ManagementRoute[] = [ // server/management-api { method: "POST", path: "/api/stop", module: "server/management-api", mutates: true }, + // server/management/quota-reset-routes + { method: "GET", path: "/api/quota-resets", module: "server/management/quota-reset-routes", mutates: false }, // codex/auth-api { method: "DELETE", path: "/api/codex-auth/accounts", module: "codex/auth-api", mutates: true }, { method: "GET", path: "/api/codex-auth/accounts", module: "codex/auth-api", mutates: false }, diff --git a/tests/gui/rate-limit-reset-credits.test.ts b/tests/gui/rate-limit-reset-credits.test.ts index 4300136701..f80643ddff 100644 --- a/tests/gui/rate-limit-reset-credits.test.ts +++ b/tests/gui/rate-limit-reset-credits.test.ts @@ -504,6 +504,7 @@ describe("rate-limit reset credits", () => { shortPercent: 97, shortResetAt: 1787401330, shortWindowSeconds: 18000, + shortObservedAt: expect.any(Number), weeklyPercent: 12, weeklyResetAt: 1788000000, updatedAt: expect.any(Number), diff --git a/tests/usage/quota-reset-notify.test.ts b/tests/usage/quota-reset-notify.test.ts index fb053e10d8..7d0a8a574c 100644 --- a/tests/usage/quota-reset-notify.test.ts +++ b/tests/usage/quota-reset-notify.test.ts @@ -481,14 +481,11 @@ describe("activation is the single switch", () => { // The end-to-end proof: config -> activation -> the production quota writer -> HTTP body. // Every earlier test exercises one link; this is the only one that shows the chain holds. const bodies: string[] = []; - const server = Bun.serve({ - port: 0, - hostname: "127.0.0.1", - async fetch(req) { - bodies.push(await req.text()); - return new Response("ok"); - }, - }); + const realFetch = globalThis.fetch; + globalThis.fetch = (async (_input: unknown, init?: RequestInit) => { + bodies.push(String(init?.body ?? "")); + return new Response("ok"); + }) as typeof globalThis.fetch; const home = mkdtempSync(join(tmpdir(), "ocx-live-")); writeFileSync(join(home, "config.json"), JSON.stringify({ @@ -499,7 +496,7 @@ describe("activation is the single switch", () => { }, quotaResetNotify: { enabled: true, - webhookUrl: `http://127.0.0.1:${server.port}/hook`, + webhookUrl: "https://hooks.example.test/quota-reset", allowPrivateNetwork: true, // Passive-only: this asserts the live request path fires without any timer involved. pollSeconds: 0, @@ -543,7 +540,7 @@ describe("activation is the single switch", () => { resetQuotaResetActivationForTests(); resetQuotaResetNotifyCacheForTests(); clearAccountQuota(); - server.stop(true); + globalThis.fetch = realFetch; if (previousHome === undefined) delete process.env["OPENCODEX_HOME"]; else process.env["OPENCODEX_HOME"] = previousHome; }