Files
Agent-Workbench/scripts/verify-original-purge-release-evidence.mjs
T

90 lines
6.8 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert/strict';
import { createHash } from 'node:crypto';
// Offline verification only: no Provider, desktop input, plugin or network.
const root = path.resolve('docs/original-purge-release-f-evidence');
const sha = bytes => createHash('sha256').update(bytes).digest('hex');
function raw(relative) {
const file = path.resolve(root, relative);
assert.ok(file.startsWith(root + path.sep), 'Evidence stays within the sealed directory.');
return fs.readFileSync(file);
}
const read = relative => JSON.parse(raw(relative));
const manifest = read('manifest.json');
assert.equal(manifest.schemaVersion, 1); assert.equal(manifest.slice, 'original-purge-local-release-f');
assert.equal(manifest.version, '1.24.0'); assert.equal(manifest.realModelRequests, 0);
const names = new Set(), files = new Map();
for (const entry of manifest.entries) {
assert.equal(names.has(entry.name), false); names.add(entry.name);
const bytes = raw(entry.file); assert.equal(bytes.length, entry.bytes, entry.name); assert.equal(sha(bytes), entry.sha256, entry.name);
if (files.has(entry.file)) assert.equal(files.get(entry.file), entry.sha256);
files.set(entry.file, entry.sha256);
}
assert.equal(files.size, manifest.count);
assert.equal([...files.keys()].reduce((sum, file) => sum + raw(file).length, 0), manifest.bytes);
assert.equal(sha(fs.readFileSync(manifest.dManifest)), manifest.dManifestSha256);
assert.equal(sha(fs.readFileSync(manifest.eManifest)), manifest.eManifestSha256);
const d = JSON.parse(fs.readFileSync(manifest.dManifest)), e = JSON.parse(fs.readFileSync(manifest.eManifest));
assert.equal(e.requests, 52); assert.equal(e.reportedTokens, 621486); assert.equal(e.unknownRequests, 0);
assert.deepEqual(manifest.sourceInputs, d.sourceInputs.map(({ path, bytes, sha256 }) => ({ path, bytes, sha256 })));
const selected = key => read(manifest.selected[key]);
const release = selected('release.json'), preflight = selected('preflight.json');
assert.equal(release.documentation.sourceCommit, manifest.sourceCommit);
assert.equal(path.basename(release.portableRoot), manifest.candidate); assert.equal(preflight.success, true);
const rebuilt = selected('rebuild');
assert.equal(rebuilt.success, true); assert.equal(rebuilt.sourceZip.sha256, release.source.sha256);
assert.equal(rebuilt.sourceCommit, manifest.sourceCommit); assert.equal(rebuilt.compiled.length, 22); assert.deepEqual(rebuilt.mismatches, []);
assert.equal(rebuilt.realModelRequests, 0);
const portableManifest = selected('portableManifest'), portableFiles = new Map(portableManifest.files.map(file => [file.path, file]));
const changed = [];
for (const item of manifest.lineage) {
const old = d.buildInputs.find(old => old.path === item.path); assert.ok(old, item.path);
assert.deepEqual(item.originalD, { bytes: old.bytes, sha256: old.sha256 });
const portable = portableFiles.get(item.path); assert.ok(portable);
const built = rebuilt.compiled.find(file => file.path === item.path); assert.ok(built);
assert.deepEqual(built.expected, built.actual);
assert.deepEqual(built.actual, { bytes: portable.bytes, sha256: portable.sha256 });
assert.equal(item.sha256, portable.sha256); assert.equal(item.bytes, portable.bytes);
if (item.sha256 !== old.sha256) changed.push(item.path);
}
assert.deepEqual(changed, ['dist-server/install-manager.mjs']);
const rejected = selected('negativeRebuild');
assert.equal(rejected.success, false); assert.equal(rejected.mismatches.length, 1);
assert.equal(rejected.mismatches[0].path, changed[0]);
const archives = selected('archives'); assert.equal(archives.success, true); assert.equal(archives.archives.length, 3);
for (const archive of archives.archives) {
assert.equal(archive.sha256, release[archive.kind].sha256); assert.equal(archive.crcPassed, true); assert.equal(archive.manifestAndDirectoryMatch, true);
}
const portable = selected('portable'); assert.equal(portable.success, true); assert.equal(portable.appRoot, release.portableRoot);
assert.equal(portable.realModel, false);
const installation = selected('installation');
assert.equal(installation.success, true); assert.equal(installation.realModelRequests, 0); assert.equal(installation.results.length, 12);
assert.equal(installation.packagedSource, path.resolve(release.portableRoot)); assert.ok(installation.results.every(result => result.passed));
for (const phase of ['before.json', 'install.json', 'final.json']) assert.equal(selected(phase).success, true);
const final = selected('final.json');
assert.equal(final.pid, 36552); assert.equal(final.hasKey, true); assert.equal(final.realModelRequests, 0); assert.equal(final.inspectorClosed, true);
assert.deepEqual(final.retained, { originalRows: 'exact', originalExports: 'exact', originalArtifactBytes: 'exact', originalModelCenter: 'exact' });
assert.equal(final.pointer.active.directory, manifest.candidate);
assert.equal(final.pointer.active.manifestSha256, sha(raw(manifest.selected.portableManifest)));
assert.equal(final.operation.state, 'completed'); assert.equal(final.desktopWindows, 0);
assert.equal(final.nativeWindowReview.status, 'not_performed'); assert.deepEqual(final.nativeWindowReview, manifest.nativeWindowReview);
assert.equal(selected('nativeStop').fallbackUIInput, false);
assert.equal(final.availability.status, 'available'); assert.equal(final.purge.status, 'available');
const identity = JSON.parse(fs.readFileSync('docs/original-purge-release-identity.json'));
assert.equal(identity.sourceCommit, manifest.sourceCommit); assert.equal(identity.candidate, manifest.candidate);
assert.equal(identity.evidence.sha256, sha(raw('manifest.json'))); assert.equal(identity.evidence.files, manifest.count);
assert.equal(identity.manifestSha256, final.identity.manifestSha256); assert.equal(identity.runtimeIdentity, final.identity.identitySha256);
assert.deepEqual(identity.formalNativeWindowReview, final.nativeWindowReview); assert.deepEqual(identity.counts, final.counts);
const audit = selected('efficiency-audit-v3.json');
assert.equal(audit.manifestSha256, manifest.eManifestSha256); assert.equal(audit.realModelRequests, 0);
const react = audit.reports.find(sample => sample.name === 'react');
assert.equal(react.pages.length, 11);
assert.equal(react.pages.filter(page => page.alreadyCovered && page.nextOffset > page.offset).length, 4);
assert.equal(react.pages.filter(page => page.nextOffset === page.offset).length, 1);
assert.deepEqual(react.requests.slice(6).map(request => request.completeSource.filter(file => file.retained).length), [6, 5, 5, 4, 2, 2]);
console.log(JSON.stringify({ success: true, slice: manifest.slice, candidate: manifest.candidate, files: manifest.count, bytes: manifest.bytes,
sourceInputs: manifest.sourceInputs.length, compiled: rebuilt.compiled.length, isolatedInstallerGroups: installation.results.length,
originalState: final.retained, nativeWindowReview: 'not_performed', realModelRequests: 0 }));