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/styles.css', root), 'utf8'); const layouts = await Promise.all([ 'resources/views/venix/cloud/page.tpl', 'resources/views/venix/user/layout_header.tpl', 'resources/views/venix/user/layout_plain_header.tpl', 'resources/views/venix/auth/layout_header.tpl', ].map(path => readFile(new URL(path, root), 'utf8'))); for (const layout of layouts) { assert.match(layout, /\/cloud\/styles\.css\?v=/, 'A user-facing layout does not load the shared interaction stylesheet.'); } 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(), 'user-touch-highlight-')); const fixture = join(directory, 'fixture.html'); const safeCss = css.replaceAll(' 链接按钮 行按钮
角色按钮
折叠按钮
`); try { const { stdout } = await execFileAsync(chrome, [ '--headless=new', '--disable-gpu', '--no-sandbox', '--hide-scrollbars', '--touch-events=enabled', '--window-size=390,844', '--dump-dom', `file://${fixture}`, ], { maxBuffer: 8 * 1024 * 1024 }); const encoded = stdout.match(/data-metrics="([^"]+)"/)?.[1]; assert.ok(encoded, 'Headless browser did not return touch-highlight metrics.'); const metrics = JSON.parse(decodeURIComponent(encoded)); for (const [id, value] of Object.entries(metrics)) { assert.ok(value === 'rgba(0, 0, 0, 0)' || value === 'transparent', `${id} still renders the mobile black tap highlight (${value}).`); } } finally { await rm(directory, { recursive: true, force: true }); } } const rootRule = css.match(/:root\s*\{([^}]*)\}/)?.[1] || ''; assert.match(rootRule, /-webkit-tap-highlight-color\s*:\s*transparent/, 'The shared user stylesheet does not disable the WebKit tap overlay.'); assert.doesNotMatch(rootRule, /outline\s*:/, 'The global touch fix must not remove keyboard focus outlines.'); console.log(`User touch-highlight checks passed${chrome ? ' with headless browser.' : ' (browser unavailable; static contract only).'}`);