import assert from 'node:assert/strict'; import { execFile } from 'node:child_process'; import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { promisify } from 'node:util'; const execFileAsync = promisify(execFile); const root = new URL('../', import.meta.url); const css = await readFile(new URL('public/cloud/client.css', root), 'utf8'); const template = await readFile( new URL('resources/views/venix/cloud/pages/invoices.tpl', root), 'utf8', ); const module = await readFile(new URL('public/cloud/invoices.js', root), 'utf8'); const service = await readFile( new URL('app/Services/Cloud/CloudInvoicePageService.php', root), 'utf8', ); assert.match(template, /class="invoice-balance-summary"/, 'The balance label and amount must share a stable summary container.'); assert.match(template, /class="invoice-balance-hint"/, 'The balance card must explain what the wallet balance can be used for.'); assert.match(css, /\.invoice-balance-summary\s*\{/, 'The balance summary has no dedicated visual hierarchy.'); assert.match(css, /\.invoice-filter-actions \.button-ghost\s*\{[^}]*background:\s*#fff/, 'The invoice reset action must remain visibly white against the page background.'); assert.doesNotMatch(template, /type="date"|invoices-date-|date_(?:from|to)/, 'The invoice template still exposes the retired date filter.'); assert.doesNotMatch(module, /normalizeDateFilter|date_(?:from|to)|invoices-date-/, 'The invoice browser module still carries retired date-filter state.'); assert.doesNotMatch(service, /date_(?:from|to)|DateTimeImmutable/, 'The invoice query service still carries retired date-filter logic.'); assert.match(css, /@media \(max-width: 360px\)[\s\S]*?\.invoice-balance-card\s*\{[^}]*grid-template-columns:\s*1fr/, 'Very narrow screens must stack the balance action below the amount.'); const chromeCandidates = [ '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', '/Applications/Chromium.app/Contents/MacOS/Chromium', '/usr/bin/google-chrome', '/usr/bin/chromium', '/usr/bin/chromium-browser', ]; let chrome = ''; for (const candidate of chromeCandidates) { try { await execFileAsync(candidate, ['--version']); chrome = candidate; break; } catch { /* Try the next local browser. */ } } if (chrome) { const directory = await mkdtemp(join(tmpdir(), 'invoice-mobile-layout-')); const fixture = join(directory, 'fixture.html'); const safeCss = css.replaceAll('