conversation-session-dynamic-workflow-holes.test.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. import { TID_CHAT_WORKFLOW_RUN_DIGEST } from "@zcode/shared";
  2. import { clearAppData } from "../helpers/desktop-app.js";
  3. import {
  4. approveV4Permission,
  5. prepareV4ConversationE2E,
  6. waitForV4Pane,
  7. sendV4Prompt,
  8. waitForV4AssistantMessageContaining,
  9. } from "../helpers/v4-conversation.js";
  10. import { getLatestUpstreamToolResultByToolCallId } from "#e2e/helpers/conversation-session-network";
  11. // 留白(docs/dynamic-workflow/presentation.md「Holes on the timeline」、docs/dynamic-workflow/launch.md
  12. // 「The `FillWorkflowHole` tool」、docs/dynamic-workflow/transcript-and-notifications.md「The hole row's live state」)
  13. // 的三条桌面链路:run 卡上的留白站与等待态、通知行的三态、补全之后卡与侧板长出新的站。
  14. //
  15. // case-local 回放只决定模型调用;真实 Skill、工作流编译、审批、留白通知与补全仍走产品链路。
  16. // 第一处留白的等待态检查完成后,再发送真实补全指令,避免自动回复抢先消除待验证的 UI 状态。
  17. const RUN_DIGEST = `[data-testid^="${TID_CHAT_WORKFLOW_RUN_DIGEST}"]`;
  18. // 留白 id 是名字的键(apps/zcode-cli/packages/dynamic-workflow/docs/analysis.md「Sites」):「决定分组」→ 这个 id。
  19. const DECIDE_HOLE_ID = "hole#21b40fca";
  20. describe("动态工作流 · 留白", () => {
  21. before(async () => {
  22. await prepareV4ConversationE2E();
  23. });
  24. after(async () => {
  25. await browser.electron.restoreAllMocks();
  26. await clearAppData();
  27. });
  28. it("DWH-01 卡上画出留白站,run 到达时变成等待态并长出「1 处留白待补全」", async function () {
  29. this.timeout(240000);
  30. await sendV4Prompt("E2E_DWH_START 使用工作流演示留白:先等待决定分组,再等待评判。");
  31. await approveV4Permission();
  32. // 原因:工作流使用专属摘要,不再渲染通用 ToolCallBlock;真实工具结果确认创建成功。
  33. await browser.waitUntil(
  34. async () =>
  35. (await getLatestUpstreamToolResultByToolCallId("toolu_dwh_create"))?.isError === false,
  36. { timeout: 60_000, timeoutMsg: "CreateWorkflow 未执行成功" },
  37. );
  38. const digest = await $(RUN_DIGEST);
  39. await digest.waitForDisplayed({ timeout: 120000 });
  40. // 留白站:虚线灯 + 名字(类型不上界面);触到它的轨道段是虚线;尾巴留白之后有 40px 残段。
  41. const holeStation = await digest.$(
  42. '[data-testid="workflow-timeline-station"][data-station-hole]',
  43. );
  44. await holeStation.waitForDisplayed({ timeout: 60000 });
  45. expect(await holeStation.getText()).toContain("决定分组");
  46. expect(await holeStation.getText()).not.toContain("Plan");
  47. await expect(
  48. digest.$('[data-testid="workflow-timeline-rail"][data-rail-dashed="true"]'),
  49. ).toBeExisting();
  50. await expect(digest.$('[data-testid="workflow-timeline-tail-stub"]')).toBeExisting();
  51. // 到达:灯换警示色描边、元数据写「等待补全」、表头长出笔芯片;灯不搏动。
  52. await browser.waitUntil(
  53. async () => (await holeStation.getAttribute("data-station-hole")) === "waiting",
  54. { timeout: 120000, timeoutMsg: "run 没有停在留白上" },
  55. );
  56. await expect(holeStation.$('[data-testid="workflow-hole-waiting"]')).toBeDisplayed();
  57. await expect(holeStation.$(".wf-lamp-hole-waiting")).toBeExisting();
  58. await expect(holeStation.$(".wf-lamp-running")).not.toBeExisting();
  59. const chip = await digest.$('[data-testid="workflow-digest-holes"]');
  60. await chip.waitForDisplayed({ timeout: 30000 });
  61. expect(await chip.getText()).toContain("1 处留白待补全");
  62. // 开着的留白是主代理车道上的一步,不是子代理:含 `hole()` 调用的那一站不多出「未命名子代理」。
  63. for (const pill of await digest.$$('[data-testid="workflow-agent-pill"]')) {
  64. expect(await pill.getText()).not.toContain("未命名子代理");
  65. }
  66. });
  67. it("DWH-02 通知行:笔图标、「工作流留白 · 等待补全」,展开体有提示、位置、草稿路径与等待时长", async function () {
  68. this.timeout(120000);
  69. const row = await $(
  70. '[data-testid^="chat-workflow-notification-row-"][data-hole-state="waiting"]',
  71. );
  72. await row.waitForDisplayed({ timeout: 120000 });
  73. expect(await row.getText()).toContain("工作流留白 · 等待补全");
  74. expect(await row.$('[data-testid="workflow-hole-notification-name"]').getText()).toBe(
  75. "决定分组",
  76. );
  77. await row.$('[role="button"]').click();
  78. const body = await row.$('[data-testid="workflow-hole-notification-body"]');
  79. await body.waitForDisplayed({ timeout: 10000 });
  80. await expect(body).toHaveText(expect.stringContaining("补全须返回 Plan"));
  81. await expect(body.$('[data-testid="workflow-hole-notification-draft"]')).toBeExisting();
  82. await expect(body.$('[data-testid="workflow-hole-notification-waited"]')).toBeExisting();
  83. });
  84. it("DWH-03 补全接进 run:补全行说「留白已补全」,卡长出头与新站,通知行翻成「留白已补全」", async function () {
  85. this.timeout(240000);
  86. await waitForV4Pane((pane) => !pane.canStop, "留白通知回复未结束", 30000);
  87. // 两秒新鲜态是视觉瞬态;在真实操作前观察 DOM,不靠加延时或抢时序截图。
  88. await browser.execute(() => {
  89. const probe = window as Window & { __dwhFreshSeen?: boolean };
  90. probe.__dwhFreshSeen = false;
  91. const observer = new MutationObserver(() => {
  92. if (
  93. document.querySelector(
  94. '[data-testid="workflow-timeline-fill-frame"][data-fill-fresh="true"]',
  95. )
  96. ) {
  97. probe.__dwhFreshSeen = true;
  98. observer.disconnect();
  99. }
  100. });
  101. observer.observe(document.body, {
  102. childList: true,
  103. subtree: true,
  104. attributes: true,
  105. attributeFilter: ["data-fill-fresh"],
  106. });
  107. });
  108. await sendV4Prompt("E2E_DWH_FILL_NOW 补全决定分组,加入收集和分组两个阶段,继续等评判。");
  109. await browser.waitUntil(
  110. async () =>
  111. (await getLatestUpstreamToolResultByToolCallId("toolu_dwh_fill"))?.isError === false,
  112. { timeout: 60_000, timeoutMsg: "FillWorkflowHole 未执行成功" },
  113. );
  114. await waitForV4AssistantMessageContaining("补全", 180000);
  115. const fillRow = await $(
  116. '[data-testid="workflow-tool-summary"][data-tool-call-id]:has([data-testid="workflow-summary-hole-name"])',
  117. );
  118. await fillRow.waitForDisplayed({ timeout: 60000 });
  119. expect(await fillRow.getText()).toContain("留白已补全");
  120. expect(await fillRow.$('[data-testid="workflow-summary-hole-phases"]').getText()).toContain(
  121. "个阶段",
  122. );
  123. const digest = await $(RUN_DIGEST);
  124. const head = await digest.$('[data-testid="workflow-timeline-fill-head"]');
  125. await head.waitForDisplayed({ timeout: 60000 });
  126. expect(await head.getText()).toContain("决定分组");
  127. // 刚接进 run 的两秒里框自己画一遍(警示色的一笔);之后只在指针落在头上时画出。
  128. expect(
  129. await browser.execute(() => (window as Window & { __dwhFreshSeen?: boolean }).__dwhFreshSeen),
  130. ).toBe(true);
  131. await browser.waitUntil(
  132. async () =>
  133. !(await digest
  134. .$('[data-testid="workflow-timeline-fill-frame"][data-fill-fresh="true"]')
  135. .isExisting()),
  136. { timeout: 10000, timeoutMsg: "框的新鲜态没有在两秒后退去" },
  137. );
  138. // 站不点亮任何东西:指针落在补全写下的站上,框不画。
  139. await (
  140. await digest.$(`[data-testid="workflow-timeline-station"][data-fill="${DECIDE_HOLE_ID}"]`)
  141. ).moveTo();
  142. await expect(
  143. digest.$('[data-testid="workflow-timeline-fill-frame"][data-fill-on="true"]'),
  144. ).not.toBeExisting();
  145. // 头点亮它自己的框,而且只有这一个。
  146. await head.moveTo();
  147. await expect(
  148. digest.$(
  149. `[data-testid="workflow-timeline-fill-frame"][data-fill-frame="${DECIDE_HOLE_ID}"][data-fill-on="true"]`,
  150. ),
  151. ).toBeExisting();
  152. expect(
  153. await digest.$$('[data-testid="workflow-timeline-fill-frame"][data-fill-on="true"]'),
  154. ).toHaveLength(1);
  155. // 第一处已补全,run 立即到达第二处;仍有一处待补全,不能要求全局芯片消失。
  156. await expect(digest.$('[data-testid="workflow-digest-holes"]')).toHaveText(
  157. expect.stringContaining("1 处留白待补全"),
  158. );
  159. await expect(
  160. digest.$('[data-testid="workflow-timeline-station"][data-station-hole="waiting"]'),
  161. ).toHaveText(expect.stringContaining("评判"));
  162. const row = await $(
  163. '[data-testid^="chat-workflow-notification-row-"][data-hole-state="filled"]',
  164. );
  165. await row.waitForDisplayed({ timeout: 60000 });
  166. expect(await row.getText()).toContain("留白已补全");
  167. });
  168. it("DWH-04 侧板:留白节头、等待体,补全后的标题行(它是框的头)与不缩进的补全节;侧栏运行行写「评判 · 等待补全」", async function () {
  169. this.timeout(120000);
  170. const digest = await $(RUN_DIGEST);
  171. await (await digest.$('[data-testid="workflow-timeline-fill-head"]')).click();
  172. const heading = await $('[data-testid="workflow-run-fill-heading"]');
  173. await heading.waitForDisplayed({ timeout: 60000 });
  174. expect(await heading.getText()).toContain("决定分组");
  175. await expect(
  176. $(`[data-testid="workflow-run-phase"][data-phase-fill="${DECIDE_HOLE_ID}"]`),
  177. ).toBeExisting();
  178. // 标题行是这次补全的头:指针落上去,侧板画出同一个框(竖着)。
  179. await heading.moveTo();
  180. await expect(
  181. $(
  182. `[data-testid="workflow-run-fill-frame"][data-fill-frame="${DECIDE_HOLE_ID}"][data-fill-on="true"]`,
  183. ),
  184. ).toBeExisting();
  185. // 还开着的尾巴留白在侧板里是虚线灯 + 名字;类型不上界面。
  186. const tail = await $('[data-testid="workflow-run-phase"][data-phase-hole="waiting"]');
  187. await expect(tail).toBeExisting();
  188. expect(await tail.getText()).toContain("评判");
  189. expect(await tail.getText()).not.toContain("Verdict");
  190. // 侧栏运行行:run 停在第二处留白时写「评判 · 等待补全」,迷你轨道的那盏灯是虚线警示色。
  191. const line = await $('[data-workflow-run-line="true"]');
  192. await browser.waitUntil(async () => (await line.getText()).includes("等待补全"), {
  193. timeout: 120000,
  194. timeoutMsg: "侧栏运行行没有写「等待补全」",
  195. });
  196. await expect(line.$('[data-rail-hole="waiting"]')).toBeExisting();
  197. await expect($('[data-testid="workflow-run-hole-waiting"]')).toBeExisting();
  198. // 等待体里画主代理收到的提示语(run 状态 holes[].prompt,来自 hole-reached)。
  199. await expect($('[data-testid="workflow-run-hole-prompt"]')).toBeExisting();
  200. await expect($('[data-testid="workflow-run-holes"]')).toBeExisting();
  201. });
  202. });