Files
oh-my-pi/packages/coding-agent/test/tiny-models-cli.test.ts
T
roboomp f5be8953c4 fix(cli): surfaced tiny model download errors
Preserved worker-side download errors through TinyTitleClient and included them in tiny-models text and JSON failures.

Fixes #3839
2026-06-29 22:56:40 +00:00

54 lines
2.2 KiB
TypeScript

import { afterEach, describe, expect, it, spyOn, vi } from "bun:test";
import { resolveModels, runTinyModelsCommand } from "@oh-my-pi/pi-coding-agent/cli/tiny-models-cli";
import { TINY_LOCAL_MODELS } from "@oh-my-pi/pi-coding-agent/tiny/models";
import { tinyTitleClient } from "@oh-my-pi/pi-coding-agent/tiny/title-client";
afterEach(() => {
vi.restoreAllMocks();
});
describe("tiny-models download model resolution", () => {
it("excludes load-blocked models from `all` so the bulk prefetch stays green", () => {
const unsupported = TINY_LOCAL_MODELS.filter(spec => "unsupportedReason" in spec && spec.unsupportedReason).map(
spec => spec.key,
);
// Guard: keep this regression meaningful — at least one registry entry must be load-blocked.
expect(unsupported.length).toBeGreaterThan(0);
const all = resolveModels("all");
for (const key of unsupported) expect(all).not.toContain(key);
const usable = TINY_LOCAL_MODELS.filter(spec => !("unsupportedReason" in spec) || !spec.unsupportedReason).map(
spec => spec.key,
);
for (const key of usable) expect(all).toContain(key);
});
it("still resolves an explicitly requested unsupported model (only `all` is filtered)", () => {
const blocked = TINY_LOCAL_MODELS.find(spec => "unsupportedReason" in spec && spec.unsupportedReason);
expect(blocked).toBeDefined();
if (!blocked) return;
expect(resolveModels(blocked.key)).toEqual([blocked.key]);
});
it("includes worker error details in JSON failures", async () => {
const output: string[] = [];
spyOn(process.stdout, "write").mockImplementation((chunk: string | Uint8Array) => {
output.push(typeof chunk === "string" ? chunk : new TextDecoder().decode(chunk));
return true;
});
spyOn(tinyTitleClient, "downloadModel").mockResolvedValue({
ok: false,
error: "Error: runtime install failed\n at worker",
});
await expect(
runTinyModelsCommand({ action: "download", model: "lfm2-700m", flags: { json: true } }),
).rejects.toThrow("One or more tiny title models failed to download");
expect(JSON.parse(output.join(""))).toEqual({
results: [{ model: "lfm2-700m", ok: false, error: "Error: runtime install failed\n at worker" }],
});
});
});