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

test("Claude refuses an invalid auto-compact value", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("compact-validation");
  await t3.open();
  await screen.getByRole("button", "Add project").waitFor({ state: "visible" });
  await app.open("/settings/providers?instanceId=claudeAgent");
  await screen.getByRole("switch", "Enable Claude").tap();
  await screen.getByRole("button", /Refresh provider status/).tap();
  await browser.locator("[data-provider-detail]").getByText("Authenticated", { exact: false }).waitFor();
  const input = screen.getByLabel("Auto-compact after");
  await input.waitFor();
  await app.screenshot("claude-ready");
  await input.fill("300k");
  await browser.keyboard.press("Enter");
  await screen.getByRole("button", /Refresh provider status/).tap();
  await screen.getByText(/Enter a valid value\. It was not saved\.|Invalid config for instance/, { exact: false }).first().waitFor();
  await browser.locator('button[aria-busy="false"]:has-text("Refresh provider status")').waitFor();
  await app.screenshot("invalid-compact-value");
  await expect(input).toHaveAttribute("aria-invalid", "true");
  await expect(browser.locator("[data-provider-detail]").getByText("Authenticated", { exact: false })).toBeVisible();
  await app.open("/settings/providers?instanceId=claudeAgent");
  await expect(screen.getByLabel("Auto-compact after")).toHaveValue("");
  await app.screenshot("not-saved");
});
