Files
OmniRoute/tests/unit/model-alias-seed.test.ts
diegosouzapw 34e8b3e243 test: repair pre-existing test-suite failures (batch 2) + real source-bug fixes
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.
2026-05-22 13:10:48 -03:00

76 lines
2.8 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-alias-seed-"));
process.env.DATA_DIR = TEST_DATA_DIR;
const core = await import("../../src/lib/db/core.ts");
const modelsDb = await import("../../src/lib/db/models.ts");
const sseModelService = await import("../../src/sse/services/model.ts");
const { DEFAULT_MODEL_ALIAS_SEED, seedDefaultModelAliases } =
await import("../../src/lib/modelAliasSeed.ts");
async function resetStorage() {
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
}
test.beforeEach(async () => {
await resetStorage();
});
test.after(async () => {
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
});
test("default model alias seed writes missing aliases and is idempotent", async () => {
const first = await seedDefaultModelAliases();
const aliases = await modelsDb.getModelAliases();
assert.deepEqual(first.failed, []);
assert.equal(first.applied.length, Object.keys(DEFAULT_MODEL_ALIAS_SEED).length);
assert.equal(aliases["gemini-3-pro-high"], "gemini-cli/gemini-3.1-pro-preview");
assert.equal(aliases["gemini-3-pro-low"], "gemini-cli/gemini-3.1-flash-lite-preview");
assert.equal(aliases["gemini-3-pro-preview"], "gemini-cli/gemini-3.1-pro-preview");
assert.equal(aliases["gemini-3.1-pro-preview"], "gemini-cli/gemini-3.1-pro-preview");
assert.equal(aliases["gemini-3-flash-preview"], "gemini-cli/gemini-3-flash-preview");
const routed = await sseModelService.getModelInfo("gemini-3-pro-high");
assert.deepEqual(routed, {
provider: "gemini-cli",
model: "gemini-3.1-pro-preview",
extendedContext: false,
});
const second = await seedDefaultModelAliases();
assert.equal(second.applied.length, 0);
assert.equal(second.failed.length, 0);
assert.equal(second.skipped.length, Object.keys(DEFAULT_MODEL_ALIAS_SEED).length);
});
test("default model alias seed preserves existing aliases and skips invalid entries", async () => {
await modelsDb.setModelAlias("gemini-3-pro-high", "custom/provider-model");
const warnings = [];
const result = await seedDefaultModelAliases({
logger: {
warn: (message) => warnings.push(String(message)),
},
seedMap: {
...DEFAULT_MODEL_ALIAS_SEED,
"broken-entry": null,
},
});
const aliases = await modelsDb.getModelAliases();
assert.equal(aliases["gemini-3-pro-high"], "custom/provider-model");
assert.ok(result.skipped.includes("gemini-3-pro-high"));
assert.ok(result.failed.includes("broken-entry"));
assert.ok(warnings.some((message) => message.includes("broken-entry")));
});