Files
houseplan-card/demo/golden/policy.mjs
T

26 lines
1.3 KiB
JavaScript

// The name must NOT end with `manifest.json`: the HACS submission check globs
// `*manifest.json` over the whole clone of the default branch and refuses a
// repository with more than one match (test/repo-hygiene.test.mjs).
export const GOLDEN_BASELINE_MANIFEST = 'baselines-index.json';
export const assertGoldenInvocation = (mode, scenarioFilter = '') => {
if (!['capture', 'verify'].includes(mode)) throw new Error(`unknown golden mode: ${mode}`);
if (mode === 'verify' && scenarioFilter)
throw new Error('golden verify must run the complete matrix; use capture for a diagnostic --scenario run');
};
/** A reviewed golden matrix is exact: neither an orphan PNG nor a stale hash
* entry may survive after a scenario is removed or renamed. */
export const goldenScenarioSetsMatch = (expected, indexed, baselineFiles) => {
const normalized = (values) => [...new Set(values)].sort();
const wanted = normalized(expected);
return JSON.stringify(normalized(indexed)) === JSON.stringify(wanted)
&& JSON.stringify(normalized(baselineFiles)) === JSON.stringify(wanted);
};
export const goldenRunFailed = (mode, manifestValid, results) => {
if (results.some((result) => result.status === 'error')) return true;
return mode === 'verify'
&& (!manifestValid || results.some((result) => result.status !== 'passed'));
};