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

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