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

test("Long ACP Registry searches remain within the request limit", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("Registry search proof");
  await t3.open("/settings/providers");
  await screen.getByRole("button", "Add provider").first().tap();
  await screen.getByRole("button", "Show more").tap();
  const search = screen.getByRole("searchbox", "Search ACP Registry");
  await screen.getByRole("button", "Add GitHub Copilot").waitFor();
  await search.fill("agent".repeat(26));
  await screen.getByText(/^(Schema validation failed|No compatible agents found)$/).waitFor();
  await app.screenshot("oversized-debounced");
  await expect.soft(screen.getByText("No compatible agents found")).toBeVisible();
  await search.tap();
  await browser.keyboard.press("Enter");
  await screen.getByText(/^(Schema validation failed|No compatible agents found)$/).waitFor();
  await app.screenshot("oversized-enter");
  await expect.soft(screen.getByText("No compatible agents found")).toBeVisible();
  await search.fill("agent".repeat(24));
  await screen.getByText("No compatible agents found").waitFor();
  await app.screenshot("exactly-120-control");
  await search.fill("copilot");
  await screen.getByRole("button", "Add GitHub Copilot").waitFor();
  await app.screenshot("copilot-control");
});
