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

test("SSH clone destinations preserve literal hashes in both layouts", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("clone-folder-demo");
  const thread = await t3.thread({ project, title: "Clone folder proof", messages: ["Hello"], model: "default" });
  await browser.setViewport({ width: 1280, height: 800 });
  await t3.open(thread);
  await screen.getByTestId("composer-editor").waitFor();
  const palette = screen.getByRole("dialog", "Command palette");
  const propose = async () => {
    await browser.keyboard.press("Control+k");
    await palette.getByRole("combobox").fill("> Add project");
    await palette.getByText("Add project", { exact: true }).tap();
    await palette.getByRole("option", /^Git URL/).tap();
    await palette.getByRole("combobox").fill("ssh://git@forge.example/team#1/spec#2026.git");
    await palette.getByRole("combobox").press("Enter");
    await screen.getByRole("button", /^(?:Create & )?Clone \(/).waitFor();
    return palette.getByRole("combobox").inputValue();
  };
  const flat = await propose();
  await app.screenshot("flat-clone-destination");
  await browser.keyboard.press("Escape");
  await t3.open("/settings/threads");
  await screen.getByRole("switch", "Clone into host folders", { exact: true }).tap();
  await app.screenshot("host-folders-enabled");
  await t3.open(thread);
  await screen.getByTestId("composer-editor").waitFor();
  const host = await propose();
  await app.screenshot("host-clone-destination");
  expect({ flat, host }).toEqual({
    flat: expect.stringMatching(/\/spec#2026\/?$/),
    host: expect.stringMatching(/\/forge\.example\/team#1\/spec#2026\/?$/),
  });
});
