conversation-session-compact-interrupted.test.ts 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { clearAppData } from "../../../helpers/desktop-app.js";
  2. import {
  3. assertUpstreamRequestCapture,
  4. waitForUpstreamNetworkCapture,
  5. } from "../../../helpers/upstream-capture.js";
  6. import { UPSTREAM_MODEL } from "../../../helpers/upstream-provider.js";
  7. import {
  8. E2E_REPLY_TOKEN,
  9. buildReadonlyToolPrompt,
  10. clickChatStop,
  11. getQueueItems,
  12. prepareConversationE2E,
  13. sendPrompt,
  14. waitForChatState,
  15. waitForCompactMarkerStatus,
  16. waitForComposerText,
  17. } from "../../../helpers/conversation-session.js";
  18. const COMPACT_REQUEST_SENTINEL = "CRITICAL: Respond with TEXT ONLY";
  19. describe("会话区 Interrupted 后手动 Compact E2E", () => {
  20. after(async () => {
  21. await browser.electron.restoreAllMocks();
  22. await clearAppData();
  23. });
  24. it("completed interrupted 且 queue=0 时应允许手动 compact", async function () {
  25. this.timeout(180000);
  26. await prepareConversationE2E();
  27. const runId = Date.now();
  28. const prepPromptOne = `E2E_COMPACT_INTERRUPTED_PREP_ONE_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  29. await sendPrompt(prepPromptOne);
  30. await waitForUpstreamNetworkCapture(`E2E_COMPACT_INTERRUPTED_PREP_ONE_${runId}`);
  31. await waitForChatState(
  32. (snapshot) => snapshot.state === "idle" && snapshot.queueCount === 0,
  33. "第一轮 interrupted compact 预置消息没有完成",
  34. 30000,
  35. );
  36. const prepPromptTwo = buildReadonlyToolPrompt(
  37. `E2E_COMPACT_INTERRUPTED_PREP_TWO_${runId}`,
  38. );
  39. await sendPrompt(prepPromptTwo);
  40. await waitForUpstreamNetworkCapture(`E2E_COMPACT_INTERRUPTED_PREP_TWO_${runId}`);
  41. await waitForChatState(
  42. (snapshot) => snapshot.state === "idle" && snapshot.queueCount === 0,
  43. "第二轮 interrupted compact 预置消息没有完成",
  44. 30000,
  45. );
  46. const interruptedPrompt = `E2E_SLOW_STREAM E2E_COMPACT_INTERRUPTED_RUNNING_${runId}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  47. await sendPrompt(interruptedPrompt);
  48. await waitForComposerText("", "interrupted compact 运行轮发送后输入框没有清空");
  49. await waitForChatState(
  50. (snapshot) => snapshot.state === "streaming",
  51. "interrupted compact 运行轮没有进入 streaming",
  52. 30000,
  53. );
  54. await clickChatStop();
  55. await waitForChatState(
  56. (snapshot) => snapshot.state !== "streaming" && snapshot.queueCount === 0,
  57. "stop 后没有进入 completed interrupted 且 queue=0",
  58. 30000,
  59. );
  60. await sendPrompt("/compact");
  61. await waitForComposerText("", "interrupted 后 /compact 发送后输入框没有清空");
  62. const startedMarker = await waitForCompactMarkerStatus("started", "manual");
  63. expect(startedMarker.inputId).toBeTruthy();
  64. expect(await getQueueItems()).toHaveLength(0);
  65. const compactRecord = await waitForUpstreamNetworkCapture(COMPACT_REQUEST_SENTINEL);
  66. assertUpstreamRequestCapture(compactRecord, {
  67. expectedText: COMPACT_REQUEST_SENTINEL,
  68. model: UPSTREAM_MODEL,
  69. });
  70. const completedMarker = await waitForCompactMarkerStatus(
  71. "completed",
  72. "manual",
  73. startedMarker.inputId,
  74. );
  75. expect(completedMarker.operationId).toBeTruthy();
  76. expect(await getQueueItems()).toHaveLength(0);
  77. });
  78. });