Files
Agent-Workbench/docs/verify-adoption-ab-release.mjs
2026-11-04 13:18:02 +08:00

149 lines
13 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert/strict';
import { createHash } from 'node:crypto';
import { execFileSync } from 'node:child_process';
// Offline only: no HTTP, installer, credential access or driver replay.
const root = path.resolve('docs/adoption-ab-release-evidence'), index = process.argv.includes('--index');
assert.ok(process.argv.slice(2).every(value => value === '--index'));
const hash = bytes => createHash('sha256').update(bytes).digest('hex');
const blob = bytes => createHash('sha1').update(Buffer.from('blob ' + bytes.length + '\0')).update(bytes).digest('hex');
const read = name => JSON.parse(fs.readFileSync(path.join(root, name), 'utf8').replace(/^\uFEFF/, ''));
const bytes = name => fs.readFileSync(path.join(root, name));
const manifest = read('manifest.json'), names = new Set(); let total = 0;
for (const row of manifest.entries) {
assert.ok(row.path && !row.path.includes('\\') && !row.path.split('/').includes('..') && !path.isAbsolute(row.path));
assert.equal(names.has(row.path), false); names.add(row.path);
const data = bytes(row.path); assert.equal(data.length, row.bytes); assert.equal(hash(data), row.sha256, row.path); total += data.length;
if (row.path.endsWith('.png')) assert.equal(data.subarray(0, 8).toString('hex'), '89504e470d0a1a0a');
if (/\.jpe?g$/.test(row.path)) assert.equal(data.subarray(0, 3).toString('hex'), 'ffd8ff');
}
const walk = directory => fs.readdirSync(directory, { withFileTypes: true }).flatMap(row => {
const file = path.join(directory, row.name); assert.equal(fs.lstatSync(file).isSymbolicLink(), false);
return row.isDirectory() ? walk(file) : [path.relative(root, file).replaceAll('\\', '/')];
});
assert.deepEqual(walk(root).filter(name => name !== 'manifest.json').sort(), [...names].sort());
assert.equal(manifest.count, names.size); assert.equal(manifest.bytes, total); assert.equal(manifest.realModelRequests, 0);
assert.equal(hash(fs.readFileSync('docs/verify-adoption-ab-release.mjs')), hash(bytes('receipts/verify-seal.mjs.txt')));
const freeze = read('receipts/freeze.json'), release = read('receipts/candidate.json'), identity = read('release-identity.json');
assert.equal(freeze.sourceCommit, manifest.sourceCommit); assert.equal(identity.sourceCommit, freeze.sourceCommit);
assert.equal(release.documentation.sourceCommit, freeze.sourceCommit); assert.equal(identity.version, '1.24.9');
assert.equal(identity.candidate, path.basename(release.portableRoot)); assert.equal(identity.formalPid, 36552);
assert.deepEqual(identity.installer, release.installer);
for (const kind of ['portable', 'source', 'evidence']) assert.deepEqual(identity.archives[kind], release[kind]);
const sourceTree = execFileSync('git', ['ls-tree', '-r', '-z', '--full-tree', freeze.sourceCommit, '--', 'src', 'public', 'scripts', 'tests', 'examples', 'benchmarks', 'research',
'package.json', 'package-lock.json', 'vite.config.ts', 'tsconfig.json', 'index.html', 'mobile.html'], { encoding: 'utf8', maxBuffer: 8 * 1024 * 1024 }).split('\0').filter(Boolean);
const sourceBlobs = new Map(sourceTree.map(row => { const [meta, file] = row.split('\t'); return [file, meta.split(' ')[2]]; }));
for (const row of freeze.inputs) {
const data = bytes('source-bytes/' + row.path); assert.equal(hash(data), row.sha256);
const oid = sourceBlobs.get(row.path); assert.ok(oid, row.path);
if (blob(data) !== oid) {
assert.equal(data.includes(0), false); assert.ok(Buffer.from(data.toString('utf8')).equals(data));
assert.equal(blob(Buffer.from(data.toString('utf8').replaceAll('\r\n', '\n'))), oid, row.path + ' fixed Git source');
}
}
for (const row of freeze.compiled) assert.equal(hash(bytes('compiled/' + row.path)), row.sha256);
assert.equal(hash(bytes('portable-manifest.json')), identity.portableManifestSha256);
assert.equal(hash(bytes('source-manifest.json')), identity.sourceManifestSha256);
const stages = ['rebuild', 'archives', 'portable', 'install', 'source-a', 'source-a-desktop', 'source-b', 'source-b-desktop', 'portable-a', 'portable-a-desktop', 'portable-b', 'portable-b-desktop', 'portable-files'];
for (const stage of stages) {
const receipt = read('receipts/receipts/' + stage + '.json'); assert.equal(receipt.success, true, stage);
assert.equal(receipt.sourceCommit, freeze.sourceCommit); assert.equal(receipt.candidate, release.portableRoot);
assert.equal(hash(bytes('receipts/logs/' + stage + '.log')), receipt.logSha256);
}
const build = read('validation/rebuild/result.json'); assert.equal(build.success, true); assert.equal(build.sourceCommit, freeze.sourceCommit);
assert.equal(build.compiled.length, freeze.compiled.length); assert.deepEqual(build.mismatches, []);
const frozenNames = new Set(freeze.inputs.map(row => row.path)), extras = build.inputs.filter(row => !frozenNames.has(row.path));
assert.equal(extras.length, 5); assert.equal(build.inputCount, freeze.inputs.length + extras.length);
for (const row of extras) { assert.ok(row.path.startsWith('examples/delivery-report/dist/')); assert.equal(hash(bytes('source-bytes/' + row.path)), row.sha256); }
for (const row of freeze.inputs) assert.equal(build.inputs.find(value => value.path === row.path)?.sha256, row.sha256, row.path);
for (const row of build.compiled) assert.deepEqual(row.actual, row.expected);
for (const kind of ['portable', 'source', 'evidence']) {
const archive = read('validation/archives.json').archives.find(row => row.kind === kind); assert.ok(archive.crcPassed && archive.manifestAndDirectoryMatch);
assert.equal(archive.sha256, identity.archives[kind].sha256);
}
assert.equal(read('validation/portable.json').success, true);
const installation = read('validation/install/result.json'); assert.equal(installation.success, true); assert.equal(installation.version, '1.24.9');
assert.equal(installation.results.length, 12); assert.ok(installation.results.every(row => row.passed));
assert.equal(installation.installedUI.proofs.length, 6); assert.equal(installation.realModelRequests, 0);
let uiRuns = 0, originalArtifacts = 0, originalSnapshots = 0;
for (const scope of ['source', 'portable', 'installed']) for (const [suite, count] of [['a', 7], ['a-desktop', 3], ['b', 9], ['b-desktop', 9]]) {
const directory = 'validation/' + scope + '-' + suite, proof = read(directory + '/result.json');
assert.equal(proof.success, true); assert.equal(proof.version, '1.24.9'); assert.equal(proof.passed.length, count);
assert.equal(proof.realModelRequests, 0); assert.deepEqual(proof.errors, []); uiRuns++;
if (scope === 'portable') assert.equal(proof.appRoot, release.portableRoot);
if (scope === 'installed') assert.equal(proof.appRoot, installation.installedUI.installedRoot);
if (!suite.startsWith('b')) continue;
const artifacts = new Map(read(directory + '/source-artifacts.json').map(row => [row.id, row]));
const artifact = id => {
const row = artifacts.get(id); assert.ok(row, id); const data = bytes(directory + '/' + row.path);
assert.equal(hash(data), row.sha256); assert.equal(data.length, row.bytes); return { row, data };
};
for (const id of artifacts.keys()) { artifact(id); originalArtifacts++; }
for (const file of proof.snapshots) {
const snapshot = read(directory + '/' + file), { session, execution } = snapshot, run = execution.run, shadow = run.progressShadow; originalSnapshots++;
assert.equal(shadow.mode, 'shadow'); assert.deepEqual(shadow.scope, { projectId: session.projectId, sessionId: session.id, taskId: run.taskId, runId: run.id });
assert.equal(shadow.turns.length, run.progressShadowArtifactIds.length);
for (const [i, turn] of shadow.turns.entries()) {
const original = artifact(run.progressShadowArtifactIds[i]); assert.equal(original.row.kind, 'turn-progress-shadow');
assert.deepEqual(JSON.parse(original.data), turn); assert.equal(turn.taskId, run.taskId); assert.equal(turn.runId, run.id);
for (const ref of turn.tools) {
if (ref.tool === 'model_request') {
const event = session.events.find(row => row.id === ref.source_event_id && row.runId === run.id); assert.ok(event?.diagnostic);
assert.equal(hash(JSON.stringify(event.diagnostic)), ref.diagnostic_sha256);
} else {
const event = session.events.find(row => row.invocationId === ref.id && row.runId === run.id && row.taskId === run.taskId);
assert.ok(event); assert.equal(event.tool, ref.tool); assert.equal(event.artifactId, ref.result_artifact_id);
const call = session.providerMessages.flatMap(row => row.tool_calls ?? []).find(row => row.id === event.toolCallId); assert.ok(call);
assert.equal(call.function.name, ref.tool); assert.equal(hash(String(call.function.arguments)), ref.args_sha256);
}
if (ref.result_artifact_id) assert.equal(artifact(ref.result_artifact_id).row.sha256, ref.result_sha256);
}
}
}
}
for (const [scope, suite, count] of [['portable', 'files', 9], ['installed', 'files', 9], ['installed', 'results', 16]]) {
const proof = read('validation/' + scope + '-' + suite + '/result.json'); assert.equal(proof.success, true); assert.equal(proof.checks.length, count); assert.deepEqual(proof.errors, []);
}
const initial = read('receipts/formal/state-before.json');
assert.equal(initial.version, '1.24.8'); assert.equal(initial.hasKey, true);
for (const stage of ['upgrade', 'final']) {
const proof = read('receipts/formal/' + stage + '.json'); assert.equal(proof.success, true); assert.equal(proof.version, '1.24.9');
assert.equal(proof.pid, 36552); assert.equal(proof.inspectorClosed, true); assert.equal(proof.desktopWindows, 0);
assert.equal(proof.realModelRequests, 0); assert.equal(proof.keyReadOrResaved, false);
assert.deepEqual(proof.retention, { originalRows: 'exact', originalExports: 'exact', originalArtifactBytes: 'exact', originalModelCenter: 'exact' });
assert.equal(proof.runtimeRoot, identity.formalRuntimeRoot); assert.equal(proof.operation.state, 'completed');
const after = read('receipts/formal/' + stage + '-state-after.json');
for (const key of ['pid', 'hasKey', 'configSha256', 'projectsSha256', 'sessionsSha256', 'eventCursor', 'exports', 'persistent', 'modelCenterSha256']) assert.deepEqual(after[key], initial[key], key);
assert.deepEqual(after.database.tables, initial.database.tables); assert.deepEqual(after.database.sessionIds, initial.database.sessionIds);
}
assert.equal(read('receipts/formal/before.json').success, false); assert.equal(read('receipts/formal/before-recheck.json').success, true);
assert.equal(read('receipts/formal/installer-exit.json').code, 0);
const web = read('receipts/review/result.json'), native = read('receipts/native/result.json');
for (const proof of [web, native]) { assert.equal(proof.success, true); assert.equal(proof.version, '1.24.9'); assert.equal(proof.pid, 36552); assert.equal(proof.realModelRequests, 0); }
assert.deepEqual(web.errors, []); assert.deepEqual(web.rejectedWrites, []);
assert.deepEqual(web.views.map(row => [row.width, row.height, row.requirementItems, row.legacyShadowPanels]), [[1440, 1080, 0, 0], [390, 844, 0, 0]]);
for (const row of native.screenshots) { const data = bytes('receipts/native/' + row.path); assert.equal(data.length, row.bytes); assert.equal(hash(data), row.sha256); }
assert.match(bytes('receipts/native/main.txt').toString('utf8'), /release=1\.24\.9/);
assert.match(bytes('receipts/native/requirements.txt').toString('utf8'), /尚未逐项记录要求。模型的完成答复保留在原会话中。/);
const cost = read('receipts/update-cost.json'), operation = read('receipts/formal/upgrade.json').operation;
assert.equal(cost.operationElapsedMs, Date.parse(operation.updatedAt) - Date.parse(operation.startedAt));
assert.equal(cost.historyElapsedMs, operation.history.reduce((sum, row) => sum + row.elapsedMs, 0));
const first = bytes('receipts/related-first.tap').toString('utf8'); assert.match(first, /pass 52\b/); assert.match(first, /fail 1\b/); assert.match(first, /cancelled 1\b/);
for (const [file, count] of [['turn-progress-serial.tap', 15], ['upgrade-serial.tap', 2]]) {
const log = bytes('receipts/' + file).toString('utf8'); assert.match(log, new RegExp('pass ' + count + '\\b')); assert.match(log, /fail 0\b/); assert.match(log, /cancelled 0\b/);
}
assert.equal(read('validation/first-b-desktop/result.json').success, false);
for (const ref of read('original-references.json')) assert.equal(hash(fs.readFileSync(ref.path)), ref.sha256, ref.path);
if (index) {
const rows = execFileSync('git', ['ls-files', '--stage', '-z', '--', 'docs/adoption-ab-release-evidence'], { encoding: 'utf8', maxBuffer: 8 * 1024 * 1024 }).split('\0').filter(Boolean);
const blobs = new Map(rows.map(row => { const [meta, file] = row.split('\t'); return [file, meta.split(' ')[1]]; }));
for (const name of [...names, 'manifest.json']) {
const data = bytes(name), oid = blob(data);
assert.equal(blobs.get('docs/adoption-ab-release-evidence/' + name), oid, name + ' indexed bytes');
}
}
console.log(JSON.stringify({ success: true, files: names.size, bytes: total, sourceCommit: freeze.sourceCommit, inputs: freeze.inputs.length, compiled: freeze.compiled.length,
independentInputs: build.inputCount, uiRuns, originalArtifacts, originalSnapshots, isolatedInstallGroups: 12, realModelRequests: 0, indexChecked: index }));