| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419 |
- import type { IBroadcastService, IServiceAccessor } from "@zcode/services";
- import { createElement } from "react";
- import { renderToStaticMarkup } from "react-dom/server";
- import { testId, TID_TOOL_SUMMARY_TRIGGER } from "@zcode/shared";
- import { afterEach, describe, expect, it, vi } from "vitest";
- import { ServiceProvider } from "@/hooks/useServices.js";
- import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
- import { StoreProvider } from "@/store/StoreProvider.js";
- import { useSubagentsStore } from "@/store/subagentsStore.js";
- import { AgentToolCallBlock } from "../src/ToolCallBlocks/renderers/agent.js";
- const localStorageState = new Map<string, string>();
- Object.defineProperty(globalThis, "localStorage", {
- configurable: true,
- value: {
- getItem: (key: string) => localStorageState.get(key) ?? null,
- setItem: (key: string, value: string) => {
- localStorageState.set(key, value);
- },
- removeItem: (key: string) => {
- localStorageState.delete(key);
- },
- clear: () => {
- localStorageState.clear();
- },
- },
- });
- Object.defineProperty(globalThis, "document", {
- configurable: true,
- value: {
- documentElement: {
- classList: {
- contains: () => false,
- toggle: () => {},
- },
- },
- },
- });
- const mockBroadcastService: IBroadcastService = {
- send: async () => {},
- onMessage: () => ({ dispose: () => {} }),
- };
- const mockServices = {
- fileService: {
- readMediaPreview: async () => ({
- path: "/workspace/assets/logo.png",
- mediaType: "image/png",
- dataBase64: "",
- totalBytes: 0,
- }),
- },
- } as IServiceAccessor;
- describe("AgentToolCallBlock", () => {
- afterEach(() => {
- useSubagentsStore.setState({ agents: [] });
- });
- it("keeps an Agent without a persisted child as a static one-line summary", () => {
- const html = renderToStaticMarkup(
- createElement(
- ZCodeIntlProvider,
- { initialLocale: "zh-CN" },
- createElement(
- ServiceProvider,
- { services: mockServices },
- createElement(
- StoreProvider,
- { broadcastService: mockBroadcastService },
- createElement(AgentToolCallBlock, {
- toolCallNode: {
- toolCall: {
- toolId: "tool-agent-running",
- kind: "think",
- title: "Inspect workspace",
- input: {
- prompt: "分析当前工作区并继续拆分任务",
- subagent_type: "Explore",
- },
- output: [],
- status: "running",
- raw: {
- _meta: {
- zcode: {
- toolName: "Agent",
- },
- },
- },
- },
- childToolCalls: [],
- },
- workspacePath: "/workspace",
- displayModel: {
- inlinePreview: { type: "none" },
- planResult: null,
- viewerSource: null,
- viewerLabelId: "codeViewer.viewCode",
- showSummaryFileLink: false,
- showInput: false,
- showOutput: false,
- showKind: false,
- },
- viewerSource: null,
- rawFileSummaries: [],
- isRunning: true,
- statusLabel: "执行中",
- errorText: undefined,
- childToolList: null,
- showIcon: true,
- forceOpen: false,
- onOpenCodeViewer: undefined,
- onOpenBrowserUrl: undefined,
- }),
- ),
- ),
- ),
- );
- expect(html).toContain(testId(TID_TOOL_SUMMARY_TRIGGER, "tool-agent-running"));
- expect(html).toContain("Inspect workspace");
- expect(html).not.toContain('role="button"');
- expect(html).not.toContain("aria-expanded");
- expect(html).not.toContain("lucide-chevron-right");
- expect(html).not.toMatch(/提示词|Prompt/);
- expect(html).not.toContain("分析当前工作区并继续拆分任务");
- });
- it("uses a side-pane summary action instead of expandable details", () => {
- const html = renderToStaticMarkup(
- createElement(
- ZCodeIntlProvider,
- { initialLocale: "zh-CN" },
- createElement(
- ServiceProvider,
- { services: mockServices },
- createElement(
- StoreProvider,
- { broadcastService: mockBroadcastService },
- createElement(AgentToolCallBlock, {
- toolCallNode: {
- toolCall: {
- toolId: "tool-agent-summary-action",
- kind: "think",
- title: "Inspect workspace",
- input: {
- prompt: "分析当前工作区并继续拆分任务",
- subagent_type: "Explore",
- },
- output: [],
- status: "running",
- raw: {
- _meta: {
- zcode: {
- toolName: "Agent",
- },
- },
- },
- },
- childToolCalls: [],
- },
- workspacePath: "/workspace",
- displayModel: {
- inlinePreview: { type: "none" },
- planResult: null,
- viewerSource: null,
- viewerLabelId: "codeViewer.viewCode",
- showSummaryFileLink: false,
- showInput: false,
- showOutput: false,
- showKind: false,
- },
- viewerSource: null,
- rawFileSummaries: [],
- isRunning: true,
- statusLabel: "执行中",
- errorText: undefined,
- childToolList: null,
- showIcon: true,
- agentSummaryAction: {
- onActivate: vi.fn(),
- testId: "v4-subagent-open-side-pane-child-session",
- },
- onOpenCodeViewer: undefined,
- onOpenBrowserUrl: undefined,
- }),
- ),
- ),
- ),
- );
- expect(html).toContain('data-testid="v4-subagent-open-side-pane-child-session"');
- expect(html).toContain('aria-label="在右侧打开"');
- expect(html).not.toContain("aria-expanded");
- expect(html).not.toContain("lucide-chevron-right");
- expect(html).not.toContain("subagent-output-preview");
- expect(html).not.toContain("分析当前工作区并继续拆分任务");
- });
- it("never falls back to inline prompt or child output", () => {
- const html = renderToStaticMarkup(
- createElement(
- ZCodeIntlProvider,
- { initialLocale: "zh-CN" },
- createElement(
- ServiceProvider,
- { services: mockServices },
- createElement(
- StoreProvider,
- { broadcastService: mockBroadcastService },
- createElement(AgentToolCallBlock, {
- toolCallNode: {
- toolCall: {
- toolId: "tool-agent-drilldown-slot",
- kind: "think",
- title: "Inspect workspace",
- input: {
- prompt: "分析当前工作区并继续拆分任务",
- subagent_type: "Explore",
- },
- output: [],
- status: "running",
- raw: {
- _meta: {
- zcode: {
- toolName: "Agent",
- },
- },
- },
- },
- childToolCalls: [],
- },
- workspacePath: "/workspace",
- displayModel: {
- inlinePreview: { type: "none" },
- planResult: null,
- viewerSource: null,
- viewerLabelId: "codeViewer.viewCode",
- showSummaryFileLink: false,
- showInput: false,
- showOutput: false,
- showKind: false,
- },
- viewerSource: null,
- rawFileSummaries: [],
- isRunning: true,
- statusLabel: "执行中",
- errorText: undefined,
- childToolList: null,
- showIcon: true,
- forceOpen: true,
- onOpenCodeViewer: undefined,
- onOpenBrowserUrl: undefined,
- }),
- ),
- ),
- ),
- );
- expect(html).not.toMatch(/提示词|Prompt/);
- expect(html).not.toContain("分析当前工作区并继续拆分任务");
- expect(html).not.toContain("subagent-output-preview");
- expect(html).not.toContain("aria-expanded");
- expect(html).not.toContain("lucide-chevron-right");
- expect(html).not.toContain("在右侧打开");
- expect(html).not.toContain("子会话");
- });
- it("colors the subagent name from the configured agent color", () => {
- useSubagentsStore.setState({
- agents: [
- {
- id: "agent-explore",
- name: "Explore",
- description: "Explore workspace",
- systemPrompt: "Explore",
- color: "red",
- path: "/workspace/.zcode/agents/explore.md",
- scope: "user",
- source: "user",
- enabled: true,
- },
- ],
- });
- const html = renderToStaticMarkup(
- createElement(
- ZCodeIntlProvider,
- { initialLocale: "zh-CN" },
- createElement(
- ServiceProvider,
- { services: mockServices },
- createElement(
- StoreProvider,
- { broadcastService: mockBroadcastService },
- createElement(AgentToolCallBlock, {
- toolCallNode: {
- toolCall: {
- toolId: "tool-agent-configured-color",
- kind: "think",
- title: "Agent",
- input: {
- prompt: "检查工作区",
- subagent_type: "Explore",
- },
- output: [],
- status: "completed",
- raw: {},
- },
- childToolCalls: [],
- },
- workspacePath: "/workspace",
- displayModel: {
- inlinePreview: { type: "none" },
- planResult: null,
- viewerSource: null,
- viewerLabelId: "codeViewer.viewCode",
- showSummaryFileLink: false,
- showInput: false,
- showOutput: false,
- showKind: false,
- },
- viewerSource: null,
- rawFileSummaries: [],
- isRunning: false,
- statusLabel: "完成",
- errorText: undefined,
- childToolList: null,
- showIcon: true,
- forceOpen: false,
- onOpenCodeViewer: undefined,
- onOpenBrowserUrl: undefined,
- }),
- ),
- ),
- ),
- );
- expect(html).toContain("Explore");
- expect(html).toContain("text-rose-700");
- expect(html).toContain("inline-flex max-w-36 items-center");
- expect(html).toContain("leading-[1.5]");
- expect(html).not.toContain("leading-none");
- });
- it("keeps the agent type blank while subagent_type may still be streaming", () => {
- const html = renderToStaticMarkup(
- createElement(
- ZCodeIntlProvider,
- { initialLocale: "zh-CN" },
- createElement(
- ServiceProvider,
- { services: mockServices },
- createElement(
- StoreProvider,
- { broadcastService: mockBroadcastService },
- createElement(AgentToolCallBlock, {
- toolCallNode: {
- toolCall: {
- toolId: "tool-agent-streaming-type",
- kind: "Agent",
- title: "Agent",
- input: {
- description: "检查流式参数",
- prompt: "等待完整输入",
- },
- output: "",
- status: "pending",
- raw: {
- toolName: "Agent",
- inputPreviewComplete: false,
- },
- },
- childToolCalls: [],
- },
- workspacePath: "/workspace",
- displayModel: {
- inlinePreview: { type: "none" },
- planResult: null,
- viewerSource: null,
- viewerLabelId: "codeViewer.viewCode",
- showSummaryFileLink: false,
- showInput: false,
- showOutput: false,
- showKind: false,
- },
- viewerSource: null,
- rawFileSummaries: [],
- isRunning: true,
- statusLabel: "等待中",
- errorText: undefined,
- childToolList: null,
- showIcon: true,
- forceOpen: false,
- onOpenCodeViewer: undefined,
- onOpenBrowserUrl: undefined,
- }),
- ),
- ),
- ),
- );
- expect(html).toContain("检查流式参数");
- expect(html).not.toContain("general-purpose");
- });
- it("falls back to the default general-purpose agent type only after complete input omits subagent_type", () => {
- const html = renderToStaticMarkup(
- createElement(
- ZCodeIntlProvider,
- { initialLocale: "zh-CN" },
- createElement(
- ServiceProvider,
- { services: mockServices },
- createElement(
- StoreProvider,
- { broadcastService: mockBroadcastService },
- createElement(AgentToolCallBlock, {
- toolCallNode: {
- toolCall: {
- toolId: "tool-agent-default-type",
- kind: "Agent",
- title: "Agent",
- input: {
- description: "抓取 bettingexpert 赔率",
- prompt: "获取赔率信息",
- run_in_background: true,
- },
- output: "Async agent launched successfully.",
- status: "running",
- raw: {
- inputPreviewComplete: true,
- _meta: {
- zcode: {
- toolName: "Agent",
- },
- },
- },
- },
- childToolCalls: [],
- },
- workspacePath: "/workspace",
- displayModel: {
- inlinePreview: { type: "none" },
- planResult: null,
- viewerSource: null,
- viewerLabelId: "codeViewer.viewCode",
- showSummaryFileLink: false,
- showInput: false,
- showOutput: false,
- showKind: false,
- },
- viewerSource: null,
- rawFileSummaries: [],
- isRunning: true,
- statusLabel: "执行中",
- errorText: undefined,
- childToolList: null,
- showIcon: true,
- forceOpen: false,
- onOpenCodeViewer: undefined,
- onOpenBrowserUrl: undefined,
- }),
- ),
- ),
- ),
- );
- expect(html).toContain("general-purpose");
- });
- it("uses the latest child tool summary for a collapsed running subagent", () => {
- const html = renderToStaticMarkup(
- createElement(
- ZCodeIntlProvider,
- { initialLocale: "zh-CN" },
- createElement(
- ServiceProvider,
- { services: mockServices },
- createElement(
- StoreProvider,
- { broadcastService: mockBroadcastService },
- createElement(AgentToolCallBlock, {
- toolCallNode: {
- toolCall: {
- toolId: "tool-agent-child-summary",
- kind: "Agent",
- title: "Agent",
- input: {
- prompt: "读取核心入口文件",
- subagent_type: "Explore",
- },
- output: "",
- status: "running",
- raw: {
- _meta: {
- zcode: {
- toolName: "Agent",
- },
- },
- },
- },
- childToolCalls: [
- {
- toolCall: {
- toolId: "tool-agent-child-read",
- kind: "read",
- title: "Read",
- input: {
- path: "/workspace/src/App.tsx",
- },
- output: "",
- status: "running",
- raw: {},
- },
- childToolCalls: [],
- },
- ],
- },
- workspacePath: "/workspace",
- displayModel: {
- inlinePreview: { type: "none" },
- planResult: null,
- viewerSource: null,
- viewerLabelId: "codeViewer.viewCode",
- showSummaryFileLink: false,
- showInput: false,
- showOutput: false,
- showKind: false,
- },
- viewerSource: null,
- rawFileSummaries: [],
- isRunning: true,
- statusLabel: "执行中",
- errorText: undefined,
- childToolList: null,
- showIcon: true,
- forceOpen: false,
- onOpenCodeViewer: undefined,
- onOpenBrowserUrl: undefined,
- }),
- ),
- ),
- ),
- );
- // Bugfix: Agent 收起态参考普通 active Explore 聚合,使用最新子工具摘要,
- // 同时外层仍展示子智能体,而不是把子智能体类型 Explore 当 kind label。
- expect(html).toContain("lucide-bot");
- expect(html).toMatch(/>(SubAgent|子智能体)</);
- expect(html).toContain("·");
- expect(html).toContain("正在读取");
- expect(html).toContain("App.tsx");
- expect(html).toContain("/workspace/src");
- expect(html).not.toContain("读取核心入口文件");
- });
- it("does not keep a completed subagent visually running while a child tool is running", () => {
- const html = renderToStaticMarkup(
- createElement(
- ZCodeIntlProvider,
- { initialLocale: "zh-CN" },
- createElement(
- ServiceProvider,
- { services: mockServices },
- createElement(
- StoreProvider,
- { broadcastService: mockBroadcastService },
- createElement(AgentToolCallBlock, {
- toolCallNode: {
- toolCall: {
- toolId: "tool-agent-completed-child-running",
- kind: "Agent",
- title: "Agent",
- input: {
- prompt: "读取核心入口文件",
- subagent_type: "Explore",
- },
- output: "",
- status: "completed",
- raw: {
- _meta: {
- zcode: {
- toolName: "Agent",
- },
- },
- },
- },
- childToolCalls: [
- {
- toolCall: {
- toolId: "tool-agent-child-read-still-running",
- kind: "read",
- title: "Read",
- input: {
- path: "/workspace/src/App.tsx",
- },
- output: "",
- status: "in_progress",
- raw: {},
- },
- childToolCalls: [],
- },
- ],
- },
- workspacePath: "/workspace",
- displayModel: {
- inlinePreview: { type: "none" },
- planResult: null,
- viewerSource: null,
- viewerLabelId: "codeViewer.viewCode",
- showSummaryFileLink: false,
- showInput: false,
- showOutput: false,
- showKind: false,
- },
- viewerSource: null,
- rawFileSummaries: [],
- isRunning: false,
- statusLabel: "已执行",
- errorText: undefined,
- childToolList: null,
- showIcon: true,
- forceOpen: false,
- onOpenCodeViewer: undefined,
- onOpenBrowserUrl: undefined,
- }),
- ),
- ),
- ),
- );
- // Bugfix: 父 Agent 的完成态只看父 tool 生命周期;
- // 子工具属于展开区明细,不能让 completed 父块继续显示 running 渐变。
- expect(html).toMatch(/>(SubAgent|子智能体)</);
- expect(html).toContain("Explore");
- expect(html).not.toContain("正在读取");
- expect(html).not.toContain("App.tsx");
- expect(html).not.toContain("animated-gradient-text");
- expect(html).not.toContain("读取核心入口文件");
- });
- it("allows disabling subagent summary roll animation", () => {
- const html = renderToStaticMarkup(
- createElement(
- ZCodeIntlProvider,
- { initialLocale: "zh-CN" },
- createElement(
- ServiceProvider,
- { services: mockServices },
- createElement(
- StoreProvider,
- { broadcastService: mockBroadcastService },
- createElement(AgentToolCallBlock, {
- toolCallNode: {
- toolCall: {
- toolId: "tool-agent-animation-disabled",
- kind: "Agent",
- title: "Agent",
- input: {
- prompt: "读取核心入口文件",
- subagent_type: "Explore",
- },
- output: "",
- status: "running",
- raw: {
- _meta: {
- zcode: {
- toolName: "Agent",
- },
- },
- },
- },
- childToolCalls: [
- {
- toolCall: {
- toolId: "tool-agent-animation-disabled-child",
- kind: "read",
- title: "Read",
- input: {
- path: "/workspace/src/App.tsx",
- },
- output: "",
- status: "in_progress",
- raw: {},
- },
- childToolCalls: [],
- },
- ],
- },
- workspacePath: "/workspace",
- displayModel: {
- inlinePreview: { type: "none" },
- planResult: null,
- viewerSource: null,
- viewerLabelId: "codeViewer.viewCode",
- showSummaryFileLink: false,
- showInput: false,
- showOutput: false,
- showKind: false,
- },
- viewerSource: null,
- rawFileSummaries: [],
- isRunning: true,
- statusLabel: "执行中",
- errorText: undefined,
- childToolList: null,
- showIcon: true,
- forceOpen: false,
- disableSummaryContentAnimation: true,
- onOpenCodeViewer: undefined,
- onOpenBrowserUrl: undefined,
- }),
- ),
- ),
- ),
- );
- expect(html).toContain("正在读取");
- expect(html).toContain("App.tsx");
- expect(html).not.toContain("overflow-hidden align-middle");
- });
- it("keeps the child action label for completed subagent child summaries", () => {
- const html = renderToStaticMarkup(
- createElement(
- ZCodeIntlProvider,
- { initialLocale: "zh-CN" },
- createElement(
- ServiceProvider,
- { services: mockServices },
- createElement(
- StoreProvider,
- { broadcastService: mockBroadcastService },
- createElement(AgentToolCallBlock, {
- toolCallNode: {
- toolCall: {
- toolId: "tool-agent-completed-child-summary",
- kind: "Agent",
- title: "Agent",
- input: {
- prompt: "读取核心入口文件",
- subagent_type: "Explore",
- },
- output: "",
- status: "running",
- raw: {
- _meta: {
- zcode: {
- toolName: "Agent",
- },
- },
- },
- },
- childToolCalls: [
- {
- toolCall: {
- toolId: "tool-agent-completed-child-read",
- kind: "read",
- title: "Read",
- input: {
- path: "/workspace/src/App.tsx",
- },
- output: "",
- status: "completed",
- raw: {},
- },
- childToolCalls: [],
- },
- ],
- },
- workspacePath: "/workspace",
- displayModel: {
- inlinePreview: { type: "none" },
- planResult: null,
- viewerSource: null,
- viewerLabelId: "codeViewer.viewCode",
- showSummaryFileLink: false,
- showInput: false,
- showOutput: false,
- showKind: false,
- },
- viewerSource: null,
- rawFileSummaries: [],
- isRunning: true,
- statusLabel: "执行中",
- errorText: undefined,
- childToolList: null,
- showIcon: true,
- forceOpen: false,
- onOpenCodeViewer: undefined,
- onOpenBrowserUrl: undefined,
- }),
- ),
- ),
- ),
- );
- expect(html).toContain("·");
- expect(html).toContain("App.tsx");
- expect(html).toContain("正在读取");
- });
- it("summarizes TodoWrite child tools with todo progress and active content", () => {
- const html = renderToStaticMarkup(
- createElement(
- ZCodeIntlProvider,
- { initialLocale: "zh-CN" },
- createElement(
- ServiceProvider,
- { services: mockServices },
- createElement(
- StoreProvider,
- { broadcastService: mockBroadcastService },
- createElement(AgentToolCallBlock, {
- toolCallNode: {
- toolCall: {
- toolId: "tool-agent-todo-child-summary",
- kind: "Agent",
- title: "Agent",
- input: {
- prompt: "实现 toolcall 摘要优化",
- subagent_type: "Explore",
- },
- output: "",
- status: "running",
- raw: {
- _meta: {
- zcode: {
- toolName: "Agent",
- },
- },
- },
- },
- childToolCalls: [
- {
- toolCall: {
- toolId: "tool-agent-child-todo",
- toolName: "TodoWrite",
- kind: "TodoWrite",
- title: "TodoWrite",
- input: {
- todos: [
- {
- content: "确认现有 Agent 摘要行为",
- status: "completed",
- },
- {
- content: "补齐待办子工具摘要",
- status: "in_progress",
- },
- {
- content: "跑回归测试",
- status: "pending",
- },
- ],
- },
- output: "",
- status: "running",
- raw: {},
- },
- childToolCalls: [],
- },
- ],
- },
- workspacePath: "/workspace",
- displayModel: {
- inlinePreview: { type: "none" },
- planResult: null,
- viewerSource: null,
- viewerLabelId: "codeViewer.viewCode",
- showSummaryFileLink: false,
- showInput: false,
- showOutput: false,
- showKind: false,
- },
- viewerSource: null,
- rawFileSummaries: [],
- isRunning: true,
- statusLabel: "执行中",
- errorText: undefined,
- childToolList: null,
- showIcon: true,
- forceOpen: false,
- onOpenCodeViewer: undefined,
- onOpenBrowserUrl: undefined,
- }),
- ),
- ),
- ),
- );
- expect(html).toContain("·");
- expect(html).toContain("更新待办");
- expect(html).toContain("1/3");
- expect(html).toContain("补齐待办子工具摘要");
- expect(html).not.toContain("Running TodoWrite");
- });
- it("uses SubAgent as the outer kind instead of the resolved agent type", () => {
- const html = renderToStaticMarkup(
- createElement(
- ZCodeIntlProvider,
- { initialLocale: "zh-CN" },
- createElement(
- ServiceProvider,
- { services: mockServices },
- createElement(
- StoreProvider,
- { broadcastService: mockBroadcastService },
- createElement(AgentToolCallBlock, {
- toolCallNode: {
- toolCall: {
- toolId: "tool-agent-numbered",
- kind: "think",
- title: "Agent",
- input: {
- description: "Explore project structure",
- prompt: "搜索国际与商业新闻",
- },
- output: JSON.stringify({
- status: "completed",
- agentId: "agent_6e358228-a52f-427a-b1ae-d30b5cd9899e",
- agentType: "Explore",
- description: "Explore project structure",
- }),
- status: "completed",
- raw: {
- _meta: {
- zcode: {
- toolName: "Agent",
- },
- },
- },
- },
- childToolCalls: [],
- },
- workspacePath: "/workspace",
- displayModel: {
- inlinePreview: { type: "none" },
- planResult: null,
- viewerSource: null,
- viewerLabelId: "codeViewer.viewCode",
- showSummaryFileLink: false,
- showInput: false,
- showOutput: false,
- showKind: false,
- },
- viewerSource: null,
- rawFileSummaries: [],
- isRunning: false,
- statusLabel: "已执行",
- errorText: undefined,
- childToolList: null,
- showIcon: true,
- forceOpen: false,
- sourceLabel: "SubAgent",
- onOpenCodeViewer: undefined,
- onOpenBrowserUrl: undefined,
- }),
- ),
- ),
- ),
- );
- // 外层 kind 固定显示 SubAgent;真实子智能体类型作为彩色名称展示。
- expect(html).toMatch(/>(SubAgent|子智能体)</);
- expect(html).toContain("·");
- expect(html).toContain("Explore project structure");
- expect(html).not.toContain("子智能体 2");
- expect(html).not.toMatch(/>Agent</);
- expect(html).toMatch(/>Explore</);
- });
- it("uses spawn_agent subagent nickname as the summary primary text", () => {
- const html = renderToStaticMarkup(
- createElement(
- ZCodeIntlProvider,
- { initialLocale: "zh-CN" },
- createElement(
- ServiceProvider,
- { services: mockServices },
- createElement(
- StoreProvider,
- { broadcastService: mockBroadcastService },
- createElement(AgentToolCallBlock, {
- toolCallNode: {
- toolCall: {
- toolId: "tool-spawn-agent-locke",
- kind: "spawn_agent",
- title: "spawn_agent",
- input: {
- agent_type: "explorer",
- message: "在当前项目里做只读结构检查",
- },
- output: "",
- status: "completed",
- raw: {
- name: "spawn_agent",
- _meta: {
- zcode: {
- toolName: "spawn_agent",
- nickname: "Locke",
- },
- },
- },
- },
- childToolCalls: [],
- },
- workspacePath: "/workspace",
- displayModel: {
- inlinePreview: { type: "none" },
- planResult: null,
- viewerSource: null,
- viewerLabelId: "codeViewer.viewCode",
- showSummaryFileLink: false,
- showInput: false,
- showOutput: false,
- showKind: false,
- },
- viewerSource: null,
- rawFileSummaries: [],
- isRunning: false,
- statusLabel: "已执行",
- errorText: undefined,
- childToolList: null,
- showIcon: true,
- forceOpen: false,
- onOpenCodeViewer: undefined,
- onOpenBrowserUrl: undefined,
- }),
- ),
- ),
- ),
- );
- // Bugfix: provider 原生子 agent 工具名 spawn_agent 直接展示会暴露实现细节;
- // 外层 kind 固定为 SubAgent,nickname 作为彩色名称和摘要正文展示。
- expect(html).not.toMatch(/>explorer</);
- expect(html).toMatch(/>(SubAgent|子智能体)</);
- expect(html).toContain("Locke");
- expect(html).not.toContain("子智能体 1");
- expect(html).not.toContain("spawn_agent");
- expect(html).not.toContain("在当前项目里做只读结构检查");
- });
- it("falls back to spawn_agent agent_type when nickname is not available", () => {
- const html = renderToStaticMarkup(
- createElement(
- ZCodeIntlProvider,
- { initialLocale: "zh-CN" },
- createElement(
- ServiceProvider,
- { services: mockServices },
- createElement(
- StoreProvider,
- { broadcastService: mockBroadcastService },
- createElement(AgentToolCallBlock, {
- toolCallNode: {
- toolCall: {
- toolId: "tool-spawn-agent-explorer",
- kind: "spawn_agent",
- title: "spawn_agent",
- input: {
- agent_type: "explorer",
- message: "在当前项目里做只读结构检查",
- },
- output: "",
- status: "pending",
- raw: {
- name: "spawn_agent",
- },
- },
- childToolCalls: [],
- },
- workspacePath: "/workspace",
- displayModel: {
- inlinePreview: { type: "none" },
- planResult: null,
- viewerSource: null,
- viewerLabelId: "codeViewer.viewCode",
- showSummaryFileLink: false,
- showInput: false,
- showOutput: false,
- showKind: false,
- },
- viewerSource: null,
- rawFileSummaries: [],
- isRunning: true,
- statusLabel: "执行中",
- errorText: undefined,
- childToolList: null,
- showIcon: true,
- forceOpen: false,
- onOpenCodeViewer: undefined,
- onOpenBrowserUrl: undefined,
- }),
- ),
- ),
- ),
- );
- expect(html).toContain("explorer");
- expect(html).toMatch(/>(SubAgent|子智能体)</);
- expect(html).not.toContain("子智能体 1");
- expect(html).not.toContain("spawn_agent");
- });
- it("renders prompt and child tool calls without result content", () => {
- const html = renderToStaticMarkup(
- createElement(
- ZCodeIntlProvider,
- { initialLocale: "zh-CN" },
- createElement(
- ServiceProvider,
- { services: mockServices },
- createElement(
- StoreProvider,
- { broadcastService: mockBroadcastService },
- createElement(AgentToolCallBlock, {
- toolCallNode: {
- toolCall: {
- toolId: "tool-agent-render",
- kind: "think",
- title: "Explore project structure",
- input: {
- prompt: "请分析项目结构并列出入口点",
- subagent_type: "Explore",
- },
- output: [
- {
- type: "text",
- text: "这段结果不应该直接展示在 Agent 展开区",
- },
- ],
- status: "completed",
- raw: {
- _meta: {
- zcode: {
- toolName: "Agent",
- },
- },
- },
- },
- childToolCalls: [
- {
- toolCall: {
- toolId: "tool-agent-child",
- kind: "search",
- title: "Find package.json",
- input: {
- query: "package.json",
- },
- output: "...",
- status: "completed",
- raw: {},
- },
- childToolCalls: [],
- },
- ],
- },
- workspacePath: "/workspace",
- displayModel: {
- inlinePreview: { type: "none" },
- planResult: null,
- viewerSource: null,
- viewerLabelId: "codeViewer.viewCode",
- showSummaryFileLink: false,
- showInput: false,
- showOutput: false,
- showKind: false,
- },
- viewerSource: null,
- rawFileSummaries: [],
- isRunning: false,
- statusLabel: "已执行",
- errorText: undefined,
- childToolList: null,
- showIcon: true,
- forceOpen: true,
- onOpenCodeViewer: undefined,
- onOpenBrowserUrl: undefined,
- }),
- ),
- ),
- ),
- );
- // Agent/Task 在消息流中固定为单行;详情只通过持久化 child session 打开。
- expect(html).toMatch(/>(SubAgent|子智能体)</);
- expect(html).toMatch(/>Explore</);
- expect(html).toContain("Explore project structure");
- expect(html).not.toMatch(/提示词|Prompt/);
- expect(html).not.toContain("请分析项目结构并列出入口点");
- expect(html).not.toContain("Find package.json");
- expect(html).not.toContain("aria-expanded");
- expect(html).not.toContain("这段结果不应该直接展示在 Agent 展开区");
- });
- it("keeps background agent internals out of the static summary", () => {
- const html = renderToStaticMarkup(
- createElement(
- ZCodeIntlProvider,
- { initialLocale: "zh-CN" },
- createElement(
- ServiceProvider,
- { services: mockServices },
- createElement(
- StoreProvider,
- { broadcastService: mockBroadcastService },
- createElement(AgentToolCallBlock, {
- toolCallNode: {
- toolCall: {
- toolId: "tool-background-agent",
- kind: "think",
- title: "Task",
- input: {
- prompt: "搜索今日新闻",
- run_in_background: true,
- },
- output: [
- {
- type: "text",
- text: "Async agent launched successfully.\nagentId: internal-agent-id (internal ID - do not mention to user.)\noutput_file: /tmp/background-agent.output\n",
- },
- ],
- status: "completed",
- raw: {
- _meta: {
- zcode: {
- toolName: "Agent",
- backgroundAgent: {
- runInBackground: true,
- agentId: "internal-agent-id",
- outputFile: "/tmp/background-agent.output",
- },
- },
- },
- },
- },
- childToolCalls: [],
- },
- workspacePath: "/workspace",
- displayModel: {
- inlinePreview: { type: "none" },
- planResult: null,
- viewerSource: null,
- viewerLabelId: "codeViewer.viewCode",
- showSummaryFileLink: false,
- showInput: false,
- showOutput: false,
- showKind: false,
- },
- viewerSource: null,
- rawFileSummaries: [],
- isRunning: false,
- statusLabel: "已执行",
- errorText: undefined,
- childToolList: null,
- showIcon: true,
- forceOpen: true,
- onOpenCodeViewer: undefined,
- onOpenBrowserUrl: undefined,
- }),
- ),
- ),
- ),
- );
- expect(html).toMatch(/子智能体|SubAgent/);
- expect(html).not.toContain("/tmp/background-agent.output");
- expect(html).not.toContain("internal-agent-id");
- });
- it("does not inline background child activity", () => {
- const html = renderToStaticMarkup(
- createElement(
- ZCodeIntlProvider,
- { initialLocale: "zh-CN" },
- createElement(
- ServiceProvider,
- { services: mockServices },
- createElement(
- StoreProvider,
- { broadcastService: mockBroadcastService },
- createElement(AgentToolCallBlock, {
- toolCallNode: {
- toolCall: {
- toolId: "tool-background-agent-activity",
- kind: "think",
- title: "Task",
- input: {
- prompt: "后台调研项目结构",
- run_in_background: true,
- },
- output: "",
- content: "已读取 package.json,继续分析入口文件。",
- thought: "先确认项目结构。",
- status: "completed",
- raw: {
- _meta: {
- zcode: {
- toolName: "Agent",
- backgroundAgent: {
- runInBackground: true,
- },
- },
- },
- },
- },
- childToolCalls: [],
- },
- workspacePath: "/workspace",
- displayModel: {
- inlinePreview: { type: "none" },
- planResult: null,
- viewerSource: null,
- viewerLabelId: "codeViewer.viewCode",
- showSummaryFileLink: false,
- showInput: false,
- showOutput: false,
- showKind: false,
- },
- viewerSource: null,
- rawFileSummaries: [],
- isRunning: false,
- statusLabel: "已执行",
- errorText: undefined,
- childToolList: null,
- showIcon: true,
- forceOpen: true,
- onOpenCodeViewer: undefined,
- onOpenBrowserUrl: undefined,
- }),
- ),
- ),
- ),
- );
- expect(html).not.toContain("先确认项目结构。");
- expect(html).not.toContain("已读取 package.json");
- expect(html).not.toContain("data-markdown-table-sticky-scrollbar");
- });
- it("does not inline either task notification or raw background transcript", () => {
- const html = renderToStaticMarkup(
- createElement(
- ZCodeIntlProvider,
- { initialLocale: "zh-CN" },
- createElement(
- ServiceProvider,
- { services: mockServices },
- createElement(
- StoreProvider,
- { broadcastService: mockBroadcastService },
- createElement(AgentToolCallBlock, {
- toolCallNode: {
- toolCall: {
- toolId: "tool-background-agent-summary",
- kind: "think",
- title: "Implement Todo types and components",
- input: {
- prompt: "实现 Todo 类型和组件",
- run_in_background: true,
- },
- output: "",
- content: '{"isSidechain":true,"message":"raw transcript"}',
- status: "completed",
- raw: {
- _meta: {
- zcode: {
- toolName: "Agent",
- backgroundAgent: {
- runInBackground: true,
- },
- taskNotification: {
- outputFile: "/tmp/background-agent.output",
- result: "All files are created and the project builds successfully.",
- },
- },
- },
- },
- },
- childToolCalls: [],
- },
- workspacePath: "/workspace",
- displayModel: {
- inlinePreview: { type: "none" },
- planResult: null,
- viewerSource: null,
- viewerLabelId: "codeViewer.viewCode",
- showSummaryFileLink: false,
- showInput: false,
- showOutput: false,
- showKind: false,
- },
- viewerSource: null,
- rawFileSummaries: [],
- isRunning: false,
- statusLabel: "已执行",
- errorText: undefined,
- childToolList: null,
- showIcon: true,
- forceOpen: true,
- onOpenCodeViewer: undefined,
- onOpenBrowserUrl: undefined,
- }),
- ),
- ),
- ),
- );
- expect(html).not.toContain("All files are created and the project builds successfully.");
- expect(html).not.toContain("raw transcript");
- });
- });
|