conversation-session-v4-fork-edit-branch.test.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // catalog E09(forkUsesEditedActiveBranch)验收(case catalog 战役)。
  2. // 证据层 L3:edit 重跑替换分支 → fork 编辑后的 assistant → child 只含 active branch,
  3. // 不带被 rewind 掉的旧 user/assistant 分支。历史对账链路 = rowId→messageId 翻译 +
  4. // RewindTriggered 截断 + fork 复制 + child 冷订阅 transcript 合成 hydration(曾出过 bug 的面)。
  5. import { clearAppData } from "../helpers/desktop-app.js";
  6. import {
  7. clickFirstV4Fork,
  8. editFirstV4UserQuery,
  9. getV4PaneSnapshot,
  10. prepareV4ConversationE2E,
  11. sendV4Prompt,
  12. waitForV4Edit,
  13. waitForV4Fork,
  14. waitForV4Pane,
  15. waitForV4TimelineContaining,
  16. } from "../helpers/v4-conversation.js";
  17. describe("v4 catalog E09:fork 使用编辑后的 active branch", () => {
  18. after(async () => {
  19. await browser.electron.restoreAllMocks();
  20. await clearAppData();
  21. });
  22. it("edit 重跑后 fork → child 只含编辑分支,不带旧分支", async () => {
  23. await prepareV4ConversationE2E();
  24. // 原始首轮
  25. await sendV4Prompt("E2E_V4_BRANCH_T1 原始问题");
  26. await waitForV4TimelineContaining("V4_BRANCH_T1_REPLY", 60000);
  27. const parent = await waitForV4Pane(
  28. (s) => s.sessionId !== "draft" && s.sessionId !== null && !s.canStop,
  29. "首轮没有完成",
  30. 45000,
  31. );
  32. const parentSessionId = parent.sessionId;
  33. // edit:行内 newText + Send → rewind 截断 + 重跑
  34. await waitForV4Edit();
  35. await editFirstV4UserQuery("E2E_V4_BRANCH_EDITED 编辑后的问题");
  36. // branch cut 可见后,replacement user row 也必须从权威投影恢复,不能只剩截断结果。
  37. await waitForV4TimelineContaining("E2E_V4_BRANCH_EDITED", 30000);
  38. await waitForV4TimelineContaining("V4_BRANCH_EDITED_REPLY", 60000);
  39. const afterEdit = await getV4PaneSnapshot();
  40. expect(afterEdit.timelineText).not.toContain("V4_BRANCH_T1_REPLY");
  41. expect(afterEdit.timelineText).not.toContain("E2E_V4_BRANCH_T1");
  42. // fork 编辑后的 assistant 行
  43. await waitForV4Pane((s) => !s.canStop, "edit 重跑没有收口", 45000);
  44. await waitForV4Fork();
  45. expect(await clickFirstV4Fork()).toBe(true);
  46. const child = await waitForV4Pane(
  47. (s) => s.sessionId !== null && s.sessionId !== "draft" && s.sessionId !== parentSessionId,
  48. "fork 后 pane 没有切到 child session",
  49. 60000,
  50. );
  51. expect(child.sessionId).not.toBe(parentSessionId);
  52. // child 历史 = 编辑后的 active branch;旧分支不得进入 child。
  53. // 注:rewind 合成 notice(rewoundPromptPreview)会引用被编辑掉的原 prompt 文本,
  54. // 这是 transcript 对 rewind 的记录、不是旧分支复活——强断言只看旧 assistant 回复
  55. // 与旧 user turn 是否作为真实轮次存在。
  56. await waitForV4TimelineContaining("V4_BRANCH_EDITED_REPLY", 30000);
  57. const childSnapshot = await getV4PaneSnapshot();
  58. expect(childSnapshot.timelineText).toContain("E2E_V4_BRANCH_EDITED");
  59. expect(childSnapshot.timelineText).not.toContain("V4_BRANCH_T1_REPLY");
  60. });
  61. });