Open History to see the last commit
1// @effect-diagnostics nodeBuiltinImport:off - compares the generated bundle directly with its checked-in bytes.
2import * as NodeFS from "node:fs";
3
4import { catalog } from "@handy-computer/models";
5import { expect, it } from "vite-plus/test";
6
7import manifest from "../package.json" with { type: "json" };
8import { generateSpeechCatalog, renderSpeechCatalog } from "./speech-catalog.ts";
9
10const generate = (models = catalog.models) =>
11 generateSpeechCatalog(
12 { ...catalog.data, models },
13 manifest.devDependencies["@handy-computer/models"],
14 manifest.dependencies["transcribe-cpp"],
15 );
16
17it("reproduces the bundled registry byte for byte without upstream requests", async () => {
18 expect(NodeFS.readFileSync(new URL("../src/speech/catalog.json", import.meta.url), "utf8")).toBe(
19 await renderSpeechCatalog(
20 catalog.data,
21 manifest.devDependencies["@handy-computer/models"],
22 manifest.dependencies["transcribe-cpp"],
23 ),
24 );
25 for (const model of generate().models) {
26 const source = catalog.models.find((entry) => entry.repository === model.id)!;
27 expect(model).toMatchObject({
28 revision: source.revision,
29 name: source.name,
30 ...source.files[source.quant],
31 supportsStreaming: source.capabilities.streaming,
32 supportsLanguageDetection: source.capabilities.languageDetection,
33 supportsTranslation: source.capabilities.translate,
34 });
35 }
36 const parakeet = catalog.models[0]!;
37 const withoutFrenchOrSpeed = generateSpeechCatalog(
38 {
39 ...catalog.data,
40 models: [{ ...parakeet, languages: ["en", "fr"] }],
41 results: { [parakeet.id]: { accuracy: { en: { error: 3.99 } }, performance: {} } },
42 },
43 "0.2.3",
44 "0.4.1",
45 );
46 expect(withoutFrenchOrSpeed.models[0]?.benchmark).toEqual({
47 accuracy: { en: { grade: "A-", errorPercent: 3.99 } },
48 secondsPer30s: null,
49 });
50 expect(generate().models[0]?.benchmark.secondsPer30s).toBeCloseTo(1.19, 2);
51});
52
53it("filters restricted licenses, unsupported roles, engines, architectures and files", () => {
54 const model = catalog.models[0]!;
55 for (const override of [
56 { role: "langid" as const },
57 { role: "vad" as const },
58 { role: "diarize" as const },
59 { license: "cc-by-nc-4.0" },
60 { license: "CC-BY-NC-SA-4.0" },
61 { license: "cc-by-nc-nd-3.0" },
62 { license: "cc-by-nc" },
63 { license: "CC BY-NC 4.0" },
64 { license: "custom_NC" },
65 { minEngine: "0.4.2" },
66 { minEngine: "0.5.0" },
67 { family: "future_arch" },
68 ...[
69 "nested/model.gguf",
70 "nested\\model.gguf",
71 "../model.gguf",
72 "model.bin",
73 "model.safetensors",
74 ].map((filename) => ({ files: { [model.quant]: { ...model.files[model.quant]!, filename } } })),
75 ]) {
76 expect(generate([{ ...model, ...override }]).models).toEqual([]);
77 }
78 for (const license of ["other", "apache-2.0", "cc-by-4.0", "cc-by-sa-4.0", "unlicense"]) {
79 expect(generate([{ ...model, license, minEngine: "0.4.1" }]).models).toHaveLength(1);
80 }
81 const moonshine = catalog.models.find((entry) => entry.id === "moonshine-tiny-ja")!;
82 for (const [id, allowed] of [
83 ["moonshine-tiny-ja", false],
84 ["moonshine-base-vi", false],
85 ["moonshine-base-es", false],
86 ["moonshine-base", true],
87 ["moonshine-streaming-tiny-ja", true],
88 ] as const) {
89 const entry = { ...moonshine, id, repository: `handy-computer/${id}-gguf`, license: "mit" };
90 expect(generate([entry]).models, id).toHaveLength(allowed ? 1 : 0);
91 }
92});
93
94it("rejects missing defaults, unpinned or corrupt metadata, collisions, and unreviewed engine/schema changes", () => {
95 const model = catalog.models[0]!;
96 const file = model.files[model.quant]!;
97 for (const override of [
98 { files: {} },
99 { revision: "main" },
100 { repository: "../model" },
101 { languages: [] },
102 ...[{ sha256: "bad" }, { size: 0 }, { size: 1.5 }].map((entry) => ({
103 files: { [model.quant]: { ...file, ...entry } },
104 })),
105 ]) {
106 expect(() => generate([{ ...model, ...override }])).toThrow();
107 }
108 expect(() => generate([model, model])).toThrow(/Duplicate/);
109 expect(() => generate([model, { ...model, repository: "handy-computer/another" }])).toThrow(
110 /Duplicate/,
111 );
112 expect(() => generateSpeechCatalog(catalog.data, "0.2.3", "0.4.2")).toThrow(/loader support/);
113 expect(() =>
114 generateSpeechCatalog({ ...catalog.data, schema: 3 as 2 }, "0.2.3", "0.4.1"),
115 ).toThrow(/schema/);
116});