Add Playwright UI tests and before/after screenshots to CI #120

Open
jared wants to merge 1 commits from ci-playwright-ui into development
pull from: ci-playwright-ui
Owner

Follow-up to #119, as agreed: Pulse's Playwright CI (Pulse #49 and #56), adapted for Tinker. Building it turned up three real bugs, fixed here.

What CI gains

UI (playwright), on every push and PR. Deploys now wait for it, as they already wait for the lint jobs.

  • Runs in the official Playwright image, like Pulse. tests/ui/setup.sh installs PHP and a throwaway MariaDB in the job container.
  • tests/ui/stack.sh migrates a fresh database, loads synthetic seed data and serves the app with php -S.
  • 21 tests:
    • Every main page loads (dashboard, three tickets, create, four admin pages).
    • Description and comment markdown renders (#114).
    • A <script> tag and a javascript: link in a description stay inert.
    • node_network_up stays literal, and edit mode shows the raw source.
    • Anonymous requests get a 401.
    • On a Pixel 7, pages don't scroll sideways.
  • Every test also fails on any page error, console error or HTTP ≥ 400 from the app. The one exception is the designed avatar 404 for users without an lldap photo.
  • On failure, the Playwright report, traces and screenshots are uploaded.

UI screenshots (before/after), on PRs that change assets/ or views/:

  • Starts the base branch and the PR side by side with the same seed data.
  • Captures the dashboard, three tickets and the create page in dark, light and phone views.
  • Uploads one side-by-side PNG per changed view as the ui-screenshots artifact, plus unchanged.txt.
  • Seed timestamps are fixed and the browser clock and timezone are pinned, so identical pages come out byte-identical.

This PR touches views/, so its own run will produce that artifact.

Fixes found along the way

  1. migrate.php failed on a fresh database. It split statements on ;, and migrations 001 and 003 have a ; inside a -- comment. It now drops whole-line comments before splitting, and all 8 migrations apply cleanly. Production is unaffected: everything there is already applied.
  2. API rate limits ignored .env (and TRUSTED_PROXIES).
    • Every API endpoint calls RateLimitMiddleware::apply() before loading config.php, so on all 25 endpoints the limiter used its hard-coded fallbacks.
    • It also never saw TRUSTED_PROXIES, so the per-IP bucket probably keyed on the proxy's address. All users behind Authelia would then share one bucket of 120 API requests a minute.
    • The limiter now loads config itself. The per-IP limits are configurable (RATE_LIMIT_IP, RATE_LIMIT_IP_API), with unchanged defaults (300 / 120), and are documented in .env.example and the README.
    • Verified locally: with RATE_LIMIT_IP_API=5, requests 6 to 8 get 429.
    • The tests found it: 429s turned the suite flaky.
  3. Broken avatar image in the header. The avatar error fallback (layout_footer.php) was registered after the header avatar. When the 404 came back first, users without an lldap photo got a broken-image icon instead of their initials. It now also checks images that had already failed.

Before/after (local run with the CI script; development on the left, this PR on the right)

The only visual change is fix 3: the header avatar.

dashboard dark

plain ticket dark

Verified locally

  • The suite passes 21/21 three times in a row against this branch.
  • stack.sh brings up the current development too. It runs this branch's migration runner inside the base checkout, so bases from before fix 1 still migrate.
  • The screenshot script against two copies of the same code: 15/15 views unchanged.
  • phpcs is clean; eslint reports no errors.

Safety

  • Seed script: tests/ui/seed.php is CLI only. It connects only as the throwaway tinker_ui user, only to databases named tinker_ui*, and deletes only its own ticket ids.
  • Router: router.php only runs under php -S.
  • stack.sh refuses to overwrite a .env it didn't write.
  • Still served by nginx: tests/ is behind Authelia like everything else, but a location ^~ /tests/ { return 404; }, next to the existing /vendor/ rule, would hide it entirely. I haven't changed the nginx config.

Not fixed, noted

A request with Remote-User but no Remote-Name or Remote-Email gets a 500 (a TypeError in UserModel::syncUserFromAuthelia). Authelia always sends all three, so it only showed up in hand-made test requests.

🤖 Generated with Claude Code

Follow-up to #119, as agreed: Pulse's Playwright CI (Pulse #49 and #56), adapted for Tinker. Building it turned up three real bugs, fixed here. ## What CI gains **`UI (playwright)`**, on every push and PR. Deploys now wait for it, as they already wait for the lint jobs. - Runs in the official Playwright image, like Pulse. `tests/ui/setup.sh` installs PHP and a throwaway MariaDB in the job container. - `tests/ui/stack.sh` migrates a fresh database, loads synthetic seed data and serves the app with `php -S`. - 21 tests: - Every main page loads (dashboard, three tickets, create, four admin pages). - Description and comment markdown renders (#114). - A `<script>` tag and a `javascript:` link in a description stay inert. - `node_network_up` stays literal, and edit mode shows the raw source. - Anonymous requests get a 401. - On a Pixel 7, pages don't scroll sideways. - Every test also fails on any page error, console error or HTTP ≥ 400 from the app. The one exception is the designed avatar 404 for users without an lldap photo. - On failure, the Playwright report, traces and screenshots are uploaded. **`UI screenshots (before/after)`**, on PRs that change `assets/` or `views/`: - Starts the base branch and the PR side by side with the same seed data. - Captures the dashboard, three tickets and the create page in dark, light and phone views. - Uploads one side-by-side PNG per changed view as the `ui-screenshots` artifact, plus `unchanged.txt`. - Seed timestamps are fixed and the browser clock and timezone are pinned, so identical pages come out byte-identical. This PR touches `views/`, so its own run will produce that artifact. ## Fixes found along the way 1. **`migrate.php` failed on a fresh database.** It split statements on `;`, and migrations 001 and 003 have a `;` inside a `--` comment. It now drops whole-line comments before splitting, and all 8 migrations apply cleanly. Production is unaffected: everything there is already applied. 2. **API rate limits ignored `.env` (and `TRUSTED_PROXIES`).** - Every API endpoint calls `RateLimitMiddleware::apply()` before loading `config.php`, so on all 25 endpoints the limiter used its hard-coded fallbacks. - It also never saw `TRUSTED_PROXIES`, so the per-IP bucket probably keyed on the proxy's address. All users behind Authelia would then share one bucket of 120 API requests a minute. - The limiter now loads config itself. The per-IP limits are configurable (`RATE_LIMIT_IP`, `RATE_LIMIT_IP_API`), with unchanged defaults (300 / 120), and are documented in `.env.example` and the README. - Verified locally: with `RATE_LIMIT_IP_API=5`, requests 6 to 8 get 429. - The tests found it: 429s turned the suite flaky. 3. **Broken avatar image in the header.** The avatar error fallback (`layout_footer.php`) was registered after the header avatar. When the 404 came back first, users without an lldap photo got a broken-image icon instead of their initials. It now also checks images that had already failed. ## Before/after (local run with the CI script; development on the left, this PR on the right) The only visual change is fix 3: the header avatar. ![dashboard dark](https://code.lotusguild.org/LotusGuild/tinker_tickets/raw/branch/pr-120-screenshots/dashboard-dark.png) ![plain ticket dark](https://code.lotusguild.org/LotusGuild/tinker_tickets/raw/branch/pr-120-screenshots/ticket-plain-dark.png) ## Verified locally - The suite passes 21/21 three times in a row against this branch. - `stack.sh` brings up the current `development` too. It runs this branch's migration runner inside the base checkout, so bases from before fix 1 still migrate. - The screenshot script against two copies of the same code: 15/15 views unchanged. - phpcs is clean; eslint reports no errors. ## Safety - **Seed script:** `tests/ui/seed.php` is CLI only. It connects only as the throwaway `tinker_ui` user, only to databases named `tinker_ui*`, and deletes only its own ticket ids. - **Router:** `router.php` only runs under `php -S`. - **`stack.sh`** refuses to overwrite a `.env` it didn't write. - **Still served by nginx:** `tests/` is behind Authelia like everything else, but a `location ^~ /tests/ { return 404; }`, next to the existing `/vendor/` rule, would hide it entirely. I haven't changed the nginx config. ## Not fixed, noted A request with `Remote-User` but no `Remote-Name` or `Remote-Email` gets a 500 (a `TypeError` in `UserModel::syncUserFromAuthelia`). Authelia always sends all three, so it only showed up in hand-made test requests. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jared added 1 commit 2026-11-23 19:07:22 -05:00
Add Playwright UI tests and before/after screenshots to CI
Lint / UI screenshots (before/after) (push) Skipped
Lint / JS (eslint) (push) Successful in 16s
Lint / PHP (phpcs PSR-12) (push) Successful in 30s
Lint / PHP requirements (version + extensions) (push) Successful in 50s
Lint / UI (playwright) (push) Successful in 3m29s
Lint / Deploy (push) Skipped
Lint / Notify on failure (push) Skipped
Security / PHP Security (semgrep) (push) Successful in 2m59s
Lint / JS (eslint) (pull_request) Successful in 16s
Lint / PHP (phpcs PSR-12) (pull_request) Successful in 33s
Lint / PHP requirements (version + extensions) (pull_request) Successful in 32s
Lint / UI (playwright) (pull_request) Successful in 2m23s
Lint / Deploy (pull_request) Skipped
Lint / Notify on failure (pull_request) Skipped
Security / PHP Security (semgrep) (pull_request) Successful in 1m32s
Lint / UI screenshots (before/after) (pull_request) Successful in 4m14s
f1decca31f
New UI (playwright) job: PHP and MariaDB inside the Playwright image, a
seeded instance (tests/ui/stack.sh, synthetic data only) and 21 tests:
every main page loads with no page errors, console errors or failed
requests, description and comment markdown render safely (#114), and
pages fit a phone screen. Deploys now wait for it.

New UI screenshots (before/after) job: for PRs that change assets/ or
views/, runs the base branch and the PR side by side with the same data
and uploads one side-by-side PNG per page and view (dark, light, phone).
Modelled on Pulse's ui and ui-screenshots jobs.

Fixes found while building it:
- migrate.php split statements on semicolons inside -- comments, so 001
  and 003 failed on a fresh database.
- API endpoints applied rate limiting before loading config, so
  RATE_LIMIT_DEFAULT/RATE_LIMIT_API from .env and TRUSTED_PROXIES were
  ignored there: every user behind the proxy shared one per-IP bucket.
  The limiter now loads config itself; the per-IP limits are configurable
  (RATE_LIMIT_IP, RATE_LIMIT_IP_API) with unchanged defaults.
- The avatar error fallback was registered in the footer, after the
  header avatar, so a fast 404 left a broken image instead of initials.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jared referenced this issue from a commit 2026-11-23 19:07:31 -05:00
All checks were successful
Lint / UI screenshots (before/after) (push) Skipped
Lint / JS (eslint) (push) Successful in 16s
Lint / PHP (phpcs PSR-12) (push) Successful in 30s
Lint / PHP requirements (version + extensions) (push) Successful in 50s
Lint / UI (playwright) (push) Successful in 3m29s
Lint / Deploy (push) Skipped
Lint / Notify on failure (push) Skipped
Security / PHP Security (semgrep) (push) Successful in 2m59s
Lint / JS (eslint) (pull_request) Successful in 16s
Lint / PHP (phpcs PSR-12) (pull_request) Successful in 33s
Lint / PHP requirements (version + extensions) (pull_request) Successful in 32s
Lint / UI (playwright) (pull_request) Successful in 2m23s
Lint / Deploy (pull_request) Skipped
Lint / Notify on failure (pull_request) Skipped
Security / PHP Security (semgrep) (pull_request) Successful in 1m32s
Lint / UI screenshots (before/after) (pull_request) Successful in 4m14s
This pull request has changes conflicting with the target branch.
  • .env.example
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin ci-playwright-ui:ci-playwright-ui
git checkout ci-playwright-ui
Sign in to join this conversation.