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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. await waitForV4TimelineContaining("V4_BRANCH_EDITED_REPLY", 60000);
  37. const afterEdit = await getV4PaneSnapshot();
  38. expect(afterEdit.timelineText).not.toContain("V4_BRANCH_T1_REPLY");
  39. expect(afterEdit.timelineText).not.toContain("E2E_V4_BRANCH_T1");
  40. // fork 编辑后的 assistant 行
  41. await waitForV4Pane((s) => !s.canStop, "edit 重跑没有收口", 45000);
  42. await waitForV4Fork();
  43. expect(await clickFirstV4Fork()).toBe(true);
  44. const child = await waitForV4Pane(
  45. (s) =>
  46. s.sessionId !== null &&
  47. s.sessionId !== "draft" &&
  48. s.sessionId !== parentSessionId,
  49. "fork 后 pane 没有切到 child session",
  50. 60000,
  51. );
  52. expect(child.sessionId).not.toBe(parentSessionId);
  53. // child 历史 = 编辑后的 active branch;旧分支不得进入 child。
  54. // 注:rewind 合成 notice(rewoundPromptPreview)会引用被编辑掉的原 prompt 文本,
  55. // 这是 transcript 对 rewind 的记录、不是旧分支复活——强断言只看旧 assistant 回复
  56. // 与旧 user turn 是否作为真实轮次存在。
  57. await waitForV4TimelineContaining("V4_BRANCH_EDITED_REPLY", 30000);
  58. const childSnapshot = await getV4PaneSnapshot();
  59. expect(childSnapshot.timelineText).toContain("E2E_V4_BRANCH_EDITED");
  60. expect(childSnapshot.timelineText).not.toContain("V4_BRANCH_T1_REPLY");
  61. });
  62. });