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

/**
 * Playwright config for verifying closed issues against a RUNNING staging instance
 * (pm2 `ppms-staging`, port 3200 on pms1), reached over an SSH tunnel:
 *
 *   ssh -N -L 3200:localhost:3200 shad0w@<pms1>
 *   PLAYWRIGHT_BASE_URL=http://localhost:3200 \
 *     pnpm exec playwright test --config playwright.staging.config.ts
 *
 * Unlike playwright.config.ts this does NOT start a local dev server — it drives the
 * already-deployed staging build. Login uses the seeded `@pelagia.local` test users
 * (prisma/seed-test-users.ts), so no production credentials are required.
 *
 * Staging runs `next dev`, so the first hit on a route compiles on demand and can be
 * slow — timeouts are deliberately generous and workers default to 1 to keep the
 * shared staging DB state predictable across specs.
 */
export default defineConfig({
  testDir: "./tests/staging",
  fullyParallel: false,
  forbidOnly: !!process.env.CI,
  retries: 1,
  workers: 1,
  reporter: [["list"], ["html", { open: "never", outputFolder: "playwright-report-staging" }]],
  timeout: 90_000,
  expect: { timeout: 20_000 },
  use: {
    baseURL: process.env.PLAYWRIGHT_BASE_URL ?? "http://localhost:3200",
    trace: "retain-on-failure",
    navigationTimeout: 45_000,
    actionTimeout: 20_000,
  },
  projects: [
    {
      name: "chromium",
      // Use a system browser channel (Google Chrome) so the suite does not depend on
      // the bundled chrome-headless-shell download. Override with PW_CHANNEL=msedge
      // if Chrome is unavailable. Both ship on a standard Windows install.
      use: { ...devices["Desktop Chrome"], channel: process.env.PW_CHANNEL ?? "chrome" },
    },
  ],
});
