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
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:
1 parent
bdc6028572
commit
f1decca31f
22 files changed
+777
-8
No files matched your search
@@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
playwright-report/
|
||||
test-results/
|
||||
@@ -0,0 +1,61 @@
|
||||
'use strict';
|
||||
|
||||
// Shared fixture: every test gets a page signed in through Authelia-style
|
||||
// Remote-* headers (TRUSTED_PROXIES is empty in the test .env, so they are
|
||||
// accepted from 127.0.0.1), and fails if the page throws, logs a console error,
|
||||
// or any local request returns >= 400.
|
||||
const { test: base, expect } = require('@playwright/test');
|
||||
|
||||
const SSO = {
|
||||
'Remote-User': 'ci.tester',
|
||||
'Remote-Name': 'CI Tester',
|
||||
'Remote-Email': 'ci@example.invalid',
|
||||
'Remote-Groups': 'admin',
|
||||
};
|
||||
|
||||
const isLocal = url => /^https?:\/\/(127\.0\.0\.1|localhost)(:\d+)?\//.test(url);
|
||||
// Users without an lldap avatar get a 404 and the initials fallback; that is
|
||||
// the designed behaviour, not a failure (LDAP is off in the tests).
|
||||
const isAvatar = url => url.includes('/api/user_avatar.php');
|
||||
|
||||
const test = base.extend({
|
||||
extraHTTPHeaders: [SSO, { option: true }],
|
||||
|
||||
// Problems seen on the page; tests that expect one can clear the list.
|
||||
// eslint-disable-next-line no-empty-pattern -- Playwright requires the destructuring
|
||||
problems: async ({}, use) => { await use([]); },
|
||||
|
||||
page: async ({ page, problems }, use) => {
|
||||
// Nothing leaves the machine: no SSO headers to third parties and no
|
||||
// dependence on Google Fonts. The fallback fonts are fine for assertions.
|
||||
await page.route(url => !isLocal(url.href), route => route.abort());
|
||||
|
||||
page.on('pageerror', e => problems.push(`page error: ${e.message}`));
|
||||
page.on('console', m => {
|
||||
if (m.type() !== 'error') return;
|
||||
const src = (m.location() && m.location().url) || '';
|
||||
if (src && !isLocal(src)) return;
|
||||
if (/Failed to load resource: net::ERR_FAILED/.test(m.text())) return; // the blocked external requests
|
||||
if (isAvatar(src)) return; // the avatar 404 below
|
||||
problems.push(`console error: ${m.text()}`);
|
||||
});
|
||||
page.on('response', r => {
|
||||
if (isLocal(r.url()) && r.status() >= 400 && !(r.status() === 404 && isAvatar(r.url()))) {
|
||||
problems.push(`HTTP ${r.status()} ${r.request().method()} ${r.url()}`);
|
||||
}
|
||||
});
|
||||
|
||||
// Skip the once-per-session boot overlay (base.js runBoot, lt_booted_<app>).
|
||||
await page.addInitScript(() => {
|
||||
const get = Storage.prototype.getItem;
|
||||
Storage.prototype.getItem = function (k) {
|
||||
return String(k).startsWith('lt_booted_') ? '1' : get.call(this, k);
|
||||
};
|
||||
});
|
||||
|
||||
await use(page);
|
||||
expect(problems, 'page errors, console errors or failed requests').toEqual([]);
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = { test, expect, SSO, isLocal };
|
||||
@@ -0,0 +1,56 @@
|
||||
'use strict';
|
||||
|
||||
// Ticket descriptions and comments render as markdown (#114), safely.
|
||||
const { test, expect } = require('./fixtures');
|
||||
|
||||
test('description markdown renders as formatted HTML', async ({ page }) => {
|
||||
await page.goto('/ticket/100000001');
|
||||
const view = page.locator('#ticketDescriptionView');
|
||||
await expect(view.locator('h2', { hasText: 'Goal' })).toBeVisible();
|
||||
await expect(view.locator('strong', { hasText: 'PBS datastore' })).toBeVisible();
|
||||
await expect(view.locator('table tr')).toHaveCount(4);
|
||||
await expect(view.locator('pre code')).toContainText('proxmox-backup-manager datastore create');
|
||||
await expect(view.locator('a[href="https://wiki.example.invalid/backups"]')).toBeVisible();
|
||||
await expect(view.locator('a[href$="/ticket/100000002"]')).toBeVisible();
|
||||
await expect(view).not.toContainText('## Goal');
|
||||
});
|
||||
|
||||
test('HTML and javascript: links in a description stay inert', async ({ page }) => {
|
||||
await page.goto('/ticket/100000001');
|
||||
const view = page.locator('#ticketDescriptionView');
|
||||
await expect(view).toContainText("<script>window.__seedXss = 1</script>");
|
||||
await expect(view.locator('script')).toHaveCount(0);
|
||||
await expect(view.locator('a[href^="javascript:"]')).toHaveCount(0);
|
||||
expect(await page.evaluate(() => window.__seedXss)).toBeUndefined();
|
||||
});
|
||||
|
||||
test('underscores inside identifiers stay literal', async ({ page }) => {
|
||||
await page.goto('/ticket/100000002');
|
||||
const view = page.locator('#ticketDescriptionView');
|
||||
await expect(view).toContainText('node_network_up is 0');
|
||||
await expect(view.locator('em', { hasText: 'Opened automatically by Gandalf.' })).toBeVisible();
|
||||
});
|
||||
|
||||
test('plain text keeps its paragraphs', async ({ page }) => {
|
||||
await page.goto('/ticket/100000003');
|
||||
const view = page.locator('#ticketDescriptionView');
|
||||
await expect(view).toContainText('Tried a new roll, same result.');
|
||||
await expect(view).toContainText('Not urgent, the spare printer works.');
|
||||
});
|
||||
|
||||
test('edit mode shows the raw markdown source', async ({ page }) => {
|
||||
await page.goto('/ticket/100000001');
|
||||
await page.click('#editButton');
|
||||
const textarea = page.locator('#ticketDescription');
|
||||
await expect(textarea).toBeVisible();
|
||||
await expect(textarea).toHaveValue(/^## Goal\n/);
|
||||
});
|
||||
|
||||
test('markdown comments render', async ({ page }) => {
|
||||
await page.goto('/ticket/100000001');
|
||||
await page.click('#comments-tab-btn');
|
||||
const comment = page.locator('.comment-text').first();
|
||||
await expect(comment.locator('strong', { hasText: 'Next:' })).toBeVisible();
|
||||
await expect(comment.locator('code', { hasText: 'snake_case_job' })).toBeVisible();
|
||||
await expect(comment).toContainText('verify_jobs');
|
||||
});
|
||||
Generated
+58
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"name": "tinker-tickets-ui-tests",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "tinker-tickets-ui-tests",
|
||||
"devDependencies": {
|
||||
"@playwright/test": "1.64.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@playwright/test": {
|
||||
"version": "1.64.1",
|
||||
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.64.1.tgz",
|
||||
"integrity": "sha512-IaYGml/nSOiZWROfPtuIL7neuu9qDOZ3TNvNljUIrhDMxiGTgPjzj/g9p9RxpS2tSepPDRY+UwAaEeiKtUvIAg==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"playwright": "1.64.1"
|
||||
},
|
||||
"bin": {
|
||||
"playwright": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/playwright": {
|
||||
"version": "1.64.1",
|
||||
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.64.1.tgz",
|
||||
"integrity": "sha512-HCrVhHr5QQuwYoswEUGTb7gGp522yflbv/ST8nF4sFWGuLjQCt17Q/EubpGGSNKYn1tsTCPZxqHhHCfVURu7UA==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"playwright-core": "1.64.1"
|
||||
},
|
||||
"bin": {
|
||||
"playwright": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/playwright-core": {
|
||||
"version": "1.64.1",
|
||||
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.64.1.tgz",
|
||||
"integrity": "sha512-BC4s8y6SEVA6Q1rSxZTto8hI1KUI3xXlHGZgvGqP4IqPdI/a6FX9H29IDNz7vKo9l21b6LfYosScPL6M3xxyDQ==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"playwright-core": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "tinker-tickets-ui-tests",
|
||||
"private": true,
|
||||
"description": "Playwright UI tests and before/after screenshots for Tinker Tickets (CI only).",
|
||||
"scripts": {
|
||||
"test": "playwright test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "1.64.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
|
||||
// Every main page loads for a signed-in admin with no page errors, console
|
||||
// errors or failed requests (checked by the fixture).
|
||||
const { test, expect } = require('./fixtures');
|
||||
|
||||
const PAGES = [
|
||||
['/', 'dashboard'],
|
||||
['/ticket/100000001', 'markdown ticket'],
|
||||
['/ticket/100000002', 'alert ticket'],
|
||||
['/ticket/100000003', 'plain-text ticket'],
|
||||
['/ticket/create', 'create ticket'],
|
||||
['/admin/templates', 'templates admin'],
|
||||
['/admin/workflow', 'workflow admin'],
|
||||
['/admin/audit-log', 'audit log'],
|
||||
['/admin/api-keys', 'API keys'],
|
||||
];
|
||||
|
||||
for (const [path, name] of PAGES) {
|
||||
test(`${name} (${path}) loads cleanly`, async ({ page }) => {
|
||||
const res = await page.goto(path);
|
||||
expect(res.status()).toBe(200);
|
||||
await page.waitForLoadState('networkidle');
|
||||
await expect(page.locator('body')).not.toContainText('Fatal error');
|
||||
await expect(page.locator('body')).not.toContainText('Warning:');
|
||||
});
|
||||
}
|
||||
|
||||
test('the dashboard lists the seeded tickets', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
await expect(page.getByRole('heading', { level: 1 })).toContainText('TICKETS');
|
||||
for (const id of ['100000001', '100000002', '100000003']) {
|
||||
await expect(page.locator(`a[href*="/ticket/${id}"]`).first()).toBeVisible();
|
||||
}
|
||||
});
|
||||
|
||||
test('requests without the SSO headers are not let in', async ({ baseURL }) => {
|
||||
// Plain fetch: Playwright's own request contexts pick up the fixture's SSO
|
||||
// headers.
|
||||
const res = await fetch(new URL('/', baseURL), { redirect: 'manual' });
|
||||
expect(res.status, 'anonymous request to the dashboard').toBe(401);
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
// Playwright UI tests. They expect a running instance with the seed data:
|
||||
// tests/ui/stack.sh starts one (see the README's "UI tests" section).
|
||||
const { defineConfig, devices } = require('@playwright/test');
|
||||
|
||||
const CI = !!process.env.CI;
|
||||
|
||||
module.exports = defineConfig({
|
||||
testDir: '.',
|
||||
testMatch: '**/*.ui.js',
|
||||
// One shared database: run serially so tests can't race each other.
|
||||
workers: 1,
|
||||
fullyParallel: false,
|
||||
forbidOnly: CI,
|
||||
retries: CI ? 1 : 0,
|
||||
timeout: 30_000,
|
||||
expect: { timeout: 10_000 },
|
||||
reporter: CI ? [['list'], ['html', { open: 'never' }]] : 'list',
|
||||
use: {
|
||||
baseURL: process.env.TINKER_UI_URL || 'http://127.0.0.1:8400',
|
||||
trace: 'retain-on-failure',
|
||||
screenshot: 'only-on-failure',
|
||||
},
|
||||
projects: [
|
||||
{ name: 'desktop', use: { ...devices['Desktop Chrome'], viewport: { width: 1280, height: 900 } }, testIgnore: '**/responsive.ui.js' },
|
||||
{ name: 'mobile', use: { ...devices['Pixel 7'] }, testMatch: '**/responsive.ui.js' },
|
||||
],
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
// Runs in the `mobile` project (Pixel 7): pages must fit the phone width,
|
||||
// with no horizontal page scroll. Wide content (tables, code) scrolls inside
|
||||
// its own box instead.
|
||||
const { test, expect } = require('./fixtures');
|
||||
|
||||
const PATHS = ['/', '/ticket/100000001', '/ticket/100000002', '/ticket/create'];
|
||||
|
||||
for (const path of PATHS) {
|
||||
test(`${path} fits a phone screen`, async ({ page }) => {
|
||||
await page.goto(path);
|
||||
await page.waitForLoadState('networkidle');
|
||||
const overflow = await page.evaluate(() => {
|
||||
const doc = document.documentElement;
|
||||
const wide = [...document.querySelectorAll('body *')]
|
||||
.filter(el => el.getBoundingClientRect().right > doc.clientWidth + 1 && el.getClientRects().length)
|
||||
.slice(0, 5)
|
||||
.map(el => el.tagName.toLowerCase() + (el.id ? '#' + el.id : '')
|
||||
+ (typeof el.className === 'string' && el.className.trim() ? '.' + el.className.trim().split(/\s+/).join('.') : ''));
|
||||
return { scrollWidth: doc.scrollWidth, clientWidth: doc.clientWidth, wide };
|
||||
});
|
||||
expect(overflow.scrollWidth, `wider than the screen: ${overflow.wide.join(', ')}`)
|
||||
.toBeLessThanOrEqual(overflow.clientWidth);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Router for PHP's built-in server in the UI tests (tests/ui/stack.sh): static
|
||||
* files are served as-is, PHP files run, everything else goes to index.php, as
|
||||
* nginx's try_files does in production.
|
||||
*/
|
||||
|
||||
if (php_sapi_name() !== 'cli-server') {
|
||||
http_response_code(404);
|
||||
exit;
|
||||
}
|
||||
|
||||
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||
$file = $_SERVER['DOCUMENT_ROOT'] . $path;
|
||||
if ($path !== '/' && is_file($file)) {
|
||||
if (!str_ends_with($file, '.php')) {
|
||||
return false;
|
||||
}
|
||||
require $file;
|
||||
return true;
|
||||
}
|
||||
require $_SERVER['DOCUMENT_ROOT'] . '/index.php';
|
||||
@@ -0,0 +1,112 @@
|
||||
'use strict';
|
||||
|
||||
// Before/after screenshots for UI pull requests.
|
||||
//
|
||||
// node tests/ui/screenshots.js <out-dir> before=<url> after=<url>
|
||||
//
|
||||
// Both instances run tests/ui/stack.sh, so they hold the same seed data and
|
||||
// differences come from the code. Captures each page on desktop (dark and
|
||||
// light theme) and on a phone, then composes one side-by-side image per page
|
||||
// and view (<page>-<view>.png), rendered in the browser so no image tooling is
|
||||
// needed. Views that look identical are listed in unchanged.txt.
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { chromium, devices } = require('@playwright/test');
|
||||
const { SSO, isLocal } = require('./fixtures');
|
||||
|
||||
// The day after the seed's timestamps, so "1d ago" reads the same on both sides.
|
||||
const NOW = new Date('2026-11-21T09:00:00Z');
|
||||
|
||||
const PAGES = {
|
||||
dashboard: '/',
|
||||
'ticket-markdown': '/ticket/100000001',
|
||||
'ticket-alert': '/ticket/100000002',
|
||||
'ticket-plain': '/ticket/100000003',
|
||||
'ticket-create': '/ticket/create',
|
||||
};
|
||||
const VIEWS = {
|
||||
dark: { theme: 'dark', opts: { viewport: { width: 1280, height: 900 } } },
|
||||
light: { theme: 'light', opts: { viewport: { width: 1280, height: 900 } } },
|
||||
phone: { theme: 'dark', opts: { ...devices['Pixel 7'] } },
|
||||
};
|
||||
|
||||
async function capture(browser, label, base, dir) {
|
||||
const shots = {};
|
||||
for (const [view, { theme, opts }] of Object.entries(VIEWS)) {
|
||||
const ctx = await browser.newContext({ ...opts, colorScheme: theme, extraHTTPHeaders: SSO, reducedMotion: 'reduce', timezoneId: 'UTC' });
|
||||
await ctx.route(u => !isLocal(u.href), r => r.abort());
|
||||
await ctx.addInitScript(t => {
|
||||
try { localStorage.setItem('lt_theme', t); } catch (e) { /* ignore */ }
|
||||
const get = Storage.prototype.getItem;
|
||||
Storage.prototype.getItem = function (k) {
|
||||
return String(k).startsWith('lt_booted_') ? '1' : get.call(this, k);
|
||||
};
|
||||
}, theme);
|
||||
const page = await ctx.newPage();
|
||||
await page.clock.setFixedTime(NOW);
|
||||
for (const [name, p] of Object.entries(PAGES)) {
|
||||
await page.goto(base + p);
|
||||
await page.waitForLoadState('networkidle');
|
||||
// Every image settled: loaded, or (avatars without an lldap photo)
|
||||
// swapped for the initials fallback.
|
||||
await page.waitForFunction(() => [...document.images].every(i => i.complete
|
||||
&& (i.naturalWidth > 0 || !i.closest('.lt-avatar') || i.classList.contains('lt-avatar-img-err'))), null, { timeout: 5000 })
|
||||
.catch(() => {});
|
||||
await page.evaluate(t => document.documentElement.setAttribute('data-theme', t), theme);
|
||||
await page.waitForTimeout(500);
|
||||
const key = `${name}-${view}`;
|
||||
const file = path.join(dir, `${label}-${key}.png`);
|
||||
await page.screenshot({ path: file, fullPage: true });
|
||||
shots[key] = file;
|
||||
}
|
||||
await ctx.close();
|
||||
}
|
||||
return shots;
|
||||
}
|
||||
|
||||
async function compose(browser, name, before, after, out) {
|
||||
const b64 = f => 'data:image/png;base64,' + fs.readFileSync(f).toString('base64');
|
||||
const html = `<!doctype html><meta charset="utf-8"><style>
|
||||
body{margin:0;background:#0b0e14;color:#ddd;font:16px monospace}
|
||||
.row{display:flex;gap:16px;padding:16px;align-items:flex-start}
|
||||
.col{flex:1;min-width:0} h2{margin:0 0 8px;font-size:16px}
|
||||
.b h2{color:#ff7878}.a h2{color:#78ffa0} img{width:100%;border:1px solid #333}
|
||||
</style><div class="row">
|
||||
<div class="col b"><h2>BEFORE (base) ${name}</h2><img src="${b64(before)}"></div>
|
||||
<div class="col a"><h2>AFTER (this PR) ${name}</h2><img src="${b64(after)}"></div>
|
||||
</div>`;
|
||||
const page = await browser.newPage({ viewport: { width: 1600, height: 800 } });
|
||||
await page.setContent(html);
|
||||
await page.screenshot({ path: out, fullPage: true });
|
||||
await page.close();
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const [outDir, ...targets] = process.argv.slice(2);
|
||||
const urls = Object.fromEntries(targets.map(t => t.split('=')));
|
||||
if (!outDir || !urls.before || !urls.after) {
|
||||
console.error('usage: screenshots.js <out-dir> before=<url> after=<url>');
|
||||
process.exit(2);
|
||||
}
|
||||
const raw = path.join(outDir, 'raw');
|
||||
fs.mkdirSync(raw, { recursive: true });
|
||||
|
||||
const browser = await chromium.launch();
|
||||
try {
|
||||
const before = await capture(browser, 'before', urls.before, raw);
|
||||
const after = await capture(browser, 'after', urls.after, raw);
|
||||
const unchanged = [];
|
||||
for (const name of Object.keys(after)) {
|
||||
if (before[name] && fs.readFileSync(before[name]).equals(fs.readFileSync(after[name]))) {
|
||||
unchanged.push(name);
|
||||
continue;
|
||||
}
|
||||
await compose(browser, name, before[name], after[name], path.join(outDir, `${name}.png`));
|
||||
console.log(`changed: ${name}`);
|
||||
}
|
||||
fs.writeFileSync(path.join(outDir, 'unchanged.txt'), unchanged.join('\n') + '\n');
|
||||
console.log(`unchanged: ${unchanged.length ? unchanged.join(', ') : 'none'}`);
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
})().catch(e => { console.error(e); process.exit(1); });
|
||||
@@ -0,0 +1,115 @@
|
||||
<?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";
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
# CI only: installs PHP and a throwaway MariaDB inside the Playwright job
|
||||
# container (Ubuntu, as root) and starts MariaDB on 127.0.0.1:3306. Run once per
|
||||
# job, before tests/ui/stack.sh. MariaDB runs in the job container rather than
|
||||
# as a service container because the Gitea runner puts jobs on Docker's default
|
||||
# bridge network, where services can't be reached by name (same as Pulse).
|
||||
set -euo pipefail
|
||||
|
||||
# The Playwright image points apt at Azure's Ubuntu mirror, which our runner
|
||||
# can't always reach; use the main Ubuntu mirror instead, and retry.
|
||||
for f in /etc/apt/sources.list /etc/apt/sources.list.d/*.list /etc/apt/sources.list.d/*.sources; do
|
||||
[ -f "$f" ] && sed -i 's#http://azure\.archive\.ubuntu\.com/#http://archive.ubuntu.com/#g' "$f"
|
||||
done
|
||||
PKGS="mariadb-server php-cli php-mysql php-mbstring php-curl php-ldap php-xml"
|
||||
for attempt in 1 2 3; do
|
||||
# shellcheck disable=SC2086
|
||||
if apt-get -o Acquire::Retries=3 update -qq \
|
||||
&& DEBIAN_FRONTEND=noninteractive apt-get -o Acquire::Retries=3 install -y -qq --no-install-recommends $PKGS >/dev/null; then
|
||||
break
|
||||
fi
|
||||
[ "$attempt" = 3 ] && { echo "::error::could not install $PKGS"; exit 1; }
|
||||
echo "apt failed (attempt $attempt); retrying in 10s"
|
||||
sleep 10
|
||||
done
|
||||
|
||||
mkdir -p /run/mysqld && chown mysql:mysql /run/mysqld
|
||||
if ! mariadb-admin ping --silent 2>/dev/null; then
|
||||
(mariadbd --user=mysql --bind-address=127.0.0.1 --port=3306 >/tmp/mariadb.log 2>&1 &)
|
||||
fi
|
||||
for _ in $(seq 1 30); do mariadb-admin ping --silent 2>/dev/null && break; sleep 1; done
|
||||
mariadb -e "CREATE USER IF NOT EXISTS 'tinker_ui'@'127.0.0.1' IDENTIFIED BY 'ci-only';"
|
||||
echo "$(php --version | head -1), $(mariadb --version)"
|
||||
Executable
+72
@@ -0,0 +1,72 @@
|
||||
#!/bin/bash
|
||||
# Starts one Tinker Tickets instance for the UI tests on a fresh database:
|
||||
#
|
||||
# tests/ui/stack.sh <checkout-dir> <port> <db-name>
|
||||
#
|
||||
# Creates the database, writes the checkout's .env (throwaway values only),
|
||||
# applies the checkout's migrations, loads the synthetic seed
|
||||
# data and serves the checkout with PHP's built-in server. The seed and router
|
||||
# always come from this script's directory, so the same data goes into the
|
||||
# base branch's checkout for before/after screenshots.
|
||||
#
|
||||
# Needs a MariaDB on 127.0.0.1 with a 'tinker_ui' user (tests/ui/setup.sh in
|
||||
# CI) and root access to it over the local socket. Logs go to
|
||||
# <checkout>/.ui-stack/server.log.
|
||||
set -euo pipefail
|
||||
CHECKOUT=$(cd "${1:?checkout dir}" && pwd)
|
||||
PORT=${2:?port}
|
||||
DB=${3:?database name}
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
|
||||
case "$DB" in
|
||||
tinker_ui*) ;;
|
||||
*) echo "refusing: database name must start with tinker_ui" >&2; exit 2 ;;
|
||||
esac
|
||||
|
||||
mariadb -e "DROP DATABASE IF EXISTS \`$DB\`; CREATE DATABASE \`$DB\`;
|
||||
GRANT ALL ON \`$DB\`.* TO 'tinker_ui'@'127.0.0.1';"
|
||||
|
||||
if [ -e "$CHECKOUT/.env" ] && ! grep -q "^; tinker-ui-stack" "$CHECKOUT/.env"; then
|
||||
echo "refusing: $CHECKOUT/.env exists and was not written by this script" >&2
|
||||
exit 2
|
||||
fi
|
||||
cat > "$CHECKOUT/.env" <<EOF
|
||||
; tinker-ui-stack: throwaway UI test settings, safe to delete
|
||||
DB_HOST=127.0.0.1
|
||||
DB_USER=tinker_ui
|
||||
DB_PASS=ci-only
|
||||
DB_NAME=$DB
|
||||
LDAP_ENABLED=false
|
||||
TIMEZONE=UTC
|
||||
; One client IP makes every request in a test run; the default limits would
|
||||
; turn later pages into 429s.
|
||||
RATE_LIMIT_DEFAULT=100000
|
||||
RATE_LIMIT_API=100000
|
||||
RATE_LIMIT_IP=100000
|
||||
RATE_LIMIT_IP_API=100000
|
||||
EOF
|
||||
|
||||
# This branch's migration runner, run from inside the checkout so it reads
|
||||
# that checkout's config and migrations: a base branch with an older runner
|
||||
# (before the comment fix) still gets its schema.
|
||||
cp "$HERE/../../migrations/migrate.php" "$CHECKOUT/migrations/.ui-migrate.php"
|
||||
php "$CHECKOUT/migrations/.ui-migrate.php"
|
||||
rm -f "$CHECKOUT/migrations/.ui-migrate.php"
|
||||
DB_NAME=$DB php "$HERE/seed.php"
|
||||
|
||||
mkdir -p "$CHECKOUT/.ui-stack"
|
||||
(cd "$CHECKOUT" && setsid php -S "127.0.0.1:$PORT" -t . "$HERE/router.php" \
|
||||
> "$CHECKOUT/.ui-stack/server.log" 2>&1 &)
|
||||
|
||||
for _ in $(seq 1 30); do
|
||||
code=$(curl -s -o /dev/null -w '%{http_code}' -H 'Remote-User: ci.tester' -H 'Remote-Name: CI Tester' \
|
||||
-H 'Remote-Email: ci@example.invalid' -H 'Remote-Groups: admin' "http://127.0.0.1:$PORT/" || true)
|
||||
if [ "$code" = 200 ]; then
|
||||
echo "Tinker Tickets ($CHECKOUT) on http://127.0.0.1:$PORT, database $DB"
|
||||
exit 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
echo "::error::Tinker Tickets did not answer on port $PORT (last HTTP ${code:-none})"
|
||||
tail -n 50 "$CHECKOUT/.ui-stack/server.log" || true
|
||||
exit 1
|
||||
Reference in new issue
Block a user