Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Retain actual auth renderer facts beside strict goldens

pulse-triage[bot]bd6de2bed32c
diff --git a/tests/integration/scripts/capture-auth-renderer.d.mts b/tests/integration/scripts/capture-auth-renderer.d.mts
new file mode 100644
index 0000000000..80eb2d35c6
--- /dev/null
+++ b/tests/integration/scripts/capture-auth-renderer.d.mts
@@ -0,0 +1,3 @@
+import type { Page } from '@playwright/test';
+
+export function captureAuthRenderer(page: Page): Promise<Record<string, unknown>>;
diff --git a/tests/integration/scripts/capture-auth-renderer.mjs b/tests/integration/scripts/capture-auth-renderer.mjs
new file mode 100644
index 0000000000..4caf23d226
--- /dev/null
+++ b/tests/integration/scripts/capture-auth-renderer.mjs
@@ -0,0 +1,97 @@
+import { createHash } from 'node:crypto';
+
+// Read renderer facts, not page contents or account/session state. CDP reads
+// the already loaded stylesheets; this collector makes no HTTP requests and
+// never changes CSS, fonts, the viewport or the screenshot assertion.
+export async function captureAuthRenderer(page) {
+ const browser = page.context().browser();
+ const result = {
+ schema_version: 1,
+ browser: { name: browser?.browserType().name(), version: browser?.version() },
+ viewport: null,
+ heading_style: null,
+ fonts: [],
+ stylesheets: [],
+ gaps: [],
+ };
+ try {
+ const observed = await page.evaluate(() => {
+ const heading = document.querySelector('h1');
+ const style = heading && getComputedStyle(heading);
+ return {
+ viewport: { width: innerWidth, height: innerHeight, scale: devicePixelRatio },
+ heading_style: style && {
+ family: style.fontFamily,
+ size: style.fontSize,
+ weight: style.fontWeight,
+ line_height: style.lineHeight,
+ letter_spacing: style.letterSpacing,
+ },
+ };
+ });
+ result.viewport = observed.viewport;
+ result.heading_style = observed.heading_style;
+ if (!observed.heading_style) result.gaps.push('heading-missing');
+ } catch {
+ result.gaps.push('computed-style-unavailable');
+ }
+ if (result.browser.name !== 'chromium') {
+ result.gaps.push('platform-fonts-and-css-cdp-unavailable');
+ return result;
+ }
+
+ let session;
+ try {
+ session = await page.context().newCDPSession(page);
+ const sheets = new Map();
+ session.on('CSS.styleSheetAdded', ({ header }) => {
+ if (sheets.size < 32) sheets.set(header.styleSheetId, header);
+ else if (!sheets.has(header.styleSheetId) && !result.gaps.includes('stylesheet-limit')) {
+ result.gaps.push('stylesheet-limit');
+ }
+ });
+ await session.send('DOM.enable');
+ await session.send('CSS.enable');
+ const { root } = await session.send('DOM.getDocument', { depth: 0 });
+ const { nodeId } = await session.send('DOM.querySelector', { nodeId: root.nodeId, selector: 'h1' });
+ if (nodeId) {
+ try {
+ const { fonts } = await session.send('CSS.getPlatformFontsForNode', { nodeId });
+ result.fonts = fonts.slice(0, 32).map((font) => ({
+ family: font.familyName,
+ postscript: font.postScriptName,
+ custom: font.isCustomFont,
+ glyphs: font.glyphCount,
+ }));
+ if (!fonts.length) result.gaps.push('platform-fonts-empty');
+ if (fonts.length > 32) result.gaps.push('font-limit');
+ } catch {
+ result.gaps.push('platform-fonts-unavailable');
+ }
+ }
+ for (const styleSheetId of sheets.keys()) {
+ try {
+ const { text } = await session.send('CSS.getStyleSheetText', { styleSheetId });
+ const bytes = Buffer.byteLength(text);
+ if (bytes > 1024 * 1024) {
+ result.gaps.push('stylesheet-byte-limit');
+ continue;
+ }
+ result.stylesheets.push({ bytes, sha256: createHash('sha256').update(text).digest('hex') });
+ } catch {
+ result.gaps.push('stylesheet-unavailable');
+ }
+ }
+ if (!sheets.size) result.gaps.push('stylesheets-empty');
+ } catch {
+ // Diagnostic failures stay explicit without logging protocol error text,
+ // which can include page URLs. They do not replace the strict pixel result.
+ result.gaps.push('cdp-unavailable');
+ } finally {
+ if (session) {
+ try { await session.detach(); }
+ catch { result.gaps.push('cdp-detach-unavailable'); }
+ }
+ }
+ return result;
+}
diff --git a/tests/integration/scripts/capture-auth-renderer.test.mjs b/tests/integration/scripts/capture-auth-renderer.test.mjs
new file mode 100644
index 0000000000..c51d478be8
--- /dev/null
+++ b/tests/integration/scripts/capture-auth-renderer.test.mjs
@@ -0,0 +1,116 @@
+import assert from 'node:assert/strict';
+import { createHash } from 'node:crypto';
+import { readFileSync } from 'node:fs';
+import test from 'node:test';
+import { runInNewContext } from 'node:vm';
+import { captureAuthRenderer } from './capture-auth-renderer.mjs';
+
+function fixture({ name = 'chromium', fail = [], count = 1, css = '.probe{font-weight:800}', fonts, missingHeading = false } = {}) {
+ const commands = [];
+ let added;
+ let detached = false;
+ const session = {
+ on(event, callback) { assert.equal(event, 'CSS.styleSheetAdded'); added = callback; },
+ async send(method, args) {
+ commands.push(method);
+ if (fail.includes(method)) throw new Error('private-page-url-and-error');
+ if (method === 'CSS.enable') {
+ for (let i = 0; i < count; i++) added({ header: { styleSheetId: String(i), sourceURL: 'private-page-url' } });
+ }
+ if (method === 'DOM.getDocument') { assert.equal(args.depth, 0); return { root: { nodeId: 1 } }; }
+ if (method === 'DOM.querySelector') { assert.equal(args.selector, 'h1'); return { nodeId: missingHeading ? 0 : 2 }; }
+ if (method === 'CSS.getPlatformFontsForNode') return { fonts: fonts ?? [{ familyName: 'Actual font', postScriptName: 'ActualFont', isCustomFont: false, glyphCount: 16 }] };
+ if (method === 'CSS.getStyleSheetText') return { text: css };
+ return {};
+ },
+ async detach() { detached = true; if (fail.includes('detach')) throw new Error('private-page-url'); },
+ };
+ const context = {
+ browser: () => ({ browserType: () => ({ name: () => name }), version: () => '141.0.7390.37' }),
+ async newCDPSession() { if (fail.includes('session')) throw new Error('private-page-url'); return session; },
+ };
+ const page = {
+ context: () => context,
+ async evaluate(fn) {
+ if (fail.includes('evaluate')) throw new Error('private-page-url');
+ return runInNewContext(`(${fn})()`, {
+ document: { querySelector(selector) { assert.equal(selector, 'h1'); return missingHeading ? null : { textContent: 'private-account-label' }; } },
+ getComputedStyle: () => ({ fontFamily: 'system-ui', fontSize: '36px', fontWeight: '800', lineHeight: '40px', letterSpacing: 'normal' }),
+ innerWidth: 1366, innerHeight: 900, devicePixelRatio: 1,
+ });
+ },
+ };
+ return { page, commands, detached: () => detached };
+}
+
+test('records actual fonts and complete UTF-8 CSS hashes, not computed family alone', async () => {
+ const css = '.probe{font-family:"日本語"}';
+ const f = fixture({ css });
+ const result = await captureAuthRenderer(f.page);
+ assert.deepEqual(result.gaps, []);
+ assert.equal(result.heading_style.family, 'system-ui');
+ assert.equal(result.fonts[0].family, 'Actual font');
+ assert.deepEqual(result.stylesheets, [{ bytes: Buffer.byteLength(css), sha256: createHash('sha256').update(css).digest('hex') }]);
+ assert.deepEqual(f.commands, ['DOM.enable', 'CSS.enable', 'DOM.getDocument', 'DOM.querySelector', 'CSS.getPlatformFontsForNode', 'CSS.getStyleSheetText']);
+ assert.equal(f.detached(), true);
+ assert.doesNotMatch(JSON.stringify(result), /private-|日本語|\.probe/);
+});
+
+test('independent font and CSS failures remain explicit and are never retried', async () => {
+ const f = fixture({ fail: ['CSS.getPlatformFontsForNode', 'CSS.getStyleSheetText'] });
+ const result = await captureAuthRenderer(f.page);
+ assert.deepEqual(result.gaps, ['platform-fonts-unavailable', 'stylesheet-unavailable']);
+ assert.equal(f.commands.filter((x) => x === 'CSS.getPlatformFontsForNode').length, 1);
+ assert.equal(f.commands.filter((x) => x === 'CSS.getStyleSheetText').length, 1);
+ assert.equal(f.detached(), true);
+ assert.doesNotMatch(JSON.stringify(result), /private-/);
+});
+
+test('WebKit retains computed facts without attempting unsupported CDP', async () => {
+ const f = fixture({ name: 'webkit' });
+ const result = await captureAuthRenderer(f.page);
+ assert.deepEqual(result.gaps, ['platform-fonts-and-css-cdp-unavailable']);
+ assert.equal(result.viewport.width, 1366);
+ assert.deepEqual(f.commands, []);
+});
+
+test('creation, computed-style and protocol failures return explicit partial evidence', async () => {
+ for (const failure of ['session', 'evaluate', 'DOM.enable']) {
+ const f = fixture({ fail: [failure] });
+ const result = await captureAuthRenderer(f.page);
+ assert.ok(result.gaps.includes(failure === 'evaluate' ? 'computed-style-unavailable' : 'cdp-unavailable'));
+ assert.equal(f.detached(), failure !== 'session');
+ assert.doesNotMatch(JSON.stringify(result), /private-/);
+ }
+});
+
+test('caps stylesheet/font counts and oversized CSS without implying completeness', async () => {
+ const font = { familyName: 'Actual font', postScriptName: 'ActualFont', isCustomFont: false, glyphCount: 16 };
+ const f = fixture({ count: 33, fonts: Array(33).fill(font), css: 'x'.repeat(1024 * 1024 + 1) });
+ const result = await captureAuthRenderer(f.page);
+ assert.equal(result.fonts.length, 32);
+ assert.equal(result.stylesheets.length, 0);
+ assert.ok(result.gaps.includes('font-limit'));
+ assert.ok(result.gaps.includes('stylesheet-limit'));
+ assert.ok(result.gaps.includes('stylesheet-byte-limit'));
+ assert.equal(f.commands.filter((x) => x === 'CSS.getStyleSheetText').length, 32);
+ assert.equal(f.detached(), true);
+});
+
+test('missing headings, empty fonts/stylesheets and detach failures stay visible', async () => {
+ assert.ok((await captureAuthRenderer(fixture({ missingHeading: true }).page)).gaps.includes('heading-missing'));
+ assert.ok((await captureAuthRenderer(fixture({ fonts: [] }).page)).gaps.includes('platform-fonts-empty'));
+ assert.ok((await captureAuthRenderer(fixture({ count: 0 }).page)).gaps.includes('stylesheets-empty'));
+ assert.ok((await captureAuthRenderer(fixture({ fail: ['detach'] }).page)).gaps.includes('cdp-detach-unavailable'));
+});
+
+test('every existing auth golden attaches facts before the unchanged strict assertions', () => {
+ const spec = readFileSync(new URL('../tests/06-theme-visual.spec.ts', import.meta.url), 'utf8');
+ assert.equal((spec.match(/await attachRenderer\(page\);/g) ?? []).length, 4);
+ for (const name of ['auth-login-light', 'auth-login-dark', 'auth-settings-light', 'auth-settings-dark']) {
+ assert.match(spec, new RegExp(`await attachRenderer\\(page\\);\\s+await expect\\(page\\).toHaveScreenshot\\('${name}\\.png'`));
+ }
+ assert.doesNotMatch(spec, /(?:maxDiffPixels|maxDiffPixelRatio|threshold|updateSnapshots)\s*:/);
+ assert.match(spec, /getByText\('Organization', \{ exact: true \}\)/);
+ assert.match(spec, /getByText\('Overview', \{ exact: true \}\)/);
+});
diff --git a/tests/integration/tests/06-theme-visual.spec.ts b/tests/integration/tests/06-theme-visual.spec.ts
index 12d82c8dba..e25a80d9c6 100644
--- a/tests/integration/tests/06-theme-visual.spec.ts
+++ b/tests/integration/tests/06-theme-visual.spec.ts
@@ -1,5 +1,6 @@
import { expect, Page, test } from '@playwright/test';
import { ensureAuthenticated, maybeCompleteSetupWizard, waitForPulseReady } from './helpers';
+import { captureAuthRenderer } from '../scripts/capture-auth-renderer.mjs';
type ThemePreference = 'light' | 'dark';
@@ -218,8 +219,19 @@ test.describe.serial('Theme visual regression (auth surfaces)', () => {
await page.setViewportSize(VISUAL_VIEWPORT);
});
+ // Preserve actual font selection and complete CSS byte identities on both
+ // passes and failures. A font package install or a short asset name is not
+ // evidence of what this renderer used; keep the pixel thresholds unchanged.
+ async function attachRenderer(page: Page): Promise<void> {
+ await test.info().attach('auth-renderer', {
+ body: Buffer.from(JSON.stringify(await captureAuthRenderer(page), null, 2)),
+ contentType: 'application/json',
+ });
+ }
+
test('logged-out login surface (light)', async ({ page }) => {
await openLoggedOutLogin(page, 'light');
+ await attachRenderer(page);
await expect(page).toHaveScreenshot('auth-login-light.png', {
fullPage: true,
@@ -235,6 +247,7 @@ test.describe.serial('Theme visual regression (auth surfaces)', () => {
test('logged-out login surface (dark)', async ({ page }) => {
await openLoggedOutLogin(page, 'dark');
+ await attachRenderer(page);
await expect(page).toHaveScreenshot('auth-login-dark.png', {
fullPage: true,
@@ -250,6 +263,7 @@ test.describe.serial('Theme visual regression (auth surfaces)', () => {
test('authenticated security-auth surface (light)', async ({ page }) => {
await openAuthenticatedSecurityAuth(page, 'light');
+ await attachRenderer(page);
await expect(page).toHaveScreenshot('auth-settings-light.png', {
fullPage: true,
@@ -260,6 +274,7 @@ test.describe.serial('Theme visual regression (auth surfaces)', () => {
test('authenticated security-auth surface (dark)', async ({ page }) => {
await openAuthenticatedSecurityAuth(page, 'dark');
+ await attachRenderer(page);
await expect(page).toHaveScreenshot('auth-settings-dark.png', {
fullPage: true,