mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-07 07:42:13 +03:00
Repaired 47 of 49 pre-existing failing unit test files on release/v3.8.2 (down to docs-site-overhaul, a tr46/tsx/Node24 toolchain blocker, tracked separately). Stale tests reconciled with current source (catalog/registry/version drift), the notable ones: openai gpt-4o / gpt-4o-mini removed from the registry; Antigravity Claude models removed from the public catalog; DEFAULT_CLAUDE_CODE_VERSION and DEFAULT_CODEX_CLIENT_VERSION bumps; voyage-3-large → voyage-4; model-alias seed now routes via gemini-cli; remapToolNames API change; getLKGP return shape; sidebar nav overhaul; CLI commands now write via process.stdout.write; cloudEnabled default true. Real SOURCE bugs found by the tests and fixed (not masked): - fix(db): commandCodeAuth.toSafeStatus + evals.ts read the `*Json` camel keys that rowToCamel does not produce — it auto-parses `*_json` columns under the base name, so metadata/outputs/summary/results/tags were always empty. Read the base keys. - fix(executors): re-register claude-web / cw-web in the executor index (the provider shipped in #2476 but was never wired into the registry). - fix(validation): build the OpenAI-like /models probe with addModelsSuffix so an OpenAI base URL validates against /v1/models, not /v1/chat/completions/models; honor a ya29.* Google OAuth token as Bearer even when authType is apikey/header (it was shadowed by an unreachable else-if); make the Anthropic /models probe best-effort (try/catch) so a 404/malformed-URL throw no longer marks a valid key invalid. - fix(security): add the requireCliToolsAuth guard to the GET handlers of cli-tools/guide-settings/[toolId] and cli-tools/hermes-agent-settings (host config access was unguarded). - revert(stream): restore the SSE heartbeat default to 15s (the 4s round-8 change regressed runtime-timeouts; #2544's early-keepalive route wrapper remains the fix). Also: env-doc sync (OMNIROUTE_SKIP_DB_HEALTHCHECK) and new sidebar i18n keys.
64 lines
2.8 KiB
TypeScript
64 lines
2.8 KiB
TypeScript
/**
|
|
* Issue #2247 — disambiguation of the Qoder OAuth/CLI vs API-key error
|
|
* surface in the provider test route. These tests cover the small helper
|
|
* extracted from src/app/api/providers/[id]/test/route.ts (`hasQoderToken`)
|
|
* to confirm the new branching logic.
|
|
*
|
|
* We intentionally keep this as a focused unit test of the helper rather
|
|
* than spinning up the full route, because the route handler runs SQLite
|
|
* migrations + the OAuth refresh path which require an isolated DATA_DIR
|
|
* and are covered elsewhere.
|
|
*/
|
|
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
|
|
const ROUTE_FILE = path.resolve("src/app/api/providers/[id]/test/route.ts");
|
|
|
|
test("#2247 — route.ts exposes Qoder PAT disambiguation message", () => {
|
|
const source = fs.readFileSync(ROUTE_FILE, "utf8");
|
|
|
|
// The new message tells the user how to fix it instead of just "CLI not installed"
|
|
assert.match(
|
|
source,
|
|
/Personal Access Token is stored on this connection\. Switch this connection to API Key auth/,
|
|
"expected the disambiguated Qoder message to be present in test/route.ts"
|
|
);
|
|
});
|
|
|
|
test("#2247 — hasQoderToken helper detects connection-level apiKey", () => {
|
|
const source = fs.readFileSync(ROUTE_FILE, "utf8");
|
|
// Helper must be exported as a function so the dis-ambiguation branch
|
|
// resolves the token presence correctly.
|
|
assert.match(source, /function hasQoderToken\(connection: any\): boolean/);
|
|
// It checks both apiKey and providerSpecificData.{personalAccessToken,pat,accessToken}
|
|
assert.match(source, /connection\?\.apiKey/);
|
|
assert.match(source, /personalAccessToken/);
|
|
});
|
|
|
|
test("#2247 — disambiguated branch is gated on Qoder + non-apikey + token present", () => {
|
|
const source = fs.readFileSync(ROUTE_FILE, "utf8");
|
|
assert.match(source, /isQoderOauthWithToken\s*=\s*\n?\s*provider === "qoder"/);
|
|
assert.match(source, /connection\?\.authType !== "apikey"/);
|
|
assert.match(source, /hasQoderToken\(connection\)/);
|
|
});
|
|
|
|
test("#2247 — original generic 'Local CLI runtime is not installed' is kept for non-Qoder providers", () => {
|
|
const source = fs.readFileSync(ROUTE_FILE, "utf8");
|
|
assert.match(source, /"Local CLI runtime is not installed"/);
|
|
});
|
|
|
|
test("#2247 — early-return on runtime diagnosis short-circuits upstream test", () => {
|
|
const source = fs.readFileSync(ROUTE_FILE, "utf8");
|
|
// The caller must check runtime?.diagnosis first and not fall through to
|
|
// upstream auth tests (which is what produces the cascading 401).
|
|
const runtimeBlock = source.split("getProviderRuntimeStatus(connection);")[1] || "";
|
|
assert.match(
|
|
runtimeBlock.slice(0, 600),
|
|
/if \(\(runtime as any\)\?\.diagnosis\)/,
|
|
"expected the route to check runtime?.diagnosis immediately after getProviderRuntimeStatus()"
|
|
);
|
|
});
|