import { expect } from "e2e";
import * as Effect from "effect/Effect";
import { ProviderInstanceId } from "@t3tools/contracts";
import { T3_HOME } from "../e2e.config.ts";
import { rpcClient, runPromise, test, WEB } from "./t3.ts";

test("History import excludes Claude synthetic authentication failures", WEB, async ({ t3, app, screen }) => {
  await runPromise(Effect.gen(function* () {
    const client = yield* rpcClient(T3_HOME, app.baseUrl ?? "");
    yield* client["server.updateSettings"]({ patch: {}, providerInstanceMutation: {
      operation: "upsert", instanceId: ProviderInstanceId.make("claudeAgent"),
      instance: { driver: "claudeAgent", enabled: true, config: { binaryPath: "/bin/false" } }
    }});
  }).pipe(Effect.scoped));
  await t3.open("/welcome");
  await screen.getByRole("button", "Review all 1").tap();
  await screen.getByRole("button", "Select all", { exact: true }).tap();
  await screen.getByText("Other folders", { exact: true }).tap();
  await app.screenshot("history-candidates");
  await screen.getByRole("button", "Import 1 project and start", { exact: true }).tap();
  await screen.getByTestId("sidebar-settled-shelf-toggle").tap();
  await screen.getByText("plugin", { exact: true }).first().waitFor();
  await screen.getByTestId("composer-editor").waitFor();
  await app.screenshot("imported-history");
  await expect(screen.getByText("plugin", { exact: true })).toHaveCount(1);
});
