Files
tinker_tickets/tests/ui/seed.php
jaredandClaude Opus 5.5 f1decca31f
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
Add Playwright UI tests and before/after screenshots to CI
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>
2026-11-23 19:06:52 -05:00

116 lines
4.2 KiB
PHP

<?php
/**
* Synthetic seed data for the UI tests and before/after screenshots.
*
* CLI only, and only into a database whose name starts with tinker_ui:
*
* DB_NAME=tinker_ui php tests/ui/seed.php
*
* Connects as the throwaway tinker_ui user (tests/ui/setup.sh), never with the
* app's .env credentials. Replaces only the tickets it owns (ids 1000000xx),
* so it can be re-run. Every value here is made up.
*/
if (php_sapi_name() !== 'cli') {
http_response_code(404);
exit;
}
$dbName = (string)getenv('DB_NAME');
if (!str_starts_with($dbName, 'tinker_ui')) {
fwrite(STDERR, "refusing: DB_NAME must start with tinker_ui\n");
exit(2);
}
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$db = new mysqli('127.0.0.1', 'tinker_ui', 'ci-only', $dbName);
$db->set_charset('utf8mb4');
// Fixed times, so before/after screenshots match (screenshots.js pins the
// browser clock to the day after).
$db->query("SET time_zone = '+00:00'");
$created = '2026-11-20 09:00:00';
// A manual or MCP ticket written in markdown: everything #114 renders.
$markdown = <<<'MD'
## Goal
Replace the shared NAS backup target with the new **PBS datastore** on `storage-02`, so nightly jobs stop competing with Ceph recovery traffic.
## Plan
- [x] Create datastore `pbs-main` (ZFS mirror, 2 x 8 TB)
- [x] Add the datastore to all six nodes
- [ ] Move the nightly jobs to the new target
- [ ] Remove the old NFS export
## Sizing
| Dataset | Used | Growth / month |
|---|---|---|
| VM disks | 2.1 TB | 40 GB |
| LXC rootfs | 310 GB | 6 GB |
| Config backups | 2 GB | under 1 GB |
## Commands
```bash
proxmox-backup-manager datastore create pbs-main /mnt/datastore/pbs-main
pvesm add pbs pbs-main --server 10.0.0.20 --datastore pbs-main
```
See the runbook at https://wiki.example.invalid/backups and the related ticket #100000002.
Escaping check: <script>window.__seedXss = 1</script> and [a bad link](javascript:window.__seedXss=1) must stay inert.
MD;
// A Gandalf-style alert: identifiers with underscores must stay literal.
$gandalf = <<<'MD'
## Network Interface Alert
- **Host:** node-03
- **Interface:** `enp5s0`
- **Detected:** 2026-11-20 06:09:05 UTC
- **Consecutive check failures:** 2
Interface enp5s0 on node-03 was up and is now reporting link-down via node_exporter (node_network_up is 0). node-03 itself is still reporting, so it may be reachable over its other interfaces.
### What to check
1. Check the switch port: is it down on the switch side too?
2. Reseat or swap the cable or DAC; for an optic, check the module for a fault.
3. On node-03, check `ip link show enp5s0` and `dmesg` for NIC or driver errors.
_Opened automatically by Gandalf._
MD;
// A plain-text ticket with no markdown at all.
$plain = "The label printer in the rack room jams on every second label.\n"
. "Tried a new roll, same result.\n\nNot urgent, the spare printer works.";
$tickets = [
['100000001', '[backup][manual][storage] Move nightly backups to the new PBS datastore', $markdown, 'Task', 3],
['100000002', '[node-03][auto][network] Interface enp5s0 link-down', $gandalf, 'Issue', 2],
['100000003', 'Label printer jams on every second label', $plain, 'Issue', 4],
];
$comment = "Datastore is up. **Next:** move the jobs.\n\n"
. "- verify `snake_case_job` still runs\n- check the verify_jobs list after the move";
$ids = implode(',', array_map(fn($t) => "'" . $t[0] . "'", $tickets));
$db->query("DELETE FROM ticket_comments WHERE ticket_id IN ($ids)");
$db->query("DELETE FROM tickets WHERE ticket_id IN ($ids)");
$insert = $db->prepare(
"INSERT INTO tickets (ticket_id, title, description, status, priority, category, type, hash, created_at, updated_at)
VALUES (?, ?, ?, 'Open', ?, 'Hardware', ?, ?, ?, ?)"
);
foreach ($tickets as [$id, $title, $description, $type, $priority]) {
$hash = hash('sha256', 'tinker-ui-seed-' . $id);
$insert->bind_param('sssissss', $id, $title, $description, $priority, $type, $hash, $created, $created);
$insert->execute();
}
$addComment = $db->prepare(
"INSERT INTO ticket_comments (ticket_id, user_name, comment_text, markdown_enabled, created_at)
VALUES ('100000001', 'Seed User', ?, 1, ?)"
);
$addComment->bind_param('ss', $comment, $created);
$addComment->execute();
echo 'seeded ' . count($tickets) . " tickets into $dbName\n";