Plan: Playwright E2E Test Suite

Status

Step Description Status

1

Project scaffold (package.json, playwright.config.ts, tsconfig.json, Dockerfile)

Done (2026-04-05)

2

Auth setup (Keycloak OIDC browser login for 3 users, storage state)

Done (2026-04-05)

3

Helpers (waitForHtmx, clickTab) + 6 page objects

Done (2026-04-05)

4

Auth + dashboard + navigation specs (25 tests)

Done (2026-04-05)

5

Case search + case detail specs (18 tests)

Done (2026-04-05)

6

Applications + renewals specs (12 tests)

Done (2026-04-05)

7

RBAC + accessibility specs (8 tests)

Done (2026-04-05)

8

Wire xtask e2e + docker-compose e2e service + healthchecks on all 19 services

Done (2026-04-05)

9

Validate against live devstack, documentation

Done (2026-04-26) — cargo xtask e2e + the pre-push hook validate against live devstack on every push (most recent run: 103 tests in 37 s). Documentation lives in .claude/docs/local-dev.md (E2E command + dev-loop notes) and xtask/src/cmd/e2e.rs flag docstrings. The 14-file spec suite (tests/e2e/specs/) covers auth, dashboard, case-search, case-detail, applications, renewals, navigation, RBAC, accessibility (light + dark), workflow guidance, plus CAPS + WIC tabs landed via canopy-seed-caps-wic-fixtures.

Epic: &43
Issues: TBD
Branch: feature/playwright-e2e
Labels: type::feature, priority::high, program::infrastructure, service::web

Context

The worker portal has wired handlers, seed data, OIDC auth, and a TypeScript manifest. E2E tests are the last gate before security hardening. This implements worker-portal-snap Step 10 (Playwright E2E), expanding the 5 scenarios in that plan to 61 comprehensive tests.

The test suite follows CRAIG’s proven pattern: Dockerized Playwright, real Keycloak login, page objects, seed-independent assertions.

Scope

In scope:

  • Dockerized Playwright via docker-compose e2e profile

  • Real Keycloak OIDC browser login (PKCE S256) for jane.doe, bob.smith, admin

  • 6 page objects (dashboard, case search, case detail, application, renewal, login)

  • 9 spec files: auth (6), dashboard (7), case-search (7), case-detail (11), applications (8), renewals (4), navigation (10), rbac (3), accessibility (5 gated)

  • All assertions seed-independent (structural, not value-based)

  • Docker healthchecks on all 19 application services

  • cargo xtask e2e command matching CRAIG’s pattern

Out of scope:

  • Security hardening tests (separate plan, depends on this)

  • Performance/load testing (separate plan)

  • Service-to-service auth token (known gap — tests handle gracefully)

Design

Dockerized Execution

Tests run in the official mcr.microsoft.com/playwright Docker image. The canopy-e2e service is gated behind the e2e profile so it doesn’t start with normal docker compose up. cargo xtask e2e regenerates the seed manifest, builds the Playwright image, and runs tests.

Auth Setup

Real Keycloak browser login for each test user — no mocked sessions. Storage state saved per role: auth/caseworker.json, auth/bob-smith.json, auth/admin.json. Subsequent test projects load storage state so every spec starts authenticated.

Seed-Independent Assertions

Tests use semantic predicates (findApproved(), findExpedited()) to navigate to entities. Assertions check structure ("table has rows", "element is visible") not values ("name is Golda"). Tests pass with any seed value, not just seed 42.

Healthchecks

