import { expect } from "e2e";
import { T3_HOME } from "../e2e.config.ts";
import { makeState, runPromise, test, WEB } from "./t3.ts";

 test("CLI first-line titles omit a cluster split at the boundary", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project("Title boundary demo");
  const cli = makeState(T3_HOME).cli;
  const prefix = "a".repeat(78);
  const cases = [
    { label: "Hindi vowel sign", prompt: `${prefix}कि यह फ़ाइल ठीक करें` },
    { label: "Decomposed accent", prompt: `${prefix}e\u0301 and the rest of a long first line` },
  ];
  const titles: string[] = [];
  for (const sample of cases) {
    const started = await runPromise(cli(["thread", "start", project, sample.prompt, "--provider", "devReplay", "--model", "showcase", "--wait", "--json"]));
    const thread = JSON.parse(started.stdout);
    await t3.open({ threadId: thread.threadId });
    await browser.locator('nav h2').waitFor();
    const message = screen.getByRole("button", `Agent ${sample.prompt.normalize("NFC")}`, { exact: true });
    await message.scrollIntoView();
    await message.tap();
    await browser.locator("[data-user-message-body]").scrollIntoView();
    await app.screenshot(sample.label);
    titles.push(await browser.locator('nav h2').textContent());
  }
  expect(titles).toEqual([`${prefix}…`, `${prefix}…`]);
});
