conversation-session-v4-rewind-queue-background.test.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // PV4-20/PV4-23:compact 期间 held queue 在 edit 后保持;被裁 turn 的后台 Bash 先取消再 bump generation。
  2. import { clearAppData } from "#e2e/helpers/desktop-app";
  3. import {
  4. countUpstreamRequests,
  5. countUpstreamRequestsContaining,
  6. } from "#e2e/helpers/conversation-session-network";
  7. import {
  8. clickV4Stop,
  9. clickV4QueueItemSendNow,
  10. describeV4BackgroundFailureState,
  11. editFirstV4UserQuery,
  12. getV4BackgroundWorks,
  13. getV4PaneSnapshot,
  14. getV4QueueItems,
  15. openV4RunningBackgroundWorks,
  16. prepareV4ConversationE2E,
  17. sendV4Prompt,
  18. switchV4Mode,
  19. waitForV4CompactMarker,
  20. waitForV4Edit,
  21. waitForV4Pane,
  22. waitForV4PausedQueueBanner,
  23. waitForV4QueueCount,
  24. waitForV4TimelineContaining,
  25. } from "#e2e/helpers/v4-conversation";
  26. describe("PV4-20/PV4-23 rewind queue and background fencing", () => {
  27. after(async () => {
  28. await browser.electron.restoreAllMocks();
  29. await clearAppData();
  30. });
  31. it("PV4-20 edit 保留 held queue,再按原 ID/顺序各消费一次", async function () {
  32. this.timeout(150000);
  33. await prepareV4ConversationE2E();
  34. await sendV4Prompt("E2E_PV4_20_ORIGINAL compact 前的 latest query");
  35. await waitForV4TimelineContaining("PV4_20_ORIGINAL_REPLY", 60000);
  36. // Bug 根因:autoDrain 局部按钮已从产品 UI 删除,旧 case 在 draft 上点击一个已不存在
  37. // 的 testid,并没有建立 held queue。当前可达路径是先中断一次 compact,把两个 future
  38. // intent 与第二个 compact 一起 held,再 send-now 第二个 compact 覆盖 latest query。
  39. await sendV4Prompt("/compact");
  40. await waitForV4CompactMarker({ origin: "manual", status: "running" }, 60000);
  41. await sendV4Prompt("E2E_PV4_20_QUEUE_ONE 队列第一项");
  42. await waitForV4QueueCount(1, 30000);
  43. await sendV4Prompt("E2E_PV4_20_QUEUE_TWO 队列第二项");
  44. await waitForV4QueueCount(2, 30000);
  45. await clickV4Stop();
  46. await waitForV4Pane(
  47. (snapshot) => !snapshot.canStop,
  48. "PV4-20 stop 第二次 compact 后没有回到 idle",
  49. 30000,
  50. );
  51. await waitForV4PausedQueueBanner(15000);
  52. // compactActive 时第二个 compact 按 operation lock 会被拒绝;stop 后在 held 状态
  53. // 提交才会按当前产品规则追加队尾,再由 send-now 只取出这一项。
  54. await sendV4Prompt("/compact");
  55. await waitForV4QueueCount(3, 30000);
  56. const queued = await getV4QueueItems();
  57. expect(queued.slice(0, 2).map((item) => item.text)).toEqual([
  58. expect.stringContaining("E2E_PV4_20_QUEUE_ONE"),
  59. expect.stringContaining("E2E_PV4_20_QUEUE_TWO"),
  60. ]);
  61. expect(await clickV4QueueItemSendNow(queued[2]!.queueItemId)).toBe(true);
  62. await waitForV4CompactMarker({ origin: "manual", status: "success" }, 90000);
  63. await waitForV4QueueCount(2, 30000);
  64. const before = await getV4QueueItems();
  65. expect(before).toEqual(queued.slice(0, 2));
  66. await waitForV4Edit();
  67. await editFirstV4UserQuery("E2E_PV4_20_EDITED 保留 held queue 重发");
  68. await waitForV4TimelineContaining("PV4_20_EDITED_REPLY", 60000);
  69. const after = await getV4QueueItems();
  70. expect(after).toEqual(before);
  71. expect((await getV4PaneSnapshot()).timelineText).not.toContain("PV4_20_ORIGINAL_REPLY");
  72. expect(await countUpstreamRequestsContaining("E2E_PV4_20_EDITED")).toBe(1);
  73. expect(await clickV4QueueItemSendNow(before[0]!.queueItemId)).toBe(true);
  74. await waitForV4TimelineContaining("PV4_20_QUEUE_ONE_REPLY", 60000);
  75. await waitForV4QueueCount(1, 30000);
  76. expect((await getV4QueueItems())[0]?.queueItemId).toBe(before[1]!.queueItemId);
  77. expect(await clickV4QueueItemSendNow(before[1]!.queueItemId)).toBe(true);
  78. await waitForV4TimelineContaining("PV4_20_QUEUE_TWO_REPLY", 60000);
  79. await waitForV4QueueCount(0, 30000);
  80. expect(
  81. await countUpstreamRequests({
  82. lastUserMessageIncludes: ["E2E_PV4_20_QUEUE_ONE"],
  83. }),
  84. ).toBe(1);
  85. expect(
  86. await countUpstreamRequests({
  87. lastUserMessageIncludes: ["E2E_PV4_20_QUEUE_TWO"],
  88. }),
  89. ).toBe(1);
  90. });
  91. it("PV4-23 edit 前取消被裁 turn 的后台 Bash,新分支只启动一次", async function () {
  92. this.timeout(150000);
  93. await prepareV4ConversationE2E();
  94. await switchV4Mode("yolo");
  95. await sendV4Prompt("E2E_PV4_23_BACKGROUND_ORIGINAL 启动后台 Bash");
  96. try {
  97. await waitForV4TimelineContaining("PV4_23_BACKGROUND_ORIGINAL_REPLY", 90000);
  98. } catch (error) {
  99. throw new Error(
  100. `PV4-23 原 turn 没有出现后台 Bash 跟进回复: ${await describeV4BackgroundFailureState()}`,
  101. { cause: error },
  102. );
  103. }
  104. await openV4RunningBackgroundWorks(60000);
  105. const running = (await getV4BackgroundWorks()).find((work) => work.status === "running");
  106. expect(running?.workId).toBeTruthy();
  107. await waitForV4Edit();
  108. await editFirstV4UserQuery("E2E_PV4_23_BACKGROUND_EDITED 取消旧后台后重发");
  109. await waitForV4TimelineContaining("PV4_23_BACKGROUND_EDITED_REPLY", 90000);
  110. await waitForV4Pane((snapshot) => !snapshot.canStop, "PV4-23 edit 后没有回到 idle", 60000);
  111. await browser.waitUntil(
  112. async () => !(await getV4BackgroundWorks()).some((work) => work.workId === running?.workId),
  113. {
  114. timeout: 60000,
  115. timeoutMsg: "PV4-23 被裁 turn 的后台 Bash 仍在 running 列表",
  116. },
  117. );
  118. const finalSnapshot = await getV4PaneSnapshot();
  119. expect(finalSnapshot.timelineText).not.toContain("PV4_23_BACKGROUND_ORIGINAL_REPLY");
  120. expect(await countUpstreamRequestsContaining("E2E_PV4_23_BACKGROUND_EDITED")).toBe(1);
  121. });
  122. });