messageTaskControlToolCallBlock.test.ts 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944
  1. import { createElement, type ComponentType } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it } from "vitest";
  4. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  5. import type { TaskChatToolCallTreeNode } from "@/lib/toolCallTree.js";
  6. import { ToolCallBlock } from "@/ToolCallBlocks.js";
  7. import { RespondToCoordinatorToolCallBlock } from "@/ToolCallBlocks/renderers/respond-to-coordinator.js";
  8. import { SendMessageToolCallBlock } from "@/ToolCallBlocks/renderers/send-message.js";
  9. import { TaskOutputToolCallBlock } from "@/ToolCallBlocks/renderers/task-output.js";
  10. import { TaskStopToolCallBlock } from "@/ToolCallBlocks/renderers/task-stop.js";
  11. import type { ToolCallBlockRenderContext } from "@/ToolCallBlocks/shared.js";
  12. const displayModel = {
  13. inlinePreview: { type: "none" as const },
  14. planResult: null,
  15. viewerSource: null,
  16. viewerLabelId: "codeViewer.viewCode" as const,
  17. showSummaryFileLink: false,
  18. showInput: false,
  19. showOutput: true,
  20. showKind: false,
  21. };
  22. function renderToolCall(toolCall: TaskChatToolCallTreeNode["toolCall"]) {
  23. return renderToStaticMarkup(
  24. createElement(
  25. ZCodeIntlProvider,
  26. { initialLocale: "zh-CN" },
  27. createElement(ToolCallBlock, {
  28. toolCallNode: {
  29. toolCall,
  30. childToolCalls: [],
  31. },
  32. workspacePath: "/workspace",
  33. }),
  34. ),
  35. );
  36. }
  37. function renderDedicatedToolCall(
  38. Renderer: ComponentType<ToolCallBlockRenderContext>,
  39. toolCall: TaskChatToolCallTreeNode["toolCall"],
  40. overrides: Partial<ToolCallBlockRenderContext> = {},
  41. ) {
  42. return renderToStaticMarkup(
  43. createElement(
  44. ZCodeIntlProvider,
  45. { initialLocale: "zh-CN" },
  46. createElement(Renderer, {
  47. toolCallNode: {
  48. toolCall,
  49. childToolCalls: [],
  50. },
  51. workspacePath: "/workspace",
  52. displayModel,
  53. viewerSource: null,
  54. rawFileSummaries: [],
  55. isRunning: false,
  56. statusLabel: "已执行",
  57. childToolList: null,
  58. showIcon: true,
  59. forceOpen: true,
  60. canToggle: true,
  61. ...overrides,
  62. }),
  63. ),
  64. );
  65. }
  66. describe("message and task control tool call routing", () => {
  67. it("routes SendMessage to a semantic summary", () => {
  68. const html = renderToolCall({
  69. toolId: "send-1",
  70. toolName: "SendMessage",
  71. kind: "SendMessage",
  72. title: "SendMessage",
  73. input: {
  74. to: "agent_alpha",
  75. summary: "同步结论",
  76. message: "请复核结果",
  77. },
  78. output: {
  79. status: "success",
  80. messageId: "msg_1",
  81. delivery: "queued",
  82. },
  83. status: "completed",
  84. raw: {},
  85. });
  86. const sentIndex = html.indexOf("消息");
  87. const summaryIndex = html.indexOf("同步结论");
  88. const connectorIndex = html.indexOf("给");
  89. const targetIndex = html.indexOf("agent_alpha");
  90. expect(sentIndex).toBeGreaterThanOrEqual(0);
  91. expect(summaryIndex).toBeGreaterThan(sentIndex);
  92. expect(connectorIndex).toBeGreaterThan(summaryIndex);
  93. expect(targetIndex).toBeGreaterThan(connectorIndex);
  94. expect(html).not.toContain("已发送");
  95. expect(html).toContain("同步结论");
  96. expect(html).toContain("agent_alpha");
  97. });
  98. it("routes TaskStop to a semantic summary", () => {
  99. const html = renderToolCall({
  100. toolId: "stop-1",
  101. toolName: "TaskStop",
  102. kind: "TaskStop",
  103. title: "TaskStop",
  104. input: {
  105. task_id: "task_alpha",
  106. },
  107. output: JSON.stringify({
  108. message: "Successfully stopped task: task_alpha",
  109. task_id: "task_alpha",
  110. task_type: "local_agent",
  111. }),
  112. status: "completed",
  113. raw: {},
  114. });
  115. expect(html).toContain("停止任务");
  116. expect(html).not.toContain("已停止任务");
  117. expect(html).toContain("task_alpha");
  118. expect(html).not.toContain("local_agent");
  119. });
  120. it("routes TaskOutput to its task status summary", () => {
  121. const html = renderToolCall({
  122. toolId: "output-1",
  123. toolName: "TaskOutput",
  124. kind: "TaskOutput",
  125. title: "TaskOutput",
  126. input: {
  127. task_id: "task_alpha",
  128. block: false,
  129. timeout: 0,
  130. },
  131. output: "<retrieval_status>success</retrieval_status>",
  132. status: "completed",
  133. raw: {
  134. display: {
  135. kind: "task_output",
  136. retrievalStatus: "success",
  137. taskStatus: "completed",
  138. },
  139. },
  140. });
  141. expect(html).toContain("任务输出");
  142. expect(html).toContain("task_alpha");
  143. expect(html).not.toContain("&lt;retrieval_status&gt;");
  144. });
  145. it("routes RespondToCoordinator to its queued summary", () => {
  146. const html = renderToolCall({
  147. toolId: "respond-1",
  148. toolName: "RespondToCoordinator",
  149. kind: "RespondToCoordinator",
  150. title: "RespondToCoordinator",
  151. input: {
  152. summary: "已找到根因",
  153. message: "完整回复正文",
  154. },
  155. output: "Response response-1 was queued for the coordinator.",
  156. status: "completed",
  157. raw: {
  158. display: {
  159. kind: "respond_to_coordinator",
  160. status: "success",
  161. },
  162. },
  163. });
  164. expect(html).toContain("回复已排队");
  165. expect(html).toContain("已找到根因");
  166. expect(html).not.toContain("完整回复正文");
  167. expect(html).not.toContain("response-1");
  168. });
  169. });
  170. describe("message and task control tool call details", () => {
  171. it("renders only SendMessage target, summary, and message details", () => {
  172. const html = renderDedicatedToolCall(SendMessageToolCallBlock, {
  173. toolId: "send-details",
  174. toolName: "SendMessage",
  175. kind: "SendMessage",
  176. title: "SendMessage",
  177. input: {
  178. to: "agent_alpha",
  179. summary: "同步结论",
  180. message: "请复核结果并返回风险项。",
  181. },
  182. status: "completed",
  183. raw: {
  184. rawOutput: {
  185. status: "success",
  186. messageId: "msg_alpha",
  187. agentId: "agent_alpha",
  188. delivery: "queued",
  189. taskId: "task_alpha",
  190. outputFile: "/tmp/agent-alpha.txt",
  191. message: "Message queued for local agent.",
  192. },
  193. },
  194. });
  195. expect(html).toContain("目标");
  196. expect(html).toContain("agent_alpha");
  197. expect(html).toContain("摘要");
  198. expect(html).toContain("同步结论");
  199. expect(html).toContain("消息");
  200. expect(html).toContain("请复核结果并返回风险项。");
  201. expect(html).not.toContain("投递状态");
  202. expect(html).not.toContain("已排队");
  203. expect(html).not.toContain("消息 ID");
  204. expect(html).not.toContain("msg_alpha");
  205. expect(html).not.toContain("Agent ID");
  206. expect(html).not.toContain("任务 ID");
  207. expect(html).not.toContain("输出文件");
  208. expect(html).not.toContain("/tmp/agent-alpha.txt");
  209. expect(html).not.toContain("Message queued for local agent.");
  210. expect(html).not.toContain("&quot;messageId&quot;");
  211. expect(html).not.toContain("&quot;delivery&quot;");
  212. });
  213. it("does not make a streaming SendMessage expandable before details arrive", () => {
  214. const html = renderDedicatedToolCall(
  215. SendMessageToolCallBlock,
  216. {
  217. toolId: "send-streaming-empty",
  218. toolName: "SendMessage",
  219. kind: "SendMessage",
  220. title: "SendMessage",
  221. input: {},
  222. status: "pending",
  223. raw: {
  224. kind: "tool_input_start",
  225. },
  226. },
  227. {
  228. isRunning: true,
  229. },
  230. );
  231. expect(html).not.toContain('role="button"');
  232. });
  233. it("does not render SendMessage plain-text model content as success details", () => {
  234. const resultText = "Message msg_beta was steered for local agent agent_beta.";
  235. const html = renderDedicatedToolCall(SendMessageToolCallBlock, {
  236. toolId: "send-text-result",
  237. toolName: "SendMessage",
  238. kind: "SendMessage",
  239. title: "SendMessage",
  240. input: {
  241. to: "agent_beta",
  242. summary: "补充上下文",
  243. message: "请继续检查当前改动。",
  244. },
  245. output: resultText,
  246. status: "completed",
  247. raw: {
  248. result: {
  249. content: resultText,
  250. },
  251. },
  252. });
  253. expect(html).not.toContain("结果");
  254. expect(html).not.toContain(resultText);
  255. expect(html).not.toContain("&quot;content&quot;");
  256. });
  257. it("renders a structured SendMessage business failure as failed", () => {
  258. const html = renderDedicatedToolCall(SendMessageToolCallBlock, {
  259. toolId: "send-business-failure",
  260. toolName: "SendMessage",
  261. kind: "SendMessage",
  262. title: "SendMessage",
  263. input: {
  264. to: "agent_missing",
  265. summary: "继续检查",
  266. message: "请继续检查当前改动。",
  267. },
  268. output: {
  269. status: "failed",
  270. messageId: "msg_failed",
  271. agentId: "agent_missing",
  272. error: "No active local_agent task found for target agent_missing.",
  273. message: "No active local_agent task found for target agent_missing.",
  274. },
  275. status: "completed",
  276. raw: {},
  277. });
  278. expect(html).toContain("消息");
  279. expect(html).toContain("执行失败");
  280. expect(html).not.toContain("No active local_agent task found");
  281. expect(html).not.toContain("已发送");
  282. });
  283. it.each([
  284. {
  285. name: "a live tool result",
  286. raw: {
  287. result: {
  288. display: {
  289. kind: "local_agent_message",
  290. status: "failed",
  291. error: "No active local_agent task found for target agent_missing.",
  292. message: "The target agent is no longer running.",
  293. },
  294. },
  295. },
  296. },
  297. {
  298. name: "persisted tool metadata",
  299. raw: {
  300. display: {
  301. kind: "local_agent_message",
  302. status: "failed",
  303. error: "No active local_agent task found for target agent_missing.",
  304. message: "The target agent is no longer running.",
  305. },
  306. },
  307. },
  308. {
  309. name: "a provider raw output",
  310. raw: {
  311. rawOutput: {
  312. display: {
  313. kind: "local_agent_message",
  314. status: "failed",
  315. error: "No active local_agent task found for target agent_missing.",
  316. message: "The target agent is no longer running.",
  317. },
  318. },
  319. },
  320. },
  321. ])("renders a projected SendMessage failure from $name", ({ raw }) => {
  322. const html = renderDedicatedToolCall(SendMessageToolCallBlock, {
  323. toolId: "send-projected-failure",
  324. toolName: "SendMessage",
  325. kind: "SendMessage",
  326. title: "SendMessage",
  327. input: {
  328. to: "agent_missing",
  329. summary: "继续检查",
  330. message: "请继续检查当前改动。",
  331. },
  332. output: "The target agent is no longer running.",
  333. status: "completed",
  334. raw,
  335. });
  336. expect(html).toContain("消息");
  337. expect(html).toContain("执行失败");
  338. expect(html).not.toContain("已发送");
  339. });
  340. it("renders TaskStop fields from JSON output without raw JSON", () => {
  341. const html = renderDedicatedToolCall(TaskStopToolCallBlock, {
  342. toolId: "stop-details",
  343. toolName: "TaskStop",
  344. kind: "TaskStop",
  345. title: "TaskStop",
  346. input: {
  347. shell_id: "legacy_shell_alpha",
  348. },
  349. output: JSON.stringify({
  350. message: "Successfully stopped task: task_alpha (pnpm test)",
  351. task_id: "task_alpha",
  352. task_type: "background_shell",
  353. command: "pnpm test",
  354. }),
  355. status: "completed",
  356. raw: {
  357. rawOutput: {
  358. message: "raw fallback should not render",
  359. },
  360. },
  361. });
  362. expect(html).not.toContain("任务 ID");
  363. expect(html).toContain("task_alpha");
  364. expect(html).toContain("任务类型");
  365. expect(html).toContain("background_shell");
  366. expect(html).toContain("命令");
  367. expect(html).toContain("pnpm test");
  368. expect(html).toContain("结果");
  369. expect(html).toContain("Successfully stopped task: task_alpha");
  370. expect(html).not.toContain("Successfully stopped task: task_alpha (pnpm test)");
  371. expect(html.match(/pnpm test/gu)).toHaveLength(1);
  372. expect(html).not.toContain("raw fallback should not render");
  373. expect(html).not.toContain("&quot;task_id&quot;");
  374. expect(html).not.toContain("&quot;task_type&quot;");
  375. });
  376. it("renders a projected local agent command as a task description", () => {
  377. const html = renderDedicatedToolCall(TaskStopToolCallBlock, {
  378. toolId: "stop-local-agent-description",
  379. toolName: "TaskStop",
  380. kind: "TaskStop",
  381. title: "TaskStop",
  382. input: {
  383. task_id: "agent_alpha",
  384. },
  385. output: "Successfully stopped task: agent_alpha (检查赔率来源)",
  386. status: "completed",
  387. raw: {
  388. result: {
  389. display: {
  390. kind: "task_stop",
  391. taskId: "agent_alpha",
  392. taskType: "local_agent",
  393. command: "检查赔率来源",
  394. message: "Successfully stopped task: agent_alpha (检查赔率来源)",
  395. },
  396. },
  397. },
  398. });
  399. expect(html).toContain("任务描述");
  400. expect(html).not.toContain(">命令<");
  401. expect(html).toMatch(/<dt[^>]*>任务描述<\/dt><dd[^>]*>检查赔率来源<\/dd>/u);
  402. });
  403. it("does not expose a legacy local agent prompt as a task description", () => {
  404. const legacyPrompt = "请搜索多个来源并输出完整的世界杯赔率研究报告";
  405. const html = renderDedicatedToolCall(TaskStopToolCallBlock, {
  406. toolId: "stop-legacy-local-agent",
  407. toolName: "TaskStop",
  408. kind: "TaskStop",
  409. title: "TaskStop",
  410. input: {
  411. task_id: "agent_legacy",
  412. },
  413. output: JSON.stringify({
  414. message: `Successfully stopped task: agent_legacy (${legacyPrompt})`,
  415. task_id: "agent_legacy",
  416. task_type: "local_agent",
  417. command: legacyPrompt,
  418. }),
  419. status: "completed",
  420. raw: {},
  421. });
  422. expect(html).toContain("Successfully stopped task: agent_legacy");
  423. expect(html).not.toContain(legacyPrompt);
  424. expect(html).not.toContain("任务描述");
  425. });
  426. it("keeps a custom TaskStop result unchanged", () => {
  427. const html = renderDedicatedToolCall(TaskStopToolCallBlock, {
  428. toolId: "stop-custom-result",
  429. toolName: "TaskStop",
  430. kind: "TaskStop",
  431. title: "TaskStop",
  432. input: {
  433. task_id: "task_custom",
  434. },
  435. output: JSON.stringify({
  436. message: "Task stopped after cleanup completed.",
  437. task_id: "task_custom",
  438. task_type: "background_shell",
  439. command: "pnpm test",
  440. }),
  441. status: "completed",
  442. raw: {},
  443. });
  444. expect(html).toContain("Task stopped after cleanup completed.");
  445. });
  446. it.each([
  447. {
  448. name: "a live tool result",
  449. raw: {
  450. result: {
  451. display: {
  452. kind: "task_stop",
  453. taskId: "task_display",
  454. taskType: "background_shell",
  455. command: "pnpm test",
  456. message: "Successfully stopped task: task_display (pnpm test)",
  457. },
  458. },
  459. },
  460. },
  461. {
  462. name: "persisted tool metadata",
  463. raw: {
  464. display: {
  465. kind: "task_stop",
  466. taskId: "task_display",
  467. taskType: "background_shell",
  468. command: "pnpm test",
  469. message: "Successfully stopped task: task_display (pnpm test)",
  470. },
  471. },
  472. },
  473. {
  474. name: "a provider raw output",
  475. raw: {
  476. rawOutput: {
  477. display: {
  478. kind: "task_stop",
  479. taskId: "task_display",
  480. taskType: "background_shell",
  481. command: "pnpm test",
  482. message: "Successfully stopped task: task_display (pnpm test)",
  483. },
  484. },
  485. },
  486. },
  487. ])("renders projected TaskStop details from $name", ({ raw }) => {
  488. const html = renderDedicatedToolCall(TaskStopToolCallBlock, {
  489. toolId: "stop-projected-details",
  490. toolName: "TaskStop",
  491. kind: "TaskStop",
  492. title: "TaskStop",
  493. input: {
  494. task_id: "task_input",
  495. },
  496. output: '{"message":"model content"}\n\n[Hook additional context]\n#1\nextra context',
  497. status: "completed",
  498. raw,
  499. });
  500. expect(html).toContain("task_display");
  501. expect(html).toContain("background_shell");
  502. expect(html).toContain("pnpm test");
  503. expect(html).toContain("Successfully stopped task: task_display");
  504. expect(html).not.toContain("Successfully stopped task: task_display (pnpm test)");
  505. expect(html.match(/pnpm test/gu)).toHaveLength(1);
  506. expect(html).not.toContain("extra context");
  507. });
  508. it("shows when projected TaskStop details were truncated", () => {
  509. const html = renderDedicatedToolCall(TaskStopToolCallBlock, {
  510. toolId: "stop-truncated-details",
  511. toolName: "TaskStop",
  512. kind: "TaskStop",
  513. title: "TaskStop",
  514. input: {
  515. task_id: "task_large",
  516. },
  517. status: "completed",
  518. raw: {
  519. result: {
  520. display: {
  521. kind: "task_stop",
  522. taskId: "task_large",
  523. taskType: "background_shell",
  524. command: "long command\n...[truncated]",
  525. message: "Successfully stopped task\n...[truncated]",
  526. truncated: true,
  527. },
  528. },
  529. },
  530. });
  531. expect(html).toContain("部分任务详情已截断");
  532. });
  533. it("parses the explicit hook envelope for a legacy TaskStop result", () => {
  534. const html = renderDedicatedToolCall(TaskStopToolCallBlock, {
  535. toolId: "stop-legacy-hook-details",
  536. toolName: "TaskStop",
  537. kind: "TaskStop",
  538. title: "TaskStop",
  539. input: {
  540. task_id: "task_legacy",
  541. },
  542. output:
  543. '{"message":"Successfully stopped task: task_legacy (pnpm test)","task_id":"task_legacy","task_type":"background_shell","command":"pnpm test"}\n\n[Hook additional context]\n#1\nextra context',
  544. status: "completed",
  545. raw: {},
  546. });
  547. expect(html).toContain("background_shell");
  548. expect(html).toContain("pnpm test");
  549. expect(html).toContain("Successfully stopped task: task_legacy");
  550. expect(html).not.toContain("Successfully stopped task: task_legacy (pnpm test)");
  551. expect(html.match(/pnpm test/gu)).toHaveLength(1);
  552. expect(html).not.toContain("extra context");
  553. });
  554. it("uses failure wording when TaskStop execution fails", () => {
  555. const html = renderDedicatedToolCall(
  556. TaskStopToolCallBlock,
  557. {
  558. toolId: "stop-failure",
  559. toolName: "TaskStop",
  560. kind: "TaskStop",
  561. title: "TaskStop",
  562. input: {
  563. task_id: "task_missing",
  564. },
  565. status: "failed",
  566. raw: {},
  567. },
  568. {
  569. statusLabel: "执行失败",
  570. errorText: "No task found with ID: task_missing",
  571. },
  572. );
  573. expect(html).toContain("停止任务");
  574. expect(html).toContain("执行失败");
  575. expect(html).not.toContain("已停止任务");
  576. });
  577. it("renders a denied TaskStop reason as the expanded result", () => {
  578. const html = renderDedicatedToolCall(
  579. TaskStopToolCallBlock,
  580. {
  581. toolId: "stop-denied-details",
  582. toolName: "TaskStop",
  583. kind: "TaskStop",
  584. title: "TaskStop",
  585. input: {
  586. task_id: "task_denied",
  587. },
  588. status: "denied",
  589. raw: {},
  590. },
  591. {
  592. errorText: "TaskStop is disabled by policy",
  593. },
  594. );
  595. expect(html).toContain("结果");
  596. expect(html).toContain("TaskStop is disabled by policy");
  597. });
  598. it("does not make a stopped TaskStop expandable when no details exist", () => {
  599. const html = renderDedicatedToolCall(TaskStopToolCallBlock, {
  600. toolId: "stop-empty-details",
  601. toolName: "TaskStop",
  602. kind: "TaskStop",
  603. title: "TaskStop",
  604. input: {
  605. task_id: "task_stopped",
  606. },
  607. status: "stopped",
  608. raw: {},
  609. });
  610. expect(html).not.toContain('role="button"');
  611. });
  612. it("renders only bounded TaskOutput output and its truncation notice", () => {
  613. const output = "x".repeat(2_000);
  614. const html = renderDedicatedToolCall(TaskOutputToolCallBlock, {
  615. toolId: "output-details",
  616. toolName: "TaskOutput",
  617. kind: "TaskOutput",
  618. title: "TaskOutput",
  619. input: {
  620. task_id: "task_large",
  621. block: false,
  622. timeout: 0,
  623. },
  624. output: "<retrieval_status>success</retrieval_status>",
  625. status: "completed",
  626. raw: {
  627. result: {
  628. display: {
  629. kind: "task_output",
  630. retrievalStatus: "success",
  631. output,
  632. truncated: true,
  633. },
  634. description: "must stay hidden",
  635. error: "must stay hidden",
  636. outputFile: "/tmp/task.output",
  637. },
  638. },
  639. });
  640. expect(html).toContain("任务输出");
  641. expect(html).toContain("已获取");
  642. expect(html).toContain("task_large");
  643. expect(html).toContain(output);
  644. expect(html).toContain("后续内容已省略");
  645. expect(html).not.toContain("&lt;retrieval_status&gt;");
  646. expect(html).not.toContain("must stay hidden");
  647. expect(html).not.toContain("/tmp/task.output");
  648. });
  649. it("does not make TaskOutput expandable without projected output", () => {
  650. const html = renderDedicatedToolCall(TaskOutputToolCallBlock, {
  651. toolId: "output-empty",
  652. toolName: "TaskOutput",
  653. kind: "TaskOutput",
  654. title: "TaskOutput",
  655. input: {
  656. task_id: "task_empty",
  657. block: false,
  658. timeout: 0,
  659. },
  660. status: "completed",
  661. raw: {
  662. display: {
  663. kind: "task_output",
  664. retrievalStatus: "success",
  665. },
  666. },
  667. });
  668. expect(html).toContain("已获取");
  669. expect(html).not.toContain('role="button"');
  670. });
  671. it.each([
  672. {
  673. name: "running retrieval",
  674. status: "completed",
  675. isRunning: false,
  676. display: { retrievalStatus: "not_ready", taskStatus: "running" },
  677. expected: "任务运行中",
  678. },
  679. {
  680. name: "timed out retrieval",
  681. status: "completed",
  682. isRunning: false,
  683. display: { retrievalStatus: "timeout", taskStatus: "running" },
  684. expected: "等待超时",
  685. },
  686. {
  687. name: "failed task",
  688. status: "completed",
  689. isRunning: false,
  690. display: { retrievalStatus: "success", taskStatus: "failed" },
  691. expected: "任务失败",
  692. },
  693. {
  694. name: "stopped task",
  695. status: "completed",
  696. isRunning: false,
  697. display: { retrievalStatus: "success", taskStatus: "killed" },
  698. expected: "任务已停止",
  699. },
  700. {
  701. name: "tool execution",
  702. status: "in_progress",
  703. isRunning: true,
  704. display: undefined,
  705. expected: "正在获取任务输出",
  706. },
  707. {
  708. name: "tool failure",
  709. status: "failed",
  710. isRunning: false,
  711. display: undefined,
  712. expected: "执行失败",
  713. },
  714. {
  715. name: "denied tool",
  716. status: "denied",
  717. isRunning: false,
  718. display: undefined,
  719. expected: "已拒绝",
  720. },
  721. {
  722. name: "stopped tool",
  723. status: "stopped",
  724. isRunning: false,
  725. display: undefined,
  726. expected: "已停止",
  727. },
  728. ])("renders TaskOutput $name status", ({ status, isRunning, display, expected }) => {
  729. const html = renderDedicatedToolCall(
  730. TaskOutputToolCallBlock,
  731. {
  732. toolId: `output-${status}`,
  733. toolName: "TaskOutput",
  734. kind: "TaskOutput",
  735. title: "TaskOutput",
  736. input: { task_id: "task_status", block: false, timeout: 0 },
  737. status,
  738. raw: display
  739. ? {
  740. display: {
  741. kind: "task_output",
  742. ...display,
  743. },
  744. }
  745. : {},
  746. },
  747. {
  748. isRunning,
  749. errorText: status === "failed" ? "TaskOutput execution failed" : undefined,
  750. },
  751. );
  752. expect(html).toContain(expected);
  753. });
  754. it("renders RespondToCoordinator summary and queue status without details", () => {
  755. const html = renderDedicatedToolCall(RespondToCoordinatorToolCallBlock, {
  756. toolId: "respond-details",
  757. toolName: "RespondToCoordinator",
  758. kind: "RespondToCoordinator",
  759. title: "RespondToCoordinator",
  760. input: {
  761. summary: "根因已经确认",
  762. message: "不应出现在卡片中的完整回复",
  763. },
  764. output: "Response response-1 was queued for the coordinator.",
  765. status: "completed",
  766. raw: {
  767. result: {
  768. display: {
  769. kind: "respond_to_coordinator",
  770. status: "success",
  771. },
  772. responseId: "response-1",
  773. error: "must stay hidden",
  774. },
  775. },
  776. });
  777. expect(html).toContain("回复已排队");
  778. expect(html).toContain("根因已经确认");
  779. expect(html).not.toContain('role="button"');
  780. expect(html).not.toContain("不应出现在卡片中的完整回复");
  781. expect(html).not.toContain("response-1");
  782. expect(html).not.toContain("must stay hidden");
  783. });
  784. it.each([
  785. {
  786. name: "running",
  787. status: "in_progress",
  788. isRunning: true,
  789. displayStatus: undefined,
  790. expected: "正在回复",
  791. },
  792. {
  793. name: "queued",
  794. status: "completed",
  795. isRunning: false,
  796. displayStatus: "success",
  797. expected: "回复已排队",
  798. },
  799. {
  800. name: "business failure",
  801. status: "completed",
  802. isRunning: false,
  803. displayStatus: "failed",
  804. expected: "执行失败",
  805. },
  806. {
  807. name: "denied",
  808. status: "denied",
  809. isRunning: false,
  810. displayStatus: undefined,
  811. expected: "已拒绝",
  812. },
  813. {
  814. name: "stopped",
  815. status: "stopped",
  816. isRunning: false,
  817. displayStatus: undefined,
  818. expected: "已停止",
  819. },
  820. ])(
  821. "renders RespondToCoordinator $name status",
  822. ({ status, isRunning, displayStatus, expected }) => {
  823. const html = renderDedicatedToolCall(
  824. RespondToCoordinatorToolCallBlock,
  825. {
  826. toolId: `respond-${status}`,
  827. toolName: "RespondToCoordinator",
  828. kind: "RespondToCoordinator",
  829. title: "RespondToCoordinator",
  830. input: { summary: "回复摘要", message: "完整回复" },
  831. status,
  832. raw: displayStatus
  833. ? {
  834. display: {
  835. kind: "respond_to_coordinator",
  836. status: displayStatus,
  837. },
  838. }
  839. : {},
  840. },
  841. {
  842. isRunning,
  843. },
  844. );
  845. expect(html).toContain(expected);
  846. },
  847. );
  848. });
  849. describe("message and task control terminal states", () => {
  850. it.each([
  851. { status: "stopped", expected: "已停止" },
  852. { status: "denied", expected: "已拒绝" },
  853. ])("does not present SendMessage $status as sent", ({ status, expected }) => {
  854. const html = renderToolCall({
  855. toolId: `send-${status}`,
  856. toolName: "SendMessage",
  857. kind: "SendMessage",
  858. title: "SendMessage",
  859. input: {
  860. to: "agent_alpha",
  861. summary: "同步结论",
  862. message: "请复核结果",
  863. },
  864. status,
  865. raw: {},
  866. });
  867. expect(html).toContain(expected);
  868. expect(html).not.toContain("已发送");
  869. });
  870. it.each([
  871. { status: "stopped", expected: "已停止" },
  872. { status: "denied", expected: "已拒绝" },
  873. ])("does not present TaskStop $status as stopped successfully", ({ status, expected }) => {
  874. const html = renderToolCall({
  875. toolId: `stop-${status}`,
  876. toolName: "TaskStop",
  877. kind: "TaskStop",
  878. title: "TaskStop",
  879. input: {
  880. task_id: "task_alpha",
  881. },
  882. status,
  883. raw: {},
  884. });
  885. expect(html).toContain(expected);
  886. expect(html).toContain("停止任务");
  887. });
  888. });