conversation-session-goal-interruptions.test.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import { clearAppData } from "#e2e/helpers/desktop-app";
  2. import { releaseControlledReplay } from "#e2e/helpers/controlled-replay";
  3. import {
  4. E2E_REPLY_TOKEN,
  5. clickV4Stop,
  6. prepareV4ConversationE2E,
  7. sendV4Prompt,
  8. startNewV4Draft,
  9. waitForV4AssistantMessageContaining,
  10. waitForV4ConversationState,
  11. waitForV4ComposerText,
  12. waitForV4UserMessageContaining,
  13. } from "#e2e/helpers/v4-conversation";
  14. import {
  15. getUpstreamRequestRecordCount,
  16. waitForUpstreamRequest,
  17. waitForUpstreamRequestContaining,
  18. } from "#e2e/helpers/conversation-session-network";
  19. import { waitForCompactMarkerStatus } from "#e2e/helpers/conversation-session-compact";
  20. const COMPACT_REQUEST_SENTINEL = "CRITICAL: Respond with TEXT ONLY";
  21. const GOAL_INTERRUPTIONS_TIMEOUT_MS = 180000;
  22. describe("会话区 Goal Interruptions E2E", () => {
  23. afterEach(async () => {
  24. await stopIfBusy();
  25. });
  26. after(async () => {
  27. await browser.electron.restoreAllMocks();
  28. await clearAppData();
  29. });
  30. it("goal verifier 运行中 stop 后,普通文本应立即开始下一轮", async function () {
  31. this.timeout(GOAL_INTERRUPTIONS_TIMEOUT_MS);
  32. await prepareV4ConversationE2E();
  33. await startNewV4Draft();
  34. const runId = Date.now();
  35. const goalMarker = `E2E_GOAL_VERIFIER_STOP_${runId}`;
  36. const nextMarker = `E2E_GOAL_VERIFIER_STOP_NEXT_${runId}`;
  37. const requestCountBefore = await getUpstreamRequestRecordCount();
  38. await sendV4Prompt(
  39. `/goal ${goalMarker}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`,
  40. );
  41. await waitForV4ComposerText("", "goal verifier stop /goal 发送后输入框没有清空");
  42. await waitForV4UserMessageContaining(goalMarker);
  43. await waitForUpstreamRequest(
  44. {
  45. includes: [goalMarker, "Verify whether the active session goal"],
  46. excludes: [nextMarker],
  47. },
  48. "goal verifier stop 没有进入 verifier request",
  49. 90000,
  50. { afterIndex: requestCountBefore },
  51. );
  52. // V4 的 Stop 控件和队列/目标投影是当前状态来源;旧 runtimeStatus 已不再写入。
  53. await clickV4Stop();
  54. await waitForV4ConversationState(
  55. (snapshot) =>
  56. snapshot.state !== "streaming" &&
  57. snapshot.queueCount === 0 &&
  58. snapshot.targetStatus === "paused",
  59. "goal verifier stop 后没有收口到 completed/paused",
  60. 30000,
  61. );
  62. await sendV4Prompt(`${nextMarker}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`);
  63. await waitForV4ComposerText("", "goal verifier stop 后下一轮发送没有清空输入框");
  64. await waitForUpstreamRequestContaining(nextMarker, 30000);
  65. await waitForV4AssistantMessageContaining(E2E_REPLY_TOKEN);
  66. await waitForV4ConversationState(
  67. (snapshot) => snapshot.state === "idle" && snapshot.queueCount === 0,
  68. "goal verifier stop 后下一轮没有完成并保持 queue=0",
  69. 90000,
  70. );
  71. });
  72. it("goal verifier 运行中 stop 后,可以 compact 并继续发送普通文本", async function () {
  73. this.timeout(GOAL_INTERRUPTIONS_TIMEOUT_MS);
  74. await prepareV4ConversationE2E();
  75. await startNewV4Draft();
  76. const runId = Date.now();
  77. const goalMarker = `E2E_GOAL_VERIFIER_COMPACT_${runId}`;
  78. const nextMarker = `E2E_GOAL_VERIFIER_COMPACT_NEXT_${runId}`;
  79. const compactSummaryMarker = "E2E_GOAL_VERIFIER_COMPACT_SUMMARY_MARKER";
  80. const requestCountBefore = await getUpstreamRequestRecordCount();
  81. await sendV4Prompt(
  82. `/goal ${goalMarker}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`,
  83. );
  84. await waitForV4ComposerText("", "goal verifier compact /goal 发送后输入框没有清空");
  85. await waitForUpstreamRequest(
  86. {
  87. includes: [goalMarker, "Verify whether the active session goal"],
  88. excludes: [nextMarker],
  89. },
  90. "goal verifier compact 没有进入 verifier request",
  91. 90000,
  92. { afterIndex: requestCountBefore },
  93. );
  94. await clickV4Stop();
  95. await waitForV4ConversationState(
  96. (snapshot) =>
  97. snapshot.state !== "streaming" &&
  98. snapshot.queueCount === 0 &&
  99. snapshot.targetStatus === "paused",
  100. "goal verifier compact stop 后没有收口到 completed/paused",
  101. 30000,
  102. );
  103. await sendV4Prompt("/compact");
  104. await waitForV4ComposerText("", "goal verifier compact 后 /compact 没有清空输入框");
  105. const startedMarker = await waitForCompactMarkerStatus("started", "manual");
  106. expect(startedMarker.inputId).toBeTruthy();
  107. await waitForUpstreamRequest(
  108. {
  109. includes: [COMPACT_REQUEST_SENTINEL, goalMarker],
  110. },
  111. "goal verifier compact 没有发起 manual compact 请求",
  112. 30000,
  113. { afterIndex: requestCountBefore },
  114. );
  115. // 快速摘要曾在 38ms 内完成,轮询来不及观察 started;确认开始后再放行受控响应。
  116. await releaseControlledReplay("upstream-goal-verifier-compact-summary");
  117. await waitForCompactMarkerStatus("completed", "manual", startedMarker.inputId);
  118. await sendV4Prompt(`${nextMarker}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`);
  119. await waitForV4ComposerText("", "goal verifier compact 后下一轮发送没有清空输入框");
  120. await waitForUpstreamRequest(
  121. {
  122. includes: [nextMarker, compactSummaryMarker],
  123. lastUserMessageIncludes: [nextMarker],
  124. },
  125. "goal verifier compact 后下一轮请求没有基于 compact 后摘要继续",
  126. 30000,
  127. { afterIndex: requestCountBefore },
  128. );
  129. await waitForV4AssistantMessageContaining(E2E_REPLY_TOKEN);
  130. await waitForV4ConversationState(
  131. (snapshot) => snapshot.state === "idle" && snapshot.queueCount === 0,
  132. "goal verifier compact 后下一轮没有完成并保持 queue=0",
  133. 90000,
  134. );
  135. });
  136. });
  137. async function stopIfBusy() {
  138. const snapshot = await waitForV4ConversationState(
  139. () => true,
  140. "goal interruptions afterEach 读取 chat state 失败",
  141. 1000,
  142. ).catch(() => null);
  143. if (snapshot?.state !== "streaming") {
  144. return;
  145. }
  146. await clickV4Stop().catch(() => undefined);
  147. await waitForV4ConversationState(
  148. (candidate) => candidate.state !== "streaming",
  149. "goal interruptions 清理阶段没有退出 streaming",
  150. 30000,
  151. ).catch(() => undefined);
  152. }