| 1 | import { readFileSync } from "node:fs"; |
| 2 | import { describe, expect, it } from "vitest"; |
| 3 | import { parseModelCatalog } from "./model-catalog.mjs"; |
| 4 | |
| 5 | const source = JSON.parse(readFileSync(new URL("../../crates/config/assets/models_dev.bundled.json", import.meta.url), "utf8")); |
| 6 | |
| 7 | describe("reviewed public model projection", () => { |
| 8 | it("preserves all public identities, labels and proven source-support dates", () => { |
| 9 | const rows = parseModelCatalog(source); |
| 10 | expect(rows).toHaveLength(78); |
| 11 | expect(new Set(rows?.map(row => row.id)).size).toBe(78); |
| 12 | for (const original of source._reviewed.public_models) { |
| 13 | expect(rows?.find(row => row.id === original.id)).toMatchObject({ provider: original.label, addedAt: original.added_at }); |
| 14 | } |
| 15 | expect(rows?.find(row => row.id === "kimi-k3")?.maxOutput).toBe(131072); |
| 16 | }); |
| 17 | |
| 18 | it("uses supplied exact source facts and labels without a build-time fallback", () => { |
| 19 | const fixture = structuredClone(source); |
| 20 | fixture._reviewed.public_models[0].label = "Exact pinned label"; |
| 21 | fixture._reviewed.intrinsic[fixture._reviewed.public_models[0].id.toLowerCase()].context_window = 123456; |
| 22 | const row = parseModelCatalog(JSON.stringify(fixture))?.find(row => row.id === fixture._reviewed.public_models[0].id); |
| 23 | expect(row?.provider).toBe("Exact pinned label"); |
| 24 | expect(row?.contextWindow).toBe(123456); |
| 25 | expect(parseModelCatalog(null)).toBeNull(); |
| 26 | expect(parseModelCatalog("not json")).toBeNull(); |
| 27 | expect(parseModelCatalog({ models: source.models, providers: source.providers })).toBeNull(); |
| 28 | }); |
| 29 | |
| 30 | it("does not union private configured or provider-scoped rows into public labels", () => { |
| 31 | const fixture = structuredClone(source); |
| 32 | fixture.providers.private = { models: { "private-label": { id: "private-label", reasoning: true, limit: { context: 999999 } } } }; |
| 33 | expect(parseModelCatalog(fixture)).toEqual(parseModelCatalog(source)); |
| 34 | fixture._reviewed.public_models.push({ id: "private-label", label: "Private", added_at: null, aliases: [] }); |
| 35 | expect(parseModelCatalog(fixture)).toBeNull(); |
| 36 | }); |
| 37 | |
| 38 | it("refuses duplicate, hostile, zero, boolean and malformed-date facts", () => { |
| 39 | const mutations = [ |
| 40 | (fixture: typeof source) => fixture._reviewed.public_models.push(fixture._reviewed.public_models[0]), |
| 41 | (fixture: typeof source) => fixture._reviewed.public_models[0].id = "hostile\u202ename", |
| 42 | (fixture: typeof source) => fixture._reviewed.public_models[0].label = "bad\u001b[31m", |
| 43 | (fixture: typeof source) => fixture._reviewed.public_models[0].added_at = "2026-99-99", |
| 44 | (fixture: typeof source) => fixture._reviewed.public_models[0].added_at = "2026-02-30", |
| 45 | (fixture: typeof source) => fixture._reviewed.intrinsic[fixture._reviewed.public_models[0].id.toLowerCase()].max_output = true, |
| 46 | (fixture: typeof source) => fixture._reviewed.intrinsic[fixture._reviewed.public_models[0].id.toLowerCase()].context_window = 0, |
| 47 | ]; |
| 48 | for (const mutate of mutations) { |
| 49 | const fixture = structuredClone(source); |
| 50 | mutate(fixture); |
| 51 | expect(parseModelCatalog(fixture)).toBeNull(); |
| 52 | } |
| 53 | }); |
| 54 | }); |
| 55 |