import { defineConfig, devices } from '@playwright/test'

// Third Playwright config in the repo, and the reason it is separate is worth
// stating because "just add it to playwright.a11y.config.ts" is the obvious wrong
// move:
//
//   playwright.config.ts             — visual regression (pixels)
//   playwright.a11y.config.ts        — the FULL axe bar. 33/33 red since
//                                      2026-05-18 and expected to stay red until
//                                      the Owner rules on color-contrast. It
//                                      blocks nothing today.
//   this file                        — the non-color-contrast subset, which is
//                                      GREEN and therefore can actually gate.
//
// A red suite cannot protect anything: once `test:a11y` is red from
// color-contrast, reintroducing all 43 nodes of aria-required-parent /
// aria-toggle-field-name / aria-input-field-name / listitem /
// scrollable-region-focusable changes its output from "red" to "red". That is
// exactly how the cluster fixed in 008bd0ba could come back unnoticed.
//
// ⚠️ This config does NOT weaken `test:a11y`. That suite keeps asserting every
// rule with no allowlist and no severity threshold, per the Owner's 2026-05-18
// decision. This one is additive and strictly narrower.
//
// ── WHERE THIS GATE IS MOUNTED (this comment is the mount source of truth) ───
// `pnpm audit:a11y-non-contrast` runs from exactly ONE place:
//
//   scripts/release.mjs — step 1, tag time, on the owner's machine. BLOCKING,
//   and deliberately WITHOUT a skip flag. Same position and same reason as
//   `test:visual` and the render gate. Asserted by
//   tests/a11y-non-contrast-gate.test.ts ("release.mjs invokes it as a blocking
//   step"), so this claim cannot rot silently.
//
// It is mounted in `.husky/pre-commit`, `prepublishOnly`, `.gitea/workflows/**`
// and `.github/workflows/**` ZERO times, and that is BY DESIGN, not a gap:
//   • it needs a dev server + chromium, and one test covers 33 pages × 2 themes
//     (~2.5 min measured) — too slow for a hook that already runs 3-5 min;
//   • the Gitea act_runner is non-privileged and CANNOT install chromium
//     (INFRA-F40/F71), so putting it in `prepublishOnly` would kill the release
//     chain outright, since that chain runs prepublishOnly on both Node 20 & 22.
//
// ⛔ Do NOT "fix the missing mount". 2026-08-13 a session counted those four
// places, got 0/0/0/0, and concluded the gate ran nowhere — it missed release.mjs,
// which is the repo's standing home for chromium-dependent gates. If you are
// re-deriving mount points by grepping call sites, read the script/config header
// instead: several mount shapes coexist here and grepping gives contradictory
// counts (memory `script-header-is-mount-truth`).

export default defineConfig({
  testDir: 'tests/a11y-non-contrast',
  use: {
    baseURL: 'http://localhost:5173',
    viewport: { width: 1280, height: 900 },
  },
  projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }],
  webServer: {
    command: 'pnpm dev',
    url: 'http://localhost:5173',
    reuseExistingServer: true,
    timeout: 120_000,
  },
  testMatch: '**/*.spec.ts',
  // The whole sweep is a single test (see the spec header for why: a fresh worker
  // after a failure resets module-scope counters and silently shrinks the
  // denominator). One test covering 33 pages × 2 themes needs far more than
  // Playwright's 30s default — measured ~2.5 min, budgeted at 10.
  timeout: 600_000,
  fullyParallel: false,
  workers: 1,
})
