mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
* fix: stop opencode-go quota lookup defaulting to Z.AI endpoint (#7022) getOpenCodeGoUsage() defaulted OPENCODE_GO_QUOTA_URL to https://api.z.ai/api/monitor/usage/quota/limit, a Zhipu AI (Z.AI/GLM) endpoint unrelated to opencode.ai. Whenever a connection had no dashboard-scraping config (workspaceId/authCookie), the user's real OpenCode Go API key was sent as a Bearer token to that third-party host by default, with no operator opt-in. Remove the hardcoded default: the quota-by-API-key fetch now only runs when the operator explicitly sets OMNIROUTE_OPENCODE_GO_QUOTA_URL. With it unset (the default), getOpenCodeGoUsage() returns a descriptive message and makes zero outbound calls, since OpenCode Go has no public quota API. Also updates .env.example and both EN/zh-CN copies of docs/reference/ENVIRONMENT.md to drop the stale Z.AI default value and fix the stale open-sse/services/usage.ts source-file reference. Regression test: tests/unit/opencode-go-quota-no-zai.test.ts (RED on current code, GREEN after the fix). * fix: align opencode-go-usage tests with opt-in quota URL contract (#7022) The prior commit removed the hardcoded api.z.ai default from OPENCODE_GO_QUOTA_URL, making the quota-by-API-key path opt-in via OMNIROUTE_OPENCODE_GO_QUOTA_URL. Six pre-existing tests in opencode-go-usage.test.ts still asserted the old default-fetch behavior and the old Z.AI-specific error wording, so they broke. Set OMNIROUTE_OPENCODE_GO_QUOTA_URL before the module import (the value is read once at load time) to simulate an operator who opted in, and update the two error-message assertions to the new generic wording ("the configured OMNIROUTE_OPENCODE_GO_QUOTA_URL endpoint" instead of "the Z.AI quota API"). Each test still verifies exactly the same behavior it did before (invalid key, fetch failure, 200 with auth error in body, invalid JSON, quota shape) — only the opt-in setup and message wording changed.
32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { test } from "node:test";
|
|
|
|
import { getOpenCodeGoUsage } from "../../open-sse/services/opencodeOllamaUsage.ts";
|
|
|
|
test("getOpenCodeGoUsage does not send the user's OpenCode Go API key to api.z.ai by default", async () => {
|
|
const originalFetch = globalThis.fetch;
|
|
const originalEnv = process.env.OMNIROUTE_OPENCODE_GO_QUOTA_URL;
|
|
delete process.env.OMNIROUTE_OPENCODE_GO_QUOTA_URL;
|
|
|
|
let calledHost: string | null = null;
|
|
globalThis.fetch = (async (input: RequestInfo | URL) => {
|
|
const url = typeof input === "string" ? input : input.toString();
|
|
calledHost = new URL(url).host;
|
|
throw new Error(`unexpected outbound fetch to ${url}`);
|
|
}) as typeof fetch;
|
|
|
|
try {
|
|
const result = await getOpenCodeGoUsage("sk-fake-opencode-go-key", undefined);
|
|
assert.notStrictEqual(calledHost, "api.z.ai");
|
|
assert.strictEqual(calledHost, null);
|
|
assert.ok(
|
|
typeof result.message === "string" && result.message.length > 0,
|
|
"expected a descriptive message when no quota URL is configured"
|
|
);
|
|
} finally {
|
|
globalThis.fetch = originalFetch;
|
|
if (originalEnv === undefined) delete process.env.OMNIROUTE_OPENCODE_GO_QUOTA_URL;
|
|
else process.env.OMNIROUTE_OPENCODE_GO_QUOTA_URL = originalEnv;
|
|
}
|
|
});
|