All 19 application services now have Docker healthchecks (wget -qO- http://localhost:{port}/healthz). The E2E container depends on canopy-web: condition: service_healthy.

Steps

Step 1: Project scaffold

Files: tests/e2e/package.json, tests/e2e/tsconfig.json, tests/e2e/playwright.config.ts, tests/e2e/Dockerfile

Step 2: Auth setup

Files: tests/e2e/auth/setup.ts

Step 3: Helpers + page objects

Files: tests/e2e/lib/helpers.ts, tests/e2e/lib/pages/*.page.ts

Steps 4-7: Test specs

Files: tests/e2e/specs/*.spec.ts (9 files, 61 tests)

Step 8: Infrastructure

Files: xtask/src/cmd/e2e.rs, docker-compose.yml

Step 9: Validation + documentation

Validate against live devstack. Update local-dev.md with cargo xtask e2e usage.

Files Touched

File Change

tests/e2e/ (21 new files)

Playwright config, auth setup, helpers, page objects, 9 spec files, Dockerfile

xtask/src/cmd/e2e.rs

Wire to docker compose --profile e2e

docker-compose.yml

Add canopy-e2e service + healthchecks on all 19 app services

Verification

  1. cargo xtask dev restart --shared-db

  2. cargo xtask seed --seed 42 --households 50

  3. cargo xtask e2e — 59 tests pass (5 accessibility skipped)

  4. cargo xtask seed --seed 99 --households 50 → cargo xtask e2e — still passes

  5. CANOPY_A11Y_AUDIT=1 cargo xtask e2e — accessibility audit runs

  6. JUnit XML at test-results/e2e/results.xml

Documentation Updates

  • .claude/docs/local-dev.md — document cargo xtask e2e

  • CHANGELOG.adoc — entry for E2E test suite

  • docs/modules/ROOT/pages/plans/worker-portal-snap.adoc — mark Step 10 complete

Errata

Infrastructure bugs discovered during E2E validation

  1. Session store database misconfiguration — canopy-web and canopy-portal were both using canopy_security as their DATABASE_URL. The tower-sessions-sqlx-store migration silently failed because canopy-security’s _sqlx_migrations table already existed. Fixed by creating dedicated canopy_web and canopy_portal databases in devstack/postgres/init.sql. CRAIG avoids this entirely by using MemoryStore.

  2. Static assets missing from Docker runtime — The Dockerfile runtime stage copied binaries and rulesets but not services/canopy-web/static/ (htmx.min.js, alpine.min.js). Added COPY --from=builder for BFF static assets.

  3. SRI integrity hash mismatch — htmx and Alpine.js were loaded from unpkg CDN with incorrect SHA-384 integrity hashes. The browser silently blocked both scripts (SRI failure does not trigger onerror). Switched to local-only vendor loading matching CRAIG’s pattern. CDN loading with SRI is unreliable for air-gapped and Dockerized environments.

  4. OIDC callback hardcoded redirect — auth::callback() always redirected to / after login. Added return_to URL preservation so users land back on the page they were trying to reach. This is an improvement over CRAIG’s pattern (which also hardcodes /).

Potential Improvements

  • Service-to-service auth — BFF calls to upstream services (canopy-applications, canopy-security, etc.) return 401. The application process page renders but with empty/default data. Needs a service account or token forwarding mechanism.

  • Vendored JS dependency tracking — htmx.min.js and alpine.min.js are vendored without version tracking. Consider a vendor.toml manifest checked by cargo xtask validate.

  • Session cookie persistence — With PostgresStore, each E2E test still re-authenticates via Keycloak SSO because the storageState cookie references a session from the auth-setup project which gets a different session ID after the redirect chain. The return_to pattern makes this transparent but a session-aware test setup could reduce auth round-trips.


Tracked follow-ups (filed 2026-04-24 after audit of plan Errata + Potential Improvements sections across the repo):

  • #322 — Persist session cookies across Playwright tests (from Potential Improvements)

  • #336 — Vendored JS dependency manifest (from Potential Improvements)

Tracked follow-ups (filed 2026-05-04 during PI sweep):

  • #411 — Resolved 2026-05-05 via OIDC RFC 6749 refresh_token grant in canopy-web’s AuthenticatedWorker extractor. Worker portal no longer 401s after the access-token TTL elapses. See bff-token-refresh.

Edit this page · default