Files
next-tjwater-agent/tests/chat/models.test.ts
T
jiang 7383ed6d13 feat(agent): migrate OpenCode 2 runtime and sandbox tools
Upgrade the runtime and native plugin API to OpenCode 2.0.24. Restore
session-scoped learning, credential renewal, typed project queries and
controlled frontend actions from the legacy Agent.

Replace host Shell execution with an approved Landlock/seccomp executor
and persistent per-session workspaces. Add typed Bocha search and Tianditu
geocoding bridges using the owning session credential. Require a working
kernel sandbox before startup and persist workspace files in deployments.

Validation completed before this commit: TypeScript checks, 150 Bun tests,
Docker build and UID 10001 sandbox execution, native Shell approval and
session recovery. Tianditu succeeded; Bocha currently reports exhausted
account quota. Unrelated investigation-report contract work is excluded.
2026-10-08 15:46:37 +08:00

71 lines
1.9 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import {
agentModelOptions,
isSupportedModel,
resolveDefaultModel,
supportedModels,
} from "../../src/chat/models.js";
import { 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("rejects unsupported default models", () => {
expect(resolveDefaultModel("deepseek/deepseek-v4-pro")).toBe(
"deepseek/deepseek-v4-pro",
);
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");
});
});