mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-13 18:32:12 +03:00
Real and nasty precisely because it is silent: `z.string().url()` accepts `localhost:20128` as scheme `localhost:` plus a path, every model gets published with an unusable api url, and the failure happens inside the client so the gateway logs show nothing. Backing the option schema, the publish boundary and the snapshot filter with one `isHttpUrl` in v2 is the right call — those three cannot drift apart. Duplicating the predicate in v1 rather than sharing it is also correct, since the two packages ship independently. --- Validated in one consolidated worktree cut from `release/v3.8.51`, boarded together with the rest of this batch — zero conflicts between them. - `typecheck:core` clean; `check:changelog-integrity` OK - complexity 2799 / baseline 3218 and cognitive-complexity 1265 / baseline 1437 — both under baseline - 86 focused assertions green across the batch's 10 unit test files, plus 16/16 on the v1 plugin option schema and 16/16 on the v2 option tests - `check-file-size` rebaselined for this batch's real growth (annotation `_rebaseline_2026_09_11_mergebatch_v3851_maxmad_opencode`, landed on #13141). `open-sse/utils/stream.ts` was deliberately left frozen: it is already 3115 > 3098 on the pure tip with zero contribution from this batch. ⚠️ base-red inherited: #12732 — `Docs Gates`, `Merge integrity`, `No new ESLint warnings`, `Unit Tests fast-path` and `Fast Quality Gates` all reproduce on the pure `release/v3.8.51` tip (provider count 356 vs the 358 the modules define, SKILL.md drift, and the `stream.ts` freeze above). None of them touch these diffs. Thanks @maxmad64bis.
125 lines
4.5 KiB
TypeScript
125 lines
4.5 KiB
TypeScript
/**
|
|
* T-08 options-schema tests.
|
|
*
|
|
* Covers `parseOmniRoutePluginOptions(opts)` — the strict Zod gate that
|
|
* validates the second-arg `PluginOptions` bag from opencode.json before
|
|
* any hook is wired. Anti-pattern checklist mirrored here:
|
|
*
|
|
* - `null` / `undefined` must collapse to `{}` (defaults apply downstream).
|
|
* - Unknown keys must THROW (`.strict()` catches opencode.json typos).
|
|
* - Validation runs at parse time, not import time (module loads cleanly).
|
|
*/
|
|
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { parseOmniRoutePluginOptions } from "../src/index.js";
|
|
|
|
test("parseOmniRoutePluginOptions: undefined → {}", () => {
|
|
assert.deepEqual(parseOmniRoutePluginOptions(undefined), {});
|
|
});
|
|
|
|
test("parseOmniRoutePluginOptions: null → {}", () => {
|
|
assert.deepEqual(parseOmniRoutePluginOptions(null), {});
|
|
});
|
|
|
|
test("parseOmniRoutePluginOptions: empty object → {}", () => {
|
|
assert.deepEqual(parseOmniRoutePluginOptions({}), {});
|
|
});
|
|
|
|
test("parseOmniRoutePluginOptions: valid providerId → returns it", () => {
|
|
const r = parseOmniRoutePluginOptions({ providerId: "omniroute-preprod" });
|
|
assert.equal(r.providerId, "omniroute-preprod");
|
|
});
|
|
|
|
test("parseOmniRoutePluginOptions: invalid providerId (special chars) → throws", () => {
|
|
assert.throws(
|
|
() => parseOmniRoutePluginOptions({ providerId: "omniroute prod!" }),
|
|
/providerId.*slug/i
|
|
);
|
|
});
|
|
|
|
test("parseOmniRoutePluginOptions: empty providerId → throws", () => {
|
|
assert.throws(() => parseOmniRoutePluginOptions({ providerId: "" }), /providerId/i);
|
|
});
|
|
|
|
test("parseOmniRoutePluginOptions: valid modelCacheTtl → returns it", () => {
|
|
const r = parseOmniRoutePluginOptions({ modelCacheTtl: 60_000 });
|
|
assert.equal(r.modelCacheTtl, 60_000);
|
|
});
|
|
|
|
test("parseOmniRoutePluginOptions: negative modelCacheTtl → throws", () => {
|
|
assert.throws(() => parseOmniRoutePluginOptions({ modelCacheTtl: -1 }), /modelCacheTtl/i);
|
|
});
|
|
|
|
test("parseOmniRoutePluginOptions: zero modelCacheTtl → throws (positive required)", () => {
|
|
assert.throws(() => parseOmniRoutePluginOptions({ modelCacheTtl: 0 }), /modelCacheTtl/i);
|
|
});
|
|
|
|
test("parseOmniRoutePluginOptions: invalid baseURL (not a URL) → throws", () => {
|
|
assert.throws(() => parseOmniRoutePluginOptions({ baseURL: "not-a-url" }), /baseURL/i);
|
|
});
|
|
|
|
test("parseOmniRoutePluginOptions: baseURL without an http(s) scheme → throws", () => {
|
|
// `new URL()` reads "localhost:20128" as the scheme "localhost:" followed by
|
|
// a path, so the address parses and the models are published with an api url
|
|
// no client can call.
|
|
for (const baseURL of ["localhost:20128", "localhost:20128/v1", "ftp://or.example.com", "or.example.com"]) {
|
|
assert.throws(
|
|
() => parseOmniRoutePluginOptions({ baseURL }),
|
|
/baseURL must be an http\(s\) URL/,
|
|
`expected ${baseURL} to be rejected`
|
|
);
|
|
}
|
|
});
|
|
|
|
test("parseOmniRoutePluginOptions: http and https baseURLs are accepted, padding trimmed", () => {
|
|
for (const baseURL of ["http://localhost:20128", "https://or.example.com/v1"]) {
|
|
assert.equal(parseOmniRoutePluginOptions({ baseURL }).baseURL, baseURL);
|
|
assert.equal(parseOmniRoutePluginOptions({ baseURL: ` ${baseURL} ` }).baseURL, baseURL);
|
|
}
|
|
});
|
|
|
|
test("parseOmniRoutePluginOptions: unknown key → throws (strict mode catches typos)", () => {
|
|
assert.throws(
|
|
() =>
|
|
parseOmniRoutePluginOptions({
|
|
providerId: "omniroute",
|
|
provider_id: "typo-here",
|
|
}),
|
|
/provider_id|unrecognized/i
|
|
);
|
|
});
|
|
|
|
test("parseOmniRoutePluginOptions: all four fields populated correctly → returns them", () => {
|
|
const opts = {
|
|
providerId: "omniroute-prod",
|
|
displayName: "OmniRoute Production",
|
|
modelCacheTtl: 120_000,
|
|
baseURL: "https://or.example.com/v1",
|
|
};
|
|
const r = parseOmniRoutePluginOptions(opts);
|
|
assert.deepEqual(r, opts);
|
|
});
|
|
|
|
test("parseOmniRoutePluginOptions: error message lists every issue path", () => {
|
|
// Two bad fields at once → error string should mention BOTH.
|
|
try {
|
|
parseOmniRoutePluginOptions({
|
|
providerId: "",
|
|
baseURL: "garbage",
|
|
});
|
|
assert.fail("expected throw");
|
|
} catch (err) {
|
|
const msg = (err as Error).message;
|
|
assert.match(msg, /providerId/);
|
|
assert.match(msg, /baseURL/);
|
|
}
|
|
});
|
|
|
|
test("parseOmniRoutePluginOptions: module import alone does NOT throw", async () => {
|
|
// Re-importing the entry must not trigger validation; validation only fires
|
|
// on explicit parseOmniRoutePluginOptions / OmniRoutePlugin invocation.
|
|
const mod = await import("../src/index.js");
|
|
assert.equal(typeof mod.parseOmniRoutePluginOptions, "function");
|
|
});
|