import { expect } from "e2e";
import { test, WEB, runPromise } from "./t3.ts";
import { run } from "./shell.ts";

const URL = "https://github.com/pingdotgg/t3code/pull/46260#0123456789abcdef0123456789abcdef01234567";
test("GitHub SHA-like description heading opens Summary", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("heading-proof");
  await runPromise(run("git", ["remote", "add", "origin", "https://github.com/pingdotgg/t3code.git"], { cwd: project }));
  const thread = await t3.thread({ project, title: "GitHub heading link", model: "default", messages: [`Check ${URL}`] });
  await t3.open(thread);
  await screen.getByRole("button", /^Agent Check/).tap();
  await screen.getByRole("link", /46260/).first().tap();
  const summary = screen.getByRole("button", "Summary", { exact: true });
  await summary.waitFor({ timeout: 60000 });
  await screen.getByRole("heading", "fix(shared): open SHA-like GitHub PR heading links in the summary", { exact: true }).waitFor({ timeout: 60000 });
  try {
    await expect(summary).toHaveAttribute("aria-pressed", "true");
  } finally {
    await app.screenshot("github-sha-heading-tab");
  }
});
