Files
OmniRoute/tests/unit/github-live-catalog-combo-12137.test.ts
Ravi Tharuma 6aa3690dea feat(providers): filter GitHub combo members against live catalog (#12473)
Validado em lote numa worktree combinada com os 10 PRs desta leva sobre o tip de `release/v3.8.51`: `typecheck:core` limpo, `check-file-size` OK e **241/242** nos 29 arquivos de teste que os PRs tocam.

A única "falha" não é falha: `tests/unit/autoCombo/strict-zero-cost-filter.test.ts` é um teste em estilo Vitest que eu incluí por engano na invocação do runner nativo do Node — ele quebra no import (`@vitest/runner`), não numa asserção. Ao investigar, descobri que esse arquivo não roda em nenhum dos dois runners hoje (o glob do `test:unit` não lista `autoCombo` e o `include` do Vitest só pega `.tsx` nessa pasta); é um problema pré-existente do repositório, sem relação com esta leva, e vou registrá-lo separadamente.

O #12636 conflitava apenas na lista de testes do `@omniroute/opencode-plugin/package.json`, de forma aditiva: o tip já tinha `models-fetcher.test.ts` (do #12607, irmão desta mesma leva) e o #12636 acrescenta `telemetry.test.ts`. Fiz a união dos dois lados (25 arquivos contra 24 de cada) em vez de escolher um, o que teria removido um arquivo da suíte do plugin em silêncio.

Obrigado, @RaviTharuma.
2026-09-03 23:39:43 -03:00

87 lines
3.0 KiB
TypeScript

/**
* #12137 — explicit GitHub combo members vs live synced catalog.
*/
import test from "node:test";
import assert from "node:assert/strict";
import { catalogContainsModel } from "../../src/lib/db/models/activeSyncedCatalog.ts";
import {
comboCheckProvider,
ghComboGate,
} from "../../src/sse/handlers/chat/githubLiveCatalogFilter.ts";
test("fail-open when the GitHub catalog is not authoritative yet", () => {
assert.equal(
catalogContainsModel(
{
authoritative: false,
models: [{ id: "claude-sonnet-5", name: "Claude Sonnet 5", source: "imported" }],
},
"claude-sonnet-5"
),
null
);
});
test("rejects explicit members missing from an authoritative GitHub catalog", () => {
assert.equal(
catalogContainsModel(
{
authoritative: true,
models: [{ id: "claude-sonnet-5", name: "Claude Sonnet 5", source: "imported" }],
},
"github/claude-fable-5"
),
false
);
});
test("accepts prefixed and bare ids that are in the live catalog", () => {
const catalog = {
authoritative: true,
models: [{ id: "claude-sonnet-5", name: "Claude Sonnet 5", source: "imported" }],
};
assert.equal(catalogContainsModel(catalog, "claude-sonnet-5"), true);
assert.equal(catalogContainsModel(catalog, "github/claude-sonnet-5"), true);
});
test("comboCheckProvider applies the prefix-override guard", () => {
assert.equal(comboCheckProvider("github/claude-sonnet-5", { provider: "github" }), "github");
assert.equal(
comboCheckProvider("github/claude-sonnet-5", { provider: "github" }, "github"),
"github"
);
assert.equal(
comboCheckProvider("xiaomi/mimo-v2-flash", { provider: "xiaomi" }, "opengate"),
"opengate"
);
assert.equal(comboCheckProvider("gh/claude-sonnet-5", { provider: "github" }, "gh"), "github");
});
test("ghComboGate allows undetermined providers and fail-opens unsynced catalogs", async () => {
const scope = {};
const unsynced = async () => ({
authoritative: false,
models: [{ id: "claude-sonnet-5", name: "Claude Sonnet 5", source: "imported" as const }],
});
assert.equal(await ghComboGate(scope, "", "claude-sonnet-5", unsynced), true);
assert.equal(await ghComboGate(scope, "openai", "gpt-4", unsynced), null);
assert.equal(await ghComboGate(scope, "github", "claude-sonnet-5", unsynced), null);
});
test("ghComboGate skips GitHub members missing from an authoritative catalog", async () => {
const scope = {};
let loads = 0;
const load = async () => {
loads += 1;
return {
authoritative: true,
models: [{ id: "claude-sonnet-5", name: "Claude Sonnet 5", source: "imported" as const }],
};
};
assert.equal(await ghComboGate(scope, "github", "claude-fable-5", load), false);
assert.equal(await ghComboGate(scope, "github", "claude-sonnet-5", load), null);
assert.equal(await ghComboGate(scope, "github", "github/claude-sonnet-5", load), null);
assert.equal(loads, 1, "catalog fetch is memoized per request scope");
assert.equal(await ghComboGate({}, "gh", "claude-fable-5", load), false);
});