fix(ci): make historical replay suites self-contained
This commit is contained in:
@@ -58,6 +58,9 @@ try {
|
||||
report.sourceBefore = unpackVerifiedSource(archive, run.source);
|
||||
assert.equal(fs.existsSync(path.join(run.source,'node_modules')), false, 'Fresh source must not have dependencies');
|
||||
writeNewJson(path.join(run.evidence,'source-before.json'), report.sourceBefore);
|
||||
stage = 'replay-fixtures';
|
||||
await nodeCommand('replay-fixtures', ['scripts/verify-replay-fixtures.mjs',path.join(run.evidence,'replay-fixtures-result.json')]);
|
||||
report.replayFixtures = JSON.parse(readOutput('replay-fixtures'));
|
||||
stage = 'official-contracts';
|
||||
await nodeCommand('official-registry', ['scripts/verify-official-model-registry.mjs',path.join(run.evidence,'official-registry-result.json')]);
|
||||
await nodeCommand('official-contracts', ['scripts/verify-official-contracts.mjs','--output',path.join(run.evidence,'official-contracts-result.json')]);
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { digest, fileDigest, writeNewJson } from './ci-utils.mjs';
|
||||
|
||||
const sourceRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
function inventory(root) {
|
||||
const directory = path.join(root, 'tests/fixtures/ci-replay'), file = path.join(directory, 'INDEX.json');
|
||||
const index = JSON.parse(fs.readFileSync(file)); assert.equal(index.schemaVersion, 1); assert.match(index.sourceCommit, /^[a-f0-9]{40}$/);
|
||||
assert.ok(Array.isArray(index.files) && index.files.length > 0);
|
||||
const names = new Set();
|
||||
for (const item of index.files) {
|
||||
assert.ok(typeof item.file === 'string' && !item.file.startsWith('/') && !item.file.includes('\\') && !item.file.split('/').some(part => !part || part === '.' || part === '..' || part.includes(':')), 'Invalid replay fixture path');
|
||||
assert.equal(names.has(item.file), false, 'Duplicate replay fixture'); names.add(item.file);
|
||||
assert.ok(Number.isSafeInteger(item.bytes) && item.bytes >= 0); assert.match(item.sha256, /^[a-f0-9]{64}$/);
|
||||
assert.ok(Array.isArray(item.originalSources) && item.originalSources.length > 0, 'Missing original replay provenance');
|
||||
for (const original of item.originalSources) { assert.match(original.sha256, /^[a-f0-9]{64}$/); assert.match(original.gitBlob, /^[a-f0-9]{40}$/); }
|
||||
}
|
||||
return { directory, file, index };
|
||||
}
|
||||
|
||||
export function replayFixtureBytes(name, root = sourceRoot) {
|
||||
const { directory, index } = inventory(root), item = index.files.find(value => value.file === name);
|
||||
assert.ok(item, 'Undeclared replay fixture: ' + name);
|
||||
const file = path.resolve(directory, item.file); assert.ok(file.startsWith(path.resolve(directory) + path.sep));
|
||||
const stat = fs.lstatSync(file); assert.ok(stat.isFile() && !stat.isSymbolicLink(), 'Replay fixture must be an ordinary file');
|
||||
const bytes = fs.readFileSync(file); assert.equal(bytes.length, item.bytes, 'Replay fixture bytes changed: ' + name);
|
||||
assert.equal(digest(bytes), item.sha256, 'Replay fixture SHA changed: ' + name);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
export function replayFixtureJson(name, root = sourceRoot) {
|
||||
const value = JSON.parse(replayFixtureBytes(name, root)); assert.equal(value.schemaVersion, 1); return value;
|
||||
}
|
||||
|
||||
export function verifyReplayFixtures(root = sourceRoot) {
|
||||
const { file, index } = inventory(root);
|
||||
for (const item of index.files) replayFixtureBytes(item.file, root);
|
||||
return { passed: true, files: index.files.length, bytes: index.files.reduce((total, item) => total + item.bytes, 0), indexSha256: fileDigest(file), sourceCommit: index.sourceCommit,
|
||||
scope: 'Declared minimal parsed historical inputs and exact locked public source bytes. Original archives are retained separately; no live model, engine dispatch or Purge benefit verification.' };
|
||||
}
|
||||
|
||||
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
||||
try {
|
||||
if (process.argv.length > 3) throw new Error('node scripts/verify-replay-fixtures.mjs [NEW_REPORT]');
|
||||
const result = verifyReplayFixtures(); if (process.argv[2]) writeNewJson(path.resolve(process.argv[2]), result); console.log(JSON.stringify(result));
|
||||
} catch (error) { console.error(error.stack); process.exitCode = 1; }
|
||||
}
|
||||
Reference in New Issue
Block a user