nonCliAcpRetirement.test.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import assert from "node:assert/strict";
  2. import test from "node:test";
  3. import {
  4. appSettingsSchema,
  5. appSettingsPatchSchema,
  6. } from "../../shared/src/validationAppSettings.js";
  7. import { zcodeTaskMetaSchema } from "../../shared/src/validation.js";
  8. import { readAskUserQuestionAnswers } from "../src/lib/askUserQuestion.js";
  9. import {
  10. getAgentPrimaryText,
  11. getAgentKindLabel,
  12. } from "../src/ToolCallBlocks/renderers/agentHelpers.js";
  13. import { getToolCallErrorText } from "../src/lib/toolError.js";
  14. import { resolveToolCallIdentity } from "../src/lib/toolIdentity.js";
  15. import { extractStructuredDiff } from "../src/lib/toolDiffPreview.js";
  16. const meta = {
  17. taskId: "session-example",
  18. traceId: "trace-example",
  19. title: "Example",
  20. workspacePath: "/example/workspace",
  21. createdAt: 1,
  22. updatedAt: 2,
  23. mode: "build",
  24. provider: "glm",
  25. };
  26. test("current task metadata is accepted without upgrading third-party Agent identities", () => {
  27. assert.equal(zcodeTaskMetaSchema.parse(meta).provider, "glm");
  28. for (const provider of ["claude", "codex", "gemini", "opencode"]) {
  29. assert.equal(zcodeTaskMetaSchema.safeParse({ ...meta, provider }).success, false, provider);
  30. }
  31. });
  32. test("obsolete Agent settings are stripped without dropping current user preferences", () => {
  33. const settings = {
  34. enabledBuiltinAgentCliProviders: ["claude", "codex"],
  35. localePreference: "en-US",
  36. };
  37. for (const schema of [appSettingsSchema, appSettingsPatchSchema]) {
  38. const parsed = schema.parse(settings);
  39. assert.equal(parsed.localePreference, "en-US");
  40. assert.equal("enabledBuiltinAgentCliProviders" in parsed, false);
  41. }
  42. });
  43. test("current question results work while Claude ACP text is no longer interpreted as answers", () => {
  44. const input = { question: "Choose", options: [{ label: "One" }, { label: "Two" }] };
  45. assert.deepEqual(
  46. readAskUserQuestionAnswers({ input, output: { type: "answered", selected: "One" } }),
  47. { Choose: "One" },
  48. );
  49. assert.deepEqual(
  50. readAskUserQuestionAnswers({ input, output: { type: "answered_custom", text: "Custom" } }),
  51. { Choose: "Custom" },
  52. );
  53. assert.deepEqual(readAskUserQuestionAnswers({ output: { answers: { Choose: "Two" } } }), {
  54. Choose: "Two",
  55. });
  56. for (const output of ['"Choose"="One"', { content: [{ text: '"Choose"="One"' }] }]) {
  57. assert.equal(readAskUserQuestionAnswers({ input, output }), undefined);
  58. assert.equal(readAskUserQuestionAnswers({ input, raw: { output } }), undefined);
  59. assert.equal(readAskUserQuestionAnswers({ input, raw: { rawOutput: output } }), undefined);
  60. }
  61. });
  62. test("ZCode subagent identity wins over retired Codex nicknames", () => {
  63. const tool = {
  64. id: "tool-example",
  65. kind: "Agent",
  66. title: "Agent",
  67. status: "completed" as const,
  68. input: { subagent_type: "researcher", description: "Inspect sources" },
  69. raw: { nickname: "retired nickname" },
  70. };
  71. assert.equal(getAgentPrimaryText(tool, "Agent"), "Inspect sources");
  72. assert.equal(getAgentKindLabel(tool, "Agent"), "researcher");
  73. assert.equal(resolveToolCallIdentity({ toolName: "Task" }).family, "agent");
  74. assert.equal(resolveToolCallIdentity({ kind: "spawn_agent" }).family, "unknown");
  75. });
  76. test("current tool errors remain available without Claude ACP status overrides", () => {
  77. assert.equal(
  78. getToolCallErrorText({ status: "failed", error: "Permission denied" }),
  79. "Permission denied",
  80. );
  81. assert.equal(
  82. getToolCallErrorText({
  83. status: "failed",
  84. output: "<tool_use_error>Invalid input</tool_use_error>",
  85. }),
  86. "Invalid input",
  87. );
  88. assert.equal(
  89. getToolCallErrorText({
  90. status: "completed",
  91. raw: { status: "failed", rawOutput: "legacy error" },
  92. }),
  93. undefined,
  94. );
  95. });
  96. test("generic structured diffs still accept current tool content", () => {
  97. const diff = { type: "diff", path: "/example/file.ts", oldText: "before", newText: "after" };
  98. assert.deepEqual(extractStructuredDiff({ content: [diff] }), {
  99. path: diff.path,
  100. oldText: diff.oldText,
  101. newText: diff.newText,
  102. });
  103. });