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

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>
This commit is contained in:
jaredandClaude Opus 5.5 committed 2026-11-23 19:06:52 -05:00
1 parent bdc6028572
commit f1decca31f
22 files changed
+777 -8

No files matched your search

+17 -2
View File
@@ -195,7 +195,7 @@ How it fits together (see issue #111 for the full design):
### Security Features
- **CSRF Protection**: Token-based protection with constant-time comparison. `bootstrap.php` rotates the token on a successful write and returns the current token in every response (including on rejection); the client (`lt.api`) resyncs from that value. Rejected requests do not rotate the token.
- **Rate Limiting**: Session-based AND IP-based rate limiting to prevent abuse
- **Rate Limiting**: Session-based AND IP-based rate limiting to prevent abuse. Limits are requests per minute from `.env`: `RATE_LIMIT_DEFAULT` / `RATE_LIMIT_API` per session, `RATE_LIMIT_IP` / `RATE_LIMIT_IP_API` per client IP (defaults 100 / 60 / 300 / 120). The client IP is read through `TRUSTED_PROXIES`.
- **Security Headers**: CSP with nonces (no unsafe-inline), X-Frame-Options, X-Content-Type-Options
- **SQL Injection Prevention**: All queries use prepared statements with parameter binding
- **XSS Protection**: HTML escaped in markdown parser, CSP headers block inline scripts
@@ -685,14 +685,29 @@ Key conventions and gotchas for working with this codebase:
|---|---|---|
| `lint.yml` (php-lint) | phpcs PSR-12 standard | Every push and PR |
| `lint.yml` (js-lint) | ESLint on `assets/js/` | Every push and PR |
| `lint.yml` (ui) | Playwright UI tests in `tests/ui/` against a seeded instance (desktop and Pixel 7) | Every push and PR |
| `lint.yml` (ui-screenshots) | Before/after screenshots of the base branch and the PR, uploaded as the `ui-screenshots` artifact | PRs that change `assets/` or `views/` |
| `security.yml` | semgrep with `p/php` + `p/owasp-top-ten` configs | Every push, PR, and weekly (Monday 6am) |
| `deploy` job in `lint.yml` | Calls deploy webhooks on CT132 (10.10.10.45): `tinker-deploy` (main) or `tinker-beta-deploy` (development); tags deployed commit `deploy-YYYY.MM.DD-N` | Push to `main` or `development`, after both lint jobs pass |
| `deploy` job in `lint.yml` | Calls deploy webhooks on CT132 (10.10.10.45): `tinker-deploy` (main) or `tinker-beta-deploy` (development); tags deployed commit `deploy-YYYY.MM.DD-N` | Push to `main` or `development`, after the lint, requirements and UI jobs pass |
| `notify-failure` job in `lint.yml` | Posts CI failure alert to Matrix via webhook | Push to any branch when lint fails |
Branch protection is enabled on `main` — both lint jobs must pass before any PR can merge.
Lint config: `.phpcs.xml` (PSR-12 with project-specific tweaks), `.eslintrc.json` (root, browser env).
### UI tests
`tests/ui/` holds the Playwright suite, the synthetic seed data and the scripts CI uses. Every test fails on a page error, console error or failed local request. To run them locally (needs PHP, MariaDB with root socket access, and Node):
```bash
mariadb -e "CREATE USER IF NOT EXISTS 'tinker_ui'@'127.0.0.1' IDENTIFIED BY 'ci-only';"
git worktree add /tmp/tinker-ui HEAD # stack.sh writes a throwaway .env into the checkout
tests/ui/stack.sh /tmp/tinker-ui 8400 tinker_ui
cd tests/ui && npm ci && npx playwright install chromium && npx playwright test
```
`stack.sh` only touches databases named `tinker_ui*` and refuses to overwrite a `.env` it didn't write. It raises the rate limits in that `.env`, since one IP makes every request in a run. For before/after shots, start a base checkout on another port and run `node tests/ui/screenshots.js <out-dir> before=http://127.0.0.1:8401 after=http://127.0.0.1:8400`.
## License
Internal use only - LotusGuild Infrastructure