conversation-session-v4-queue-drain.test.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // catalog C02(queueAutoDrain)+ queuedPromptMessagePreserved 验收(case catalog 战役)。
  2. // 证据层 L3:running 中入队 → 当前流结束后 runtime 自动 drain 队首(同 turn 第二次
  3. // roundtrip)→ 排队文本必须以可见 user row 落入 timeline(live 投影修复回归,
  4. // 见 fix(protocol-v4) heldQueueDisposition/drained user row 提交),且回复出现、queue 清空。
  5. import { clearAppData } from "#e2e/helpers/desktop-app";
  6. import {
  7. getV4QueueItems,
  8. prepareV4ConversationE2E,
  9. sendV4Prompt,
  10. waitForV4Pane,
  11. waitForV4QueueCount,
  12. waitForV4TimelineContaining,
  13. } from "#e2e/helpers/v4-conversation";
  14. describe("v4 catalog C02:queue 自动消费与消息保留", () => {
  15. after(async () => {
  16. await browser.electron.restoreAllMocks();
  17. await clearAppData();
  18. });
  19. it("running 中入队 → 自动 drain → 排队文本落为可见 user row + 回复出现", async () => {
  20. await prepareV4ConversationE2E();
  21. // 首轮 8s 慢流,留出入队窗口
  22. await sendV4Prompt("E2E_V4_DRAIN_SLOW 慢慢回答");
  23. await waitForV4TimelineContaining("V4_DRAIN_STREAMING", 45000);
  24. await waitForV4Pane(
  25. (s) => s.canStop && s.sessionId !== "draft" && s.sessionId !== null,
  26. "首轮没有进入 running(canStop)",
  27. 45000,
  28. );
  29. // running 中入队一条(autoDrain 默认 true)
  30. await sendV4Prompt("E2E_V4_DRAIN_Q1 排队等答的问题");
  31. await waitForV4QueueCount(1, 30000);
  32. // 慢流结束后自动 drain:回复出现
  33. await waitForV4TimelineContaining("V4_DRAIN_Q1_REPLY", 60000);
  34. await waitForV4QueueCount(0, 15000);
  35. // queuedPromptMessagePreserved:被 drain 的排队文本必须留在可见历史(user row),
  36. // 不能从 queue 消失后只剩 assistant 回复。
  37. const snapshot = await waitForV4Pane(
  38. (s) => s.timelineText.includes("E2E_V4_DRAIN_Q1"),
  39. "drained 排队文本没有以可见 user row 落入 timeline",
  40. 15000,
  41. );
  42. expect(snapshot.timelineText).toContain("V4_DRAIN_Q1_REPLY");
  43. expect(await getV4QueueItems()).toHaveLength(0);
  44. // 整轮收口
  45. await waitForV4Pane((s) => !s.canStop, "drain 后没有回到 idle", 45000);
  46. });
  47. });