30 lines
1.9 KiB
JavaScript
30 lines
1.9 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import assert from 'node:assert/strict';
|
|
import { createHash } from 'node:crypto';
|
|
const read = file => JSON.parse(fs.readFileSync(file));
|
|
const result = read('.qa/embedded-browser-all-ui-validation.json'); assert.equal(result.success, true);
|
|
let screenshots = 0, boundOriginals = 0; const directories = new Set();
|
|
for (const row of result.results) {
|
|
const value = read(row.evidence); assert.notEqual(value.success, false); assert.notEqual(value.passed, false);
|
|
const output = fs.readFileSync(row.log, 'utf8');
|
|
const location = [...output.matchAll(/^EVIDENCE (.+)\r?$/gm)].at(-1)?.[1]?.trim() ?? null;
|
|
const directory = value.directory ?? location ?? value.root;
|
|
if (directory) {
|
|
const original = path.join(directory, 'result.json');
|
|
if (fs.existsSync(original)) { assert.deepEqual(read(original), value); boundOriginals++; }
|
|
directories.add(directory);
|
|
}
|
|
for (const item of Array.isArray(value.screenshots) ? value.screenshots : []) {
|
|
const declared = typeof item === 'string' ? item : item.path ?? item.file ?? item.screenshot;
|
|
const file = declared && !fs.existsSync(declared) && directory ? path.join(directory, declared) : declared;
|
|
assert.ok(file && fs.existsSync(file), 'Original screenshot ' + file);
|
|
const bytes = fs.readFileSync(file), expected = item.sha256 ?? item.screenshotSha256;
|
|
if (expected) assert.equal(createHash('sha256').update(bytes).digest('hex'), expected, file);
|
|
screenshots++;
|
|
}
|
|
}
|
|
const receipt = { success: true, scripts: result.results.length, groups: result.groups, declaredScreenshots: screenshots, boundOriginals, explicitDirectories: directories.size, scope: 'Read-only current frozen UI original receipts and screenshots; no validation re-run or byte changes' };
|
|
fs.writeFileSync('.qa/embedded-browser-d-ui-evidence-preflight.json', JSON.stringify(receipt, null, 2) + '\n', { flag: 'wx' });
|
|
console.log(JSON.stringify(receipt));
|