test: fold tiny media fallback specs

This commit is contained in:
Peter Steinberger
2026-04-24 19:01:13 +01:00
parent 7a63dd3f12
commit a16f8dff15
4 changed files with 91 additions and 98 deletions

View File

@@ -1,50 +0,0 @@
import { describe, expect, it, vi } from "vitest";
import { runWithImageModelFallback } from "./model-fallback.js";
import { makeModelFallbackCfg } from "./test-helpers/model-fallback-config-fixture.js";
describe("runWithImageModelFallback provider resolution", () => {
it("inherits the configured image-model provider for bare override ids", async () => {
const cfg = makeModelFallbackCfg({
agents: {
defaults: {
imageModel: {
primary: "openai-codex/gpt-5.4",
fallbacks: ["openai-codex/gpt-5.4-mini"],
},
},
},
});
const run = vi.fn().mockResolvedValueOnce("ok");
const result = await runWithImageModelFallback({
cfg,
modelOverride: "gpt-5.4-mini",
run,
});
expect(result.result).toBe("ok");
expect(run.mock.calls).toEqual([["openai-codex", "gpt-5.4-mini"]]);
});
it("keeps a fully qualified override provider over the configured default", async () => {
const cfg = makeModelFallbackCfg({
agents: {
defaults: {
imageModel: {
primary: "openai-codex/gpt-5.4",
},
},
},
});
const run = vi.fn().mockResolvedValueOnce("ok");
const result = await runWithImageModelFallback({
cfg,
modelOverride: "google/gemini-3-pro-image",
run,
});
expect(result.result).toBe("ok");
expect(run.mock.calls).toEqual([["google", "gemini-3-pro-image"]]);
});
});

View File

@@ -1896,6 +1896,51 @@ describe("runWithModelFallback", () => {
});
describe("runWithImageModelFallback", () => {
it("inherits the configured image-model provider for bare override ids", async () => {
const cfg = makeCfg({
agents: {
defaults: {
imageModel: {
primary: "openai-codex/gpt-5.4",
fallbacks: ["openai-codex/gpt-5.4-mini"],
},
},
},
});
const run = vi.fn().mockResolvedValueOnce("ok");
const result = await runWithImageModelFallback({
cfg,
modelOverride: "gpt-5.4-mini",
run,
});
expect(result.result).toBe("ok");
expect(run.mock.calls).toEqual([["openai-codex", "gpt-5.4-mini"]]);
});
it("keeps a fully qualified override provider over the configured default", async () => {
const cfg = makeCfg({
agents: {
defaults: {
imageModel: {
primary: "openai-codex/gpt-5.4",
},
},
},
});
const run = vi.fn().mockResolvedValueOnce("ok");
const result = await runWithImageModelFallback({
cfg,
modelOverride: "google/gemini-3-pro-image",
run,
});
expect(result.result).toBe("ok");
expect(run.mock.calls).toEqual([["google", "gemini-3-pro-image"]]);
});
it("keeps explicit image fallbacks reachable when models allowlist is present", async () => {
const cfg = makeCfg({
agents: {

View File

@@ -1,47 +0,0 @@
import { describe, expect, it, vi } from "vitest";
import { resolveModelFromRegistry } from "./media-tool-shared.js";
describe("resolveModelFromRegistry", () => {
it("normalizes provider and model refs before registry lookup", () => {
const foundModel = { provider: "ollama", id: "qwen3.5:397b-cloud" };
const find = vi.fn(() => foundModel);
const result = resolveModelFromRegistry({
modelRegistry: { find },
provider: " OLLAMA ",
modelId: " qwen3.5:397b-cloud ",
});
expect(find).toHaveBeenCalledWith("ollama", "qwen3.5:397b-cloud");
expect(result).toBe(foundModel);
});
it("reports the normalized ref when the registry lookup misses", () => {
const find = vi.fn(() => null);
expect(() =>
resolveModelFromRegistry({
modelRegistry: { find },
provider: " OLLAMA ",
modelId: " qwen3.5:397b-cloud ",
}),
).toThrow("Unknown model: ollama/qwen3.5:397b-cloud");
});
it("falls back to provider-prefixed custom model IDs", () => {
const foundModel = { provider: "kimchi", id: "kimchi/claude-opus-4-6" };
const find = vi.fn().mockReturnValueOnce(null).mockReturnValueOnce(foundModel);
const result = resolveModelFromRegistry({
modelRegistry: { find },
provider: "kimchi",
modelId: "claude-opus-4-6",
});
expect(find.mock.calls).toEqual([
["kimchi", "claude-opus-4-6"],
["kimchi", "kimchi/claude-opus-4-6"],
]);
expect(result).toBe(foundModel);
});
});

View File

@@ -1,7 +1,7 @@
import path from "node:path";
import { pathToFileURL } from "node:url";
import { afterEach, describe, expect, it, vi } from "vitest";
import { resolveMediaToolLocalRoots } from "./media-tool-shared.js";
import { resolveMediaToolLocalRoots, resolveModelFromRegistry } from "./media-tool-shared.js";
function normalizeHostPath(value: string): string {
return path.normalize(path.resolve(value));
@@ -35,3 +35,48 @@ describe("resolveMediaToolLocalRoots", () => {
expect(normalizedRoots).not.toContain(normalizeHostPath("/"));
});
});
describe("resolveModelFromRegistry", () => {
it("normalizes provider and model refs before registry lookup", () => {
const foundModel = { provider: "ollama", id: "qwen3.5:397b-cloud" };
const find = vi.fn(() => foundModel);
const result = resolveModelFromRegistry({
modelRegistry: { find },
provider: " OLLAMA ",
modelId: " qwen3.5:397b-cloud ",
});
expect(find).toHaveBeenCalledWith("ollama", "qwen3.5:397b-cloud");
expect(result).toBe(foundModel);
});
it("reports the normalized ref when the registry lookup misses", () => {
const find = vi.fn(() => null);
expect(() =>
resolveModelFromRegistry({
modelRegistry: { find },
provider: " OLLAMA ",
modelId: " qwen3.5:397b-cloud ",
}),
).toThrow("Unknown model: ollama/qwen3.5:397b-cloud");
});
it("falls back to provider-prefixed custom model IDs", () => {
const foundModel = { provider: "kimchi", id: "kimchi/claude-opus-4-6" };
const find = vi.fn().mockReturnValueOnce(null).mockReturnValueOnce(foundModel);
const result = resolveModelFromRegistry({
modelRegistry: { find },
provider: "kimchi",
modelId: "claude-opus-4-6",
});
expect(find.mock.calls).toEqual([
["kimchi", "claude-opus-4-6"],
["kimchi", "kimchi/claude-opus-4-6"],
]);
expect(result).toBe(foundModel);
});
});