mirror of
https://github.com/Matysh/houseplan-card
synced 2026-09-28 19:01:34 +00:00
Golden frames carried the card version text (about, version banner, support/export previews), so every beta bump re-accepted up to 20 baselines that had not visually changed. The version now reaches the DOM and stand requests through displayVersion() (src/card-version.ts); the golden harness pins window.__HP_VERSION_OVERRIDE__ = '0.0.0-golden' before the card is created. CARD_VERSION literals stay where the release contract reads them; cache-busting and the console banner keep the literal. Docs screenshots: `npm run docs:accept -- --identical` re-captures locally, compares decoded RGBA pixels with the committed frames inside Chromium (scripts/png-identical.mjs) and, only when every frame is identical, refreshes the manifest fingerprints and captureScriptSha256; bytes stay, any difference refuses with a per-frame count. First run on this tree: 11/11 identical, manifest refreshed. Mutants: version-seam-ignores-override, docs-identical-accepts-any-frame. Issue: #512 User-Visible: no
46 lines
2.6 KiB
JavaScript
46 lines
2.6 KiB
JavaScript
// #512: the displayed version is a seam; the product never sets the override.
|
|
import assert from 'node:assert/strict';
|
|
import { readFileSync } from 'node:fs';
|
|
import test from 'node:test';
|
|
|
|
import { displayVersion } from '../test-build/card-version.js';
|
|
|
|
test('#512 AC2: without an override the displayed version is the real one', () => {
|
|
delete globalThis.__HP_VERSION_OVERRIDE__;
|
|
assert.equal(displayVersion('1.73.0'), '1.73.0');
|
|
});
|
|
|
|
test('#512 AC1: a non-empty string override replaces the displayed version; anything else is ignored', () => {
|
|
try {
|
|
globalThis.__HP_VERSION_OVERRIDE__ = '0.0.0-golden';
|
|
assert.equal(displayVersion('1.73.0'), '0.0.0-golden');
|
|
for (const junk of ['', 7, null, {}, true]) {
|
|
globalThis.__HP_VERSION_OVERRIDE__ = junk;
|
|
assert.equal(displayVersion('1.73.0'), '1.73.0', `override ${JSON.stringify(junk)} must be ignored`);
|
|
}
|
|
} finally {
|
|
delete globalThis.__HP_VERSION_OVERRIDE__;
|
|
}
|
|
});
|
|
|
|
test('#512: every DOM/request use of the version goes through the seam; cache-busting and the console banner keep the literal', () => {
|
|
const card = readFileSync(new URL('../src/houseplan-card.ts', import.meta.url), 'utf8');
|
|
const editor = readFileSync(new URL('../src/houseplan-editor-runtime.ts', import.meta.url), 'utf8');
|
|
const bare = (text) => text.split('\n').filter((line) => line.includes('CARD_VERSION') && !line.includes('displayVersion(CARD_VERSION)'));
|
|
const cardBare = bare(card);
|
|
assert.equal(cardBare.filter((line) => /const CARD_VERSION = '/.test(line)).length, 1);
|
|
for (const line of cardBare) {
|
|
assert.match(line, /const CARD_VERSION = '|hp_retry|console\.info/, `card: bare CARD_VERSION outside the seam: ${line.trim()}`);
|
|
}
|
|
const editorBare = bare(editor);
|
|
assert.deepEqual(editorBare.map((line) => line.trim()), [`const CARD_VERSION = '${/const CARD_VERSION = '([^']+)'/.exec(editor)[1]}';`]);
|
|
assert.match(card, /version: displayVersion\(CARD_VERSION\),/, 'PDF footer');
|
|
assert.match(card, /frontendVersion: displayVersion\(CARD_VERSION\),/, 'version-recovery banner');
|
|
assert.match(editor, /gs\.about_version', \{ v: displayVersion\(CARD_VERSION\) \}/, 'about dialog');
|
|
assert.equal((editor.match(/card_version: displayVersion\(CARD_VERSION\)/g) || []).length, 2, 'support preview + backup export');
|
|
const harness = readFileSync(new URL('../demo/golden/harness.mjs', import.meta.url), 'utf8');
|
|
assert.match(harness, /const cardVersion = '0\.0\.0-golden';/);
|
|
assert.match(harness, /window\.__HP_VERSION_OVERRIDE__ = cardVersion;/);
|
|
assert.doesNotMatch(harness, /package\.json/, 'golden no longer reads the package version');
|
|
});
|