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

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