import { defineConfig } from "@playwright/test";

// E2E config — runs Vite dev server (not full `wails dev`) on a fixed port so
// Playwright can hit the React UI without needing the Go backend compiled with
// goolm. LoginScreen + initial App boot render fine because the only Wails
// runtime call (GetLastUserID) throws inside a try/finally that flips the
// loading overlay off. See E2E.md for the rationale + how to swap to `wails
// dev -browser` if/when the full backend is available.

const DEV_PORT = Number(process.env.WAILS_E2E_PORT || 5180);
const BASE_URL = process.env.WAILS_DEV_URL || `http://localhost:${DEV_PORT}`;

export default defineConfig({
  testDir: "./e2e",
  timeout: 30_000,
  fullyParallel: false,
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 2 : 0,
  workers: 1,
  reporter: process.env.CI ? "github" : "list",
  use: {
    baseURL: BASE_URL,
    headless: true,
    trace: "on-first-retry",
    screenshot: "only-on-failure",
  },
  webServer: {
    command: `pnpm dev --port ${DEV_PORT} --strictPort`,
    url: BASE_URL,
    timeout: 60_000,
    reuseExistingServer: !process.env.CI,
    stdout: "pipe",
    stderr: "pipe",
  },
});
