import assert from 'node:assert/strict'; import { createHash } from 'node:crypto'; import { readFileSync } from 'node:fs'; import { execFileSync } from 'node:child_process'; import { fileURLToPath } from 'node:url'; // A later, offline reproduction tool. The historical verifier and verdicts stay unchanged. const read = (name) => JSON.parse(readFileSync(new URL(name, import.meta.url), 'utf8')); const hash = (value) => createHash('sha256').update(value).digest('hex'); const canonical = (value) => Array.isArray(value) ? `[${value.map(canonical).join(',')}]` : value !== null && typeof value === 'object' ? `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonical(value[key])}`).join(',')}}` : JSON.stringify(value); const result = read('result.json'); const manifest = read('manifest.json'); const answers = read('final-answers.json').answers; assert.deepEqual(manifest, result.manifest); assert.equal(hash(canonical(manifest)), result.manifestHash); assert.equal(manifest.verifier.version, '1'); assert.equal(manifest.verifier.controls.length, 4); assert.equal(result.trials.length, 8); assert.equal(answers.length, 8); assert.equal(new Set(answers.map((answer) => answer.trialId)).size, 8); const verify = (output) => JSON.parse(execFileSync(process.execPath, [fileURLToPath(new URL('verify.mjs', import.meta.url))], { input: JSON.stringify({ output }), encoding: 'utf8', timeout: 5000, maxBuffer: 100000 })); const controls = manifest.verifier.controls.map((control) => { const verdict = verify(control.output); assert.equal(verdict.passed, control.expectedPass, control.id); return { id: control.id, expectedPass: control.expectedPass, passed: verdict.passed }; }); const trials = result.trials.map((trial) => { const answer = answers.find((item) => item.trialId === trial.id); assert(answer, `Missing answer: ${trial.id}`); assert.equal(answer.outputHash, trial.outputHash); assert.equal(hash(answer.output), trial.outputHash, trial.id); const verdict = verify(answer.output); assert.deepEqual(verdict, trial.verification, trial.id); assert.equal(trial.status, verdict.passed ? 'passed' : 'failed'); return { id: trial.id, variant: trial.variant, passed: verdict.passed }; }); const equivalent = JSON.parse(answers[0].output); equivalent['ledger.csv'] = equivalent['ledger.csv'].replace('3000,3000', '03000,3000'); assert.notEqual(equivalent['ledger.csv'], JSON.parse(answers[0].output)['ledger.csv']); assert.equal(verify(JSON.stringify(equivalent)).passed, false); const counts = Object.fromEntries(['baseline', 'candidate'].map((variant) => [variant, { planned: trials.filter((trial) => trial.variant === variant).length, passed: trials.filter((trial) => trial.variant === variant && trial.passed).length, }])); assert.deepEqual(counts, { baseline: { planned: 4, passed: 4 }, candidate: { planned: 4, passed: 4 } }); console.log(JSON.stringify({ schemaVersion: '1', mode: 'offline-replay', verifierVersion: '1', controls, trials, counts, knownLimitation: 'Version 1 rejects an equivalent leading-zero money cell. Version 2 fixes that serialization defect; this replay preserves version 1.', scope: 'Replays recorded final answers and four declared controls. No agent execution, complete-context attestation, causal effect or dollar-cost measurement.', }, null, 2));