conversation-session-running-actions.test.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { clearAppData } from "#e2e/helpers/desktop-app";
  2. import {
  3. buildReadonlyToolPrompt,
  4. ensureReadonlyToolFixtureFile,
  5. } from "#e2e/helpers/conversation-session-readonly-tool";
  6. import {
  7. clickFirstV4Fork,
  8. clickV4Stop,
  9. getV4PaneSnapshot,
  10. getV4QueueItems,
  11. prepareV4ConversationE2E,
  12. selectV4TaskById,
  13. sendV4Prompt,
  14. waitForV4Fork,
  15. waitForV4Pane,
  16. waitForV4QueueCount,
  17. waitForV4TimelineContaining,
  18. } from "#e2e/helpers/v4-conversation";
  19. describe("PV4-08 running stable assistant fork E2E", () => {
  20. afterEach(async () => {
  21. await stopRunningTurnIfNeeded();
  22. });
  23. after(async () => {
  24. await browser.electron.restoreAllMocks();
  25. await clearAppData();
  26. });
  27. it("running 中 fork 更早稳定 assistant:父继续且 child 不复制 active work/queue", async function () {
  28. this.timeout(150000);
  29. await prepareV4ConversationE2E();
  30. // 原因:旧聚合 helper 隐式创建只读文件;V4 用例显式保留工具执行前置。
  31. await ensureReadonlyToolFixtureFile();
  32. const runId = Date.now();
  33. const completedMarker = `E2E_RUNNING_ACTIONS_COMPLETED_${runId}`;
  34. await sendV4Prompt(buildReadonlyToolPrompt(completedMarker));
  35. await waitForV4TimelineContaining(completedMarker, 60000);
  36. await waitForV4Pane(
  37. (snapshot) => !snapshot.canStop,
  38. "running stable fork 前置轮次没有完成",
  39. 90000,
  40. );
  41. await waitForV4Fork();
  42. const parent = await getV4PaneSnapshot();
  43. const parentSessionId = parent.sessionId;
  44. expect(parentSessionId).toBeTruthy();
  45. expect(parentSessionId).not.toBe("draft");
  46. const activeMarker = `E2E_RUNNING_ACTIONS_ACTIVE_${runId}`;
  47. await sendV4Prompt(
  48. `E2E_SLOW_STREAM ${activeMarker}: Reply with exactly "upstream-e2e-ok" and no other text.`,
  49. );
  50. await waitForV4Pane(
  51. (snapshot) => snapshot.canStop,
  52. "第二轮没有进入 controlled streaming",
  53. 30000,
  54. );
  55. const queuedMarker = `E2E_RUNNING_ACTIONS_QUEUED_${runId}`;
  56. await sendV4Prompt(`${queuedMarker}: keep this input queued.`);
  57. await waitForV4QueueCount(1, 30000);
  58. // 产品语义已改为:running 不全局禁 fork;更早 completedSuccess 最终
  59. // assistant 的 row.actions.canFork 仍为 true,当前 streaming partial 没有入口。
  60. await waitForV4Fork();
  61. expect(await clickFirstV4Fork()).toBe(true);
  62. const child = await waitForV4Pane(
  63. (snapshot) =>
  64. snapshot.sessionId !== null &&
  65. snapshot.sessionId !== "draft" &&
  66. snapshot.sessionId !== parentSessionId &&
  67. snapshot.timelineText.includes(completedMarker),
  68. "running stable fork child 没有完成稳定历史 hydration",
  69. 30000,
  70. );
  71. expect(child.timelineText).toContain(completedMarker);
  72. expect(child.timelineText).not.toContain(activeMarker);
  73. expect(child.timelineText).not.toContain(queuedMarker);
  74. expect(await getV4QueueItems()).toHaveLength(0);
  75. // 切回父会话时 active turn 与 queue 都还在,证明 fork 没有 stop、搬运或消费父状态。
  76. await selectV4TaskById(parentSessionId!);
  77. await waitForV4Pane(
  78. (snapshot) => snapshot.canStop,
  79. "fork child 后父 session 没有继续运行",
  80. 15000,
  81. );
  82. await waitForV4QueueCount(1, 15000);
  83. expect((await getV4QueueItems())[0]?.text).toContain(queuedMarker);
  84. await clickV4Stop();
  85. await waitForV4Pane(
  86. (snapshot) => !snapshot.canStop,
  87. "running stable fork 收尾 stop 没有完成",
  88. 30000,
  89. );
  90. });
  91. });
  92. async function stopRunningTurnIfNeeded() {
  93. const snapshot = await getV4PaneSnapshot();
  94. if (!snapshot.canStop) return;
  95. await clickV4Stop();
  96. await waitForV4Pane(
  97. (nextSnapshot) => !nextSnapshot.canStop,
  98. "running stable fork 收尾 stop 后没有退出 streaming",
  99. 30000,
  100. );
  101. }