tool-result-display.test.ts 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  1. import {
  2. parseToolResultDisplayPayload,
  3. ZCODE_MCP_NODE_REPL_CUA_APP_META_KEY,
  4. } from "@zcode/contracts";
  5. import { toolCallGetWorkflowRunDisplaySchema } from "@zcode/shared/zcode-protocol-v4";
  6. import { describe, expect, it } from "vitest";
  7. import {
  8. createMcpToolDisplay,
  9. createToolResultDisplay,
  10. } from "../src/tool/executor/result-display.js";
  11. describe("tool result display", () => {
  12. it("creates trusted MCP presentation before a tool result exists", () => {
  13. expect(
  14. createMcpToolDisplay({
  15. serverName: "plugin:firebase:firebase",
  16. toolName: "firebase_get_environment",
  17. description: "Get the active Firebase environment.",
  18. }),
  19. ).toEqual({
  20. kind: "mcp_tool",
  21. serverName: "plugin:firebase:firebase",
  22. toolName: "firebase_get_environment",
  23. description: "Get the active Firebase environment.",
  24. });
  25. });
  26. it("projects trusted MCP discovery metadata without deriving it from the synthetic tool name", () => {
  27. const display = createToolResultDisplay(
  28. "custom-provider-visible-name",
  29. { content: [{ type: "text", text: "ok" }] },
  30. {
  31. mcp: {
  32. serverName: "company-github-prod",
  33. toolName: "issue_query_v2",
  34. description: "Query issues visible to the current user.",
  35. },
  36. },
  37. );
  38. expect(display).toEqual({
  39. kind: "mcp_tool",
  40. serverName: "company-github-prod",
  41. toolName: "issue_query_v2",
  42. description: "Query issues visible to the current user.",
  43. });
  44. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  45. });
  46. it("carries the official MCP unavailable code from the tool error payload", () => {
  47. const display = createToolResultDisplay(
  48. "mcp__zcode-official__search_image",
  49. {
  50. content: [
  51. {
  52. type: "text",
  53. text: '{"error_code":"quota_exceeded","message":"daily quota exceeded for bucket search_image (5/5)","request_id":"req-1"}',
  54. },
  55. ],
  56. isError: true,
  57. },
  58. {
  59. mcp: {
  60. serverName: "zcode-official",
  61. toolName: "search_image",
  62. official: true,
  63. },
  64. },
  65. );
  66. expect(display).toEqual({
  67. kind: "mcp_tool",
  68. serverName: "zcode-official",
  69. toolName: "search_image",
  70. unavailable: { code: "quota_exceeded" },
  71. });
  72. // strict schema 必须接受该字段,否则整条 row 会被拒。
  73. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  74. });
  75. it("carries the coding-plan-required code as well", () => {
  76. const display = createToolResultDisplay(
  77. "mcp__zcode-official__speech_synthesize",
  78. {
  79. content: [{ type: "text", text: '{"error_code":"coding_plan_required","message":"..."}' }],
  80. isError: true,
  81. },
  82. { mcp: { serverName: "zcode-official", toolName: "speech_synthesize", official: true } },
  83. );
  84. expect(display).toMatchObject({ unavailable: { code: "coding_plan_required" } });
  85. });
  86. it("ignores the unavailable payload from a non-official MCP server", () => {
  87. // 不判来源的话,任何第三方 MCP 都能伪造一条 Coding Plan 提示误导用户去购买。
  88. const display = createToolResultDisplay(
  89. "mcp__evil__whatever",
  90. {
  91. content: [{ type: "text", text: '{"error_code":"quota_exceeded","message":"gotcha"}' }],
  92. isError: true,
  93. },
  94. { mcp: { serverName: "evil", toolName: "whatever" } },
  95. );
  96. expect(display).toEqual({ kind: "mcp_tool", serverName: "evil", toolName: "whatever" });
  97. });
  98. it("ignores unknown codes, non-JSON text and successful results", () => {
  99. const mcp = { serverName: "zcode-official", toolName: "search_image", official: true };
  100. const unknownCode = createToolResultDisplay(
  101. "mcp__zcode-official__search_image",
  102. {
  103. content: [{ type: "text", text: '{"error_code":"internal_error","message":"boom"}' }],
  104. isError: true,
  105. },
  106. { mcp },
  107. );
  108. const plainText = createToolResultDisplay(
  109. "mcp__zcode-official__search_image",
  110. { content: [{ type: "text", text: "quota exhausted" }], isError: true },
  111. { mcp },
  112. );
  113. const successful = createToolResultDisplay(
  114. "mcp__zcode-official__search_image",
  115. { content: [{ type: "text", text: '{"error_code":"quota_exceeded"}' }] },
  116. { mcp },
  117. );
  118. // internal_error 是服务端的兜底掩码,用户无法自助解决,不该弹提示。
  119. expect(unknownCode).not.toHaveProperty("unavailable");
  120. expect(plainText).not.toHaveProperty("unavailable");
  121. expect(successful).not.toHaveProperty("unavailable");
  122. });
  123. it("bounds untrusted MCP discovery metadata before it enters display persistence", () => {
  124. const display = createToolResultDisplay(
  125. "custom-provider-visible-name",
  126. { content: [{ type: "text", text: "ok" }] },
  127. {
  128. mcp: {
  129. serverName: ` ${"s".repeat(300)} `,
  130. toolName: ` ${"t".repeat(300)} `,
  131. description: ` ${"d".repeat(5_000)} `,
  132. },
  133. },
  134. );
  135. expect(display).toEqual({
  136. kind: "mcp_tool",
  137. serverName: "s".repeat(256),
  138. toolName: "t".repeat(256),
  139. description: "d".repeat(4 * 1024),
  140. });
  141. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  142. });
  143. it("omits MCP presentation when bounded identifiers are empty", () => {
  144. expect(
  145. createToolResultDisplay(
  146. "custom-provider-visible-name",
  147. {},
  148. {
  149. mcp: {
  150. serverName: " \n ",
  151. toolName: " \t ",
  152. description: "ignored",
  153. },
  154. },
  155. ),
  156. ).toBeUndefined();
  157. });
  158. it("does not split a surrogate pair at the MCP display boundary", () => {
  159. const display = createToolResultDisplay(
  160. "custom-provider-visible-name",
  161. {},
  162. {
  163. mcp: {
  164. serverName: `${"s".repeat(255)}😀`,
  165. toolName: "lookup",
  166. },
  167. },
  168. );
  169. expect(display).toMatchObject({
  170. kind: "mcp_tool",
  171. serverName: "s".repeat(255),
  172. toolName: "lookup",
  173. });
  174. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  175. });
  176. it("projects bounded Node REPL MCP images for the tool card", () => {
  177. const display = createToolResultDisplay("mcp__node_repl__js", {
  178. content: [
  179. { type: "text", text: "(no output)" },
  180. { type: "image", data: "data:image/png;base64,AAAA", mimeType: "image/png" },
  181. ],
  182. });
  183. expect(display).toEqual({
  184. kind: "node_repl_images",
  185. images: [{ base64: "AAAA", mimeType: "image/png" }],
  186. });
  187. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  188. });
  189. it("bounds Node REPL display image count independently from model content", () => {
  190. const display = createToolResultDisplay("mcp__node_repl__js", {
  191. content: ["AAAA", "BBBB", "CCCC"].map((data) => ({
  192. type: "image",
  193. data,
  194. mimeType: "image/png",
  195. })),
  196. });
  197. expect(display).toEqual({
  198. kind: "node_repl_images",
  199. images: [
  200. { base64: "AAAA", mimeType: "image/png" },
  201. { base64: "BBBB", mimeType: "image/png" },
  202. ],
  203. truncated: true,
  204. });
  205. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  206. });
  207. it("projects the node_repl CUA app identity even when the cell produced no image", () => {
  208. // 纯动作 cell(点击、输入)没有截图,但工具卡仍要显示目标 App 图标 —— 旧实现只在有图时
  209. // 才产生 display,身份被整块丢掉,卡片只剩通用图标。
  210. const display = createToolResultDisplay("mcp__node_repl__js", {
  211. content: [{ type: "text", text: "clicked" }],
  212. _meta: {
  213. [ZCODE_MCP_NODE_REPL_CUA_APP_META_KEY]: {
  214. appKey: "darwin:com.apple.notes",
  215. displayName: "Notes",
  216. },
  217. },
  218. });
  219. expect(display).toEqual({
  220. kind: "node_repl_images",
  221. app: { appKey: "darwin:com.apple.notes", displayName: "Notes" },
  222. });
  223. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  224. });
  225. it("carries both the observation screenshot and the app identity in one node_repl display", () => {
  226. const display = createToolResultDisplay("mcp__node_repl__js", {
  227. content: [{ type: "image", data: "AAAA", mimeType: "image/png" }],
  228. _meta: {
  229. [ZCODE_MCP_NODE_REPL_CUA_APP_META_KEY]: {
  230. appKey: "windows-aumid:Microsoft.WindowsCalculator",
  231. },
  232. },
  233. });
  234. expect(display).toEqual({
  235. kind: "node_repl_images",
  236. images: [{ base64: "AAAA", mimeType: "image/png" }],
  237. app: { appKey: "windows-aumid:Microsoft.WindowsCalculator" },
  238. });
  239. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  240. });
  241. it("ignores a malformed node_repl app identity instead of dropping the whole display", () => {
  242. const display = createToolResultDisplay("mcp__node_repl__js", {
  243. content: [{ type: "image", data: "AAAA", mimeType: "image/png" }],
  244. _meta: { [ZCODE_MCP_NODE_REPL_CUA_APP_META_KEY]: { appKey: "" } },
  245. });
  246. expect(display).toEqual({
  247. kind: "node_repl_images",
  248. images: [{ base64: "AAAA", mimeType: "image/png" }],
  249. });
  250. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  251. });
  252. it("keeps returning no display when a node_repl cell has neither image nor app identity", () => {
  253. expect(
  254. createToolResultDisplay("mcp__node_repl__js", {
  255. content: [{ type: "text", text: "=> 3" }],
  256. }),
  257. ).toBeUndefined();
  258. });
  259. it("does not duplicate CUA tool input in persisted display metadata", () => {
  260. const display = createToolResultDisplay("mcp__computer-use__screenshot", {
  261. content: [{ type: "text", text: "captured" }],
  262. });
  263. expect(display).toMatchObject({ kind: "cua", toolName: "screenshot" });
  264. expect(display).not.toHaveProperty("input");
  265. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  266. });
  267. it("projects target-app metadata only for the official CUA authority", () => {
  268. const output = {
  269. content: [{ type: "text", text: "pressed" }],
  270. _meta: {
  271. "zcode.cua/target-app-display-v1": {
  272. schemaVersion: 1,
  273. displayName: "Calculator",
  274. iconLocators: [{ kind: "darwin-bundle-id", value: "com.apple.calculator" }],
  275. },
  276. },
  277. };
  278. expect(
  279. createToolResultDisplay("mcp__computer-use__key", output, { officialCua: true }),
  280. ).toMatchObject({
  281. kind: "cua",
  282. targetApp: {
  283. displayName: "Calculator",
  284. iconLocators: [{ kind: "darwin-bundle-id", value: "com.apple.calculator" }],
  285. },
  286. });
  287. expect(createToolResultDisplay("mcp__computer-use__key", output)).not.toHaveProperty(
  288. "targetApp",
  289. );
  290. expect(
  291. createToolResultDisplay("mcp__third-party-computer-use__key", output, {
  292. officialCua: false,
  293. }),
  294. ).not.toHaveProperty("targetApp");
  295. });
  296. it("drops malformed request_access permission metadata", () => {
  297. const display = createToolResultDisplay(
  298. "mcp__computer-use__request_access",
  299. {
  300. content: [{ type: "text", text: "permission report" }],
  301. _meta: {
  302. "zcode.cua/request-access-status-v1": {
  303. schemaVersion: 1,
  304. platform: "darwin",
  305. grantOwner: "dev.zcode.cua-helper.dev",
  306. accessibility: "unknown",
  307. screenRecording: "denied",
  308. },
  309. },
  310. },
  311. { officialCua: true },
  312. );
  313. expect(display).not.toHaveProperty("permissionStatus");
  314. });
  315. it("projects a bounded local-agent message failure", () => {
  316. const display = createToolResultDisplay("SendMessage", {
  317. status: "failed",
  318. messageId: "msg_failed",
  319. agentId: "agent_missing",
  320. delivery: "queued",
  321. error: "No active local_agent task found for target agent_missing.",
  322. message: "The target agent is no longer running.",
  323. outputFile: "/tmp/agent-missing.txt",
  324. taskId: "task_missing",
  325. });
  326. expect(display).toEqual({
  327. kind: "local_agent_message",
  328. status: "failed",
  329. error: "No active local_agent task found for target agent_missing.",
  330. message: "The target agent is no longer running.",
  331. });
  332. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  333. });
  334. it("bounds oversized SendMessage display fields independently from result serialization", () => {
  335. const error = "错".repeat(10_000);
  336. const message = "信".repeat(10_000);
  337. const display = createToolResultDisplay("SendMessage", {
  338. status: "failed",
  339. messageId: "msg_large",
  340. error,
  341. message,
  342. });
  343. if (display?.kind !== "local_agent_message") {
  344. throw new Error("Expected SendMessage display payload");
  345. }
  346. expect(Buffer.byteLength(display.error ?? "", "utf8")).toBeLessThanOrEqual(4 * 1024);
  347. expect(Buffer.byteLength(display.message ?? "", "utf8")).toBeLessThanOrEqual(4 * 1024);
  348. expect(display.error).toMatch(/\n\.\.\.\[truncated\]$/u);
  349. expect(display.message).toMatch(/\n\.\.\.\[truncated\]$/u);
  350. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  351. });
  352. it("does not treat the session mailbox tool as a local-agent message", () => {
  353. expect(
  354. createToolResultDisplay("send_message", {
  355. status: "failed",
  356. messageId: "msg_mailbox",
  357. error: "Mailbox delivery failed.",
  358. }),
  359. ).toBeUndefined();
  360. });
  361. it("projects TaskStop details independently from model content", () => {
  362. const output = {
  363. message: "Successfully stopped task: task_alpha (pnpm test)",
  364. task_id: "task_alpha",
  365. task_type: "background_shell",
  366. command: "pnpm test",
  367. };
  368. const display = createToolResultDisplay("TaskStop", output);
  369. expect(display).toEqual({
  370. kind: "task_stop",
  371. taskId: "task_alpha",
  372. taskType: "background_shell",
  373. command: "pnpm test",
  374. message: "Successfully stopped task: task_alpha",
  375. });
  376. expect(output.message).toBe("Successfully stopped task: task_alpha (pnpm test)");
  377. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  378. });
  379. it("bounds oversized TaskStop display fields independently from result serialization", () => {
  380. const command = "界".repeat(20_000);
  381. const display = createToolResultDisplay("TaskStop", {
  382. message: `Task stop details: ${command}`,
  383. task_id: "task_large",
  384. task_type: "background_shell",
  385. command,
  386. });
  387. expect(display).toMatchObject({
  388. kind: "task_stop",
  389. truncated: true,
  390. });
  391. if (display?.kind !== "task_stop") {
  392. throw new Error("Expected TaskStop display payload");
  393. }
  394. expect(Buffer.byteLength(display.command ?? "", "utf8")).toBeLessThanOrEqual(16 * 1024);
  395. expect(Buffer.byteLength(display.message, "utf8")).toBeLessThanOrEqual(16 * 1024);
  396. expect(display.command).toMatch(/\n\.\.\.\[truncated\]$/u);
  397. expect(display.message).toMatch(/\n\.\.\.\[truncated\]$/u);
  398. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  399. });
  400. it.each(["success", "not_ready", "timeout"] as const)(
  401. "projects TaskOutput %s status without provider-only fields",
  402. (retrievalStatus) => {
  403. const output = {
  404. retrieval_status: retrievalStatus,
  405. task:
  406. retrievalStatus === "timeout"
  407. ? null
  408. : {
  409. task_id: "task_alpha",
  410. task_type: "local_agent",
  411. status: retrievalStatus === "not_ready" ? "running" : "completed",
  412. description: "Inspect the project",
  413. output: retrievalStatus === "not_ready" ? "partial output\n" : "final output\n",
  414. error: "provider-only error",
  415. prompt: "provider-only prompt",
  416. result: "provider-only result",
  417. outputFile: "/tmp/task.output",
  418. },
  419. };
  420. const display = createToolResultDisplay("TaskOutput", output);
  421. expect(display).toEqual(
  422. retrievalStatus === "timeout"
  423. ? {
  424. kind: "task_output",
  425. retrievalStatus: "timeout",
  426. }
  427. : {
  428. kind: "task_output",
  429. retrievalStatus,
  430. taskStatus: retrievalStatus === "not_ready" ? "running" : "completed",
  431. output: retrievalStatus === "not_ready" ? "partial output" : "final output",
  432. },
  433. );
  434. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  435. if (output.task) {
  436. expect(output.task.output).toMatch(/\n$/u);
  437. }
  438. },
  439. );
  440. it("bounds TaskOutput output at 2,000 characters and omits blank output", () => {
  441. const createTaskOutput = (output: string) =>
  442. createToolResultDisplay("TaskOutput", {
  443. retrieval_status: "success",
  444. task: {
  445. task_id: "task_large",
  446. task_type: "local_bash",
  447. status: "completed",
  448. description: "Run command",
  449. output,
  450. },
  451. });
  452. expect(createTaskOutput(" \n\t")).toEqual({
  453. kind: "task_output",
  454. retrievalStatus: "success",
  455. taskStatus: "completed",
  456. });
  457. expect(createTaskOutput("x".repeat(2_000))).toEqual({
  458. kind: "task_output",
  459. retrievalStatus: "success",
  460. taskStatus: "completed",
  461. output: "x".repeat(2_000),
  462. });
  463. expect(createTaskOutput(`${"x".repeat(2_000)}y`)).toEqual({
  464. kind: "task_output",
  465. retrievalStatus: "success",
  466. taskStatus: "completed",
  467. output: "x".repeat(2_000),
  468. truncated: true,
  469. });
  470. });
  471. it("bounds an unexpected TaskOutput status before it enters display metadata", () => {
  472. const display = createToolResultDisplay("TaskOutput", {
  473. retrieval_status: "success",
  474. task: {
  475. task_id: "task_status",
  476. task_type: "local_workflow",
  477. status: "s".repeat(65),
  478. description: "Workflow",
  479. output: "",
  480. },
  481. });
  482. expect(display).toEqual({
  483. kind: "task_output",
  484. retrievalStatus: "success",
  485. taskStatus: "s".repeat(64),
  486. });
  487. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  488. });
  489. it.each(["success", "failed"] as const)(
  490. "projects RespondToCoordinator %s without message or response id",
  491. (status) => {
  492. const display = createToolResultDisplay("RespondToCoordinator", {
  493. status,
  494. responseId: "response-1",
  495. message: "Continue the assigned task.",
  496. error: status === "failed" ? "Queue unavailable" : undefined,
  497. });
  498. expect(display).toEqual({
  499. kind: "respond_to_coordinator",
  500. status,
  501. });
  502. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  503. },
  504. );
  505. it("keeps the existing file diff projection", () => {
  506. expect(
  507. createToolResultDisplay("WriteLike", {
  508. filePath: "/workspace/demo.ts",
  509. structuredPatch: [
  510. {
  511. oldStart: 1,
  512. oldLines: 1,
  513. newStart: 1,
  514. newLines: 1,
  515. lines: ["-old", "+new"],
  516. },
  517. ],
  518. }),
  519. ).toEqual({
  520. kind: "file_diff",
  521. filePath: "/workspace/demo.ts",
  522. additions: 1,
  523. deletions: 1,
  524. structuredPatch: [
  525. {
  526. oldStart: 1,
  527. oldLines: 1,
  528. newStart: 1,
  529. newLines: 1,
  530. lines: ["-old", "+new"],
  531. },
  532. ],
  533. truncated: false,
  534. });
  535. });
  536. it("projects a clean CreateWorkflow compile as a structured display", () => {
  537. const display = createToolResultDisplay("CreateWorkflow", {
  538. diagnostics: [],
  539. ok: true,
  540. response: "The workflow script compiled cleanly.",
  541. });
  542. expect(display).toEqual({
  543. kind: "create_workflow",
  544. ok: true,
  545. errorCount: 0,
  546. diagnostics: [],
  547. });
  548. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  549. });
  550. it("carries the bounded CreateWorkflow causality graph through to the display", () => {
  551. const causalityGraph = {
  552. steps: [
  553. {
  554. id: "ask#1",
  555. kind: "ask",
  556. label: "planner",
  557. line: 2,
  558. column: 24,
  559. lane: "actor#1",
  560. },
  561. {
  562. id: "ask#2",
  563. kind: "ask",
  564. label: "reviewer",
  565. line: 3,
  566. column: 24,
  567. lane: "actor#2",
  568. repeat: "stack",
  569. },
  570. ],
  571. lanes: [
  572. { id: "actor#1", name: "planner", line: 2, column: 17 },
  573. { id: "actor#2", name: "reviewer", line: 3, column: 17 },
  574. ],
  575. participants: [
  576. { id: "unphased:actor#1", phase: "unphased", lane: "actor#1", steps: ["ask#1"] },
  577. {
  578. id: "unphased:actor#2",
  579. phase: "unphased",
  580. lane: "actor#2",
  581. steps: ["ask#2"],
  582. many: true,
  583. },
  584. ],
  585. handoffs: [{ from: "unphased:actor#1", to: "unphased:actor#2", types: ["string"] }],
  586. sink: ["ask#2"],
  587. };
  588. const display = createToolResultDisplay("CreateWorkflow", {
  589. diagnostics: [],
  590. ok: true,
  591. response: "The workflow script compiled cleanly.",
  592. causalityGraph,
  593. });
  594. if (display?.kind !== "create_workflow") {
  595. throw new Error("Expected CreateWorkflow display payload");
  596. }
  597. expect(display.causalityGraph).toEqual(causalityGraph);
  598. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  599. });
  600. it("carries may-set lane-expansion copies (`source`) through to the display", () => {
  601. // display 走 .strict() 解析:契约里少一个 source 不是「字段被丢掉」,而是整张图被拒、
  602. // GUI 一张卡片都拿不到。所以这条路径必须与工具输出一起钉住。
  603. const copy = {
  604. id: "ask#1~actor#1",
  605. kind: "ask",
  606. label: "ask",
  607. line: 6,
  608. column: 20,
  609. lane: "actor#1",
  610. lanes: ["actor#1", "actor#2"],
  611. source: "ask#1",
  612. repeat: "serial",
  613. };
  614. const causalityGraph = {
  615. steps: [copy, { ...copy, id: "ask#1~actor#2", lane: "actor#2" }],
  616. lanes: [
  617. { id: "actor#1", name: "black" },
  618. { id: "actor#2", name: "white" },
  619. ],
  620. participants: [
  621. { id: "unphased:actor#1", phase: "unphased", lane: "actor#1", steps: ["ask#1~actor#1"] },
  622. { id: "unphased:actor#2", phase: "unphased", lane: "actor#2", steps: ["ask#1~actor#2"] },
  623. ],
  624. handoffs: [{ from: "unphased:actor#1", to: "unphased:actor#2", back: true }],
  625. sink: ["ask#1~actor#1", "ask#1~actor#2"],
  626. };
  627. const display = createToolResultDisplay("CreateWorkflow", {
  628. diagnostics: [],
  629. ok: true,
  630. response: "The workflow script compiled cleanly.",
  631. causalityGraph,
  632. });
  633. if (display?.kind !== "create_workflow") {
  634. throw new Error("Expected CreateWorkflow display payload");
  635. }
  636. expect(display.causalityGraph).toEqual(causalityGraph);
  637. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  638. });
  639. it("rejects a CreateWorkflow output whose causality graph exceeds the contract bounds", () => {
  640. // 越界图不该出现(handler 已限长),但如果出现,输出解析失败 → 不产出 display,
  641. // 而不是把无界载荷放进实时事件。
  642. const display = createToolResultDisplay("CreateWorkflow", {
  643. diagnostics: [],
  644. ok: true,
  645. response: "The workflow script compiled cleanly.",
  646. causalityGraph: {
  647. steps: Array.from({ length: 65 }, (_, index) => ({
  648. id: `ask#${index}`,
  649. kind: "ask",
  650. label: "a",
  651. lane: "actor#1",
  652. })),
  653. lanes: [{ id: "actor#1" }],
  654. participants: [],
  655. handoffs: [],
  656. },
  657. });
  658. expect(display).toBeUndefined();
  659. });
  660. it("projects CreateWorkflow diagnostics without deriving them from the response text", () => {
  661. const display = createToolResultDisplay("CreateWorkflow", {
  662. diagnostics: [
  663. { line: 3, column: 5, code: 2304, message: "Cannot find name 'agent'." },
  664. { line: 8, column: 1, code: 1005, message: "';' expected." },
  665. ],
  666. ok: false,
  667. response: "The workflow script has type errors:\nL3:C5 Cannot find name 'agent'.",
  668. });
  669. expect(display).toEqual({
  670. kind: "create_workflow",
  671. ok: false,
  672. errorCount: 2,
  673. diagnostics: [
  674. { line: 3, column: 5, code: 2304, message: "Cannot find name 'agent'." },
  675. { line: 8, column: 1, code: 1005, message: "';' expected." },
  676. ],
  677. });
  678. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  679. });
  680. it("bounds CreateWorkflow diagnostics count and message length independently from model content", () => {
  681. const diagnostics = Array.from({ length: 150 }, (_, index) => ({
  682. line: index,
  683. column: index,
  684. code: 2304,
  685. message: "e".repeat(5_000),
  686. }));
  687. const display = createToolResultDisplay("CreateWorkflow", {
  688. diagnostics,
  689. ok: false,
  690. response: "The workflow script has type errors:",
  691. });
  692. if (display?.kind !== "create_workflow") {
  693. throw new Error("Expected CreateWorkflow display payload");
  694. }
  695. expect(display.errorCount).toBe(150);
  696. expect(display.diagnostics).toHaveLength(100);
  697. expect(display.truncated).toBe(true);
  698. for (const diagnostic of display.diagnostics) {
  699. expect(diagnostic.message.length).toBeLessThanOrEqual(2_048);
  700. }
  701. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  702. });
  703. it("ignores non-CreateWorkflow tools and malformed CreateWorkflow output", () => {
  704. expect(
  705. createToolResultDisplay("NotCreateWorkflow", {
  706. diagnostics: [],
  707. ok: true,
  708. response: "unrelated",
  709. }),
  710. ).toBeUndefined();
  711. expect(createToolResultDisplay("CreateWorkflow", { ok: "yes" })).toBeUndefined();
  712. });
  713. });
  714. describe("workflow observation tool displays", () => {
  715. const getWorkflowRunHealth = {
  716. lastProgressAt: 1_900,
  717. consecutiveFailures: 0,
  718. cachedSteps: 1,
  719. pendingQuestionsKnown: true,
  720. };
  721. const getWorkflowRunRunningOutput = {
  722. runId: "wf_demo",
  723. label: "nightly-sync",
  724. labelSource: "name",
  725. status: "running",
  726. ownedByThisSession: true,
  727. createdAt: 1_000,
  728. updatedAt: 2_000,
  729. summary: "Running for 1s. 4 of 7 dispatched steps settled, 2 running (1 executing).",
  730. generatedAt: 2_400,
  731. usage: {
  732. spentTokens: 12_345,
  733. nodesObserved: 7,
  734. nodesRunning: 2,
  735. nodesCompleted: 4,
  736. nodesFailed: 1,
  737. },
  738. actors: [
  739. { siteId: "agent#1", ordinal: 1, name: "scout" },
  740. { siteId: "agent#2", ordinal: 2 },
  741. ],
  742. logTail: [
  743. { sequence: 1, message: "started" },
  744. // 带落库时刻的一条:卡上的日志年龄对 generatedAt 算,所以 `at` 必须原样过卡。
  745. { sequence: 2, message: "fan-out complete", at: Date.UTC(2026, 7, 21, 9, 4, 0) },
  746. ],
  747. phases: [
  748. {
  749. name: "collect",
  750. state: "done" as const,
  751. rounds: 1,
  752. nodesSettled: 2,
  753. nodesRunning: 0,
  754. enteredAt: 1_000,
  755. exitedAt: 1_400,
  756. },
  757. {
  758. name: "judge",
  759. state: "current" as const,
  760. rounds: 1,
  761. nodesSettled: 2,
  762. nodesRunning: 2,
  763. enteredAt: 1_400,
  764. },
  765. ],
  766. subagents: [
  767. {
  768. siteId: "agent#1",
  769. ordinal: 1,
  770. name: "scout",
  771. state: "executing" as const,
  772. phaseName: "judge",
  773. currentAsk: {
  774. siteId: "ask#2",
  775. ordinal: 0,
  776. actorSeq: 1,
  777. instructionsHead: "Judge the first seven specs",
  778. startedAt: 1_500,
  779. turn: 3,
  780. toolCalls: 5,
  781. lastTool: { name: "Read", target: "a.ts", at: 1_900 },
  782. },
  783. stepsSettled: 1,
  784. stepsFailed: 0,
  785. tokens: 900,
  786. lastProgressAt: 1_900,
  787. },
  788. {
  789. siteId: "agent#2",
  790. ordinal: 2,
  791. state: "waiting" as const,
  792. wait: { cause: "backoff" as const, reason: "429", retryAfterMs: 20_000, since: 1_800 },
  793. stepsSettled: 0,
  794. stepsFailed: 0,
  795. tokens: 0,
  796. },
  797. ],
  798. health: getWorkflowRunHealth,
  799. };
  800. it("projects a running GetWorkflowRun output as a structured display", () => {
  801. const display = createToolResultDisplay("GetWorkflowRun", getWorkflowRunRunningOutput);
  802. expect(display).toEqual({
  803. kind: "get_workflow_run",
  804. runId: "wf_demo",
  805. label: "nightly-sync",
  806. status: "running",
  807. summary: getWorkflowRunRunningOutput.summary,
  808. generatedAt: 2_400,
  809. usage: getWorkflowRunRunningOutput.usage,
  810. phases: getWorkflowRunRunningOutput.phases,
  811. // 嵌套的 currentAsk / wait 在卡面上摊平成一行;等待原因的自由文本不上卡。
  812. subagents: [
  813. {
  814. siteId: "agent#1",
  815. ordinal: 1,
  816. name: "scout",
  817. state: "executing",
  818. phaseName: "judge",
  819. instructionsHead: "Judge the first seven specs",
  820. startedAt: 1_500,
  821. turn: 3,
  822. toolCalls: 5,
  823. lastTool: { name: "Read", target: "a.ts", at: 1_900 },
  824. stepsSettled: 1,
  825. stepsFailed: 0,
  826. tokens: 900,
  827. lastProgressAt: 1_900,
  828. },
  829. {
  830. siteId: "agent#2",
  831. ordinal: 2,
  832. state: "waiting",
  833. waitCause: "backoff",
  834. retryAfterMs: 20_000,
  835. waitSince: 1_800,
  836. stepsSettled: 0,
  837. stepsFailed: 0,
  838. tokens: 0,
  839. },
  840. ],
  841. health: getWorkflowRunHealth,
  842. actors: getWorkflowRunRunningOutput.actors,
  843. logTail: getWorkflowRunRunningOutput.logTail,
  844. });
  845. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  846. });
  847. // 情势上线之前持久化的载荷没有这五件;display schema 是 strict 的,设成必填会让升级后
  848. // 打开的每一条历史会话里这张卡整块被剥、退化成纯文本。
  849. it("still parses a payload persisted before the situation report existed", () => {
  850. const legacy = {
  851. kind: "get_workflow_run" as const,
  852. runId: "wf_old",
  853. label: "yesterday",
  854. status: "completed" as const,
  855. usage: getWorkflowRunRunningOutput.usage,
  856. actors: getWorkflowRunRunningOutput.actors,
  857. logTail: getWorkflowRunRunningOutput.logTail,
  858. };
  859. expect(parseToolResultDisplayPayload(legacy)).toEqual(legacy);
  860. });
  861. // phases「无则缺席」(空数组读起来像「阶段表是空的」);subagents 恒在场。
  862. it("omits an empty phase table but keeps an empty roster", () => {
  863. const display = createToolResultDisplay("GetWorkflowRun", {
  864. ...getWorkflowRunRunningOutput,
  865. phases: undefined,
  866. subagents: [],
  867. });
  868. if (display?.kind !== "get_workflow_run")
  869. throw new Error("Expected get_workflow_run display payload");
  870. expect("phases" in display).toBe(false);
  871. expect(display.subagents).toEqual([]);
  872. });
  873. // 工具面已在 handler 里裁到 64 并打了 subagentsTruncated;卡面继承那个标记,
  874. // 因为卡上也只该有它真的画出来的那些行。
  875. it("inherits the roster's truncation flag onto the card", () => {
  876. const subagent = getWorkflowRunRunningOutput.subagents[1]!;
  877. const display = createToolResultDisplay("GetWorkflowRun", {
  878. ...getWorkflowRunRunningOutput,
  879. subagents: Array.from({ length: 64 }, () => subagent),
  880. subagentsTruncated: true,
  881. });
  882. if (display?.kind !== "get_workflow_run")
  883. throw new Error("Expected get_workflow_run display payload");
  884. expect(display.subagents).toHaveLength(64);
  885. expect(display.truncated).toBe(true);
  886. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  887. });
  888. it("keeps the newest log entries and flags truncation on GetWorkflowRun display", () => {
  889. const logTail = Array.from({ length: 50 }, (_, index) => ({
  890. sequence: index + 1,
  891. message: `entry ${index + 1}`,
  892. }));
  893. const display = createToolResultDisplay("GetWorkflowRun", {
  894. ...getWorkflowRunRunningOutput,
  895. logTail,
  896. });
  897. if (display?.kind !== "get_workflow_run") {
  898. throw new Error("Expected get_workflow_run display payload");
  899. }
  900. expect(display.logTail).toHaveLength(40);
  901. // 截头不截尾:留下的必须是 sequence 11..50。
  902. expect(display.logTail[0]?.sequence).toBe(11);
  903. expect(display.logTail.at(-1)?.sequence).toBe(50);
  904. expect(display.truncated).toBe(true);
  905. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  906. });
  907. it("bounds the GetWorkflowRun result text independently of the model channel", () => {
  908. const display = createToolResultDisplay("GetWorkflowRun", {
  909. ...getWorkflowRunRunningOutput,
  910. status: "completed",
  911. result: "x".repeat(10_000),
  912. });
  913. if (display?.kind !== "get_workflow_run") {
  914. throw new Error("Expected get_workflow_run display payload");
  915. }
  916. expect(display.result!.length).toBeLessThanOrEqual(4_000);
  917. expect(display.truncated).toBe(true);
  918. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  919. });
  920. // 回归(docs/dynamic-workflow/launch.md「Their cards」):工具输出的 `error.providerStop`
  921. // 一度被原样搬进工具卡 display,而渲染端按 packages/shared 的镜像 schema 严格校验每一帧,
  922. // 多一个键就是整条 row 被拒——一个会话因此停在 fault.subscription.recoveryFailed 上。
  923. // 第二条断言就是那道两侧同步的闸:卡片载荷必须过得了渲染端的那把尺。
  924. it("keeps the GetWorkflowRun card error at code and message, matching the renderer mirror", () => {
  925. const display = createToolResultDisplay("GetWorkflowRun", {
  926. ...getWorkflowRunRunningOutput,
  927. status: "stopped",
  928. stopReason: "provider",
  929. error: {
  930. code: "ProviderStop",
  931. message: "The provider stopped the run: rate limited.",
  932. providerStop: {
  933. kind: "quota",
  934. reason: "rate_limited",
  935. providerId: "bigmodel",
  936. modelId: "glm-4.6",
  937. providerCode: "1308",
  938. subagent: "agent#1",
  939. subagentName: "scout",
  940. phase: "plan",
  941. rawMessage: "您已达到五小时内的用量上限",
  942. },
  943. },
  944. });
  945. if (display?.kind !== "get_workflow_run") {
  946. throw new Error("Expected get_workflow_run display payload");
  947. }
  948. expect(display.error).toEqual({
  949. code: "ProviderStop",
  950. message: "The provider stopped the run: rate limited.",
  951. });
  952. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  953. // 渲染端的那把尺:两侧不同步时这里先红。
  954. const mirrored = toolCallGetWorkflowRunDisplaySchema.strict().safeParse(display);
  955. expect(mirrored.success ? [] : mirrored.error.issues).toEqual([]);
  956. });
  957. it("projects ListWorkflowRuns rows verbatim with the output's truncated flag", () => {
  958. const output = {
  959. runs: [
  960. {
  961. runId: "wf_a",
  962. label: "alpha",
  963. labelSource: "name",
  964. status: "completed",
  965. ownedByThisSession: true,
  966. createdAt: 1,
  967. updatedAt: 2,
  968. spentTokens: 10,
  969. },
  970. {
  971. runId: "wf_b",
  972. label: "// derive something",
  973. labelSource: "script",
  974. status: "stopped",
  975. stopReason: "interrupted",
  976. ownedByThisSession: false,
  977. possiblyInterrupted: true,
  978. createdAt: 3,
  979. updatedAt: 4,
  980. spentTokens: 20,
  981. },
  982. ],
  983. truncated: true,
  984. };
  985. const display = createToolResultDisplay("ListWorkflowRuns", output);
  986. expect(display).toEqual({ kind: "list_workflow_runs", runs: output.runs, truncated: true });
  987. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  988. });
  989. it("projects EvalWorkflowSnippet with bounded logs, response and diagnostics", () => {
  990. const longLogs = Array.from({ length: 60 }, (_, index) => `log line ${index + 1}`);
  991. const display = createToolResultDisplay("EvalWorkflowSnippet", {
  992. ok: false,
  993. diagnostics: [
  994. {
  995. code: 2322,
  996. column: 10,
  997. line: 3,
  998. message: "Type 'string' is not assignable to 'number'.",
  999. },
  1000. ],
  1001. logs: longLogs,
  1002. response: "y".repeat(9_000),
  1003. durationMs: 1_250,
  1004. });
  1005. if (display?.kind !== "eval_workflow_snippet") {
  1006. throw new Error("Expected eval_workflow_snippet display payload");
  1007. }
  1008. expect(display.ok).toBe(false);
  1009. expect(display.logs).toHaveLength(40);
  1010. expect(display.logs.at(-1)).toBe("log line 60");
  1011. expect(display.response.length).toBeLessThanOrEqual(4_000);
  1012. expect(display.durationMs).toBe(1_250);
  1013. expect(display.truncated).toBe(true);
  1014. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  1015. });
  1016. it("projects ListSavedWorkflows entries with arg names and bounded metadata", () => {
  1017. const display = createToolResultDisplay("ListSavedWorkflows", {
  1018. workflows: [
  1019. {
  1020. name: "nightly-sync",
  1021. description: "d".repeat(5_000),
  1022. scope: "project",
  1023. path: ".zcode/workflows/nightly-sync.dwf.ts",
  1024. args: {
  1025. question: { type: "string", description: "what to research", required: true },
  1026. depth: { type: "number" },
  1027. },
  1028. },
  1029. ],
  1030. invalid: [{ path: ".zcode/workflows/broken.dwf.ts", reason: "bad frontmatter" }],
  1031. });
  1032. if (display?.kind !== "saved_workflow_list") {
  1033. throw new Error("Expected saved_workflow_list display payload");
  1034. }
  1035. expect(display.workflows[0]?.argNames).toEqual(["question", "depth"]);
  1036. expect(display.workflows[0]?.description!.length).toBeLessThanOrEqual(2_048);
  1037. expect(display.invalid).toEqual([
  1038. { path: ".zcode/workflows/broken.dwf.ts", reason: "bad frontmatter" },
  1039. ]);
  1040. expect(display.truncated).toBe(true);
  1041. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  1042. });
  1043. // spec:docs/dynamic-workflow/launch.md「The model catalog」——目录行原样透传,
  1044. // 「当前」保留,超 100 行截断并打 truncated。
  1045. it("projects ListModels rows and keeps the session's current model", () => {
  1046. const display = createToolResultDisplay("ListModels", {
  1047. current: "account:bigmodel-team-coding-plan/GLM-5.3-Flash",
  1048. models: [
  1049. {
  1050. id: "account:bigmodel-team-coding-plan/GLM-5.3-Flash",
  1051. providerId: "account:bigmodel-team-coding-plan",
  1052. modelId: "GLM-5.3-Flash",
  1053. providerLabel: "BigModel",
  1054. reasoningLevels: ["low", "medium", "high"],
  1055. defaultReasoningLevel: "high",
  1056. contextWindow: 128_000,
  1057. },
  1058. {
  1059. id: "custom:myproxy/glm-4.7",
  1060. providerId: "custom:myproxy",
  1061. modelId: "glm-4.7",
  1062. reasoningLevels: [],
  1063. disabledReason: "no API key",
  1064. },
  1065. ],
  1066. });
  1067. if (display?.kind !== "list_models") {
  1068. throw new Error("Expected list_models display payload");
  1069. }
  1070. expect(display.current).toBe("account:bigmodel-team-coding-plan/GLM-5.3-Flash");
  1071. expect(display.models).toHaveLength(2);
  1072. expect(display.models[0]).toEqual({
  1073. id: "account:bigmodel-team-coding-plan/GLM-5.3-Flash",
  1074. providerId: "account:bigmodel-team-coding-plan",
  1075. modelId: "GLM-5.3-Flash",
  1076. providerLabel: "BigModel",
  1077. reasoningLevels: ["low", "medium", "high"],
  1078. defaultReasoningLevel: "high",
  1079. contextWindow: 128_000,
  1080. });
  1081. // 没有档位的行给空数组、不可选用的行带理由——两者都是读侧要分辨的状态。
  1082. expect(display.models[1]?.reasoningLevels).toEqual([]);
  1083. expect(display.models[1]?.disabledReason).toBe("no API key");
  1084. expect(display.truncated).toBeUndefined();
  1085. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  1086. });
  1087. it("caps the ListModels catalog at 100 rows and flags the truncation", () => {
  1088. const display = createToolResultDisplay("ListModels", {
  1089. models: Array.from({ length: 101 }, (_unused, index) => ({
  1090. id: `custom:proxy/model-${index}`,
  1091. providerId: "custom:proxy",
  1092. modelId: `model-${index}`,
  1093. providerLabel: "p".repeat(5_000),
  1094. reasoningLevels: [],
  1095. })),
  1096. });
  1097. if (display?.kind !== "list_models") {
  1098. throw new Error("Expected list_models display payload");
  1099. }
  1100. expect(display.models).toHaveLength(100);
  1101. expect(display.models[0]?.providerLabel!.length).toBeLessThanOrEqual(2_048);
  1102. expect(display.truncated).toBe(true);
  1103. // current 在目录里对不上时缺席——造一个空串会被读成「当前模型叫空」。
  1104. expect(display.current).toBeUndefined();
  1105. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  1106. });
  1107. it("returns undefined for unknown tools and malformed observation outputs", () => {
  1108. expect(
  1109. createToolResultDisplay("GetWorkflowRunDetail", getWorkflowRunRunningOutput),
  1110. ).toBeUndefined();
  1111. expect(createToolResultDisplay("GetWorkflowRun", { runId: 42 })).toBeUndefined();
  1112. expect(createToolResultDisplay("ListWorkflowRuns", { runs: "many" })).toBeUndefined();
  1113. expect(createToolResultDisplay("EvalWorkflowSnippet", { ok: "yes" })).toBeUndefined();
  1114. expect(createToolResultDisplay("ListSavedWorkflows", null)).toBeUndefined();
  1115. expect(createToolResultDisplay("ListModels", { models: "all of them" })).toBeUndefined();
  1116. expect(createToolResultDisplay("ListModels", null)).toBeUndefined();
  1117. });
  1118. // spec:docs/dynamic-workflow/presentation.md「The run card」——
  1119. // 载荷刻意最小 {runId},坏输出回 undefined 走文本兜底。
  1120. it("builds the ResumeWorkflowRun display payload from a successful output", () => {
  1121. const display = createToolResultDisplay("ResumeWorkflowRun", {
  1122. ok: true,
  1123. runId: "dwfrun_resume",
  1124. response: "The workflow run dwfrun_resume has been resumed and is running in the background.",
  1125. status: "backgrounded",
  1126. backgroundTaskId: "dwfrun_resume",
  1127. });
  1128. expect(display).toEqual({ kind: "resume_workflow_run", runId: "dwfrun_resume" });
  1129. expect(parseToolResultDisplayPayload(display)).toEqual(display);
  1130. });
  1131. it("returns undefined for malformed ResumeWorkflowRun outputs", () => {
  1132. // 失败路径走 ToolHandlerFailure,不构造 display——这里钉住「绝不产出半张卡」。
  1133. expect(createToolResultDisplay("ResumeWorkflowRun", { ok: false })).toBeUndefined();
  1134. expect(createToolResultDisplay("ResumeWorkflowRun", { runId: "" })).toBeUndefined();
  1135. });
  1136. });