// @vitest-environment jsdom // dwf run 详情页(docs/dynamic-workflow/presentation.md「The run pane」):状态头 / 用量行 / Cancel / // 结果与失败面板 / 待答问题 / 产物 / 空态,双语言。 // // 2026-09-04 用户指令:Results(`report` 条目)、事件日志、Script 三节已从面板撤走(技术细节, // 不给用户看),对应的用例整段删除;journal 的读面没有变化,只是这块面板不再显示它们。 // // 纯规则(Cancel 可用性、结果判定、事件摘要)在 workflowRunPanel.test.ts 里穷举; // 这里只钉「那些结果真的接到了 DOM 上」以及交互(点击 Cancel 发出哪条命令)。 import { createElement, type ReactNode } from "react"; import { act, cleanup, fireEvent, render, waitFor, within } from "@testing-library/react"; import { beforeEach, describe, expect, it, vi } from "vitest"; import { TID_WORKFLOW_ARTIFACTS_SECTION, TID_WORKFLOW_ARTIFACT_CARD } from "@zcode/shared"; import type { WorkflowRunState } from "@zcode/shared/zcode-protocol-v4"; import type { WorkflowRunSidePaneTab } from "@/lib/workspaceSidePane.js"; vi.mock("@/logger.js", () => ({ logger: { debug: vi.fn(), warn: vi.fn() }, })); // 提示只渲染 children(不改 DOM 形状),但把 title / description 记下来:Stop 钮的第二行 // 「停下的运行可以恢复」只活在提示里。 const tooltips = vi.hoisted(() => ({ calls: [] as Array<{ title: unknown; description?: string }>, })); vi.mock("@/ControlHintTooltip.js", () => ({ ControlHintTooltip: ({ children, title, description, }: { children?: ReactNode; title?: unknown; description?: string; }) => { tooltips.calls.push({ title, ...(description === undefined ? {} : { description }) }); return children; }, })); const sendCommand = vi.fn(async () => ({ status: "accepted" }) as never); const release = vi.fn(); // layer 必须是**稳定引用**:组件的租约 effect 以 layer 为依赖,每次渲染换一个新对象 // 会让 acquire → setLease → 重渲染 → 新 layer 无限循环(生产里 useV4Conversation // 返回的是 useMemo 过的 bundle,本来就稳定)。 const layer = { acquire: vi.fn(() => ({ release })) }; const workflowRunsQuery = vi.fn<() => Promise<{ runs: unknown[] }>>(async () => ({ runs: [] })); // 产物(docs/dynamic-workflow/authoring.md):清单走 journal 查询,看板条目走取数查询。 // 两条都在这里桩掉——面板挂载时无条件问一次清单(活投影不带 spec 与版本历史)。 const workflowRunArtifactsQuery = vi.fn<() => Promise<{ artifacts: unknown[] }>>(async () => ({ artifacts: [], })); const workflowRunArtifactDataQuery = vi.fn<() => Promise<{ items: unknown[]; hasMore: boolean }>>( async () => ({ items: [], hasMore: false }), ); const conversation = { layer, sendCommand, workflowRuns: workflowRunsQuery, workflowRunArtifacts: workflowRunArtifactsQuery, workflowRunArtifactData: workflowRunArtifactDataQuery, }; vi.mock("@/v4/V4ConversationContext.js", () => ({ V4PaneConversationProvider: ({ children }: { children: ReactNode }) => children, useV4Conversation: () => conversation, })); let snapshot: unknown = null; vi.mock("@/v4/useConversationProjection.js", () => ({ useConversationProjection: () => ({ snapshot }), })); // 「配置」弹层的模型清单(docs/dynamic-workflow/presentation.md「The settings popover」):面板本身不读它, // 只有弹层打开时才订阅;给一份空清单即可(字段本身在 workflowRunSettingsPopover.test.ts 里钉)。 vi.mock("@/hooks/useModelSelectionView.js", () => ({ useModelSelectionView: () => ({ state: { status: "ready", view: { revision: 1, providers: [] } }, reload: vi.fn(), }), })); // eslint-disable-next-line import/first -- 必须在全部 mock 之后再引入被测组件。 import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js"; // eslint-disable-next-line import/first import { WorkflowRunSidePane } from "@/app-shell/WorkflowRunSidePane.js"; // eslint-disable-next-line import/first import { useDynamicWorkflowAvailabilityStore } from "@/store/dynamicWorkflowAvailabilityStore.js"; /** 灰度快照(docs/dynamic-workflow/launch.md「Gray release」):默认命中,面板与改动前一致。 */ function setDynamicWorkflowEnabled(enabled: boolean): void { useDynamicWorkflowAvailabilityStore.setState({ status: "ready", enabled, config: { mode: enabled ? "alwaysOn" : "disabled", enabled, source: "remote" }, }); } const tab: WorkflowRunSidePaneTab = { id: "workflow-run:%2Fworkspace:parent-a:dwfrun-1", type: "workflow-run", workspaceKey: "/workspace", workspacePath: "/workspace", parentSessionId: "parent-a", toolCallId: "tool-wf-1", runId: "dwfrun-1", workflowName: "Fan-out review", }; interface GraphStep { id: string; kind: "ask" | "world-read"; label: string; lane: string; line?: number; phase?: string; } const STEPS: GraphStep[] = [ { id: "ask#1", kind: "ask", label: "plan", lane: "actor#1", // 检视器 SOURCE 区的 `L{n}` 需要一个落点:车道没有行号时退回它第一步的行。 line: 4, }, // 检视用的另外几张卡:workspace 车道(合成,无会话)与两条匿名车道。 { id: "world-read#1", kind: "world-read", label: "read files", lane: "workspace", }, { id: "ask#2", kind: "ask", label: "review", lane: "actor#2", }, { id: "ask#3", kind: "ask", label: "audit", lane: "actor#3", }, ]; const LANES = [ { id: "actor#1", name: "planner" }, // 两条匿名车道:编号必须出现(Anonymous Subagent 1 / 2),且与图里那份同源。 { id: "actor#2" }, { id: "actor#3" }, { id: "workspace" }, ]; /** 参与者 = 每阶段每车道一张卡,id 按分析器的 `${phase}:${lane}`;无标记脚本归 `unphased`。 */ function participantsOf(steps: readonly GraphStep[]) { const byId = new Map(); for (const step of steps) { const phase = step.phase ?? "unphased"; const id = `${phase}:${step.lane}`; const existing = byId.get(id); if (existing) existing.steps.push(step.id); else byId.set(id, { id, lane: step.lane, phase, steps: [step.id] }); } return [...byId.values()]; } const graphRow = { kind: "toolCall" as const, rowId: "row-1", toolCallId: "tool-wf-1", toolName: "CreateWorkflow", status: "success" as const, inputText: "", display: { kind: "create_workflow" as const, ok: true, errorCount: 0, diagnostics: [], causalityGraph: { steps: STEPS, lanes: LANES, participants: participantsOf(STEPS), handoffs: [], }, }, }; /** * 阶段词汇表在场的变体:单开手风琴与阶段选择需要真的有两个阶段可开。 * 基础图刻意**没有**阶段——绝大多数用例与阶段无关,给它们平白加一层商图只会让 * 「这条用例在验什么」变模糊。 */ const PHASES = [ { id: "phase#a", name: "plan", line: 3 }, { id: "phase#b", name: "review", line: 9 }, ]; const PHASE_OF: Record = { "ask#1": "phase#a", "ask#2": "phase#b", "ask#3": "phase#b", "world-read#1": "phase#a", }; function run(overrides: Partial = {}): WorkflowRunState { return { runId: "dwfrun-1", toolCallId: "tool-wf-1", status: "running", usage: { spentTokens: 0, nodesUsed: 0 }, actors: [], nodes: [], lastEventSequence: 0, ...overrides, }; } function setSnapshot( options: { run?: WorkflowRunState; withGraphRow?: boolean; /** 换成带 `phase()` 词汇表的图(模块板面);缺省是今天的 step/车道图。 */ phased?: boolean; } = {}, ) { const phasedSteps = STEPS.map((step) => ({ ...step, phase: PHASE_OF[step.id]! })); const causalityGraph = options.phased === true ? { ...graphRow.display.causalityGraph, participants: participantsOf(phasedSteps), phases: PHASES, // 相邻两站之间的边:脊线只在有边的相邻两站之间画轨道段(与卡同一条规则)。 phaseEdges: [{ from: "phase#a", to: "phase#b" }], steps: phasedSteps, } : graphRow.display.causalityGraph; const row = { ...graphRow, display: { ...graphRow.display, causalityGraph } }; snapshot = { rows: { window: options.withGraphRow === false ? [] : [row] }, ...(options.run ? { workflowRuns: { revision: 1, runs: [options.run] } } : {}), }; } const onOpenWorkflowActorSession = vi.fn(); const onOpenWorkflowArtifact = vi.fn(); const onOpenWorkflowWorkspace = vi.fn(); const onOpenWorkflowRun = vi.fn(); function renderPane( locale: "en-US" | "zh-CN" = "en-US", options: { withActorCallback?: boolean; withArtifactCallback?: boolean; withWorkspaceCallback?: boolean; /** 「已被 run X 替代」的链接要宿主给开 run 的回调;缺省不给(多数用例与 lineage 无关)。 */ withOpenRunCallback?: boolean; } = {}, ) { return render( createElement( ZCodeIntlProvider, { initialLocale: locale }, createElement(WorkflowRunSidePane, { tab, ...(options.withActorCallback === false ? {} : { onOpenWorkflowActorSession }), ...(options.withArtifactCallback === false ? {} : { onOpenWorkflowArtifact }), ...(options.withWorkspaceCallback === false ? {} : { onOpenWorkflowWorkspace }), ...(options.withOpenRunCallback === true ? { onOpenWorkflowRun } : {}), }), ), ); } // 待答问题区默认收起,所以任何**条目级**断言都要先点开。这个小助手让「先展开」在用例里 // 只占一行,读者的注意力留给真正被钉的东西。 type Pane = ReturnType; /** * 换了投影之后重渲染同一棵树(行是活的,不是打开那一刻的快照)。面板是 memo 组件,投影在 * 真实应用里经由 context 订阅推进;这里的投影是 mock 出来的模块变量,所以给一个新的 tab * 对象让 memo 放行。 */ function rerenderPane(view: Pane, locale: "en-US" | "zh-CN" = "en-US"): Pane { view.rerender( createElement( ZCodeIntlProvider, { initialLocale: locale }, createElement(WorkflowRunSidePane, { tab: { ...tab }, onOpenWorkflowActorSession }), ), ); return view; } beforeEach(() => { // 本仓 vitest 没开 globals,所以 @testing-library 的自动 cleanup 不会注册; // 不显式清理,上一条用例的 DOM 会留下来,getByTestId 随即报「找到多个」。 cleanup(); sendCommand.mockClear(); workflowRunsQuery.mockClear(); workflowRunsQuery.mockImplementation(async () => ({ runs: [] })); workflowRunArtifactsQuery.mockClear(); workflowRunArtifactsQuery.mockImplementation(async () => ({ artifacts: [] })); workflowRunArtifactDataQuery.mockClear(); workflowRunArtifactDataQuery.mockImplementation(async () => ({ items: [], hasMore: false })); onOpenWorkflowActorSession.mockClear(); onOpenWorkflowArtifact.mockClear(); onOpenWorkflowWorkspace.mockClear(); setDynamicWorkflowEnabled(true); setSnapshot({ run: run() }); }); describe("WorkflowRunSidePane 状态头与阶段清单", () => { it("阶段清单按声明序一节一阶段,正在运行的阶段自己展开", () => { // docs/dynamic-workflow/presentation.md「The spine」:时间线读作一份纵向清单。 setSnapshot({ run: run({ nodes: [{ siteId: "ask#2", ordinal: 1, phase: "executing" }] }), phased: true, }); const view = renderPane(); const phases = view.getAllByTestId("workflow-run-phase"); expect(phases.map((phase) => phase.getAttribute("data-phase-id"))).toEqual([ "phase#a", "phase#b", ]); expect(phases.map((phase) => phase.textContent)).toEqual([ expect.stringContaining("plan"), expect.stringContaining("review"), ]); expect(phases[1]!.getAttribute("data-phase-status")).toBe("running"); expect(phases[1]!.getAttribute("data-phase-open")).toBe("true"); expect(phases[0]!.getAttribute("data-phase-status")).toBe("pending"); expect(phases[0]!.getAttribute("data-phase-open")).toBe("false"); }); it("运行阶段变化时把新的那一节打开,已展开的不动", () => { setSnapshot({ run: run({ nodes: [{ siteId: "ask#1", ordinal: 1, phase: "executing" }] }), phased: true, }); const view = renderPane(); expect(view.getAllByTestId("workflow-run-phase")[0]!.getAttribute("data-phase-open")).toBe( "true", ); setSnapshot({ run: run({ nodes: [ { siteId: "ask#1", ordinal: 1, phase: "settled", outcome: "ok" }, { siteId: "world-read#1", ordinal: 1, phase: "settled", outcome: "ok" }, { siteId: "ask#2", ordinal: 1, phase: "executing" }, ], }), phased: true, }); rerenderPane(view); const phases = view.getAllByTestId("workflow-run-phase"); expect(phases.map((phase) => phase.getAttribute("data-phase-open"))).toEqual(["true", "true"]); expect(phases[0]!.getAttribute("data-phase-status")).toBe("done"); }); it("脊线:轨道段按模型的墨迹分两截画在相邻两站上,灯带状态,行进段在进入运行站的那一段", () => { // docs/dynamic-workflow/presentation.md「The spine」。plan 已结算、review 在跑: // a→b 那段轨道是行进;plan 的灯绿、review 的灯琥珀带搏动。 setSnapshot({ run: run({ nodes: [ { siteId: "ask#1", ordinal: 1, phase: "settled", outcome: "ok" }, { siteId: "world-read#1", ordinal: 1, phase: "settled", outcome: "ok" }, { siteId: "ask#2", ordinal: 1, phase: "executing" }, ], }), phased: true, }); const view = renderPane(); const rails = view.getAllByTestId("workflow-run-spine-rail"); // 两截都得带着 `data-rail-position`:样式表按它选行进段的渐变(下半截淡入、上半截涨到满)。 expect(rails.map((rail) => rail.getAttribute("data-rail-position"))).toEqual([ "below", "above", ]); expect(rails.map((rail) => rail.getAttribute("data-rail-ink"))).toEqual(["march", "march"]); expect(rails[0]!.className).toContain("wf-spine-march"); expect(rails[0]!.className).toContain("w-[1.5px]"); const lamps = view.getAllByTestId("workflow-run-phase-lamp"); expect(lamps.map((lamp) => lamp.getAttribute("data-lamp"))).toEqual(["done", "running"]); expect(lamps[1]!.className).toContain("wf-lamp-running"); // 灯在节头按钮里:悬停节头时既有的 `.wf-station-open:hover .wf-lamp` 光环规则接得上。 expect(lamps[0]!.closest('[data-testid="workflow-run-phase-toggle"]')).toBeTruthy(); }); it("脊线:没有边的相邻两站之间不画轨道段;折起的阶段在节头带头像串,展开后头像串让位给药丸", () => { setSnapshot({ run: run({ nodes: [{ siteId: "ask#2", ordinal: 1, phase: "executing" }] }), phased: true, }); const view = renderPane(); // plan 折着:头像串在场(planner + workspace = 2 枚,无 +n);review 展开:没有头像串。 const [plan, review] = view.getAllByTestId("workflow-run-phase"); const cluster = within(plan!).getByTestId("workflow-run-phase-cluster"); expect(cluster.querySelectorAll("[title]")).toHaveLength(2); expect(cluster.className).toContain("gap-1"); expect(cluster.querySelector(".rounded-full")).toBeNull(); expect(cluster.querySelectorAll("img.size-4, svg.size-4")).toHaveLength(2); expect(cluster.textContent).not.toContain("+"); expect(within(review!).queryByTestId("workflow-run-phase-cluster")).toBeNull(); // 展开 plan 后头像串消失,药丸出现。 fireEvent.click(within(plan!).getByTestId("workflow-run-phase-toggle")); expect(within(plan!).queryByTestId("workflow-run-phase-cluster")).toBeNull(); expect(within(plan!).getAllByTestId("workflow-agent-pill").length).toBeGreaterThan(0); }); it("脊线:无边的图没有轨道段;轮次写成 ⟳ n 而不是灯串", () => { setSnapshot({ run: run({ nodes: [{ siteId: "ask#2", ordinal: 1, phase: "executing" }] }), phased: true, }); // 把边拿掉:轨道段整个缺席(相邻无边留空,与卡同一条规则)。 snapshot = { ...(snapshot as { rows: { window: { display: { causalityGraph: object } }[] } }), rows: { window: ( snapshot as { rows: { window: { display: { causalityGraph: object } }[] } } ).rows.window.map((row) => ({ ...row, display: { ...row.display, causalityGraph: { ...row.display.causalityGraph, phaseEdges: [] }, }, })), }, }; const view = renderPane(); expect(view.queryAllByTestId("workflow-run-spine-rail")).toHaveLength(0); expect(view.queryByTestId("workflow-run-phase-rounds")).toBeNull(); }); it("渲染 run 状态词(灯旁永远有词)", () => { setSnapshot({ run: run({ status: "completed" }) }); const view = renderPane(); expect(view.getByTestId("workflow-run-status").textContent).toBe("Completed"); }); it("直接启动(无工具行)时从启动轮元数据取图(docs/dynamic-workflow/launch.md)", () => { const launchRow = { kind: "userInput" as const, rowId: "row-launch", text: "Started the saved workflow", origin: "workflowLaunch" as const, workflowLaunch: { runId: "dwfrun-1", toolCallId: "tool-wf-1", name: "Fan-out review", scope: "project" as const, path: "/workspace/.zcode/workflows/fan-out-review.dwf.ts", display: graphRow.display, script: "export default async function main() {}", }, }; snapshot = { rows: { window: [launchRow] }, workflowRuns: { revision: 1, runs: [run()] }, }; const view = renderPane(); expect(view.getByTestId("workflow-run-phases")).toBeTruthy(); expect(view.queryByTestId("workflow-run-graph-unavailable")).toBeNull(); }); // 直接启动的来龙去脉(docs/dynamic-workflow/launch.md「The launch turn」):作用域、说明、实参与「由你从 // 工作流中枢启动 · 时刻」只在这里说——聊天区的 run 卡与工具路径发起的一模一样。 it("直接启动的 run:状态头下有来龙去脉节——脚注、作用域徽标、说明、实参表", () => { const workflowLaunch = { runId: "dwfrun-1", toolCallId: "tool-wf-1", name: "Fan-out review", scope: "global" as const, path: "/home/u/.zcode/workflows/fan-out-review.dwf.ts", description: "Review a change from several angles.", args: { topic: "adaptive concurrency", depth: 3 }, display: graphRow.display, }; snapshot = { rows: { window: [ { kind: "turnHeader" as const, rowId: "row-header", origin: "workflowLaunch" as const, executionKind: "controlOnly" as const, state: "completedSuccess" as const, startedAt: Date.UTC(2026, 8, 14, 13, 34), workflowLaunch, }, { kind: "userInput" as const, rowId: "row-launch", text: "Started the saved workflow", origin: "workflowLaunch" as const, workflowLaunch, }, ], }, workflowRuns: { revision: 1, runs: [run()] }, }; const view = renderPane(); const provenance = view.getByTestId("workflow-run-provenance"); expect(provenance.getAttribute("data-workflow-launch-scope")).toBe("global"); expect(provenance.textContent).toContain("Started by you from the workflows hub"); expect(provenance.textContent).toContain(" · "); expect(view.getByTestId("workflow-run-provenance-scope").textContent).toBe("Global"); expect(provenance.textContent).toContain("Review a change from several angles."); const args = view.getByTestId("workflow-run-provenance-args").textContent ?? ""; expect(args).toContain("topic"); expect(args).toContain("adaptive concurrency"); expect(args).toContain("depth"); expect(args).toContain("3"); // 来龙去脉排在状态头之后、结果区 / 脊线之前。 const header = view.getByTestId("workflow-run-status").closest("div.border-b")!; expect( header.compareDocumentPosition(provenance) & Node.DOCUMENT_POSITION_FOLLOWING, ).toBeTruthy(); expect(view.getByTestId("workflow-run-phases")).toBeTruthy(); }); it("工具路径发起的 run 没有来龙去脉节", () => { setSnapshot({ run: run() }); const view = renderPane(); expect(view.queryByTestId("workflow-run-provenance")).toBeNull(); }); it("行窗口里翻不到那条工具调用时给出「没有图」而不是空清单", () => { setSnapshot({ run: run(), withGraphRow: false }); const view = renderPane(); expect(view.queryByTestId("workflow-run-phases")).toBeNull(); expect(view.getByTestId("workflow-run-graph-unavailable").textContent).toContain( "not in this conversation's visible history", ); }); }); // ── 子代理模型(docs/dynamic-workflow/presentation.md「The run pane」)── // 用户在启动时把这次 run 的子代理定在了另一个模型上;主代理仍是会话模型,所以只说子代理。 // 状态头第一行**不再**摆模型芯片(它放不下,截断后剩下的正是 provider id):模型名成了摘要行的 // 第一段——这一行本来就是「这条 run 的几个数」。规范串与强度退进 tooltip。 // 没指定过模型的 run 整段缺席——跟随会话模型是常态,没有可说的。 describe("WorkflowRunSidePane 子代理模型", () => { // 团队套餐的 provider id 是一串十六进制:这次改动要挡的就是它。 const TEAM_PLAN_MODEL = "4fc7f541-2382-4c32-be11-f021b8d7ed1d/GLM-5.3-Flash$high"; it("模型名是摘要行的第一段,不再是状态头上的芯片", () => { setSnapshot({ run: run({ subagentModel: "zhipu/glm-5.3-flash" }) }); const view = renderPane(); const segment = view.getByTestId("workflow-run-subagent-model"); expect(segment.textContent).toBe("Subagents glm-5.3-flash"); // 它住在摘要行里,不在状态头那一行(与并发芯片、Stop 钮同排的那一行)。 expect(segment.closest('[data-testid="workflow-run-usage"]')).not.toBeNull(); const summary = view.getByTestId("workflow-run-usage").textContent ?? ""; expect(summary.indexOf("Subagents glm-5.3-flash")).toBe(0); }); it("屏幕上绝不出现 provider id,哪怕它是团队套餐的 UUID;规范串退进 tooltip", () => { setSnapshot({ run: run({ subagentModel: TEAM_PLAN_MODEL }) }); const view = renderPane(); const segment = view.getByTestId("workflow-run-subagent-model"); expect(segment.textContent).toBe("Subagents GLM-5.3-Flash"); expect(segment.textContent).not.toContain("4fc7f541"); expect(document.body.textContent).not.toContain("4fc7f541"); expect(segment.getAttribute("title")).toContain(TEAM_PLAN_MODEL); // 强度不上屏,它跟规范串一起住在 tooltip 里。 expect(segment.getAttribute("title")).toContain("thinking High"); }); it("zh-CN 下同一段说中文,模型名原样不译", () => { setSnapshot({ run: run({ subagentModel: TEAM_PLAN_MODEL }) }); const view = renderPane("zh-CN"); expect(view.getByTestId("workflow-run-subagent-model").textContent).toBe( "子代理 GLM-5.3-Flash", ); }); it("图不可得(建不出时间线)退回用量行时,模型仍在行首:它与有没有图无关", () => { setSnapshot({ run: run({ subagentModel: TEAM_PLAN_MODEL, usage: { spentTokens: 12_345, nodesUsed: 3 } }), withGraphRow: false, }); const view = renderPane(); const segment = view.getByTestId("workflow-run-subagent-model"); expect(segment.textContent).toBe("Subagents GLM-5.3-Flash"); expect(document.body.textContent).not.toContain("4fc7f541"); expect(segment.getAttribute("title")).toContain(TEAM_PLAN_MODEL); // 同一行里,模型在前,用量标签与读数照旧跟在后面。 const usage = view.getByTestId("workflow-run-usage").textContent ?? ""; expect(usage.indexOf("Subagents GLM-5.3-Flash")).toBe(0); expect(usage).toContain("Usage"); expect(usage).toContain("12,345 tokens · 3 steps"); }); it("没指定过模型的 run 里整段缺席(子代理跟随会话模型)", () => { setSnapshot({ run: run() }); const view = renderPane(); expect(view.queryByTestId("workflow-run-subagent-model")).toBeNull(); expect(document.body.textContent).not.toContain("Subagents "); }); it("run 不在投影里(被淘汰 / 冷启动)时也没有这一段", () => { setSnapshot({}); const view = renderPane(); expect(view.queryByTestId("workflow-run-subagent-model")).toBeNull(); }); }); describe("WorkflowRunSidePane 摘要行", () => { it("与聊天卡页脚同文案:工作中的子代理数、步数、token,没有上限、没有进度轨", () => { setSnapshot({ run: run({ usage: { spentTokens: 12_345, nodesUsed: 3 }, actors: [{ siteId: "actor#1", ordinal: 1, status: "running" }], nodes: [{ siteId: "ask#1", ordinal: 1, phase: "executing" }], }), }); const view = renderPane(); const usage = view.getByTestId("workflow-run-usage").textContent ?? ""; expect(usage).toContain("1 agent working"); expect(usage).toContain("0/1 steps"); expect(usage).toContain("12,345 tokens"); expect(usage).not.toContain("%"); expect(view.container.querySelector("progress")).toBeNull(); }); it("图不可得(建不出时间线)时退回用量行", () => { setSnapshot({ run: run({ usage: { spentTokens: 12_345, nodesUsed: 3 } }), withGraphRow: false, }); const view = renderPane(); const usage = view.getByTestId("workflow-run-usage").textContent ?? ""; expect(usage).toContain("Usage"); expect(usage).toContain("12,345 tokens · 3 steps"); }); // 实例表撞界(docs/dynamic-workflow/presentation.md「The run pane」):摘要行里的步数已经把 // 表外的实例算进来了,脊柱却只列得出表内那些——这一句说的正是这个差额。 it("撞界的 run 在摘要行下多一句「仅展示 n/m 步的详情」,计数仍是真实步数", () => { setSnapshot({ run: run({ usage: { spentTokens: 1, nodesUsed: 1_100, nodesUnlisted: 2_000, nodesUnlistedSettled: 1_500, }, nodes: [{ siteId: "ask#1", ordinal: 1, phase: "settled", outcome: "ok" }], truncated: true, }), }); const view = renderPane(); expect(view.getByTestId("workflow-run-truncated").textContent).toBe( "Details shown for 1 of 2001 steps", ); expect(view.getByTestId("workflow-run-usage").textContent ?? "").toContain("1501/2001 steps"); }); it("没撞界、以及只有小表撞界(步数一个不少)的 run 都没有这一句", () => { setSnapshot({ run: run({ nodes: [{ siteId: "ask#1", ordinal: 1, phase: "settled" }] }) }); expect(renderPane().queryByTestId("workflow-run-truncated")).toBeNull(); cleanup(); // `truncated` 也会被 reports / artifacts / phases 触界置位;那时再念「仅展示 1/1 步」是句废话。 setSnapshot({ run: run({ nodes: [{ siteId: "ask#1", ordinal: 1, phase: "settled" }], truncated: true }), }); expect(renderPane().queryByTestId("workflow-run-truncated")).toBeNull(); }); it("zh-CN 念「仅展示 1/2,001 步的详情」", () => { setSnapshot({ run: run({ usage: { spentTokens: 1, nodesUsed: 1, nodesUnlisted: 2_000 }, nodes: [{ siteId: "ask#1", ordinal: 1, phase: "queued" }], truncated: true, }), }); expect(renderPane("zh-CN").getByTestId("workflow-run-truncated").textContent).toBe( "仅展示 1/2001 步的详情", ); }); }); describe("WorkflowRunSidePane Stop", () => { it("running 时可点,并且走既有的 cancelBackgroundWork {workId ≡ runId}", () => { setSnapshot({ run: run({ status: "running" }) }); const view = renderPane(); const button = view.getByTestId("workflow-run-cancel"); expect(button.disabled).toBe(false); fireEvent.click(button); expect(sendCommand).toHaveBeenCalledTimes(1); const envelope = sendCommand.mock.calls[0]![0] as unknown as { type: string; sessionId: string; payload: { workId: string }; }; expect(envelope.type).toBe("cancelBackgroundWork"); expect(envelope.payload).toEqual({ workId: "dwfrun-1" }); expect(envelope.sessionId).toBe("parent-a"); }); it.each(["pending", "completed", "errored", "stopped"] as const)("%s 时按钮禁用", (status) => { setSnapshot({ run: run({ status }) }); const view = renderPane(); expect(view.getByTestId("workflow-run-cancel").disabled).toBe(true); }); it("run 不在投影里时按钮禁用(对它的在飞状态一无所知)", () => { setSnapshot({}); const view = renderPane(); expect(view.getByTestId("workflow-run-cancel").disabled).toBe(true); }); it("按钮说 Stop run,图标与卡上那枚同款:实心方块", () => { setSnapshot({ run: run({ status: "running" }) }); const view = renderPane(); const button = view.getByTestId("workflow-run-cancel"); expect(button.getAttribute("aria-label")).toBe("Stop run"); expect(button.textContent).toContain("Stop run"); // 与 WorkflowRunDigest 的 Stop 钮同形:填充 currentColor 的方块,不是叉。 const icon = button.querySelector("svg"); expect(icon?.getAttribute("class")).toContain("fill-current"); expect(icon?.querySelector("rect")).toBeTruthy(); }); it("可点时提示带第二行「停下的运行可以恢复」;禁用时只剩为什么不可用", () => { setSnapshot({ run: run({ status: "running" }) }); renderPane(); expect(tooltips.calls.find((call) => call.title === "Stop run")?.description).toBe( "You can resume later; finished steps are kept.", ); cleanup(); tooltips.calls.length = 0; setSnapshot({ run: run({ status: "completed" }) }); renderPane(); const disabled = tooltips.calls.find( (call) => call.title === "Only a running workflow can be stopped.", ); expect(disabled).toBeTruthy(); expect(disabled?.description).toBeUndefined(); }); }); // 修复原因(2026-09-15,桌面实测):老 run 被误留在 running 时 Cancel 点了没反应;Resume 撞上 // 不再编译的老脚本同样只在控制台留 warn。被拒的 ACK 现在按词表变成状态头下的一句话。 describe("WorkflowRunSidePane 被拒提示", () => { it("cancel 被拒(not_found)→ 状态头下出现一句话;run 状态一变即收起", async () => { setSnapshot({ run: run({ status: "running" }) }); sendCommand.mockResolvedValueOnce({ status: "failed", reasonCode: "fault.command.backgroundWorkCancelRejected.not_found", } as never); const view = renderPane(); fireEvent.click(view.getByTestId("workflow-run-cancel")); const hint = await view.findByTestId("workflow-run-rejection"); expect(hint.textContent).toContain("not running in this agent"); // 按钮不被锁死:提示只是解释,不改变可点性。 expect(view.getByTestId("workflow-run-cancel").disabled).toBe(false); setSnapshot({ run: run({ status: "stopped", stopReason: "user" }) }); rerenderPane(view); expect(view.queryByTestId("workflow-run-rejection")).toBeNull(); }); it("resume 被拒(compile_failed)→ 一句话指向调整工作流 + ACK 的诊断在等宽块里", async () => { setSnapshot({ run: run({ status: "stopped", resumable: true }) }); sendCommand.mockResolvedValueOnce({ status: "failed", reasonCode: "fault.command.workflowRunResumeRejected.compile_failed", message: "L3:C1 Property 'askWithOldFacade' does not exist", } as never); const view = renderPane(); fireEvent.click(await view.findByTestId("workflow-run-resume")); const hint = await view.findByTestId("workflow-run-rejection"); expect(hint.textContent).toContain("no longer compiles"); expect(hint.textContent).toContain("amend the workflow"); expect(hint.querySelector("pre")?.textContent).toContain("askWithOldFacade"); }); it("词表外的 reasonCode → 通用文案带 code;accepted 不出提示", async () => { setSnapshot({ run: run({ status: "running" }) }); sendCommand.mockResolvedValueOnce({ status: "failed", reasonCode: "fault.command.executionFailed", } as never); const view = renderPane(); fireEvent.click(view.getByTestId("workflow-run-cancel")); const hint = await view.findByTestId("workflow-run-rejection"); expect(hint.textContent).toContain("fault.command.executionFailed"); setSnapshot({ run: run({ status: "stopped" }) }); rerenderPane(view); setSnapshot({ run: run({ status: "running" }) }); rerenderPane(view); fireEvent.click(view.getByTestId("workflow-run-cancel")); await Promise.resolve(); await Promise.resolve(); expect(view.queryByTestId("workflow-run-rejection")).toBeNull(); }); it("zh-CN 文案", async () => { setSnapshot({ run: run({ status: "running" }) }); sendCommand.mockResolvedValueOnce({ status: "failed", reasonCode: "fault.command.backgroundWorkCancelRejected.not_running", } as never); const view = renderPane("zh-CN"); fireEvent.click(view.getByTestId("workflow-run-cancel")); expect((await view.findByTestId("workflow-run-rejection")).textContent).toContain("已经结束"); }); }); describe("WorkflowRunSidePane 结果与失败面板", () => { it("completed 且无 resultPreview 时指向会话里的后台结果消息,不编造结果", () => { setSnapshot({ run: run({ status: "completed" }) }); const view = renderPane(); expect(view.getByTestId("workflow-run-result").textContent).toContain( "delivered to the conversation as a background result message", ); }); it("errored 时原样呈现投影给出的错误原文", () => { setSnapshot({ run: run({ status: "errored", error: "节点数超过上限 100" }) }); const view = renderPane(); const panel = view.getByTestId("workflow-run-error"); expect(panel.textContent).toContain("Run errored"); expect(panel.textContent).toContain("节点数超过上限 100"); }); it("错误原文按正文排版,不用等宽字体", () => { // 投影写进 error 的是 WorkflowErrorJson.message(product-projection.ts 的 run-settled // 分支只取 .message,code 被丢掉),而那些 message 是人话短句——"run 已取消"、 // "typed ask 结束时未提交结果"、"节点数超过上限 100"。DESIGN.md 把 font-mono 留给 // 路径/命令/代码/标识符/终端数据,一句人话不属于其中任何一类。 setSnapshot({ run: run({ status: "errored", error: "typed ask 结束时未提交结果" }) }); const view = renderPane(); const message = view.getByTestId("workflow-run-error-message"); expect(message.className).not.toContain("font-mono"); // 仍保留 pre-wrap:message 万一带换行也不能被折叠掉。 expect(message.className).toContain("whitespace-pre-wrap"); }); it("stopped 且没有错误详情时说明没有,而不是留一片空白", () => { setSnapshot({ run: run({ status: "stopped" }) }); const view = renderPane(); const panel = view.getByTestId("workflow-run-error"); expect(panel.textContent).toContain("Run stopped"); expect(panel.textContent).toContain("No error detail was recorded."); }); it("stopped 带原因:标题与状态头都跟原因词(决策 15)", () => { setSnapshot({ run: run({ status: "stopped", stopReason: "provider", error: "Sign-in expired." } as never), }); const view = renderPane(); expect(view.getByTestId("workflow-run-stop-reason").textContent).toContain("model error"); expect(view.getByTestId("workflow-run-status-reason").textContent).toContain("model error"); expect(view.getByTestId("workflow-run-error").textContent).toContain("Sign-in expired."); }); // 「停止」这个动词说不出后果,所以后果回到状态行:可恢复是投影带来的状态位,不从 status 推。 it("状态行第三个词:run 带 resumable 时说「resumable」,不带就没有那个词", () => { setSnapshot({ run: run({ status: "stopped", stopReason: "user", resumable: true }) }); const withBit = renderPane(); expect(withBit.getByTestId("workflow-run-status-resumable").textContent).toContain("resumable"); expect(withBit.getByTestId("workflow-run-status-reason").textContent).toContain("by you"); cleanup(); setSnapshot({ run: run({ status: "stopped", stopReason: "user" }) }); const without = renderPane(); expect(without.queryByTestId("workflow-run-status-resumable")).toBeNull(); cleanup(); setSnapshot({ run: run({ status: "stopped", stopReason: "user", resumable: true }) }); const zh = renderPane("zh-CN"); expect(zh.getByTestId("workflow-run-status-resumable").textContent).toContain("可恢复"); }); it("running 时既没有结果面板也没有失败面板", () => { setSnapshot({ run: run({ status: "running" }) }); const view = renderPane(); expect(view.queryByTestId("workflow-run-result")).toBeNull(); expect(view.queryByTestId("workflow-run-error")).toBeNull(); }); }); describe("WorkflowRunSidePane 升级问题", () => { const NOW = 1_756_000_000_000; const MINUTE = 60_000; const questions = [ { qid: "dwfq-dwfrun1-1", actorSiteId: "actor#1", actorOrdinal: 1, actorName: "poet", question: "评分上限是 95,但通过门槛是 96,这个门是不是坏了?", context: "已经试过 4 轮,最高分 95。", askedAt: NOW - 42 * MINUTE, }, { qid: "dwfq-dwfrun1-2", actorSiteId: "actor#2", actorOrdinal: 3, question: "用哪版风格指南?", askedAt: NOW - 90 * MINUTE, }, ]; const askers = () => run({ actors: [ { siteId: "actor#1", ordinal: 1, name: "poet", sessionId: "s-1", status: "waiting" }, { siteId: "actor#2", ordinal: 3, sessionId: "s-2", status: "waiting" }, ], nodes: [ { siteId: "ask#1", ordinal: 1, phase: "executing", actorSiteId: "actor#1", actorOrdinal: 1, }, { siteId: "ask#2", ordinal: 3, phase: "waiting", actorSiteId: "actor#2", actorOrdinal: 3 }, ], pendingQuestions: questions, }); it("挂在提问者那一行下面:问题紧跟匹配 site@ordinal 的子代理药丸", () => { setSnapshot({ run: askers() }); const view = renderPane(); const rows = view.getAllByTestId("workflow-run-question"); expect(rows).toHaveLength(2); expect(rows[0]!.getAttribute("data-qid")).toBe("dwfq-dwfrun1-1"); const pill = rows[0]!.previousElementSibling as HTMLElement; expect(pill.getAttribute("data-testid")).toBe("workflow-agent-pill"); expect(pill.textContent).toContain("poet"); expect(rows[0]!.textContent).toContain("这个门是不是坏了?"); expect(rows[0]!.textContent).toContain("已经试过 4 轮,最高分 95。"); // qid 是主代理作答要用的 token;用户答不了,但能指着它让主代理去答。 expect(rows[0]!.textContent).toContain("dwfq-dwfrun1-1"); // 挂在行下的问题不重复提问者的名字。 expect(rows[0]!.textContent).not.toContain("poet"); expect(view.queryByTestId("workflow-run-orphan-questions")).toBeNull(); }); it("每条带等待时长(读者的第一个问题恒是「这个已经等了多久」)", () => { vi.useFakeTimers(); vi.setSystemTime(NOW); try { setSnapshot({ run: askers() }); const view = renderPane(); const waited = view.getAllByTestId("workflow-run-question-waited"); expect(waited[0]!.textContent).toBe("42m ago"); expect(waited[1]!.textContent).toBe("1h ago"); } finally { vi.useRealTimers(); } }); it("等待时长自己走时钟:run 在等答案时不发事件,靠投影更新会一直显示「刚刚」", () => { vi.useFakeTimers(); vi.setSystemTime(NOW); try { setSnapshot({ run: askers() }); const view = renderPane(); const before = view.getAllByTestId("workflow-run-question-waited")[0]!.textContent; act(() => { vi.advanceTimersByTime(20 * MINUTE); }); const after = view.getAllByTestId("workflow-run-question-waited")[0]!.textContent; expect(after).not.toBe(before); } finally { vi.useRealTimers(); } }); it("askedAt 缺席(老 journal 重放)时不渲染时长,绝不编一个「刚刚」", () => { const { askedAt: _dropped, ...withoutAskedAt } = questions[0]!; setSnapshot({ run: { ...askers(), pendingQuestions: [withoutAskedAt] } }); const view = renderPane(); expect(view.getAllByTestId("workflow-run-question")).toHaveLength(1); expect(view.queryByTestId("workflow-run-question-waited")).toBeNull(); }); it("匹配不上提问者的问题挂在清单末尾,并自报名字(站点实例标签 / 匿名兜底)", () => { setSnapshot({ run: run({ pendingQuestions: [ { qid: "q-a", actorSiteId: "actor#9", actorOrdinal: 2, question: "谁来审?" }, { qid: "q-b", question: "没有主语的问题" }, ], }), }); const view = renderPane(); const block = view.getByTestId("workflow-run-orphan-questions"); expect(block.textContent).toContain("Waiting on an answer"); const rows = view.getAllByTestId("workflow-run-question"); expect(rows[0]!.textContent).toContain("actor#9@2"); expect(rows[1]!.textContent).toContain("Anonymous Subagent"); }); it("v1 只读:清单里没有任何输入控件或应答按钮", () => { setSnapshot({ run: askers() }); const view = renderPane(); const list = view.getByTestId("workflow-run-phases"); expect(list.querySelectorAll("input, textarea").length).toBe(0); expect(list.textContent).not.toContain("Answer"); }); it("零条时没有问题行,也没有末尾的孤儿块(键缺席与空数组两种形态都一样)", () => { setSnapshot({ run: run({ pendingQuestions: [] }) }); let view = renderPane(); expect(view.queryAllByTestId("workflow-run-question")).toHaveLength(0); expect(view.queryByTestId("workflow-run-orphan-questions")).toBeNull(); cleanup(); setSnapshot({ run: run() }); view = renderPane(); expect(view.queryAllByTestId("workflow-run-question")).toHaveLength(0); }); it("zh-CN 下等待时长与孤儿块标题都本地化,且没有英文兜底漏出来", () => { vi.useFakeTimers(); vi.setSystemTime(NOW); try { setSnapshot({ run: run({ pendingQuestions: [ { qid: "q-b", question: "没有主语的问题", askedAt: NOW - 42 * MINUTE }, ], }), }); const view = renderPane("zh-CN"); const text = view.getByTestId("workflow-run-orphan-questions").textContent ?? ""; expect(text).toContain("待答问题"); expect(text).toContain("42 分钟前"); expect(text).toContain("未命名子代理"); expect(text).not.toContain("Waiting on an answer"); expect(text).not.toContain("ago"); } finally { vi.useRealTimers(); } }); }); describe("WorkflowRunSidePane 淘汰 / 冷启动空态", () => { it("run 不在 workflowRuns 里时 tab 仍然打开,措辞只说实时状态没了", () => { setSnapshot({}); const view = renderPane(); const panel = view.getByTestId("workflow-run-untracked"); expect(panel.textContent).toContain("No longer tracked live"); // 关键:不能读成「这次运行不存在了」——journal 里的记录仍然完整,那正是留着这个 // tab 的理由(产物仍列得出来,见产物区那条用例)。 expect(panel.textContent).toContain("record is still complete"); }); }); describe("WorkflowRunSidePane 国际化", () => { it("状态头、用量、Stop 与结果在 zh-CN 下全部本地化", () => { setSnapshot({ run: run({ status: "completed", usage: { spentTokens: 1_000, nodesUsed: 3 }, }), }); const view = renderPane("zh-CN"); const text = view.container.textContent ?? ""; expect(view.getByTestId("workflow-run-status").textContent).toBe("已完成"); expect(text).toContain("停止运行"); // 摘要行与聊天卡页脚同文案:三条子代理车道 + 步数 + token。 expect(view.getByTestId("workflow-run-usage").textContent).toContain("3 个子代理"); expect(view.getByTestId("workflow-run-usage").textContent).toContain("1,000 tokens"); expect(text).toContain("结果"); // 没有英文兜底漏出来。 expect(text).not.toContain("Stop run"); // 旧动词彻底退场。 expect(text).not.toContain("取消运行"); }); }); // ── 阶段清单的子代理行(docs/dynamic-workflow/presentation.md「The spine」)── // 与卡上同一枚药丸,加「正在做什么」(当前步的 label)、计数、状态标记与打开 transcript 的箭头。 describe("WorkflowRunSidePane 子代理行", () => { function actor(overrides: Record = {}) { return { siteId: "actor#1", ordinal: 1, sessionId: "dwf-dwfrun-1-actor_1@1", status: "waiting" as const, ...overrides, }; } const executing = (actorOrdinal = 1) => ({ siteId: "ask#1", ordinal: actorOrdinal, phase: "executing" as const, actorSiteId: "actor#1", actorOrdinal, }); it("行带运行时名、计数与可读的状态标记;不写当前步的 label(站点名对读者没有信息量)", () => { setSnapshot({ run: run({ actors: [actor({ name: "planner" })], nodes: [executing()] }) }); const view = renderPane(); const pill = view .getAllByTestId("workflow-agent-pill") .find((candidate) => candidate.textContent?.includes("planner"))!; expect(pill.getAttribute("data-agent-status")).toBe("running"); expect(pill.querySelector('[data-testid="workflow-run-agent-activity"]')).toBeNull(); expect(pill.textContent).toContain("1 tasks"); // 状态不只靠颜色或图形:标记带可读文字。 const mark = pill.querySelector('[data-testid="workflow-pill-status"]'); expect(mark?.getAttribute("aria-label")).toBe("running"); }); /** 行尾的 ↗:一行一枚(活的 run 里每枚子代理药丸都可开),按行里的名字取。 */ const openOf = (view: ReturnType, name: string) => view .getAllByTestId("workflow-agent-pill") .find((candidate) => candidate.textContent?.includes(name))! .querySelector('[data-testid="workflow-run-agent-open"]')!; it("点行尾箭头开 transcript tab,并带上 tab 自己的 workspace scope", () => { setSnapshot({ run: run({ actors: [actor({ name: "planner" })], nodes: [executing()] }) }); const view = renderPane(); fireEvent.click(openOf(view, "planner")); expect(onOpenWorkflowActorSession).toHaveBeenCalledWith({ workspacePath: "/workspace", parentSessionId: "parent-a", runId: "dwfrun-1", actorSessionId: "dwf-dwfrun-1-actor_1@1", siteId: "actor#1", ordinal: 1, actorName: "planner", }); }); it("整行就是按钮:点药丸本身即打开,↗ 只是可打开的可见证据", () => { setSnapshot({ run: run({ actors: [actor({ name: "planner" })], nodes: [executing()] }) }); const view = renderPane(); const pill = view .getAllByTestId("workflow-agent-pill") .find((candidate) => candidate.textContent?.includes("planner"))!; expect(pill.tagName).toBe("BUTTON"); expect(pill.getAttribute("aria-label")).toBe("Open the transcript of planner"); expect(pill.querySelector('[data-testid="workflow-run-agent-open"]')).toBeTruthy(); //