Files
TJWaterAgent/tests/chat/models.test.ts
T
jiang 4c09eb39cd
Generic Container CI/CD / test-build-publish (push) Canceled after 30m50s
Agent CI/CD v2 / build-test-publish-and-deploy (push) Canceled after 30m41s
fix(agent): align DeepSeek Flash model references
2026-09-25 14:38:03 +08:00

80 lines
2.1 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import {
agentModelOptions,
isSupportedModel,
resolveDefaultModel,
supportedModels,
} from "../../src/chat/models.js";
import {
defaultAgentModelOptions,
getAgentModelIds,
parseAgentModelOptions,
} from "../../src/chat/modelConfig.js";
describe("agent model config", () => {
it("keeps every exposed option in the supported model list", () => {
expect(agentModelOptions.map((model) => model.id)).toEqual(supportedModels);
expect(
agentModelOptions.every(
(model) => model.label && model.description && model.icon,
),
).toBe(true);
});
it("validates supported model ids", () => {
expect(isSupportedModel(supportedModels[0])).toBe(true);
expect(isSupportedModel("unknown/model")).toBe(false);
});
it("defaults to the currently selectable DeepSeek models", () => {
expect(getAgentModelIds(defaultAgentModelOptions)).toEqual([
"deepseek/deepseek-flash",
"deepseek/deepseek-v4-pro",
]);
});
it("rejects unsupported default models", () => {
expect(resolveDefaultModel(supportedModels[0])).toBe(supportedModels[0]);
expect(() => resolveDefaultModel("unknown/model")).toThrow(
"unsupported default agent model",
);
});
it("parses full model option config from JSON", () => {
expect(
parseAgentModelOptions(
JSON.stringify([
{
id: "provider/model",
label: "自定义",
description: "自定义模型",
icon: "bolt",
},
]),
),
).toEqual([
{
id: "provider/model",
label: "自定义",
description: "自定义模型",
icon: "bolt",
},
]);
});
it("rejects invalid model option config", () => {
expect(() => parseAgentModelOptions("not-json")).toThrow(
"OPENCODE_MODEL_OPTIONS must be valid JSON",
);
expect(() =>
parseAgentModelOptions(
JSON.stringify([
{ id: "provider/model", label: "模型" },
{ id: "provider/model", label: "重复模型" },
]),
),
).toThrow("duplicate OPENCODE_MODEL_OPTIONS id");
});
});