Files
Agent-Workbench/scripts/verify-delivery-reliability-evidence.mjs
2026-11-03 07:58:13 +08:00

84 lines
7.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert/strict';
import { createHash } from 'node:crypto';
import { requestMetrics } from '../src/shared/contracts/model-request.mjs';
if (process.argv.includes('--help')) {
console.log('node scripts/verify-delivery-reliability-evidence.mjs — offline verify sealed G bytes, exact original/fixed context, frozen regression, UI/rebuild/installation receipts and preserved state. No model or host calls.');
process.exit(0);
}
assert.equal(process.argv.length, 2);
const root = path.resolve('docs/delivery-reliability-g-evidence');
const hash = bytes => createHash('sha256').update(bytes).digest('hex');
const read = file => JSON.parse(fs.readFileSync(path.join(root, file), 'utf8'));
const manifestBytes = fs.readFileSync(path.join(root, 'manifest.json')), manifest = JSON.parse(manifestBytes);
assert.equal(manifest.schemaVersion, 1); assert.equal(manifest.version, '1.24.1');
assert.match(manifest.sourceCommit, /^[a-f0-9]{40}$/);
const paths = new Set(); let bytes = 0;
for (const entry of manifest.entries) {
assert.ok(!paths.has(entry.path)); paths.add(entry.path);
const target = path.resolve(root, entry.path); assert.ok(target.startsWith(root + path.sep));
const raw = fs.readFileSync(target); assert.equal(raw.length, entry.bytes, entry.path); assert.equal(hash(raw), entry.sha256, entry.path); bytes += raw.length;
}
assert.equal(hash(fs.readFileSync('docs/live-original-purge-e-evidence/manifest.json')), manifest.originalEManifestSha256);
assert.equal(hash(fs.readFileSync('docs/original-purge-release-f-evidence/manifest.json')), manifest.originalFManifestSha256);
const tap = fs.readFileSync(path.join(root, manifest.checks.regression), 'utf8');
const total = Number(tap.match(/ℹ tests (\d+)/)?.[1]), passed = Number(tap.match(/ℹ pass (\d+)/)?.[1]), failed = Number(tap.match(/ℹ fail (\d+)/)?.[1]);
assert.equal(total, 155); assert.equal(total, passed); assert.equal(failed, 0);
function strings(value, output = [], depth = 0) {
if (depth > 12) return output;
if (typeof value === 'string') {
output.push(value);
for (const text of new Set([value, ...value.split('\n').filter(line => /^\s*[\[{]/.test(line))])) {
try { strings(JSON.parse(text), output, depth + 1); } catch {}
}
} else if (value && typeof value === 'object') for (const item of Object.values(value)) strings(item, output, depth + 1);
return output;
}
const before = read('context/before/result.json'), after = read('context/final/result.json');
assert.equal(before.manifestSha256, manifest.originalEManifestSha256); assert.equal(after.manifestSha256, before.manifestSha256);
assert.equal(after.realModelRequests, 0); assert.equal(before.realModelRequests, 0);
assert.deepEqual(before.reports.map(report => report.sources.filter(source => source.retained).length), [6, 5, 5, 4, 2, 2]);
for (const [index, report] of after.reports.entries()) {
assert.equal(report.sources.length, 6); assert.ok(report.sources.every(source => source.retained));
assert.equal(report.inputBudget, before.reports[index].inputBudget); assert.equal(report.softTarget, 16000);
const original = read('context/before/request-' + report.request + '.json');
const fixed = read('context/final/request-' + report.request + '.json');
assert.equal(requestMetrics(original.body).estimatedInputTokens, before.reports[index].originalInputTokens);
const metrics = requestMetrics(fixed.body); assert.equal(metrics.estimatedInputTokens, report.inputTokens); assert.ok(metrics.estimatedInputTokens <= report.inputBudget);
assert.equal(metrics.sha256, fixed.plan.requestSha256);
assert.deepEqual(fixed.body.messages[0], original.body.messages[0], 'Complete original fixed goal/context');
assert.deepEqual(fixed.body.variants.map(route => route.body.tools), original.body.variants.map(route => route.body.tools), 'Original complete tools');
for (const source of report.sources) {
const raw = fs.readFileSync(path.join('docs/live-original-purge-e-evidence/baselines/react', source.path), 'utf8');
assert.equal(raw.length, source.characters); assert.ok(strings(fixed.body.messages).includes(raw), source.path);
}
}
for (const key of ['sourceUI', 'portableUI']) {
const ui = read(manifest.checks[key]); assert.equal(ui.success, true); assert.equal(ui.version, manifest.version);
assert.equal(ui.realModelRequests, 0); assert.equal(ui.fixtureRequests, 5); assert.equal(ui.checks.length, 10); assert.deepEqual(ui.errors, []);
for (const file of ui.screenshots) assert.ok(paths.has(path.posix.join(path.posix.dirname(manifest.checks[key]), path.basename(file))));
}
const release = read(manifest.checks.release), rebuild = read(manifest.checks.rebuild), archives = read(manifest.checks.archives), portable = read(manifest.checks.portable), install = read(manifest.checks.installer);
assert.equal(release.documentation.sourceCommit, manifest.sourceCommit);
assert.equal(rebuild.success, true); assert.equal(rebuild.sourceCommit, manifest.sourceCommit); assert.equal(rebuild.sourceZip.sha256, release.source.sha256);
assert.equal(rebuild.compiled.length, 22); assert.deepEqual(rebuild.mismatches, []);
assert.equal(archives.success, true); assert.equal(archives.version, manifest.version); assert.equal(archives.archives.length, 3);
for (const archive of [release.portable, release.source, release.evidence]) assert.ok(archives.archives.some(record => record.sha256 === archive.sha256));
assert.equal(portable.success, true); assert.equal(portable.version, manifest.version); assert.equal(portable.realModel, false);
assert.ok(portable.actualRea.length > 0); assert.ok(portable.actualEngine); assert.ok(portable.actualControlled); assert.ok(portable.actualBrowser);
assert.equal(install.success, true); assert.equal(install.version, manifest.version); assert.equal(install.realModelRequests, 0);
assert.equal(install.results.length, 12); assert.ok(install.results.every(result => result.passed));
for (const key of ['formalInstall', 'formalFinal']) {
const record = read(manifest.checks[key]); assert.equal(record.success, true); assert.equal(record.version, manifest.version);
assert.equal(record.sourceCommit, manifest.sourceCommit); assert.equal(record.pid, 36552); assert.equal(record.hasKey, true);
assert.equal(record.retention.originalRows, 'exact'); assert.equal(record.retention.originalExports, 'exact');
assert.equal(record.retention.originalArtifactBytes, 'exact'); assert.equal(record.retention.originalModelCenter, 'exact');
assert.equal(record.operation.state, 'completed'); assert.equal(record.inspectorClosed, true); assert.equal(record.realModelRequests, 0);
}
console.log(JSON.stringify({ success: true, version: manifest.version, sourceCommit: manifest.sourceCommit,
files: paths.size, bytes, manifestSha256: hash(manifestBytes), regression: { total, passed, failed },
originalRetained: before.reports.map(report => report.sources.filter(source => source.retained).length), fixedRetained: after.reports.map(report => report.sources.filter(source => source.retained).length),
compiledFiles: rebuild.compiled.length, uiGroups: 20, realModelRequests: 0, scope: 'Offline sealed-byte and actual-receipt verification. No new model calls, task execution, or claim of real-model/Purge success.' }));