conversation-session-v4-sendnow.test.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // M4 门禁:sendQueuedNow(catalog B 组)。
  2. // 证据层 L3:running turn 期间入队一项 → 点「立即发送」→ sendQueuedNow 命令 →
  3. // v4-bridge:读原文 → 从 queue 移除 → stop 当前 turn → 以原文重发(stop barrier)→
  4. // 该项以新 turn 消费,回复出现。证明 stop-barrier + 立即消费全链路。
  5. import { clearAppData } from "#e2e/helpers/desktop-app";
  6. import {
  7. clickV4QueueItemSendNow,
  8. getV4QueueItems,
  9. prepareV4ConversationE2E,
  10. sendV4Prompt,
  11. waitForV4Pane,
  12. waitForV4QueueCount,
  13. waitForV4TimelineContaining,
  14. } from "#e2e/helpers/v4-conversation";
  15. import {
  16. beginConversationTelemetryCapture,
  17. waitForConversationReportInventory,
  18. } from "#e2e/helpers/conversation-telemetry-parity-capture";
  19. describe("v4 M4 门禁:sendQueuedNow", () => {
  20. after(async () => {
  21. await browser.electron.restoreAllMocks();
  22. await clearAppData();
  23. });
  24. it("running 中入队 → 立即发送 → stop 当前 + 该项以新 turn 消费", async () => {
  25. await prepareV4ConversationE2E();
  26. const capture = await beginConversationTelemetryCapture();
  27. await sendV4Prompt("E2E_V4_SENDNOW_SLOW 慢慢回答");
  28. await waitForV4TimelineContaining("V4_SENDNOW_STREAMING", 45000);
  29. await waitForV4Pane(
  30. (s) => s.canStop && s.sessionId !== "draft" && s.sessionId !== null,
  31. "首轮没有进入 running(canStop)",
  32. 45000,
  33. );
  34. await sendV4Prompt("E2E_V4_SENDNOW_ITEM 立即发我");
  35. await waitForV4QueueCount(1, 30000);
  36. const before = await getV4QueueItems();
  37. const queueItemId = before[0]!.queueItemId;
  38. // 立即发送该队列项 → stop 当前 + 消费该项
  39. const clicked = await clickV4QueueItemSendNow(queueItemId);
  40. expect(clicked).toBe(true);
  41. // 队列清空(该项被消费)+ 该项回复出现
  42. await waitForV4QueueCount(0, 30000);
  43. await waitForV4TimelineContaining("V4_SENDNOW_ITEM_REPLY", 60000);
  44. expect(await getV4QueueItems()).toHaveLength(0);
  45. await waitForV4Pane((state) => !state.canStop, "排队消息未结束", 45000);
  46. const reports = await waitForConversationReportInventory(capture, { message_completion: 2 });
  47. const completions = reports.filter((report) => report.element_name === "message_completion");
  48. expect(completions).toHaveLength(2);
  49. expect(completions.map((report) => report.event_extra_detail)).toEqual([
  50. expect.objectContaining({
  51. is_first_message: "1",
  52. send_mode: "direct",
  53. ttft_input_tokens: "",
  54. ttft_cached_input_tokens: "",
  55. ttft_output_kind: "text",
  56. }),
  57. expect.objectContaining({
  58. is_first_message: "0",
  59. send_mode: "queued",
  60. ttft_output_kind: "text",
  61. }),
  62. ]);
  63. expect(completions[0]!.talk_id).toBe(completions[1]!.talk_id);
  64. expect(completions[0]!.message_id).not.toBe(completions[1]!.message_id);
  65. });
  66. });