import { execFileSync } from "node:child_process";
import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

test("Windows Azure CLI resolves the Linux checkout pull request", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("Azure scope proof");
  const git = (...args: string[]) => execFileSync("git", args, { cwd: project, encoding: "utf8" });
  git("remote", "add", "origin", process.env.AZURE_PROOF_REPO_URL!);
  git("-c", 'credential.helper=!f() { echo username=pat; echo "password=$AZURE_DEVOPS_EXT_PAT"; }; f', "fetch", "origin", "proof-21838-base", "proof-21838-feature");
  git("checkout", "-B", "proof-21838-feature", "origin/proof-21838-feature");
  const thread = await t3.thread({ project, title: "Azure checkout scope", messages: ["Show the checkout pull request."] });
  await t3.open(thread);
  try {
    await expect(screen.getByText("WSL scope PR", { exact: false })).toBeVisible({ timeout: 60_000 });
  } finally {
    await app.screenshot("checkout-pull-request");
  }
});
