conversation-session-message-cjk-bare-url.test.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { clearAppData } from "#e2e/helpers/desktop-app";
  2. import {
  3. prepareV4ConversationE2E,
  4. sendV4Prompt,
  5. waitForV4Pane,
  6. } from "#e2e/helpers/v4-conversation";
  7. const MARKER = "E2E_MESSAGE_CJK_BARE_URL";
  8. describe("消息正文中文边界裸链接", () => {
  9. after(async () => {
  10. await clearAppData();
  11. });
  12. it("MLC02: 裸链接紧跟强调符与中文标点时只链接 URL 本身", async () => {
  13. await prepareV4ConversationE2E();
  14. await sendV4Prompt(`${MARKER}: Reply with bare links next to CJK text.`);
  15. await waitForV4Pane(
  16. (pane) => !pane.canStop && pane.timelineText.includes(`${MARKER}_DONE`),
  17. "中文边界裸链接夹具未完成",
  18. 60_000,
  19. );
  20. await browser.$('button[title="https://example.com/b"]').waitForDisplayed();
  21. const rendered = await browser.execute(() => {
  22. const linkAt = (url: string) => document.querySelector<HTMLElement>(`button[title="${url}"]`);
  23. const paragraphText = (prefix: string) =>
  24. Array.from(document.querySelectorAll("p"))
  25. .map((node) => node.textContent ?? "")
  26. .find((text) => text.startsWith(prefix));
  27. return {
  28. links: Array.from(document.querySelectorAll<HTMLElement>("button[title]"))
  29. .map((node) => ({ title: node.getAttribute("title"), text: node.textContent }))
  30. .filter((link) => link.title?.startsWith("https://example.com/")),
  31. strongWrapsSite: linkAt("https://example.com/site")?.closest("strong") != null,
  32. emphasisWrapsQuery: linkAt("https://example.com/a?q=1")?.closest("em") != null,
  33. boldLine: paragraphText("线上已替换"),
  34. emphasisLine: paragraphText("另见"),
  35. inlineCode: Array.from(document.querySelectorAll("code"))
  36. .map((node) => node.textContent)
  37. .find((text) => text?.includes("example.com/code")),
  38. blockCode: Array.from(document.querySelectorAll("[data-language] diffs-container"))
  39. .map((node) => node.shadowRoot?.textContent ?? "")
  40. .filter((text) => text.includes("-code")),
  41. };
  42. });
  43. expect(rendered.links).toEqual([
  44. { title: "https://example.com/site", text: "https://example.com/site" },
  45. { title: "https://example.com/a?q=1", text: "https://example.com/a?q=1" },
  46. { title: "https://example.com/b", text: "https://example.com/b" },
  47. ]);
  48. expect(rendered.strongWrapsSite).toBe(true);
  49. expect(rendered.emphasisWrapsQuery).toBe(true);
  50. expect(rendered.boldLine).toBe("线上已替换:https://example.com/site(115 秒,链接不变)");
  51. expect(rendered.emphasisLine).toBe(
  52. "另见 https://example.com/a?q=1,以及 https://example.com/b。结束",
  53. );
  54. expect(rendered.inlineCode).toBe("**https://example.com/code**(");
  55. expect(rendered.blockCode).toHaveLength(2);
  56. expect(rendered.blockCode[0]).toContain("引用代码:https://example.com/quote-code。");
  57. expect(rendered.blockCode[1]).toContain("列表代码:https://example.com/list-code。");
  58. expect(rendered.blockCode.join("")).not.toContain("<https://");
  59. }).timeout(120_000);
  60. });