import assert from "node:assert/strict" import { test } from "node:test" import { buildCatalog, parseBundleMetadata, parseRates, parseReference, parseReferenceRow, sliceModelObject, } from "../../scripts/sync-catalog.mjs" /** Mirrors one row of the CLI reference table, including the em-dash placeholders. */ const referenceMarkdown = [ "| Id (use EXACTLY this) | Name | Context | Efforts | $/1M in/out · cache read | Min plan | Best for |", "|---|---|---|---|---|---|---|", "| `deepseek/deepseek-v4.1-flash` | DeepSeek V4.1 Flash | 1M | low, high, max | $0.15/$0.6 · cache $0.003 | Go and above | reasoning with vision |", "| `moonshotai/Kimi-K2.7-Code` | Kimi K2.7 Code | 256K | — | $0.95/$4 · cache $0.19 | Go and above | long-horizon coding |", "| `claude-sonnet-4-6` | Claude Sonnet 4.6 | 1M | low, medium, high, xhigh, max | $3/$15 · cache $0.3 (write $3.75) | Pro and above | fast and capable |", ].join("\n") /** Trimmed shape of the minified CLI model literal. */ const cliBundle = [ "var $L={SONNET:{id:\"claude-sonnet-4-6\",inputModalities:[\"text\",\"image\"],provider:\"x\",spec:\"chatComplete\",label:\"Claude Sonnet 4.6\",reasoning:!0,reasoningEfforts:[\"low\",\"medium\",\"high\",\"xhigh\",\"max\"],contextWindow:1e6},", "FLASH:{id:\"deepseek/deepseek-v4.1-flash\",inputModalities:[\"text\",\"image\"],provider:\"y\",spec:\"chatComplete\",label:\"DeepSeek V4.1 Flash\",reasoning:!0,reasoningEfforts:[\"low\",\"high\",\"max\"],contextWindow:1e6},", "KIMI:{id:\"moonshotai/Kimi-K2.7-Code\",inputModalities:[\"text\",\"image\"],provider:\"z\",spec:\"chatComplete\",label:\"Kimi K2.7 Code\",reasoning:!0,contextWindow:262144}};", ].join("") /** Output shape of the generator, asserted field by field below. */ interface CatalogEntry { id: string name: string contextWindow: number efforts: string[] reasoning: boolean input: string[] maxOutputTokens: number cost: { input: number; output: number; cacheRead: number; cacheWrite: number } } test("parseReference reads ids, names, efforts and rates", () => { const models = parseReference(referenceMarkdown) assert.deepEqual(models.map((model) => model.id), [ "deepseek/deepseek-v4.1-flash", "moonshotai/Kimi-K2.7-Code", "claude-sonnet-4-6", ]) assert.deepEqual(models[0]?.efforts, ["low", "high", "max"]) assert.deepEqual(models[1]?.efforts, []) assert.deepEqual(models[2]?.cost, { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 }) }) test("parseReference ignores header rows and rejects unknown efforts", () => { assert.equal(parseReferenceRow("| Id (use EXACTLY this) | Name | Context | Efforts |"), undefined) assert.throws( () => parseReference("| `m` | M | 1M | turbo | $1/$2 · cache $0 | Go |"), /Unknown effort/, ) }) test("parseRates handles free and cache-write pricing", () => { assert.deepEqual(parseRates("$0/$0 · cache $0"), { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }) assert.deepEqual(parseRates("$2/$6 · cache $0.25 (write $2.5)"), { input: 2, output: 6, cacheRead: 0.25, cacheWrite: 2.5, }) }) test("sliceModelObject extracts one nested literal from the minified bundle", () => { const entry = sliceModelObject(cliBundle, "moonshotai/Kimi-K2.7-Code") assert.ok(entry?.startsWith('{id:"moonshotai/Kimi-K2.7-Code",inputModalities:')) assert.ok(entry?.includes('contextWindow:262144}')) assert.ok(entry?.endsWith('contextWindow:262144}')) assert.equal(sliceModelObject(cliBundle, "missing/model"), undefined) }) test("parseBundleMetadata reports modalities, reasoning and limits", () => { const metadata = parseBundleMetadata(cliBundle, [ "claude-sonnet-4-6", "moonshotai/Kimi-K2.7-Code", ]) as Map assert.deepEqual(metadata.get("claude-sonnet-4-6")?.input, ["text", "image"]) assert.equal(metadata.get("claude-sonnet-4-6")?.reasoning, true) assert.equal(metadata.get("claude-sonnet-4-6")?.contextWindow, 1_000_000) // Reason-only models carry no effort list but still report reasoning. assert.equal(metadata.get("moonshotai/Kimi-K2.7-Code")?.reasoning, true) assert.equal(metadata.get("moonshotai/Kimi-K2.7-Code")?.maxOutputTokens, undefined) }) test("buildCatalog merges the reference table with bundle metadata", () => { const reference = parseReference(referenceMarkdown) const metadata = parseBundleMetadata( cliBundle, reference.map((model: { id: string }) => model.id), ) const catalog = buildCatalog("1.54.0", reference, metadata) as CatalogEntry[] assert.deepEqual(catalog.map((model) => model.id), reference.map((model) => model.id)) assert.deepEqual(catalog[0], { id: "deepseek/deepseek-v4.1-flash", name: "DeepSeek V4.1 Flash", contextWindow: 1_000_000, efforts: ["low", "high", "max"], reasoning: true, input: ["text", "image"], maxOutputTokens: 0, cost: { input: 0.15, output: 0.6, cacheRead: 0.003, cacheWrite: 0 }, }) assert.equal(catalog[1]?.reasoning, true) assert.equal(catalog[2]?.cost.cacheWrite, 3.75) })