47 lines
3.4 KiB
JavaScript
47 lines
3.4 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import assert from 'node:assert/strict';
|
|
import { root, read, save, sha } from './common.mjs';
|
|
|
|
if (process.argv.includes('--verify')) {
|
|
const manifest = read('MANIFEST.json'), receipt = read('seal.json');
|
|
assert.equal(sha(fs.readFileSync(path.join(root, 'MANIFEST.json'))), receipt.manifestSha256);
|
|
for (const entry of manifest.entries) {
|
|
const bytes = fs.readFileSync(path.join(root, entry.path));
|
|
assert.equal(bytes.length, entry.bytes); assert.equal(sha(bytes), entry.sha256, entry.path);
|
|
}
|
|
assert.equal(manifest.entries.length, receipt.files);
|
|
assert.equal(manifest.entries.reduce((sum, value) => sum + value.bytes, 0), receipt.bytes);
|
|
console.log(JSON.stringify({ verified: true, files: receipt.files, bytes: receipt.bytes, manifestSha256: receipt.manifestSha256 }));
|
|
} else {
|
|
assert.equal(fs.existsSync(path.join(root, 'MANIFEST.json')), false, 'Never overwrite a sealed M4 root.');
|
|
const final = read('final-summary.json'); assert.equal(final.stage, 'final'); assert.equal(final.audit.success, true);
|
|
assert.equal(final.engineering.length, 3); assert.ok(final.engineering.every(value => value.success));
|
|
const entries = [], excluded = [];
|
|
const walk = relative => {
|
|
for (const entry of fs.readdirSync(path.join(root, relative), { withFileTypes: true })) {
|
|
const file = path.posix.join(relative.replaceAll('\\', '/'), entry.name);
|
|
if (entry.isDirectory() && entry.name === 'node_modules') {
|
|
const lockFile = path.join(root, relative, 'package-lock.json'); assert.ok(fs.existsSync(lockFile));
|
|
excluded.push({ path: file, scope: 'Reconstructible installed dependencies only; original package-lock and npm-ci log included.', lockSha256: sha(fs.readFileSync(lockFile)) });
|
|
continue;
|
|
}
|
|
assert.equal(entry.isSymbolicLink(), false, 'Evidence traversal does not follow links: ' + file);
|
|
if (entry.isDirectory()) walk(file);
|
|
else if (entry.isFile()) { const bytes = fs.readFileSync(path.join(root, file)); entries.push({ path: file, bytes: bytes.length, sha256: sha(bytes) }); }
|
|
else assert.fail('Unsupported evidence entry: ' + file);
|
|
}
|
|
};
|
|
walk(''); entries.sort((a, b) => a.path.localeCompare(b.path, 'en'));
|
|
const manifest = { schemaVersion: 1, batch: 'm4-live-baseline-2026-11-11', sealedAt: new Date().toISOString(),
|
|
scope: 'Original observations, failures, captures, audits, projects and Git, browser PNGs, machine summaries and retained ancillary observations. No real credential extraction.',
|
|
entries, excluded, selfAndReceipt: 'MANIFEST.json and seal.json created after entry hashing; their integrity is identified by the receipt.' };
|
|
save('MANIFEST.json', manifest);
|
|
const bytes = fs.readFileSync(path.join(root, 'MANIFEST.json')), receipt = { files: entries.length, bytes: entries.reduce((sum, value) => sum + value.bytes, 0),
|
|
manifestSha256: sha(bytes), manifestBytes: bytes.length, excluded, modelRequests: final.requests, reportedTotalTokens: final.reportedTotalTokens,
|
|
unknownRequests: final.unknownRequests, externalRequests: final.audit.externalModelRequests, keysReadOrResaved: false, oldSamplesReplayed: false, purgeExecuted: false };
|
|
save('seal.json', receipt);
|
|
fs.writeFileSync(path.resolve('docs/m4-live-seal-2026-11-11.json'), JSON.stringify(receipt, null, 2) + '\n', { flag: 'wx' });
|
|
console.log(JSON.stringify(receipt));
|
|
}
|