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

test("SCP clone destinations preserve hashes in repository and parent paths", WEB, async ({t3, app, screen, browser}) => {
  await browser.emulateMedia({colorScheme: "dark"});
  const project = await t3.project("demo");
  const thread = await t3.thread({project, title: "Clone destination proof", messages: ["Start"]});
  await t3.open(thread);
  const observed: string[] = [];
  async function destination(remote: string, label: string) {
    await t3.open(thread);
    await screen.getByRole("combobox", "Projects").tap();
    await screen.getByRole("option", "Add project").tap();
    await screen.getByText("Git URL", {exact:true}).tap();
    await screen.getByRole("combobox").fill(remote);
    await browser.keyboard.press("Enter");
    await screen.getByRole("button", /^(Create & )?Clone \(Enter\)$/).waitFor();
    observed.push(await browser.evaluate(() => (document.querySelector('[data-testid="command-palette"] input[role="combobox"]') as HTMLInputElement).value));
    await app.screenshot(label);
  }
  await destination("git@forge.example:team/spec#2026.git", "repository-hash");
  await destination("forge.example:team#1/spec.git", "parent-hash");
  await t3.open("/settings/threads");
  await screen.getByRole("switch", "Clone into host folders", {exact:true}).tap();
  await t3.open(thread);
  await destination("git@forge.example:team/spec#2026.git", "host-folders-hash");
  expect(observed).toEqual(["~/spec#2026", "~/spec", "~/forge.example/team/spec#2026"]);
});
