Files
OmniRoute/tests/unit/cli-tools.test.ts
Xiangzhe 9df1781065 fix(tests): drain second-wave base reds from the moving tip (#10952, #11205 follow-ups)
The base advanced twice past the branch cut (15 + 2 merges); the PR's CI
surfaced five more reds on the merged head, each discriminated:

1. check-env-doc-sync + Docs Gates: OMNIROUTE_BUILDING referenced in code
   (src/lib/buildPhase.ts, db/core, callLogArtifacts — build-phase stub
   signal from #10060 via #10952) but missing from .env.example /
   ENVIRONMENT.md. Fix: document it in both (never-set-for-server note).

2. db-core-init 'build phase uses an in-memory database' — STALE TEST:
   #10060 deliberately replaced the real in-memory build DB with a no-op
   stub (native better-sqlite3 aborts the Next.js build worker on exit,
   node::RemoveEnvironmentCleanupHook); the stub contract is pinned by
   tests/unit/build/10060-build-sqlite-stub.test.ts. The old test pinned
   the superseded contract (real memory DB with migrations). Aligned:
   stub driver, no-op queries, no file created.

3. 8134-github-t5-fallback-filter — STALE FIXTURE: #10952 added
   claude-opus-4.6 to the github registry, invalidating the fixture's
   'no 4.6 tier' assumption. The provably-absent tier moved to
   claude-opus-4-6-thinking (still absent); test rewritten against the
   real ladder (4.8 -> 4.7 -> 4.6 -> skip 4-6-thinking -> 4.5), keeping
   the original #8134 regression assertion (absent tier never returned).

4. cli-tools Codex/Copilot fingerprint — STALE PIN: #10952 bumped
   GITHUB_COPILOT_CLI_VERSION 0.54.0 -> 1.0.81-6 without the sibling
   fingerprint pin. Assertion aligned to GitHubCopilotChat/1.0.81-6.

5. stryker.conf.json — drop a duplicate tap.testFiles entry for
   quota-exhaustion-cutoff-opencode.test.ts created by the merge (the
   base registered it too after my fix in 17f5e4e0e9).

Validation: env-doc-sync gate green; 8134 2/2, cli-tools 23/23,
db-core-init build-phase test, check-env-doc-sync.test.ts all
RED->GREEN locally (node --import tsx/esm --test).

Refs #9985
2026-08-23 17:45:01 -03:00

126 lines
4.7 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
const { CLI_TOOLS } = await import("../../src/shared/constants/cliTools.ts");
const {
CLI_COMPAT_PROVIDER_IDS,
CLI_COMPAT_OMITTED_PROVIDER_IDS,
CLI_COMPAT_TOGGLE_IDS,
IMPLEMENTED_CLI_FINGERPRINT_PROVIDER_IDS,
normalizeCliCompatProviderId,
} = await import("../../src/shared/constants/cliCompatProviders.ts");
const { CLI_TOOL_IDS } = await import("../../src/shared/services/cliRuntime.ts");
const { hasRegisteredAgent } = await import("../../src/lib/acp/registry.ts");
const { applyFingerprint, isCliCompatEnabled, setCliCompatProviders } =
await import("../../open-sse/config/cliFingerprints.ts");
test("Amp CLI was removed from CLI_TOOLS per plan 14 D17 (MITM backlog plan 11)", () => {
// amp (Sourcegraph) removed from CLI_TOOLS in plan 14 because it has a closed ecosystem
// and does not support a generic custom base URL. Cross-ref: plan 11 MITM backlog.
assert.equal((CLI_TOOLS as Record<string, unknown>).amp, undefined);
// amp may still appear in cliRuntime.ts (runtime detection catalog — separate from UI catalog)
assert.equal(CLI_COMPAT_PROVIDER_IDS.includes("amp"), false);
});
test("Hermes quick-config is registered as a guide-based CLI tool", () => {
const hermes = CLI_TOOLS.hermes;
assert.ok(hermes);
assert.equal(hermes.configType, "guide");
assert.equal(hermes.defaultCommand, "hermes");
assert.ok(Array.isArray(hermes.guideSteps));
assert.ok(String(hermes.codeBlock?.code || "").includes('"baseURL": "{{baseUrl}}"'));
assert.ok(CLI_TOOL_IDS.includes("hermes"));
});
test("ACP registry accepts the Gemini CLI target used by the manager", () => {
assert.equal(hasRegisteredAgent("gemini"), true);
assert.equal(hasRegisteredAgent("definitely-not-an-agent"), false);
});
test("CLI fingerprint toggles only expose implemented fingerprints and functional legacy aliases", () => {
const implemented = new Set<string>(IMPLEMENTED_CLI_FINGERPRINT_PROVIDER_IDS);
for (const providerId of CLI_COMPAT_PROVIDER_IDS) {
assert.equal(
implemented.has(providerId),
true,
`${providerId} should have an implemented fingerprint`
);
}
for (const toggleId of CLI_COMPAT_TOGGLE_IDS) {
const providerId = normalizeCliCompatProviderId(toggleId);
assert.equal(
implemented.has(providerId),
true,
`${toggleId} should map to an implemented fingerprint provider`
);
}
for (const providerId of IMPLEMENTED_CLI_FINGERPRINT_PROVIDER_IDS) {
assert.equal(CLI_COMPAT_PROVIDER_IDS.includes(providerId), true);
}
for (const providerId of CLI_COMPAT_OMITTED_PROVIDER_IDS) {
assert.equal(CLI_COMPAT_PROVIDER_IDS.includes(providerId), false);
assert.equal((CLI_COMPAT_TOGGLE_IDS as readonly string[]).includes(providerId), false);
}
assert.equal(CLI_COMPAT_TOGGLE_IDS.includes("copilot"), true);
assert.equal((CLI_COMPAT_TOGGLE_IDS as readonly string[]).includes("github"), false);
});
test("CLI fingerprint strips OmniRoute internal body fields before upstream serialization", () => {
const claude = applyFingerprint(
"claude",
{ Authorization: "Bearer token" },
{
model: "claude-sonnet-4-6",
messages: [],
stream: true,
_claudeCodeRequiresLowercaseToolNames: true,
}
);
const body = JSON.parse(claude.bodyString);
assert.equal(body._claudeCodeRequiresLowercaseToolNames, undefined);
assert.deepEqual(Object.keys(body), ["model", "messages", "stream"]);
});
test("CLI fingerprint preserves Codex executor User-Agent and maps legacy Copilot alias", () => {
const codex = applyFingerprint(
"codex",
{
Authorization: "Bearer token",
"User-Agent": "codex-cli/0.144.1 (Windows 10.0.26200; x64)",
},
{ model: "gpt-5.5", messages: [], stream: true }
);
assert.equal(codex.headers["User-Agent"], "codex-cli/0.144.1 (Windows 10.0.26200; x64)");
assert.deepEqual(Object.keys(JSON.parse(codex.bodyString)), ["model", "stream", "messages"]);
const copilot = applyFingerprint(
"copilot",
{ Authorization: "Bearer token", Accept: "application/json" },
{ model: "gpt-4o", messages: [] }
);
// #10952 bumped GITHUB_COPILOT_CLI_VERSION 0.54.0 -> 1.0.81-6; the fingerprint
// pin tracks the advertised upstream CLI version.
assert.equal(copilot.headers["User-Agent"], "GitHubCopilotChat/1.0.81-6");
});
test("CLI fingerprint keeps legacy Copilot settings functional without exposing duplicate UI toggles", () => {
assert.equal(normalizeCliCompatProviderId("copilot"), "github");
assert.equal(normalizeCliCompatProviderId("GitHub"), "github");
try {
setCliCompatProviders(["copilot"]);
assert.equal(isCliCompatEnabled("github"), true);
assert.equal(isCliCompatEnabled("copilot"), true);
} finally {
setCliCompatProviders([]);
}
});