/// <reference lib="dom" />
import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

const MESSAGE = [
  "已保存到 /tmp/report.md。请查看",
  "保存先は /tmp/report.md、確認済み",
  "تم الحفظ /tmp/report.md،يرجى المراجعة",
  "Saved to /tmp/report.md. Please check.",
].join("\n\n");

test("Bare file paths stop before CJK and Arabic punctuation", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project("demo", { "report.md": "Synthetic report\n" });
  const thread = await t3.thread({ project, title: "Prose file paths", messages: [MESSAGE] });
  await t3.open(thread);
  await screen.getByRole("button", /^Agent 已保存到/).tap();
  await screen.getByText("Saved to", { exact: false }).waitFor();
  const links = await browser.evaluate(() => [...document.querySelectorAll('[data-user-message-body] a')].map(a => ({text: a.textContent, href: a.getAttribute('href')})));
  await app.screenshot("prose-path-punctuation");
  expect(links.filter(link => link.text?.includes("report.md"))).toHaveLength(4);
  expect(links.every(link => !/[。、،]/u.test(link.text ?? ""))).toBe(true);
});
