mobileMessageEvidence.test.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { runInNewContext } from "node:vm";
  2. import { describe, expect, it } from "vitest";
  3. import { readV4UserMessagesInBrowser } from "./e2e/helpers/mobile-message-evidence.js";
  4. function readRows(rows: Array<{ id: string; role: string; text: string; visible?: boolean }>) {
  5. const nodes = rows.map((row) => ({
  6. innerText: row.text,
  7. classList: { contains: (value: string) => value === `group/${row.role}-row` },
  8. getAttribute: () => row.id,
  9. getClientRects: () => (row.visible === false ? [] : [1]),
  10. }));
  11. return runInNewContext(`(${readV4UserMessagesInBrowser.toString()})("pane")`, {
  12. __name: (value: unknown) => value,
  13. document: {
  14. body: { innerText: "MOBILE MOBILE DESKTOP sidebar title" },
  15. querySelector: () => ({ querySelectorAll: () => nodes }),
  16. },
  17. });
  18. }
  19. describe("手机 transcript 的输入归属证据", () => {
  20. it("忽略页面标题、助手引用和隐藏旧行,只保留用户行顺序", () => {
  21. expect(
  22. readRows([
  23. { id: "old", role: "user", text: "MOBILE", visible: false },
  24. { id: "a", role: "user", text: "MOBILE" },
  25. { id: "reply", role: "assistant", text: "MOBILE DESKTOP" },
  26. { id: "b", role: "user", text: "DESKTOP" },
  27. ]),
  28. ).toEqual([
  29. { id: "a", text: "MOBILE" },
  30. { id: "b", text: "DESKTOP" },
  31. ]);
  32. });
  33. it("同一输入出现两行必须保留重复,不能按正文或 ID 去重掩盖回放错误", () => {
  34. expect(
  35. readRows([
  36. { id: "same", role: "user", text: "MOBILE" },
  37. { id: "same", role: "user", text: "MOBILE" },
  38. ]),
  39. ).toHaveLength(2);
  40. });
  41. });