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

test("Antigravity sign-in identifies a runtime SIGILL", WEB, async ({ t3, app, screen, browser }) => {
  const { chmod } = await import("node:fs/promises");
  const project = await t3.project("runtime-exit", {
    "agy_acp_server.par": "#!/bin/sh\nulimit -c 0\necho 'PRIVATE_RUNTIME_STDERR' >&2\nkill -ILL $$\n",
    "localharness_external": "#!/bin/sh\nexit 0\n",
  });
  await chmod(`${project}/agy_acp_server.par`, 0o755);
  await chmod(`${project}/localharness_external`, 0o755);
  await t3.open();
  await screen.getByRole("button", "Add project").waitFor({ state: "visible" });
  await app.open("/settings/providers");
  await screen.getByRole("switch", "Enable Antigravity").tap();
  await screen.getByRole("button", "Select Antigravity").tap();
  await screen.getByRole("textbox", "Binary path").fill(`${project}/agy_acp_server.par`);
  await browser.keyboard.press("Tab");
  await screen.getByRole("button", "Sign in", { exact: true }).tap();
  await screen.getByRole("button", "Retry sign-in", { exact: true }).waitFor({ state: "visible" });
  await app.screenshot("runtime-exit-account-status");
  await expect(screen.getByText("Antigravity exited unexpectedly after signal SIGILL. Start sign-in again.", { exact: true })).toBeVisible();
});
