conversation-session-v4-rewind-compact-extended.test.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // PV4-18/PV4-19:compact-covered 附件 intent 重放,以及多 compact boundary 跨界 edit + cold restore。
  2. import { TID_V4_COMPOSER_INPUT, TID_V4_ROW } from "@zcode/shared";
  3. import {
  4. clearAppData,
  5. setInputValueByTestIdDom,
  6. waitForDefaultWorkspaceReady,
  7. } from "../helpers/desktop-app.js";
  8. import { waitForUpstreamNetworkCapture } from "../helpers/upstream-capture.js";
  9. import {
  10. clickV4Send,
  11. editFirstV4UserQuery,
  12. getV4PaneSnapshot,
  13. pasteV4ComposerImageAttachment,
  14. prepareV4ConversationE2E,
  15. selectV4TaskById,
  16. sendV4Prompt,
  17. waitForV4Edit,
  18. waitForV4Pane,
  19. waitForV4RowAttachments,
  20. waitForV4TimelineContaining,
  21. } from "../helpers/v4-conversation.js";
  22. describe("PV4-18/PV4-19 compact-covered extended rewind", () => {
  23. after(async () => {
  24. await browser.electron.restoreAllMocks();
  25. await clearAppData();
  26. });
  27. it("PV4-18 附件 edit 保留 canonical ref,新 provider request 只收到编辑分支", async function () {
  28. this.timeout(150000);
  29. await prepareV4ConversationE2E();
  30. const filename = await pasteV4ComposerImageAttachment("pv4-18-rewind.png");
  31. await sendV4Prompt("E2E_PV4_18_ATTACHMENT_ORIGINAL 带图片的原问题");
  32. await waitForV4TimelineContaining(
  33. "PV4_18_ATTACHMENT_ORIGINAL_REPLY",
  34. 60000,
  35. );
  36. const sessionId = (await getV4PaneSnapshot()).sessionId;
  37. await compactAndWait();
  38. await waitForV4Edit();
  39. await editFirstV4UserQuery("E2E_PV4_18_ATTACHMENT_EDITED 编辑后仍带原图片");
  40. await waitForV4TimelineContaining("PV4_18_ATTACHMENT_EDITED_REPLY", 60000);
  41. const finalSnapshot = await getV4PaneSnapshot();
  42. expect(finalSnapshot.sessionId).toBe(sessionId);
  43. expect(finalSnapshot.timelineText).not.toContain(
  44. "PV4_18_ATTACHMENT_ORIGINAL_REPLY",
  45. );
  46. expect(await waitForV4RowAttachments()).toContain(filename);
  47. const capture = await waitForUpstreamNetworkCapture(
  48. "E2E_PV4_18_ATTACHMENT_EDITED",
  49. );
  50. const requestText = JSON.stringify(capture.requestJson);
  51. expect(requestText).toMatch(/image|base64|data:image/i);
  52. expect(requestText).not.toContain("PV4_18_ATTACHMENT_ORIGINAL_REPLY");
  53. });
  54. it("PV4-19 两次 compact 后跨最新 boundary edit,cold restore 保留更早 summary", async function () {
  55. this.timeout(180000);
  56. await prepareV4ConversationE2E();
  57. await sendV4Prompt("E2E_PV4_19_FIRST 第一轮");
  58. await waitForV4TimelineContaining("PV4_19_FIRST_REPLY", 60000);
  59. await compactAndWait();
  60. await sendV4Prompt("E2E_PV4_19_SECOND_ORIGINAL 第二轮原文");
  61. await waitForV4TimelineContaining("PV4_19_SECOND_ORIGINAL_REPLY", 60000);
  62. const sessionId = (await getV4PaneSnapshot()).sessionId;
  63. expect(sessionId).toBeTruthy();
  64. await compactAndWait();
  65. await waitForV4Edit();
  66. await editFirstV4UserQuery("E2E_PV4_19_SECOND_EDITED 第二轮编辑后");
  67. await waitForV4TimelineContaining("PV4_19_SECOND_EDITED_REPLY", 60000);
  68. await browser.execute(() => window.location.reload());
  69. await waitForDefaultWorkspaceReady(60000);
  70. await selectV4TaskById(sessionId!);
  71. await waitForV4Pane(
  72. (snapshot) =>
  73. snapshot.sessionId === sessionId &&
  74. snapshot.timelineText.includes("PV4_19_SECOND_EDITED_REPLY"),
  75. "PV4-19 cold restore 没有恢复编辑后 active branch",
  76. 90000,
  77. );
  78. await sendV4Prompt("E2E_PV4_19_FOLLOWUP 冷恢复后追问");
  79. await waitForV4TimelineContaining("PV4_19_FOLLOWUP_REPLY", 60000);
  80. const capture = await waitForUpstreamNetworkCapture("E2E_PV4_19_FOLLOWUP");
  81. const requestText = JSON.stringify(capture.requestJson);
  82. expect(requestText).toContain("PV4_19_FIRST_SUMMARY");
  83. expect(requestText).toContain("E2E_PV4_19_SECOND_EDITED");
  84. expect(requestText).not.toContain("PV4_19_SECOND_SUMMARY");
  85. expect(requestText).not.toContain("E2E_PV4_19_SECOND_ORIGINAL");
  86. });
  87. });
  88. async function compactAndWait() {
  89. const before = await compactSuccessMarkerCount();
  90. await setInputValueByTestIdDom(TID_V4_COMPOSER_INPUT, "/compact", {
  91. timeout: 15000,
  92. timeoutMsg: "PV4 compact composer 没有出现",
  93. });
  94. await clickV4Send();
  95. await browser.waitUntil(
  96. async () => (await compactSuccessMarkerCount()) === before + 1,
  97. { timeout: 90000, timeoutMsg: "PV4 compact success marker 数量没有增加" },
  98. );
  99. }
  100. function compactSuccessMarkerCount(): Promise<number> {
  101. return browser.execute(
  102. (rowPrefix) =>
  103. Array.from(
  104. document.querySelectorAll<HTMLElement>(
  105. `[data-testid^="${rowPrefix}-"]`,
  106. ),
  107. ).filter(
  108. (row) =>
  109. row.dataset.rowKind === "timelineMarker" &&
  110. row.dataset.markerType === "compact" &&
  111. row.dataset.status === "success" &&
  112. row.dataset.origin === "manual",
  113. ).length,
  114. TID_V4_ROW,
  115. );
  116. }