conversation-session-capsule-foreground-stop.test.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { clearAppData } from "#e2e/helpers/desktop-app";
  2. import { releaseControlledReplay } from "#e2e/helpers/controlled-replay";
  3. import { ensureToolCrossProductFullAccessMode } from "#e2e/helpers/conversation-session-tool-cross-product";
  4. import {
  5. waitForUpstreamRequest,
  6. getUpstreamRequestRecordCount,
  7. } from "#e2e/helpers/conversation-session-network";
  8. import { waitForToolCallBlockByToolCallId } from "#e2e/helpers/conversation-session-tool";
  9. import {
  10. clickRunningSubagentStop,
  11. countVisibleSubagentTabs,
  12. openRunningSubagentCapsule,
  13. readRunningSubagentControls,
  14. type RunningSubagentControl,
  15. } from "#e2e/helpers/subagent-capsule-stop";
  16. import {
  17. getV4ComposerBackgroundWorkCounts,
  18. prepareV4ConversationE2E,
  19. sendV4PromptAndWaitAccepted,
  20. waitForV4AssistantMessageContaining,
  21. waitForV4ConversationState,
  22. } from "#e2e/helpers/v4-conversation";
  23. const MARKER = "E2E_CAPSULE_FOREGROUND_STOP";
  24. const STOP_TOOL = "toolu_e2e_capsule_foreground_stop";
  25. const KEEP_TOOL = "toolu_e2e_capsule_foreground_keep";
  26. const KEEP_GATE = "capsule-foreground-keep-controlled";
  27. // SAT12 候选:需先完成 manual/capture 与 replay review,不能将类型检查视为覆盖证据。
  28. describe("SAT12 foreground capsule Stop candidate", () => {
  29. after(async () => {
  30. await browser.electron.restoreAllMocks();
  31. await clearAppData();
  32. });
  33. it("仅停止指定 foreground child,父 Agent 收到原工具结果,另一 child 继续完成", async function () {
  34. this.timeout(240000);
  35. await prepareV4ConversationE2E();
  36. await ensureToolCrossProductFullAccessMode();
  37. const runMarker = `${MARKER}_${Date.now()}`;
  38. await sendV4PromptAndWaitAccepted(
  39. `${runMarker}: launch two foreground Agent calls in parallel. One replies STOP_CHILD, the other replies KEEP_CHILD. Wait for both results, then finish.`,
  40. runMarker,
  41. "foreground 两个 Agent 首发后用户消息没有进入 timeline",
  42. 90000,
  43. );
  44. await openRunningSubagentCapsule(90000);
  45. let stop: RunningSubagentControl | undefined;
  46. let keep: RunningSubagentControl | undefined;
  47. await browser.waitUntil(
  48. async () => {
  49. const controls = await readRunningSubagentControls();
  50. stop = controls.find((row) => row.title.includes("Stop target foreground child"));
  51. keep = controls.find((row) => row.title.includes("Keep running foreground child"));
  52. return Boolean(
  53. stop?.stopVisible && keep?.stopVisible && stop.executionId && keep.executionId,
  54. );
  55. },
  56. { timeout: 90000, timeoutMsg: "没有同时出现两个带精确 Stop token 的 foreground child" },
  57. );
  58. expect(stop!.taskId).not.toBe(keep!.taskId);
  59. expect(stop!.executionId).not.toBe(keep!.executionId);
  60. expect(stop!.childSessionId).not.toBe(keep!.childSessionId);
  61. expect((await getV4ComposerBackgroundWorkCounts())?.subagentCount).toBe(2);
  62. expect(await countVisibleSubagentTabs()).toBe(0);
  63. const beforeStop = await getUpstreamRequestRecordCount();
  64. const ack = await clickRunningSubagentStop(stop!);
  65. expect(ack.status).toBe("accepted");
  66. await browser.waitUntil(
  67. async () => {
  68. const controls = await readRunningSubagentControls();
  69. return (
  70. !controls.some((row) => row.childSessionId === stop!.childSessionId) &&
  71. controls.some(
  72. (row) =>
  73. row.childSessionId === keep!.childSessionId &&
  74. row.taskId === keep!.taskId &&
  75. row.executionId === keep!.executionId,
  76. )
  77. );
  78. },
  79. { timeout: 60000, timeoutMsg: "目标 child 没收口或 sibling 执行身份被误停" },
  80. );
  81. await waitForV4ConversationState(
  82. (snapshot) => snapshot.state === "streaming" && !snapshot.stopRequested,
  83. "停止单个 child 误停了父 turn",
  84. 30000,
  85. );
  86. expect(await countVisibleSubagentTabs()).toBe(0);
  87. await releaseControlledReplay(KEEP_GATE);
  88. await browser.waitUntil(
  89. async () => (await waitForToolCallBlockByToolCallId(KEEP_TOOL, 10000)).status === "completed",
  90. { timeout: 90000, timeoutMsg: "放行后的 sibling Agent 没有完成" },
  91. );
  92. const stoppedResult = await waitForToolCallBlockByToolCallId(STOP_TOOL, 90000);
  93. const keptResult = await waitForToolCallBlockByToolCallId(KEEP_TOOL, 90000);
  94. expect(stoppedResult.status).not.toBe("running");
  95. expect(stoppedResult.text.toLowerCase()).toMatch(/stop|cancel|abort/u);
  96. expect(keptResult.status).toBe("completed");
  97. await waitForUpstreamRequest(
  98. {
  99. includes: [runMarker, STOP_TOOL, KEEP_TOOL, "E2E_CAPSULE_KEEP_DONE"],
  100. excludes: ["<task-notification>"],
  101. },
  102. "父模型未收到被停止 foreground Agent 的原工具结果和 sibling 完成结果",
  103. 90000,
  104. { afterIndex: beforeStop - 1 },
  105. );
  106. await waitForV4AssistantMessageContaining("E2E_CAPSULE_PARENT_DONE", 90000);
  107. await waitForV4ConversationState(
  108. (snapshot) => snapshot.state !== "streaming" && !snapshot.stopRequested,
  109. "两个 foreground tool result 后父 turn 没有结束",
  110. 90000,
  111. );
  112. expect(await readRunningSubagentControls()).toHaveLength(0);
  113. });
  114. });