Bake a caption strip onto every posted screenshot composite — status + name + the spec that produces it — for changed, added, and removed; removed now shows the old baseline image (was a text-only line). Zero native-dep: an embedded public-domain 8x8 bitmap font (font8x8.ts) rendered by image-ops `withBottomLabel`; the name→spec attribution is factored out of gen-manifest into a shared `spec-map.ts` resolver. Bottom strip, colour per status (green/red/orange). Applies in both compare (drift gate) and changelog (git-history diff), and post-discord now attaches the captioned removed images. Also raise the per-engine drift floor 0.2% → 0.5% (changedRatio) to absorb the sub-1% inter-run flakiness seen after the re-baseline, while still catching real localized changes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
63 lines
2.5 KiB
TypeScript
63 lines
2.5 KiB
TypeScript
/**
|
|
* Generate tests/screenshot-manifest.json — the canonical list of expected
|
|
* screenshots + the engine that renders each.
|
|
*
|
|
* The NAME list is authoritative (it's the committed baseline set) and is what
|
|
* lets compare/promote tell an intentional REMOVAL from a flaky/absent render.
|
|
* The ENGINE tag is best-effort (spec-map.ts attributes each name to the spec that
|
|
* writes it, and that spec's project/engine) and only feeds the per-engine floors.
|
|
*
|
|
* CLI (from tests/): tsx tools/screenshots/gen-manifest.ts [--check]
|
|
* --check exits 1 if the committed manifest is stale (for CI hygiene).
|
|
*/
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
import { BASELINE_DIRS, MANIFEST_PATH, isIgnored, type Manifest } from './config';
|
|
import { buildSpecResolver } from './spec-map';
|
|
|
|
function listBaselines(root: string): string[] {
|
|
const names = new Set<string>();
|
|
for (const dir of BASELINE_DIRS) {
|
|
const abs = path.join(root, dir);
|
|
if (!fs.existsSync(abs)) continue;
|
|
for (const f of fs.readdirSync(abs)) if (f.toLowerCase().endsWith('.png') && !isIgnored(f)) names.add(f);
|
|
}
|
|
return [...names].sort();
|
|
}
|
|
|
|
function main(): void {
|
|
const check = process.argv.includes('--check');
|
|
const root = process.cwd();
|
|
const resolver = buildSpecResolver(root);
|
|
|
|
let unmatched = 0;
|
|
const screenshots = listBaselines(root).map((name) => {
|
|
if (resolver.specFor(name) === null) unmatched++;
|
|
return { name, engine: resolver.engineFor(name) };
|
|
});
|
|
|
|
const manifest: Manifest & { _note: string } = {
|
|
_note: 'engine tags are best-effort (spec-map.ts); the name list is authoritative. Refine engines after calibration.',
|
|
screenshots,
|
|
};
|
|
const json = JSON.stringify(manifest, null, 2) + '\n';
|
|
const outPath = path.join(root, MANIFEST_PATH);
|
|
|
|
const dist = screenshots.reduce<Record<string, number>>((d, s) => ((d[s.engine] = (d[s.engine] ?? 0) + 1), d), {});
|
|
console.log(`[manifest] ${screenshots.length} screenshots; engines=${JSON.stringify(dist)}; default-assigned=${unmatched}`);
|
|
|
|
if (check) {
|
|
const current = fs.existsSync(outPath) ? fs.readFileSync(outPath, 'utf8') : '';
|
|
if (current !== json) {
|
|
console.error('[manifest] STALE — run `npm run screenshots:manifest` and commit');
|
|
process.exitCode = 1;
|
|
} else {
|
|
console.log('[manifest] up to date');
|
|
}
|
|
return;
|
|
}
|
|
fs.writeFileSync(outPath, json);
|
|
console.log(`[manifest] wrote ${MANIFEST_PATH}`);
|
|
}
|
|
|
|
if (require.main === module) main();
|