mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-18 21:22:28 +03:00
- canonical executable manifest (bin/cli/cli-manifest.mjs): run/configure/completion derive targets, aliases and --model wiring from one table; drift test cross-checks manifest x cliRuntime x UI catalog (tests/unit/cli/cli-manifest-drift.test.ts) - dashboard Codex generator converged to ~/.codex/config.toml (modern Codex v0.137+, verified against codex-cli 0.147.0): conservative merge, env_key auth (key never written), refuses invalid TOML, reports legacy config.yaml as migration note - omniroute run gemini: launcher over OmniRoute's /v1beta surface via GOOGLE_GEMINI_BASE_URL + isolated GEMINI_CLI_HOME forcing gemini-api-key auth (contract proven against @google/gemini-cli 0.50.0); ACP registration kept distinct - opt-in real smoke harness for upstream CLIs (RUN_CLI_SMOKE=1, credential by env NAME, redacted output): tests/integration/upstream-cli-smoke.int.test.ts - container-guard homologation for POST /api/cli-tools/apply (422 in container, dry-run preview allowed, host write passes) + docs; guard untouched - typecheck: omniglyphAdapter union narrowing, usageTracking typed signatures (UsageLike, no any), models.ts isValidModel params — typecheck:core and typecheck:noimplicit:core now clean - relay core (prior session of this effort): omniroute run for 6 CLIs, configure picker with per-context favorites/recents, contexts with optional keychain + 0600 fallback, provider CRUD with recursive redaction, completion updates, docs
137 lines
4.2 KiB
TypeScript
137 lines
4.2 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import {
|
|
buildProviderPayload,
|
|
findConnectionFromResponse,
|
|
redactProviderResponse,
|
|
resolveProviderCredential,
|
|
runProviderAddCommand,
|
|
} from "../../../bin/cli/commands/provider-crud.mjs";
|
|
|
|
test("provider payload separates management auth from provider credential", () => {
|
|
const payload = buildProviderPayload(
|
|
"glm",
|
|
{
|
|
name: "work",
|
|
defaultModel: "glm/glm-5.2",
|
|
priority: "2",
|
|
providerSpecificData: '{"region":"global"}',
|
|
apiKey: "management-token-that-must-not-be-used",
|
|
},
|
|
"provider-secret"
|
|
);
|
|
|
|
assert.deepEqual(payload, {
|
|
provider: "glm",
|
|
name: "work",
|
|
apiKey: "provider-secret",
|
|
defaultModel: "glm/glm-5.2",
|
|
priority: 2,
|
|
providerSpecificData: { region: "global" },
|
|
});
|
|
});
|
|
|
|
test("provider selector resolves id, prefix, name, and provider", () => {
|
|
const body = {
|
|
connections: [
|
|
{ id: "abc-123", name: "Work GLM", provider: "glm" },
|
|
{ id: "def-456", name: "OpenAI", provider: "openai" },
|
|
],
|
|
};
|
|
|
|
assert.equal(findConnectionFromResponse(body, "abc-123")?.name, "Work GLM");
|
|
assert.equal(findConnectionFromResponse(body, "def")?.name, "OpenAI");
|
|
assert.equal(findConnectionFromResponse(body, "work glm")?.id, "abc-123");
|
|
assert.equal(findConnectionFromResponse(body, "openai")?.id, "def-456");
|
|
assert.equal(findConnectionFromResponse(body, "missing"), null);
|
|
});
|
|
|
|
test("provider credential can be resolved from a validated environment name", async () => {
|
|
const previous = process.env.TEST_PROVIDER_SECRET;
|
|
process.env.TEST_PROVIDER_SECRET = "secret-from-env";
|
|
try {
|
|
assert.equal(
|
|
await resolveProviderCredential({ credentialEnv: "TEST_PROVIDER_SECRET" }, { prompt: false }),
|
|
"secret-from-env"
|
|
);
|
|
await assert.rejects(
|
|
resolveProviderCredential({ credentialEnv: "bad-name;rm" }, { prompt: false }),
|
|
/valid env name/
|
|
);
|
|
} finally {
|
|
if (previous === undefined) delete process.env.TEST_PROVIDER_SECRET;
|
|
else process.env.TEST_PROVIDER_SECRET = previous;
|
|
}
|
|
});
|
|
|
|
test("dry-run credential resolution never prompts or requires a secret", async () => {
|
|
assert.equal(await resolveProviderCredential({}, { prompt: false }), undefined);
|
|
assert.deepEqual(buildProviderPayload("glm", { name: "work" }, undefined), {
|
|
provider: "glm",
|
|
name: "work",
|
|
});
|
|
});
|
|
|
|
test("negated --no-credential is treated as a control flag, not the literal string", async () => {
|
|
assert.equal(
|
|
await resolveProviderCredential({ credential: false }, { prompt: false }),
|
|
undefined
|
|
);
|
|
assert.deepEqual(buildProviderPayload("ollama", { name: "local" }, undefined), {
|
|
provider: "ollama",
|
|
name: "local",
|
|
});
|
|
});
|
|
|
|
test("provider JSON output redacts raw credentials recursively", () => {
|
|
const redacted = redactProviderResponse({
|
|
connection: {
|
|
id: "conn-1",
|
|
apiKey: "provider-secret",
|
|
providerSpecificData: { client_secret: "oauth-secret" },
|
|
credentialRef: "omniroute-cli:context:remote",
|
|
},
|
|
token: "management-secret",
|
|
});
|
|
|
|
assert.deepEqual(redacted, {
|
|
connection: {
|
|
id: "conn-1",
|
|
apiKey: { present: true, length: 15 },
|
|
providerSpecificData: { client_secret: { present: true, length: 12 } },
|
|
credentialRef: "omniroute-cli:context:remote",
|
|
},
|
|
token: { present: true, length: 17 },
|
|
});
|
|
});
|
|
|
|
test("provider OAuth dry-run never starts a browser or mutates the server", async () => {
|
|
assert.equal(
|
|
await runProviderAddCommand("openai", { oauth: true, dryRun: true, silent: true }),
|
|
0
|
|
);
|
|
});
|
|
|
|
test("provider add dry-run redacts provider-specific secrets", async () => {
|
|
const output: string[] = [];
|
|
const originalLog = console.log;
|
|
console.log = (...args: unknown[]) => output.push(args.join(" "));
|
|
try {
|
|
assert.equal(
|
|
await runProviderAddCommand("glm", {
|
|
dryRun: true,
|
|
yes: true,
|
|
json: true,
|
|
providerSpecificData: JSON.stringify({ client_secret: "oauth-secret" }),
|
|
}),
|
|
0
|
|
);
|
|
} finally {
|
|
console.log = originalLog;
|
|
}
|
|
const serialized = output.join("\n");
|
|
assert.ok(!serialized.includes("oauth-secret"));
|
|
assert.match(serialized, /client_secret/);
|
|
});
|