| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954 |
- import { createElement, type ComponentType } from "react";
- import { renderToStaticMarkup } from "react-dom/server";
- import { describe, expect, it } from "vitest";
- import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
- import type { TaskChatToolCallTreeNode } from "@/lib/toolCallTree.js";
- import { ToolCallBlock } from "@/ToolCallBlocks.js";
- import { RespondToCoordinatorToolCallBlock } from "@/ToolCallBlocks/renderers/respond-to-coordinator.js";
- import { SendMessageToolCallBlock } from "@/ToolCallBlocks/renderers/send-message.js";
- import { TaskOutputToolCallBlock } from "@/ToolCallBlocks/renderers/task-output.js";
- import { TaskStopToolCallBlock } from "@/ToolCallBlocks/renderers/task-stop.js";
- import type { ToolCallBlockRenderContext } from "@/ToolCallBlocks/shared.js";
- const displayModel = {
- inlinePreview: { type: "none" as const },
- planResult: null,
- viewerSource: null,
- viewerLabelId: "codeViewer.viewCode" as const,
- showSummaryFileLink: false,
- showInput: false,
- showOutput: true,
- showKind: false,
- };
- function renderToolCall(toolCall: TaskChatToolCallTreeNode["toolCall"]) {
- return renderToStaticMarkup(
- createElement(
- ZCodeIntlProvider,
- { initialLocale: "zh-CN" },
- createElement(ToolCallBlock, {
- toolCallNode: {
- toolCall,
- childToolCalls: [],
- },
- workspacePath: "/workspace",
- }),
- ),
- );
- }
- function renderDedicatedToolCall(
- Renderer: ComponentType<ToolCallBlockRenderContext>,
- toolCall: TaskChatToolCallTreeNode["toolCall"],
- overrides: Partial<ToolCallBlockRenderContext> = {},
- ) {
- return renderToStaticMarkup(
- createElement(
- ZCodeIntlProvider,
- { initialLocale: "zh-CN" },
- createElement(Renderer, {
- toolCallNode: {
- toolCall,
- childToolCalls: [],
- },
- workspacePath: "/workspace",
- displayModel,
- viewerSource: null,
- rawFileSummaries: [],
- isRunning: false,
- statusLabel: "已执行",
- childToolList: null,
- showIcon: true,
- forceOpen: true,
- canToggle: true,
- ...overrides,
- }),
- ),
- );
- }
- describe("message and task control tool call routing", () => {
- it("routes SendMessage to a semantic summary", () => {
- const html = renderToolCall({
- toolId: "send-1",
- toolName: "SendMessage",
- kind: "SendMessage",
- title: "SendMessage",
- input: {
- to: "agent_alpha",
- summary: "同步结论",
- message: "请复核结果",
- },
- output: {
- status: "success",
- messageId: "msg_1",
- delivery: "queued",
- },
- status: "completed",
- raw: {},
- });
- const sentIndex = html.indexOf("消息");
- const summaryIndex = html.indexOf("同步结论");
- const connectorIndex = html.indexOf("给");
- const targetIndex = html.indexOf("agent_alpha");
- expect(sentIndex).toBeGreaterThanOrEqual(0);
- expect(summaryIndex).toBeGreaterThan(sentIndex);
- expect(connectorIndex).toBeGreaterThan(summaryIndex);
- expect(targetIndex).toBeGreaterThan(connectorIndex);
- expect(html).not.toContain("已发送");
- expect(html).toContain("同步结论");
- expect(html).toContain("agent_alpha");
- });
- it("routes TaskStop to a semantic summary", () => {
- const html = renderToolCall({
- toolId: "stop-1",
- toolName: "TaskStop",
- kind: "TaskStop",
- title: "TaskStop",
- input: {
- task_id: "task_alpha",
- },
- output: JSON.stringify({
- message: "Successfully stopped task: task_alpha",
- task_id: "task_alpha",
- task_type: "local_agent",
- }),
- status: "completed",
- raw: {},
- });
- expect(html).toContain("停止任务");
- expect(html).not.toContain("已停止任务");
- expect(html).toContain("task_alpha");
- expect(html).not.toContain("local_agent");
- });
- it("routes TaskOutput to its task status summary", () => {
- const html = renderToolCall({
- toolId: "output-1",
- toolName: "TaskOutput",
- kind: "TaskOutput",
- title: "TaskOutput",
- input: {
- task_id: "task_alpha",
- block: false,
- timeout: 0,
- },
- output: "<retrieval_status>success</retrieval_status>",
- status: "completed",
- raw: {
- display: {
- kind: "task_output",
- retrievalStatus: "success",
- taskStatus: "completed",
- },
- },
- });
- expect(html).toContain("任务输出");
- expect(html).toContain("task_alpha");
- expect(html).not.toContain("<retrieval_status>");
- });
- it("routes RespondToCoordinator to its queued summary", () => {
- const html = renderToolCall({
- toolId: "respond-1",
- toolName: "RespondToCoordinator",
- kind: "RespondToCoordinator",
- title: "RespondToCoordinator",
- input: {
- summary: "已找到根因",
- message: "完整回复正文",
- },
- output: "Response response-1 was queued for the coordinator.",
- status: "completed",
- raw: {
- display: {
- kind: "respond_to_coordinator",
- status: "success",
- },
- },
- });
- expect(html).toContain("回复已排队");
- expect(html).toContain("已找到根因");
- expect(html).not.toContain("完整回复正文");
- expect(html).not.toContain("response-1");
- });
- });
- describe("message and task control tool call details", () => {
- it("renders only SendMessage target, summary, and message details", () => {
- const html = renderDedicatedToolCall(SendMessageToolCallBlock, {
- toolId: "send-details",
- toolName: "SendMessage",
- kind: "SendMessage",
- title: "SendMessage",
- input: {
- to: "agent_alpha",
- summary: "同步结论",
- message: "请复核结果并返回风险项。",
- },
- status: "completed",
- raw: {
- rawOutput: {
- status: "success",
- messageId: "msg_alpha",
- agentId: "agent_alpha",
- delivery: "queued",
- taskId: "task_alpha",
- outputFile: "/tmp/agent-alpha.txt",
- message: "Message queued for local agent.",
- },
- },
- });
- expect(html).toContain("目标");
- expect(html).toContain("agent_alpha");
- expect(html).toContain("摘要");
- expect(html).toContain("同步结论");
- expect(html).toContain("消息");
- expect(html).toContain("请复核结果并返回风险项。");
- expect(html).not.toContain("投递状态");
- expect(html).not.toContain("已排队");
- expect(html).not.toContain("消息 ID");
- expect(html).not.toContain("msg_alpha");
- expect(html).not.toContain("Agent ID");
- expect(html).not.toContain("任务 ID");
- expect(html).not.toContain("输出文件");
- expect(html).not.toContain("/tmp/agent-alpha.txt");
- expect(html).not.toContain("Message queued for local agent.");
- expect(html).not.toContain(""messageId"");
- expect(html).not.toContain(""delivery"");
- });
- it("does not make a streaming SendMessage expandable before details arrive", () => {
- const html = renderDedicatedToolCall(
- SendMessageToolCallBlock,
- {
- toolId: "send-streaming-empty",
- toolName: "SendMessage",
- kind: "SendMessage",
- title: "SendMessage",
- input: {},
- status: "pending",
- raw: {
- kind: "tool_input_start",
- },
- },
- {
- isRunning: true,
- },
- );
- expect(html).not.toContain('role="button"');
- expect(html).not.toContain("rounded-lg border border-border bg-panel");
- });
- it("does not render SendMessage plain-text model content as success details", () => {
- const resultText = "Message msg_beta was steered for local agent agent_beta.";
- const html = renderDedicatedToolCall(SendMessageToolCallBlock, {
- toolId: "send-text-result",
- toolName: "SendMessage",
- kind: "SendMessage",
- title: "SendMessage",
- input: {
- to: "agent_beta",
- summary: "补充上下文",
- message: "请继续检查当前改动。",
- },
- output: resultText,
- status: "completed",
- raw: {
- result: {
- content: resultText,
- },
- },
- });
- expect(html).not.toContain("结果");
- expect(html).not.toContain(resultText);
- expect(html).not.toContain(""content"");
- });
- it("renders a structured SendMessage business failure as failed", () => {
- const html = renderDedicatedToolCall(SendMessageToolCallBlock, {
- toolId: "send-business-failure",
- toolName: "SendMessage",
- kind: "SendMessage",
- title: "SendMessage",
- input: {
- to: "agent_missing",
- summary: "继续检查",
- message: "请继续检查当前改动。",
- },
- output: {
- status: "failed",
- messageId: "msg_failed",
- agentId: "agent_missing",
- error: "No active local_agent task found for target agent_missing.",
- message: "No active local_agent task found for target agent_missing.",
- },
- status: "completed",
- raw: {},
- });
- expect(html).toContain("消息");
- expect(html).toContain("执行失败");
- expect(html).not.toContain("No active local_agent task found");
- expect(html).not.toContain("已发送");
- });
- it.each([
- {
- name: "a live tool result",
- raw: {
- result: {
- display: {
- kind: "local_agent_message",
- status: "failed",
- error: "No active local_agent task found for target agent_missing.",
- message: "The target agent is no longer running.",
- },
- },
- },
- },
- {
- name: "persisted tool metadata",
- raw: {
- display: {
- kind: "local_agent_message",
- status: "failed",
- error: "No active local_agent task found for target agent_missing.",
- message: "The target agent is no longer running.",
- },
- },
- },
- {
- name: "a provider raw output",
- raw: {
- rawOutput: {
- display: {
- kind: "local_agent_message",
- status: "failed",
- error: "No active local_agent task found for target agent_missing.",
- message: "The target agent is no longer running.",
- },
- },
- },
- },
- ])("renders a projected SendMessage failure from $name", ({ raw }) => {
- const html = renderDedicatedToolCall(SendMessageToolCallBlock, {
- toolId: "send-projected-failure",
- toolName: "SendMessage",
- kind: "SendMessage",
- title: "SendMessage",
- input: {
- to: "agent_missing",
- summary: "继续检查",
- message: "请继续检查当前改动。",
- },
- output: "The target agent is no longer running.",
- status: "completed",
- raw,
- });
- expect(html).toContain("消息");
- expect(html).toContain("执行失败");
- expect(html).not.toContain("已发送");
- });
- it("renders TaskStop fields from JSON output without raw JSON", () => {
- const html = renderDedicatedToolCall(TaskStopToolCallBlock, {
- toolId: "stop-details",
- toolName: "TaskStop",
- kind: "TaskStop",
- title: "TaskStop",
- input: {
- shell_id: "legacy_shell_alpha",
- },
- output: JSON.stringify({
- message: "Successfully stopped task: task_alpha (pnpm test)",
- task_id: "task_alpha",
- task_type: "background_shell",
- command: "pnpm test",
- }),
- status: "completed",
- raw: {
- rawOutput: {
- message: "raw fallback should not render",
- },
- },
- });
- expect(html).not.toContain("任务 ID");
- expect(html).toContain("task_alpha");
- expect(html).toContain("任务类型");
- expect(html).toContain("background_shell");
- expect(html).toContain("命令");
- expect(html).toContain("pnpm test");
- expect(html).toMatch(/<dd class="[^"]*font-mono[^"]*">pnpm test<\/dd>/u);
- expect(html).toContain("结果");
- expect(html).toContain("Successfully stopped task: task_alpha");
- expect(html).not.toContain("Successfully stopped task: task_alpha (pnpm test)");
- expect(html.match(/pnpm test/gu)).toHaveLength(1);
- expect(html).not.toContain("raw fallback should not render");
- expect(html).not.toContain(""task_id"");
- expect(html).not.toContain(""task_type"");
- });
- it("renders a projected local agent command as a task description", () => {
- const html = renderDedicatedToolCall(TaskStopToolCallBlock, {
- toolId: "stop-local-agent-description",
- toolName: "TaskStop",
- kind: "TaskStop",
- title: "TaskStop",
- input: {
- task_id: "agent_alpha",
- },
- output: "Successfully stopped task: agent_alpha (检查赔率来源)",
- status: "completed",
- raw: {
- result: {
- display: {
- kind: "task_stop",
- taskId: "agent_alpha",
- taskType: "local_agent",
- command: "检查赔率来源",
- message: "Successfully stopped task: agent_alpha (检查赔率来源)",
- },
- },
- },
- });
- expect(html).toContain("任务描述");
- expect(html).not.toContain(">命令<");
- expect(html).toMatch(
- /<dt[^>]*>任务描述<\/dt><dd class="[^"]*leading-5[^"]*">检查赔率来源<\/dd>/u,
- );
- expect(html).not.toMatch(/font-mono[^>]*>检查赔率来源/u);
- });
- it("does not expose a legacy local agent prompt as a task description", () => {
- const legacyPrompt = "请搜索多个来源并输出完整的世界杯赔率研究报告";
- const html = renderDedicatedToolCall(TaskStopToolCallBlock, {
- toolId: "stop-legacy-local-agent",
- toolName: "TaskStop",
- kind: "TaskStop",
- title: "TaskStop",
- input: {
- task_id: "agent_legacy",
- },
- output: JSON.stringify({
- message: `Successfully stopped task: agent_legacy (${legacyPrompt})`,
- task_id: "agent_legacy",
- task_type: "local_agent",
- command: legacyPrompt,
- }),
- status: "completed",
- raw: {},
- });
- expect(html).toContain("Successfully stopped task: agent_legacy");
- expect(html).not.toContain(legacyPrompt);
- expect(html).not.toContain("任务描述");
- });
- it("keeps a custom TaskStop result unchanged", () => {
- const html = renderDedicatedToolCall(TaskStopToolCallBlock, {
- toolId: "stop-custom-result",
- toolName: "TaskStop",
- kind: "TaskStop",
- title: "TaskStop",
- input: {
- task_id: "task_custom",
- },
- output: JSON.stringify({
- message: "Task stopped after cleanup completed.",
- task_id: "task_custom",
- task_type: "background_shell",
- command: "pnpm test",
- }),
- status: "completed",
- raw: {},
- });
- expect(html).toContain("Task stopped after cleanup completed.");
- });
- it.each([
- {
- name: "a live tool result",
- raw: {
- result: {
- display: {
- kind: "task_stop",
- taskId: "task_display",
- taskType: "background_shell",
- command: "pnpm test",
- message: "Successfully stopped task: task_display (pnpm test)",
- },
- },
- },
- },
- {
- name: "persisted tool metadata",
- raw: {
- display: {
- kind: "task_stop",
- taskId: "task_display",
- taskType: "background_shell",
- command: "pnpm test",
- message: "Successfully stopped task: task_display (pnpm test)",
- },
- },
- },
- {
- name: "a provider raw output",
- raw: {
- rawOutput: {
- display: {
- kind: "task_stop",
- taskId: "task_display",
- taskType: "background_shell",
- command: "pnpm test",
- message: "Successfully stopped task: task_display (pnpm test)",
- },
- },
- },
- },
- ])("renders projected TaskStop details from $name", ({ raw }) => {
- const html = renderDedicatedToolCall(TaskStopToolCallBlock, {
- toolId: "stop-projected-details",
- toolName: "TaskStop",
- kind: "TaskStop",
- title: "TaskStop",
- input: {
- task_id: "task_input",
- },
- output: '{"message":"model content"}\n\n[Hook additional context]\n#1\nextra context',
- status: "completed",
- raw,
- });
- expect(html).toContain("task_display");
- expect(html).toContain("background_shell");
- expect(html).toContain("pnpm test");
- expect(html).toContain("Successfully stopped task: task_display");
- expect(html).not.toContain("Successfully stopped task: task_display (pnpm test)");
- expect(html.match(/pnpm test/gu)).toHaveLength(1);
- expect(html).not.toContain("extra context");
- });
- it("shows when projected TaskStop details were truncated", () => {
- const html = renderDedicatedToolCall(TaskStopToolCallBlock, {
- toolId: "stop-truncated-details",
- toolName: "TaskStop",
- kind: "TaskStop",
- title: "TaskStop",
- input: {
- task_id: "task_large",
- },
- status: "completed",
- raw: {
- result: {
- display: {
- kind: "task_stop",
- taskId: "task_large",
- taskType: "background_shell",
- command: "long command\n...[truncated]",
- message: "Successfully stopped task\n...[truncated]",
- truncated: true,
- },
- },
- },
- });
- expect(html).toContain("部分任务详情已截断");
- });
- it("parses the explicit hook envelope for a legacy TaskStop result", () => {
- const html = renderDedicatedToolCall(TaskStopToolCallBlock, {
- toolId: "stop-legacy-hook-details",
- toolName: "TaskStop",
- kind: "TaskStop",
- title: "TaskStop",
- input: {
- task_id: "task_legacy",
- },
- output:
- '{"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',
- status: "completed",
- raw: {},
- });
- expect(html).toContain("background_shell");
- expect(html).toContain("pnpm test");
- expect(html).toContain("Successfully stopped task: task_legacy");
- expect(html).not.toContain("Successfully stopped task: task_legacy (pnpm test)");
- expect(html.match(/pnpm test/gu)).toHaveLength(1);
- expect(html).not.toContain("extra context");
- });
- it("uses failure wording when TaskStop execution fails", () => {
- const html = renderDedicatedToolCall(
- TaskStopToolCallBlock,
- {
- toolId: "stop-failure",
- toolName: "TaskStop",
- kind: "TaskStop",
- title: "TaskStop",
- input: {
- task_id: "task_missing",
- },
- status: "failed",
- raw: {},
- },
- {
- statusLabel: "执行失败",
- errorText: "No task found with ID: task_missing",
- },
- );
- expect(html).toContain("停止任务");
- expect(html).toContain("执行失败");
- expect(html).not.toContain("已停止任务");
- });
- it("renders a denied TaskStop reason as the expanded result", () => {
- const html = renderDedicatedToolCall(
- TaskStopToolCallBlock,
- {
- toolId: "stop-denied-details",
- toolName: "TaskStop",
- kind: "TaskStop",
- title: "TaskStop",
- input: {
- task_id: "task_denied",
- },
- status: "denied",
- raw: {},
- },
- {
- errorText: "TaskStop is disabled by policy",
- },
- );
- expect(html).toContain("结果");
- expect(html).toContain("TaskStop is disabled by policy");
- });
- it("does not make a stopped TaskStop expandable when no details exist", () => {
- const html = renderDedicatedToolCall(TaskStopToolCallBlock, {
- toolId: "stop-empty-details",
- toolName: "TaskStop",
- kind: "TaskStop",
- title: "TaskStop",
- input: {
- task_id: "task_stopped",
- },
- status: "stopped",
- raw: {},
- });
- expect(html).not.toContain('role="button"');
- expect(html).not.toContain("rounded-lg border border-border bg-panel");
- });
- it("renders only bounded TaskOutput output and its truncation notice", () => {
- const output = "x".repeat(2_000);
- const html = renderDedicatedToolCall(TaskOutputToolCallBlock, {
- toolId: "output-details",
- toolName: "TaskOutput",
- kind: "TaskOutput",
- title: "TaskOutput",
- input: {
- task_id: "task_large",
- block: false,
- timeout: 0,
- },
- output: "<retrieval_status>success</retrieval_status>",
- status: "completed",
- raw: {
- result: {
- display: {
- kind: "task_output",
- retrievalStatus: "success",
- output,
- truncated: true,
- },
- description: "must stay hidden",
- error: "must stay hidden",
- outputFile: "/tmp/task.output",
- },
- },
- });
- expect(html).toContain("任务输出");
- expect(html).toContain("已获取");
- expect(html).toContain("task_large");
- expect(html).toContain(output);
- expect(html).toContain("后续内容已省略");
- expect(html).not.toContain("<retrieval_status>");
- expect(html).not.toContain("must stay hidden");
- expect(html).not.toContain("/tmp/task.output");
- });
- it("does not make TaskOutput expandable without projected output", () => {
- const html = renderDedicatedToolCall(TaskOutputToolCallBlock, {
- toolId: "output-empty",
- toolName: "TaskOutput",
- kind: "TaskOutput",
- title: "TaskOutput",
- input: {
- task_id: "task_empty",
- block: false,
- timeout: 0,
- },
- status: "completed",
- raw: {
- display: {
- kind: "task_output",
- retrievalStatus: "success",
- },
- },
- });
- expect(html).toContain("已获取");
- expect(html).not.toContain('role="button"');
- expect(html).not.toContain("rounded-lg border border-border bg-panel");
- });
- it.each([
- {
- name: "running retrieval",
- status: "completed",
- isRunning: false,
- display: { retrievalStatus: "not_ready", taskStatus: "running" },
- expected: "任务运行中",
- },
- {
- name: "timed out retrieval",
- status: "completed",
- isRunning: false,
- display: { retrievalStatus: "timeout", taskStatus: "running" },
- expected: "等待超时",
- },
- {
- name: "failed task",
- status: "completed",
- isRunning: false,
- display: { retrievalStatus: "success", taskStatus: "failed" },
- expected: "任务失败",
- },
- {
- name: "stopped task",
- status: "completed",
- isRunning: false,
- display: { retrievalStatus: "success", taskStatus: "killed" },
- expected: "任务已停止",
- },
- {
- name: "tool execution",
- status: "in_progress",
- isRunning: true,
- display: undefined,
- expected: "正在获取任务输出",
- },
- {
- name: "tool failure",
- status: "failed",
- isRunning: false,
- display: undefined,
- expected: "执行失败",
- },
- {
- name: "denied tool",
- status: "denied",
- isRunning: false,
- display: undefined,
- expected: "已拒绝",
- },
- {
- name: "stopped tool",
- status: "stopped",
- isRunning: false,
- display: undefined,
- expected: "已停止",
- },
- ])("renders TaskOutput $name status", ({ status, isRunning, display, expected }) => {
- const html = renderDedicatedToolCall(
- TaskOutputToolCallBlock,
- {
- toolId: `output-${status}`,
- toolName: "TaskOutput",
- kind: "TaskOutput",
- title: "TaskOutput",
- input: { task_id: "task_status", block: false, timeout: 0 },
- status,
- raw: display
- ? {
- display: {
- kind: "task_output",
- ...display,
- },
- }
- : {},
- },
- {
- isRunning,
- errorText: status === "failed" ? "TaskOutput execution failed" : undefined,
- },
- );
- expect(html).toContain(expected);
- });
- it("renders RespondToCoordinator summary and queue status without details", () => {
- const html = renderDedicatedToolCall(RespondToCoordinatorToolCallBlock, {
- toolId: "respond-details",
- toolName: "RespondToCoordinator",
- kind: "RespondToCoordinator",
- title: "RespondToCoordinator",
- input: {
- summary: "根因已经确认",
- message: "不应出现在卡片中的完整回复",
- },
- output: "Response response-1 was queued for the coordinator.",
- status: "completed",
- raw: {
- result: {
- display: {
- kind: "respond_to_coordinator",
- status: "success",
- },
- responseId: "response-1",
- error: "must stay hidden",
- },
- },
- });
- expect(html).toContain("回复已排队");
- expect(html).toContain("根因已经确认");
- expect(html).not.toContain('role="button"');
- expect(html).not.toContain("不应出现在卡片中的完整回复");
- expect(html).not.toContain("response-1");
- expect(html).not.toContain("must stay hidden");
- });
- it.each([
- {
- name: "running",
- status: "in_progress",
- isRunning: true,
- displayStatus: undefined,
- expected: "正在回复",
- },
- {
- name: "queued",
- status: "completed",
- isRunning: false,
- displayStatus: "success",
- expected: "回复已排队",
- },
- {
- name: "business failure",
- status: "completed",
- isRunning: false,
- displayStatus: "failed",
- expected: "执行失败",
- },
- {
- name: "denied",
- status: "denied",
- isRunning: false,
- displayStatus: undefined,
- expected: "已拒绝",
- },
- {
- name: "stopped",
- status: "stopped",
- isRunning: false,
- displayStatus: undefined,
- expected: "已停止",
- },
- ])(
- "renders RespondToCoordinator $name status",
- ({ status, isRunning, displayStatus, expected }) => {
- const html = renderDedicatedToolCall(
- RespondToCoordinatorToolCallBlock,
- {
- toolId: `respond-${status}`,
- toolName: "RespondToCoordinator",
- kind: "RespondToCoordinator",
- title: "RespondToCoordinator",
- input: { summary: "回复摘要", message: "完整回复" },
- status,
- raw: displayStatus
- ? {
- display: {
- kind: "respond_to_coordinator",
- status: displayStatus,
- },
- }
- : {},
- },
- {
- isRunning,
- },
- );
- expect(html).toContain(expected);
- if (displayStatus === "failed") {
- expect(html).toContain("执行失败");
- }
- },
- );
- });
- describe("message and task control terminal states", () => {
- it.each([
- { status: "stopped", expected: "已停止" },
- { status: "denied", expected: "已拒绝" },
- ])("does not present SendMessage $status as sent", ({ status, expected }) => {
- const html = renderToolCall({
- toolId: `send-${status}`,
- toolName: "SendMessage",
- kind: "SendMessage",
- title: "SendMessage",
- input: {
- to: "agent_alpha",
- summary: "同步结论",
- message: "请复核结果",
- },
- status,
- raw: {},
- });
- expect(html).toContain(expected);
- expect(html).not.toContain("已发送");
- });
- it.each([
- { status: "stopped", expected: "已停止" },
- { status: "denied", expected: "已拒绝" },
- ])("does not present TaskStop $status as stopped successfully", ({ status, expected }) => {
- const html = renderToolCall({
- toolId: `stop-${status}`,
- toolName: "TaskStop",
- kind: "TaskStop",
- title: "TaskStop",
- input: {
- task_id: "task_alpha",
- },
- status,
- raw: {},
- });
- expect(html).toContain(expected);
- expect(html).toContain("停止任务");
- });
- });
|