import assert from 'node:assert/strict'; import fs from 'node:fs'; import path from 'node:path'; import { createHash } from 'node:crypto'; import { execFileSync } from 'node:child_process'; const read = filename => JSON.parse(fs.readFileSync(filename, 'utf8')); const hash = bytes => createHash('sha256').update(bytes).digest('hex'); const originalBaseline = read('docs/controlled-engine-code-baseline.json'); const baseline = fs.existsSync('docs/controlled-engine-final-release-baseline.json') ? read('docs/controlled-engine-final-release-baseline.json') : fs.existsSync('docs/controlled-engine-final-code-baseline.json') ? read('docs/controlled-engine-final-code-baseline.json') : originalBaseline; const qaChange = fs.existsSync('docs/controlled-engine-qa-path-fix-validation.json') ? read('docs/controlled-engine-qa-path-fix-validation.json') : null; const portableQa = fs.existsSync('docs/controlled-engine-portable-qa-change.json') ? read('docs/controlled-engine-portable-qa-change.json') : null; const projects = read('docs/controlled-engine-final-projects-validation.json'); const ui = read('docs/controlled-engine-all-ui-validation.json'); const logs = read('docs/controlled-engine-final-ui-logs.json'); assert.equal(baseline.success, true); assert.equal(baseline.version, '1.14.0'); assert.equal(projects.success, true); assert.equal(projects.targetVersion, '1.14.0'); assert.equal(projects.testedVersion, '1.14.0'); assert.equal(projects.results.length, 3); assert.equal(projects.cases.length, 13); assert.equal(projects.realModelRequests, 0); assert.equal(ui.success, true); assert.equal(ui.version, '1.14.0'); assert.equal(ui.groups, 178); assert.equal(ui.results.length, 23); assert.equal(logs.success, true); assert.equal(logs.logs.length, ui.results.length); for (const row of [...baseline.inputs, ...baseline.builds, ...baseline.benchmarks]) { const bytes = fs.readFileSync(row.path); assert.equal(bytes.length, row.bytes, row.path); assert.equal(hash(bytes), row.sha256, row.path); } for (const row of projects.inputs) { const filename = row.path.replaceAll('\\', '/'); if (qaChange && filename === qaChange.change.path) { assert.equal(qaChange.success, true); assert.equal(qaChange.change.path, 'scripts/verify-controlled-release.mjs'); assert.equal(row.sha256, qaChange.change.originalSha256); assert.equal(hash(fs.readFileSync(row.path)), qaChange.change.sha256); assert.equal(hash(execFileSync('git', ['show', originalBaseline.codeCommit + ':' + filename], { windowsHide: true, maxBuffer: 1048576 })), row.sha256); } else if (portableQa && filename === portableQa.change.path) { assert.equal(portableQa.success, true); assert.equal(portableQa.change.path, 'scripts/verify-release.mjs'); assert.equal(row.sha256, portableQa.change.originalSha256); assert.equal(hash(fs.readFileSync(row.path)), portableQa.change.sha256); assert.equal(hash(execFileSync('git', ['show', portableQa.sourceValidatedCommit + ':' + filename], { windowsHide: true, maxBuffer: 1048576 })), row.sha256); } else assert.equal(hash(fs.readFileSync(row.path)), row.sha256, row.path); } for (const row of logs.logs) { const bytes = fs.readFileSync(row.path); assert.equal(bytes.length, row.bytes); assert.equal(hash(bytes), row.sha256); assert.ok(bytes.equals(fs.readFileSync(row.sourcePath)), row.path); } const summaries = [], images = []; for (const [index, sample] of projects.results.entries()) { assert.equal(sample.success, true); assert.equal(sample.version, '1.14.0'); assert.equal(sample.realModelRequests, 0); assert.equal(sample.parentCheck.status, 'passed'); assert.equal(sample.parentCheck.results[0].tests.passed, [8, 9, 10][index]); assert.ok(sample.commit); assert.ok(sample.checks.some(job => job.status === 'failed' && job.results.some(result => result.tests?.failed > 0))); assert.equal(sample.metrics.unknownRequests, 0); assert.equal(sample.metrics.requests, sample.modelRequests.length); assert.ok(sample.engineRuns.length > 0); for (const run of sample.engineRuns) { assert.equal(run.status, 'completed'); assert.equal(run.native.cleanup.treeConfirmed, true); assert.equal(run.native.stderr, ''); } for (const job of sample.browserJobs) { assert.equal(job.status, 'passed'); assert.equal(job.cleanup.exited, true); assert.equal(job.assertions.passed, 8); assert.equal(job.assertions.failed, 0); assert.ok(job.screenshots.length > 0); for (const shot of job.screenshots) { assert.ok([1280, 390].includes(shot.width)); assert.ok([900, 844].includes(shot.height)); const filename = path.join(projects.directory, sample.sampleName, 'page-' + shot.width + '-' + shot.artifactId + '.png'); const bytes = fs.readFileSync(filename); assert.equal(bytes.length, shot.bytes); assert.equal(hash(bytes), shot.sha256); assert.ok(bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))); images.push({ path: filename, bytes: bytes.length, sha256: shot.sha256, width: shot.width, height: shot.height }); } } summaries.push({ kind: sample.kind, testsPassed: sample.parentCheck.results[0].tests.passed, engineRuns: sample.engineRuns.length, allOwnedTreesClosed: true, browserJobs: sample.browserJobs.length, modelFixtureRequests: sample.modelRequests.length, commit: sample.commit }); } const result = { success: true, version: '1.14.0', verifiedAt: new Date().toISOString(), codeCommit: baseline.codeCommit, frozenInputs: baseline.inputs.length, builds: baseline.builds.length, benchmarks: baseline.benchmarks.length, projectInputFiles: projects.inputs.length, projectCases: projects.cases.length, projects: summaries, uiTypes: ui.results.length, uiGroups: ui.groups, exactUiLogs: logs.logs.length, images, realModelRequests: 0, validationOnlyChange: qaChange, postSourceValidationOnlyChange: portableQa, scope: 'Rechecks existing original bytes and actual raw engine/native cleanup/browser screenshot contracts. It does not rerun projects or UI tests.' }; fs.writeFileSync('docs/controlled-engine-evidence-validation.json', JSON.stringify(result, null, 2) + '\n'); console.log(JSON.stringify({ success: true, version: result.version, uiGroups: result.uiGroups, projectCases: result.projectCases, frozenInputs: result.frozenInputs, logs: result.exactUiLogs, images: result.images.length, projects: summaries }));