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

// Frontend-only E2E. The dev server is SvelteKit (npm run dev:frontend) on
// localhost:1420 — Tauri IPC is not present. Tests must not depend on Tauri
// commands; mock the invoke boundary if you need a Tauri-flavoured surface,
// or skip the assertion with a reason and cover it via `cargo test` instead.
//
// Visual diffs are NOT failing the build yet; screenshots are captured as
// artifacts. After Phase 7 stabilises the UI, a follow-up commit promotes
// baselines and enables failing diffs.
export default defineConfig({
  testDir: "tests/e2e",
  fullyParallel: true,
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 2 : 0,
  reporter: [["list"], ["html", { open: "never", outputFolder: "playwright-report" }]],
  outputDir: "test-results",
  use: {
    baseURL: "http://localhost:1420",
    trace: "on-first-retry",
    screenshot: "only-on-failure",
  },
  projects: [
    {
      name: "chromium-900x700",
      use: { ...devices["Desktop Chrome"], viewport: { width: 900, height: 700 } },
    },
    {
      name: "chromium-1440x900",
      use: { ...devices["Desktop Chrome"], viewport: { width: 1440, height: 900 } },
    },
  ],
  webServer: {
    command: "npm run dev:frontend",
    url: "http://localhost:1420",
    reuseExistingServer: !process.env.CI,
    timeout: 120_000,
  },
});
