import assert from "node:assert/strict"; import test from "node:test"; import { appSettingsSchema, appSettingsPatchSchema, } from "../../shared/src/validationAppSettings.js"; import { zcodeTaskMetaSchema } from "../../shared/src/validation.js"; import { readAskUserQuestionAnswers } from "../src/lib/askUserQuestion.js"; import { getAgentPrimaryText, getAgentKindLabel, } from "../src/ToolCallBlocks/renderers/agentHelpers.js"; import { getToolCallErrorText } from "../src/lib/toolError.js"; import { resolveToolCallIdentity } from "../src/lib/toolIdentity.js"; import { extractStructuredDiff } from "../src/lib/toolDiffPreview.js"; const meta = { taskId: "session-example", traceId: "trace-example", title: "Example", workspacePath: "/example/workspace", createdAt: 1, updatedAt: 2, mode: "build", provider: "glm", }; test("current task metadata is accepted without upgrading third-party Agent identities", () => { assert.equal(zcodeTaskMetaSchema.parse(meta).provider, "glm"); for (const provider of ["claude", "codex", "gemini", "opencode"]) { assert.equal(zcodeTaskMetaSchema.safeParse({ ...meta, provider }).success, false, provider); } }); test("obsolete Agent settings are stripped without dropping current user preferences", () => { const settings = { enabledBuiltinAgentCliProviders: ["claude", "codex"], localePreference: "en-US", }; for (const schema of [appSettingsSchema, appSettingsPatchSchema]) { const parsed = schema.parse(settings); assert.equal(parsed.localePreference, "en-US"); assert.equal("enabledBuiltinAgentCliProviders" in parsed, false); } }); test("current question results work while Claude ACP text is no longer interpreted as answers", () => { const input = { question: "Choose", options: [{ label: "One" }, { label: "Two" }] }; assert.deepEqual( readAskUserQuestionAnswers({ input, output: { type: "answered", selected: "One" } }), { Choose: "One" }, ); assert.deepEqual( readAskUserQuestionAnswers({ input, output: { type: "answered_custom", text: "Custom" } }), { Choose: "Custom" }, ); assert.deepEqual(readAskUserQuestionAnswers({ output: { answers: { Choose: "Two" } } }), { Choose: "Two", }); for (const output of ['"Choose"="One"', { content: [{ text: '"Choose"="One"' }] }]) { assert.equal(readAskUserQuestionAnswers({ input, output }), undefined); assert.equal(readAskUserQuestionAnswers({ input, raw: { output } }), undefined); assert.equal(readAskUserQuestionAnswers({ input, raw: { rawOutput: output } }), undefined); } }); test("ZCode subagent identity wins over retired Codex nicknames", () => { const tool = { id: "tool-example", kind: "Agent", title: "Agent", status: "completed" as const, input: { subagent_type: "researcher", description: "Inspect sources" }, raw: { nickname: "retired nickname" }, }; assert.equal(getAgentPrimaryText(tool, "Agent"), "Inspect sources"); assert.equal(getAgentKindLabel(tool, "Agent"), "researcher"); assert.equal(resolveToolCallIdentity({ toolName: "Task" }).family, "agent"); assert.equal(resolveToolCallIdentity({ kind: "spawn_agent" }).family, "unknown"); }); test("current tool errors remain available without Claude ACP status overrides", () => { assert.equal( getToolCallErrorText({ status: "failed", error: "Permission denied" }), "Permission denied", ); assert.equal( getToolCallErrorText({ status: "failed", output: "Invalid input", }), "Invalid input", ); assert.equal( getToolCallErrorText({ status: "completed", raw: { status: "failed", rawOutput: "legacy error" }, }), undefined, ); }); test("generic structured diffs still accept current tool content", () => { const diff = { type: "diff", path: "/example/file.ts", oldText: "before", newText: "after" }; assert.deepEqual(extractStructuredDiff({ content: [diff] }), { path: diff.path, oldText: diff.oldText, newText: diff.newText, }); });