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

test("Antigravity discovers agy in a PATH directory ending with a literal quote", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("PATH discovery demo");
  await t3.open("/settings/providers");
  await screen.getByRole("button", "Add provider", { exact: true }).first().tap();
  await screen.getByRole("button", "Show more", { exact: true }).tap();
  await screen.getByRole("radio", "Antigravity", { exact: true }).tap();
  await screen.getByRole("button", "Next", { exact: true }).tap();
  await screen.getByRole("textbox", "Label", { exact: true }).fill("Quote PATH demo");
  await screen.getByRole("button", "Next", { exact: true }).tap();
  await screen.getByRole("button", "Add instance", { exact: true }).tap();
  await screen.getByRole("dialog", "Add provider", { exact: true }).waitFor({ state: "hidden" });
  await screen.getByRole("textbox", "Binary path", { exact: true }).fill("agy");
  await browser.keyboard.press("Tab");
  await screen.getByRole("button", "Refresh provider status", { exact: false }).tap();
  await screen.getByText("Refreshing providers", { exact: true }).waitFor({ state: "hidden", timeout: 120_000 });
  await screen.getByText("Provider instance added", { exact: true }).waitFor({ state: "hidden" });
  await screen.getByRole("textbox", "Binary path", { exact: true }).tap();
  await app.screenshot("configured-binary-path");
  await browser.evaluate(() => {
    document.querySelectorAll('[data-provider-detail] [data-slot="scroll-area-viewport"]').forEach((node) => { node.scrollTop = 0; });
  });
  await app.screenshot("path-discovery-status");
  await expect(screen.getByText("Installed · Sign-in not checked", { exact: true }).first()).toBeVisible();
});
