conversation-session-dynamic-workflow-gray-always-on-activity-retention.test.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import { openStatusCapsule } from "#e2e/helpers/status-capsule";
  2. import { join } from "node:path";
  3. import { clearAppData } from "#e2e/helpers/desktop-app";
  4. import { releaseControlledReplay } from "#e2e/helpers/controlled-replay";
  5. import { getLatestUpstreamToolResultByToolCallId } from "#e2e/helpers/conversation-session-network";
  6. import {
  7. approveV4Permission,
  8. prepareV4ConversationE2E,
  9. sendV4PromptAndWaitAccepted,
  10. waitForV4AssistantMessageContaining,
  11. waitForV4PermissionDialog,
  12. } from "#e2e/helpers/v4-conversation";
  13. const trigger = '[data-status-capsule="activity"]';
  14. const panel = '[data-status-capsule-content="activity"]';
  15. // ACT03/06:沿用服务端 always-on 夹具,实际编译、批准并运行两阶段三 Agent 工作流。
  16. describe("Activity Workflow retention candidate", () => {
  17. after(async () => {
  18. await browser.electron.restoreAllMocks();
  19. await clearAppData();
  20. });
  21. it("Workflow 内部 Agent 不重复计数,完成保留,下一轮切换历史入口", async function () {
  22. this.timeout(300000);
  23. await prepareV4ConversationE2E();
  24. await sendV4PromptAndWaitAccepted("E2E_DWR_START", "E2E_DWR_START", "工作流输入未接纳");
  25. await waitForV4PermissionDialog();
  26. await approveV4Permission();
  27. await browser.waitUntil(
  28. async () =>
  29. (await getLatestUpstreamToolResultByToolCallId("toolu_dwr_create"))?.isError === false,
  30. { timeout: 90000, timeoutMsg: "真实工作流启动失败" },
  31. );
  32. const result = await getLatestUpstreamToolResultByToolCallId("toolu_dwr_create");
  33. const runId = /started in the background with ID: (\S+?)\./.exec(result?.content ?? "")?.[1];
  34. expect(runId).toBeTruthy();
  35. await $(trigger).waitForDisplayed({ timeout: 60000 });
  36. await $(trigger).click();
  37. const item = `${panel} [data-activity-id="workflow:${runId}"]`;
  38. await $(item).waitForDisplayed({ timeout: 60000 });
  39. expect((await $$(`${panel} [data-activity-id]`)).length).toBe(1);
  40. expect(await $(`${trigger} [data-status-capsule-secondary]`).getText()).toBe("1");
  41. await browser.keys("Escape");
  42. await waitForV4AssistantMessageContaining("E2E_DWR_STARTED", 60000);
  43. await sendV4PromptAndWaitAccepted(
  44. "E2E_ACTIVITY_MIXED_START",
  45. "E2E_ACTIVITY_MIXED_START",
  46. "混合活动输入未接纳",
  47. );
  48. await $(trigger).click();
  49. await browser.waitUntil(async () => (await $$(`${panel} [data-activity-id]`).length) === 3, {
  50. timeout: 60000,
  51. timeoutMsg: "三类顶层活动未同时展示",
  52. });
  53. expect(await $(`${trigger} [data-status-capsule-secondary]`).getText()).toBe("3");
  54. await $(
  55. `${panel} [data-background-task-kind="bash"] [data-testid^="v4-background-work-cancel-"]`,
  56. ).click();
  57. await $(`${panel} [data-activity-result="stopped"]`).waitForDisplayed({ timeout: 30000 });
  58. await browser.waitUntil(
  59. async () => (await $(`${trigger} [data-status-capsule-secondary]`).getText()) === "2",
  60. { timeout: 30000, timeoutMsg: "终端停止后计数未减一" },
  61. );
  62. await releaseControlledReplay("activity-mixed-child");
  63. await $(
  64. `${panel} [data-activity-id^="agent:"] [data-activity-result="completed"]`,
  65. ).waitForDisplayed({ timeout: 60000 });
  66. expect(await $(`${trigger} [data-status-capsule-secondary]`).getText()).toBe("1");
  67. const order = await browser.execute(
  68. (selector) =>
  69. Array.from(document.querySelectorAll(`${selector} [data-activity-id]`)).map((el) =>
  70. el.getAttribute("data-activity-id"),
  71. ),
  72. panel,
  73. );
  74. expect(order[0]).toBe(`workflow:${runId}`);
  75. // 下一轮收起已结束的 child/终端;仍运行的 Workflow 完成后不能遮掉子智能体目录。
  76. await browser.keys("Escape");
  77. await sendV4PromptAndWaitAccepted(
  78. "E2E_ACTIVITY_WORKFLOW_CLEAR",
  79. "E2E_ACTIVITY_WORKFLOW_CLEAR",
  80. "历史与本轮混合输入未接纳",
  81. );
  82. await openStatusCapsule("activity");
  83. await $('[data-testid="activity-subagent-directory"]').waitForDisplayed({ timeout: 30000 });
  84. expect(await $('[data-testid="activity-workflow-directory"]').isExisting()).toBe(false);
  85. await releaseControlledReplay("dwr-agent-c");
  86. await $(`${item} [data-activity-result="completed"]`).waitForDisplayed({ timeout: 30000 });
  87. expect(await $$(`${panel} [data-activity-id]`).length).toBe(1);
  88. // 一个 Workflow 加一个独立 child 成功;内部 actor 不重复计数。
  89. expect(await $(`${trigger} [data-status-capsule-secondary]`).getText()).toBe("2");
  90. expect(await $(trigger).getText()).toMatch(/Completed|已完成/);
  91. expect(await $(trigger).isDisplayed()).toBe(true);
  92. await browser.saveScreenshot(
  93. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, "activity-mixed-ended.png"),
  94. );
  95. await $('[data-testid="activity-subagent-directory"]').waitForDisplayed({ timeout: 30000 });
  96. expect(await $('[data-testid="activity-workflow-directory"]').isExisting()).toBe(false);
  97. await openStatusCapsule("activity");
  98. await $(`${item} [data-activity-result] button`).click();
  99. await $(`div.flex.h-full[data-workflow-run-id="${runId}"]`).waitForDisplayed({
  100. timeout: 30000,
  101. });
  102. await browser.keys("Escape");
  103. await sendV4PromptAndWaitAccepted(
  104. "E2E_ACTIVITY_WORKFLOW_CLEAR",
  105. "E2E_ACTIVITY_WORKFLOW_CLEAR",
  106. "清除输入未接纳",
  107. );
  108. await $(trigger).waitForDisplayed({ timeout: 30000 });
  109. await $(trigger).click();
  110. await $('[data-testid="activity-workflow-directory"]').waitForDisplayed({ timeout: 30000 });
  111. expect(
  112. (await $$('[data-status-capsule-content="activity"] [data-activity-result]')).length,
  113. ).toBe(0);
  114. expect(await $(trigger).getText()).toMatch(/Completed|已完成/);
  115. expect(await $(`${trigger} [data-status-capsule-secondary]`).getText()).toBe("2");
  116. // 目录是现有真实侧栏路由;两种历史入口须可达并复用同会话标签。
  117. for (const kind of ["subagent", "workflow"] as const) {
  118. for (let attempt = 0; attempt < 2; attempt += 1) {
  119. await openStatusCapsule("activity");
  120. await $(`[data-testid="activity-${kind}-directory"]`).waitForDisplayed({ timeout: 30000 });
  121. await $(`[data-testid="activity-${kind}-directory"]`).click();
  122. await $(`[data-side-pane-tab-id^="${kind}-directory:"]`).waitForDisplayed({
  123. timeout: 30000,
  124. });
  125. expect(await $$(`[data-side-pane-tab-id^="${kind}-directory:"]`).length).toBe(1);
  126. }
  127. }
  128. });
  129. });