Files
OmniRoute/tests/unit/check-provider-consistency.test.ts
Tushar Agarwal a298dc6b73 feat(check): make serviceKinds required and add the reverse-walk provider consistency gate (#11392)
serviceKinds now drops .optional() in providerSchema.ts, and check-provider-consistency gains the reverse walk: a canonical provider whose serviceKinds include "llm" must have a REGISTRY entry unless it is in the new KNOWN_CATALOG_ONLY allowlist (providers routed through a connection baseUrl or a specialised executor). That turns "catalog entry outlived its registry entry" — the half-finished provider:remove — into a checkable invariant instead of something a reviewer has to notice.

Reconciled on merge, and worth reading before comparing diffs. The branch's 18 files had landed at the repository ROOT: git diff --name-status showed A gateways.ts, A providerSchema.ts, A check-provider-consistency.test.ts, A backfill-servicekinds.mjs with no directory component. The real provider files, schema, gate and test were never touched, so the +5093/-0 diff was root files AGENTS.md forbids (a test outside tests/, a script outside scripts/) and a no-op for the feature. The content was also 227 commits stale — the root gateways.ts was missing oneminai, among 267 divergent lines.

So each file's actual delta was reapplied onto the current tip rather than copied: the schema one-liner; the gate's KNOWN_CATALOG_ONLY, findCatalogOnlyLlmProviders(), the main() check and the summary line (the branch's copy also repeated the file header and imports at the end — 12 lines of residue from the same accident, dropped); the test's import block and five reverse-walk cases; and backfill-servicekinds.mjs placed at scripts/ad-hoc/, the path its own docstring names, then run against the current catalog: 315 insertions, 352/352 entries declaring serviceKinds, idempotent on a second run.

Two entries the mechanical pass could not get right, both surfaced by doing it against the live tree:

- github in oauth.ts is a single-line object, so the script's id:-per-line regex skipped it — the one failure it reported. Declared ["llm"] by hand, which is what the script's own rule computes.
- magnific came out as ["llm"] but is an image provider (icon: "image", registered in imageRegistry.ts). It is freepik renamed by migration 160, and freepik is in the script's NO_LLM set, so the rename left that set no longer matching. Your reverse walk caught it on its first run — a fair demonstration of why the gate is worth having. Corrected to [], with magnific added to NO_LLM and a note so a re-run cannot reintroduce it.

Verified: check:provider-consistency OK (268 REGISTRY entries, 352 canonical providers, 0 registry-only exceptions, 32 catalog-only), typecheck:core clean, 137/137 across the provider/schema/serviceKinds suites, check-file-size and check:cycles green.

Thanks @Tushar49 — the design is sound and the backfill script did the heavy lifting; only its placement and freshness needed fixing.
2026-09-02 00:32:53 -03:00

102 lines
3.9 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert";
import { AI_PROVIDERS } from "@/shared/constants/providers.ts";
import { REGISTRY } from "@omniroute/open-sse/config/providerRegistry.ts";
import {
findOrphanRegistryIds,
findCatalogOnlyLlmProviders,
KNOWN_REGISTRY_ONLY,
KNOWN_CATALOG_ONLY,
} from "../../scripts/check/check-provider-consistency.ts";
import { reportStaleEntries } from "../../scripts/check/lib/allowlist.mjs";
const known = new Set(["openai", "anthropic", "gemini"]);
const isKnown = (id: string) => known.has(id);
test("no orphans when every registry id is a known provider", () => {
assert.deepEqual(findOrphanRegistryIds(["openai", "anthropic"], isKnown, {}), []);
});
test("flags a registry id that is not a canonical provider (hallucinated/half-registered)", () => {
assert.deepEqual(findOrphanRegistryIds(["openai", "ghostprovider"], isKnown, {}), ["ghostprovider"]);
});
test("allowlisted ids are not flagged", () => {
assert.deepEqual(
findOrphanRegistryIds(["openai", "krutrim"], isKnown, { krutrim: "pré-existente" }),
[]
);
});
test("flags multiple orphans, preserves order", () => {
assert.deepEqual(findOrphanRegistryIds(["a", "openai", "b"], isKnown, {}), ["a", "b"]);
});
// --- stale-allowlist enforcement (6A.3) ---
test("stale-enforcement: allowlist entry no longer needed causes gate to flag it", () => {
// Simulate an allowlist with an entry that no longer has a live violation.
const liveOrphans: string[] = []; // violation was corrected
const stale = (reportStaleEntries as (a: string[], l: string[], g: string) => string[])(
["now-registered-provider"],
liveOrphans,
"provider-consistency"
);
assert.deepEqual(stale, ["now-registered-provider"]);
});
test("stale-enforcement: live repo has zero stale entries in KNOWN_REGISTRY_ONLY", () => {
// KNOWN_REGISTRY_ONLY is empty today; this test anchors that invariant and will
// catch any entry added without a corresponding live orphan.
assert.deepEqual(Object.keys(KNOWN_REGISTRY_ONLY as Record<string, string>), []);
});
// --- reverse walk (providers.ts → REGISTRY, #10513) ---
test("no reverse orphans when every llm provider has a REGISTRY entry", () => {
const canonical = {
openai: { serviceKinds: ["llm"] },
deepgram: { serviceKinds: [] }, // media-only, no registry needed
};
assert.deepEqual(findCatalogOnlyLlmProviders(canonical, ["openai"], {}), []);
});
test("flags an llm-kind canonical provider without REGISTRY entry (half-removed)", () => {
const canonical = {
deadprovider: { serviceKinds: ["llm"] },
openai: { serviceKinds: ["llm"] },
};
assert.deepEqual(findCatalogOnlyLlmProviders(canonical, ["openai"], {}), ["deadprovider"]);
});
test("non-llm providers without REGISTRY are not flagged (search/audio/local/media)", () => {
const canonical = {
"perplexity-search": { serviceKinds: ["webSearch"] },
deepgram: { serviceKinds: [] },
};
assert.deepEqual(findCatalogOnlyLlmProviders(canonical, [], {}), []);
});
test("allowlisted catalog-only providers are not flagged", () => {
const canonical = {
"azure-openai": { serviceKinds: ["llm"] },
};
assert.deepEqual(
findCatalogOnlyLlmProviders(canonical, [], { "azure-openai": "connection baseUrl" }),
[]
);
});
test("KNOWN_CATALOG_ONLY covers every live llm provider without REGISTRY entry", () => {
// Live-repo invariant: the allowlist + REGISTRY must together cover every
// llm-kind canonical provider. A NEW llm provider added to the catalog without
// a REGISTRY entry (or an allowlist entry) fails here — the exact gap
// pacocartones identified for provider:remove --dry-run verifiability.
const leftover = findCatalogOnlyLlmProviders(
AI_PROVIDERS as Record<string, { serviceKinds?: string[] }>,
Object.keys(REGISTRY as Record<string, unknown>),
KNOWN_CATALOG_ONLY
);
assert.deepEqual(leftover, []);
});