Files
Agent-Workbench/docs/embedded-browser-release-evidence/verifiers/seal-embedded-browser-d-release.mjs
T

188 lines
19 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert/strict';
import { createHash } from 'node:crypto';
const prefix = '.qa/embedded-browser-d-', root = 'docs/embedded-browser-release-evidence';
const read = file => JSON.parse(fs.readFileSync(file, 'utf8'));
const hash = bytes => createHash('sha256').update(bytes).digest('hex');
const independent = read(prefix + 'independent-continuation-result.json'), binding = read(prefix + 'package-binding.json');
const allUi = read(prefix + 'all-ui-original-result.json'), source = read(prefix + 'source-original-result.json');
const formal = read(prefix + 'formal-verify.json'), native = read(prefix + 'native-ui.json');
const ui = read(prefix + 'formal-ui-validation.json'), promotion = read(prefix + 'promotion-result.json');
const nativeBinding = read(prefix + 'native-input-binding.json');
for (const value of [independent, binding, allUi, source, formal, native, ui, promotion]) assert.equal(value.success, true);
assert.equal(independent.version, '1.22.0'); assert.equal(independent.codeCommit, binding.sourceCommit);
assert.equal(independent.release.installer.sha256, binding.setupSha256);
assert.equal(allUi.results.length, 33); assert.equal(allUi.groups, allUi.results.reduce((sum, row) => sum + row.groups, 0));
assert.equal(source.tests.tests, source.tests.pass);
for (const name of ['fail', 'cancelled', 'skipped', 'todo']) assert.equal(source.tests[name], 0);
assert.equal(source.actualEmbeddedBrowser.checks.length, 17);
assert.equal(native.actualInstalledElectron, true); assert.equal(native.results.length, 4);
assert.equal(nativeBinding.success, true); assert.equal(nativeBinding.sourceCommit, binding.sourceCommit); assert.deepEqual(nativeBinding.differences, []);
assert.equal(fs.existsSync(root), false);
const files = [], pending = [], appendedLogs = [];
function copy(from, to, expectedSha = null) {
assert.ok(!/\.sqlite(?:-|$)/i.test(from), 'Private SQLite excluded');
assert.ok(!/formal-(?:before|after-|original-pointer|original\.sqlite)/i.test(path.basename(from)), 'Private full production snapshots excluded');
assert.ok(!files.some(row => row.path === to), 'Duplicate evidence target ' + to);
const bytes = fs.readFileSync(from); if (expectedSha) assert.equal(hash(bytes), expectedSha, from);
files.push({ path: to, source: from, bytes: bytes.length, sha256: hash(bytes) });
pending.push({ target: path.join(root, to), bytes });
}
function receiptLog(from, to, expectedSha) {
const bytes = fs.readFileSync(from); if (hash(bytes) === expectedSha) { copy(from, to, expectedSha); return; }
const streaming = createHash('sha256'); let offset = 0, original = null;
for (let end = bytes.indexOf(10); end >= 0 && !original; end = bytes.indexOf(10, end + 1)) {
for (const cut of [end + 1, ...(bytes[end + 1] === 0 ? [end + 2] : [])]) {
streaming.update(bytes.subarray(offset, cut)); offset = cut;
if (streaming.copy().digest('hex') === expectedSha) { original = bytes.subarray(0, cut); break; }
}
}
assert.ok(original, 'Changed log must preserve complete original receipt prefix: ' + from);
const target = to + '.receipt-prefix';
assert.ok(!files.some(row => row.path === target));
files.push({ path: target, source: from + ' [exact original receipt prefix]', bytes: original.length, sha256: expectedSha });
pending.push({ target: path.join(root, target), bytes: original }); copy(from, to);
appendedLogs.push({ source: from, originalReceiptSha256: expectedSha, originalBytes: original.length, completeBytes: bytes.length, completeSha256: hash(bytes), appendedBytes: bytes.length - original.length });
}
const suites = new Map();
function archiveUi(name, value, hintDirectory = null) {
assert.ok(value); assert.notEqual(value.success, false); assert.notEqual(value.passed, false);
const screenshotRows = Array.isArray(value.screenshots) ? value.screenshots : [];
const firstScreenshot = screenshotRows[0];
const firstFile = typeof firstScreenshot === 'string' ? firstScreenshot : firstScreenshot?.file ?? firstScreenshot?.path ?? firstScreenshot?.screenshot;
const explicitDirectory = value.directory ?? hintDirectory ?? value.root;
const directory = explicitDirectory ?? (firstFile && fs.existsSync(firstFile) ? path.dirname(firstFile) : null);
if (!directory) return;
const actual = fs.realpathSync.native(directory);
if (suites.has(name)) return;
suites.set(name, actual);
const original = path.join(directory, 'result.json');
if (explicitDirectory && fs.existsSync(original)) { assert.deepEqual(read(original), value); copy(original, name + '/result.json'); }
for (const row of screenshotRows) {
const declared = typeof row === 'string' ? row : row.file ?? row.path ?? row.screenshot;
if (!declared) continue;
const file = fs.existsSync(declared) ? declared : path.join(directory, declared);
assert.ok(fs.existsSync(file), 'Original UI screenshot required: ' + file);
copy(file, name + '/' + path.basename(file), row.sha256 ?? row.screenshotSha256);
}
for (const entry of explicitDirectory ? fs.readdirSync(directory, { withFileTypes: true }) : []) {
if (!entry.isFile() || !/\.(?:png|jpg|html)$/.test(entry.name)) continue;
const target = name + '/' + entry.name;
if (!files.some(row => row.path === target)) copy(path.join(directory, entry.name), target);
}
const inputs = path.join(directory, 'inputs.json'); if (explicitDirectory && fs.existsSync(inputs)) copy(inputs, name + '/inputs.json');
}
for (const name of ['code-baseline', 'independent-result', 'independent-continuation-result', 'continuation-stage-binding', 'package-binding', 'source-short-path', 'source-original-result', 'archives-original-result', 'portable-original-result', 'owned-upgrade', 'owned-upgrade-continuation', 'promotion-result', 'formal-stage', 'formal-upgrade', 'formal-activate', 'formal-verify', 'install-syntax-check', 'legacy-report-retention', 'native-input-binding', 'ui-evidence-preflight']) copy(prefix + name + '.json', 'receipts/' + name + '.json');
for (const row of independent.completed) {
assert.equal(row.exitCode, 0); copy(row.logPath, 'pipeline/' + path.basename(row.logPath), row.logSha256);
copy(prefix + row.name + '-receipt.json', 'receipts/' + row.name + '-receipt.json');
}
for (const row of promotion.completed) {
assert.equal(row.exitCode, 0); copy(row.log, 'promotion/' + path.basename(row.log), row.logSha256);
copy(prefix + row.name + '-outer-receipt.json', 'receipts/' + row.name + '-outer-receipt.json');
}
for (const row of source.logs) { assert.equal(fs.statSync(row.path).size, row.bytes); copy(row.path, 'source/' + path.basename(row.path), row.sha256); }
assert.deepEqual(source.testPlan.flatMap(row => row.files).slice().sort(), fs.readdirSync(path.join(source.sourceRoot, 'tests')).filter(name => name.endsWith('.test.mjs')).sort());
copy(path.join(source.directory, 'test-plan.json'), 'source/test-plan.json');
copy(prefix + 'all-ui-original-result.json', 'historical-ui/result.json');
for (const row of allUi.results) {
const name = path.basename(row.script, '.mjs'); copy(row.evidence, 'historical-ui/' + name + '.json'); copy(row.log, 'historical-ui/' + name + '.log');
const value = read(row.evidence), output = fs.readFileSync(row.log, 'utf8');
const location = [...output.matchAll(/^EVIDENCE (.+)\r?$/gm)].at(-1)?.[1]?.trim() ?? null;
archiveUi('historical-ui/' + name, value, location);
}
for (const name of ['embedded-browser', 'environment', 'fidelity', 'wait', 'companion', 'protocols', 'vision', 'cache', 'evaluations']) {
const proof = read(prefix + 'portable-' + name + '-validated.json'); assert.equal(proof.success, true);
assert.equal(hash(fs.readFileSync(path.join(proof.directory, 'result.json'))), proof.resultSha256);
copy(prefix + 'portable-' + name + '-validated.json', 'receipts/portable-' + name + '-validated.json');
archiveUi('portable-' + name, read(path.join(proof.directory, 'result.json')));
}
for (const [name, value] of [['source-browser', source.actualEmbeddedBrowser], ['source-environment', source.actualEnvironment], ['source-companion', source.actualCompanion], ['source-protocols', source.actualProtocols], ['source-vision', source.actualVision], ['source-cache', source.actualProjectCache], ['source-evaluations', source.actualEvaluations]]) archiveUi(name, value);
for (const [name, value] of [['formal-ui', ui], ['native-ui', native]]) {
copy(prefix + (name === 'formal-ui' ? 'formal-ui-validation' : 'native-ui') + '.json', name + '/result.json');
for (const row of value.screenshots ?? value.results) {
const file = row.file ?? row.path ?? row.screenshot;
if (file) copy(file, name + '/' + path.basename(file), row.sha256 ?? row.screenshotSha256);
}
}
const installation = read(prefix + 'install-location.json'), installed = read(installation.result);
assert.equal(installed.success, true); assert.equal(installed.cases.length, 7); copy(installation.result, 'installation/result.json');
copy(prefix + 'qa-installer.json', 'installation/same-payload-installer.json');
for (const [index, row] of installed.cases.entries()) {
for (const key of ['processLog', 'setupLog', 'uninstallLog']) if (row[key]) receiptLog(row[key], 'installation/logs/' + String(index).padStart(2, '0') + '-' + path.basename(row[key]), row[key + 'Sha256']);
if (row.embeddedBrowser) {
assert.equal(row.embeddedBrowser.groups, 17);
assert.equal(hash(fs.readFileSync(path.join(row.embeddedBrowser.directory, 'result.json'))), row.embeddedBrowser.resultSha256);
copy(row.embeddedBrowser.log, 'installation/actual-browser.log', row.embeddedBrowser.logSha256);
archiveUi('installed-browser', read(path.join(row.embeddedBrowser.directory, 'result.json')));
}
}
assert.ok(installed.cases.some(row => row.embeddedBrowser?.groups === 17));
const staged = read(prefix + 'formal-stage.json'); receiptLog(staged.setupLog, 'promotion/formal-setup.log', staged.setupLogSha256);
for (const name of ['independent', 'independent-continuation', 'continuation-orchestrate', 'state', 'owned-upgrade-continuation', 'prepare-installer', 'bind-package', 'bind-native-review', 'owned-upgrade', 'formal', 'promotion', 'install-syntax-check', 'retain-legacy-report', 'review-timings', 'finalize-docs', 'final-audit', 'status', 'ui-evidence-preflight']) {
const file = name === 'retain-legacy-report' ? '.qa/retain-embedded-browser-d-legacy-report.mjs' : prefix + name + '.mjs';
copy(file, 'verifiers/' + name + '.mjs');
}
for (const name of ['prepare-embedded-browser-formal-ui', 'prepare-embedded-browser-promotion', 'verify-embedded-browser-d-formal-ui', 'verify-embedded-browser-d-native-ui', 'verify-embedded-browser-d-install', 'desktop-f-state', 'seal-embedded-browser-d-release']) copy('.qa/' + name + '.mjs', 'verifiers/' + name + '.mjs');
copy(prefix + 'source-test-inheritance.json','review/source-test-inheritance.json');
copy('.qa/verify-embedded-browser-d-state.mjs','verifiers/verify-state.mjs');
copy(prefix+'state-checks.json','review/state-checks.json');
const rejectedAcceptance=prefix+'rejected-acceptance';
copy(rejectedAcceptance+'/manifest.json','review/d-rejected-acceptance/manifest.json');
for(const row of read(rejectedAcceptance+'/manifest.json').files)copy(path.join(rejectedAcceptance,row.path),'review/d-rejected-acceptance/'+row.path,row.sha256);
const continuationPreflight=prefix+'continuation-preflight-rejected';
copy(continuationPreflight+'/manifest.json','review/continuation-preflight-rejected/manifest.json');
for(const row of read(continuationPreflight+'/manifest.json').files)copy(path.join(continuationPreflight,row.path),'review/continuation-preflight-rejected/'+row.path,row.sha256);
const preflightRoot=prefix+'preflight-rejected';
copy(preflightRoot+'/manifest.json','review/preflight-rejected/manifest.json');
for(const row of read(preflightRoot+'/manifest.json').files)copy(path.join(preflightRoot,row.path),'review/preflight-rejected/'+row.path,row.sha256);
copy('.qa/verify-embedded-browser-d-source.mjs','verifiers/verify-source-with-bound-tests.mjs');
copy('.qa/prepare-embedded-browser-d-source.mjs','verifiers/prepare-source-with-bound-tests.mjs');
copy(prefix + 'inherited-ui.json','review/inherited-ui.json');
copy('.qa/embedded-browser-c-b-git-evidence.json','review/b-git-evidence.json');
copy(prefix + 'vendor-runtime-binding.json','review/vendor-runtime-binding.json');
copy(prefix + 'bind-vendor-runtime.mjs','verifiers/bind-vendor-runtime.mjs');
copy(prefix + 'vendor-runtime-initial-review.json','review/vendor-runtime-initial-review.json');
copy(path.join(read('docs/embedded-browser-b-rejected-candidate-evidence/release.json').portableRoot,'runtime/REA-RUNTIME.json'),'review/rea-runtime-B.json',read(prefix + 'vendor-runtime-binding.json').onlyDescriptorDifference.beforeSha256);
copy(path.join(independent.release.portableRoot,'runtime/REA-RUNTIME.json'),'review/rea-runtime-D.json',read(prefix + 'vendor-runtime-binding.json').onlyDescriptorDifference.afterSha256);
copy('.qa/embedded-browser-c-bind-vendor-runtime.before-timestamp-review.mjs','verifiers/bind-vendor-runtime.before-timestamp-review.mjs');
copy('.qa/embedded-browser-c-audit-b-git.mjs','verifiers/audit-b-git.mjs');
copy(prefix + 'inherit-ui.mjs','verifiers/inherit-ui.mjs');
copy('.qa/embedded-browser-c-http-fix-result.json','review/http-fix-result.json');
copy('.qa/embedded-browser-c-http-fix.tap','review/http-fix.tap');
copy('.qa/embedded-browser-c-workers-http-before.mjs','review/workers-http-before.mjs');
copy('.qa/verify-embedded-browser-c-http-fix.mjs','verifiers/http-fix.mjs');
copy(prefix + 'timing-review.json', 'review/timing-review.json');
copy('.qa/embedded-browser-b-payload-analysis.json', 'review/next-payload-analysis.json');
copy('.qa/embedded-browser-b-payload-analysis.mjs', 'verifiers/next-payload-analysis.mjs');
copy(prefix + 'finalization.mjs', 'verifiers/finalization.mjs');
const before = read(prefix + 'formal-before.json'), after = read(prefix + 'formal-after-verify.json'), backup = read(prefix + 'formal-private-backup-receipt.json');
assert.equal(before.version, '1.21.0'); assert.equal(after.version, '1.22.0'); assert.equal(after.pid, before.pid);
const retained = { observedBefore: before.observedAt, observedAfter: after.observedAt, pid: after.pid, counts: formal.counts, retained: formal.retained,
before: { configSha256: before.configSha256, modelCenterSha256: before.modelCenterSha256, eventCursor: before.eventCursor },
after: { configSha256: after.configSha256, modelCenterSha256: after.modelCenterSha256, eventCursor: after.eventCursor },
tableDigests: Object.fromEntries(Object.entries(before.database.tables).map(([name, row]) => [name, { count: row.count, schemaSha256: row.schemaSha256, sha256: row.sha256 }])),
originalSessionExports: before.exports.length, sessionExports: after.exports.length, originalSessionExportDigests: before.exports, afterOriginalFieldDigests: after.exports, afterCompleteExecutionViewDigests: after.rawExports, executionViewSchemaChange: formal.retained.executionViewSchemaChange, originalArtifactFiles: before.persistent.artifacts.length, artifactFiles: after.persistent.artifacts.length,
privateBackup: { bytes: backup.bytes, sha256: backup.sha256, committed: false, credentialsExtracted: false }, scope: 'All original rows/exports/config/artifact bytes checked by original verifiers. Full production snapshots and SQLite stay only in ignored QA.' };
const retainedBytes = Buffer.from(JSON.stringify(retained, null, 2) + '\n');
files.push({ path: 'retained-summary.json', source: prefix + 'retained-summary.json', bytes: retainedBytes.length, sha256: hash(retainedBytes) }); pending.push({ target: path.join(root, 'retained-summary.json'), bytes: retainedBytes });
files.sort((a, b) => a.path.localeCompare(b.path));
const manifest = { schemaVersion: 1, version: '1.22.0', sourceCommit: binding.sourceCommit, createdAt: new Date().toISOString(), files, appendedLogs, realModelRequests: 0,
scope: 'Original frozen source/portable/installed browser acceptance, historical UI, formal read-only observations and phase receipts. Original development failures are separate. No private production snapshots, SQLite or model credentials.' };
fs.mkdirSync(root); for (const { target, bytes } of pending) { fs.mkdirSync(path.dirname(target), { recursive: true }); fs.writeFileSync(target, bytes, { flag: 'wx' }); }
fs.writeFileSync(prefix + 'retained-summary.json', retainedBytes, { flag: 'wx' });
fs.writeFileSync(root + '/manifest.json', JSON.stringify(manifest, null, 2) + '\n', { flag: 'wx' });
const identity = { schemaVersion: 1, version: '1.22.0', sourceCommit: binding.sourceCommit, portableRoot: binding.portableRoot, sourceRoot: binding.sourceRoot,
acceptanceContinuation: independent.acceptanceContinuation,
portableIdentity: binding.portableIdentity, portableManifestSha256: binding.portableManifestSha256, sourceManifestSha256: binding.sourceManifestSha256,
portable: binding.portable, source: binding.source, installer: binding.installer,
validation: { sourceTests: source.tests, sourceTestExecution: source.inheritedTests, sourceInputFiles: source.inputFiles, buildMatchedFiles: source.buildMatchedFiles, historicalUiScripts: allUi.results.length, historicalUiGroups: allUi.groups,
historicalUiExecutionNote: 'B serial 33-script/250-group UI receipts inherited after complete input identity proof; only HTTP test synchronization, desktop acceptance helper and evidence attributes differ. Source tests bind the complete passing C run; all runtime/desktop/engineering gates run for D. See review/inherited-ui.json.', sourceBrowserGroups: 17, portableBrowserGroups: 17, installedBrowserGroups: 17, containedSuites: 9, samePayloadInstallGroups: 7,
formalPanels: ui.results.length, nativeViews: native.results.length, nativeScreenshots: native.screenshots.length, originalCompleteWindowRuntimeFilesMatched: nativeBinding.exactRuntimeFiles, actualOldToNewUpgrade: true, realModelRequests: 0 },
formal: { pid: after.pid, runtimeRoot: after.runtimeRoot, pointer: formal.pointer, currentProviderPreserved: formal.currentProviderPreserved, retained: formal.retained, counts: formal.counts, artifactFiles: after.persistent.artifacts.length, companion: formal.companion, inspectorClosed: formal.inspectorClosed },
evidence: { manifest: root + '/manifest.json', sha256: hash(fs.readFileSync(root + '/manifest.json')), files: files.length, bytes: files.reduce((sum, row) => sum + row.bytes, 0) },
limitations: ['Preview currently supports managed Vite projects with scripts.dev exactly vite and actual prepared dependencies.', 'Original webpage views require a connected Windows desktop window; browser shell and phone can inspect retained observations.', 'Approved fixed browser actions only; no arbitrary JavaScript/CDP or workbench Node/token access.', 'No real upstream model inference, Purge benefit, generic computer control or new physical iPhone acceptance in this milestone.', 'Original failures and unknown outcomes retained; completed or possibly executed actions are not automatically replayed.'] };
fs.writeFileSync('docs/embedded-browser-release-identity.json', JSON.stringify(identity, null, 2) + '\n', { flag: 'wx' });
console.log(JSON.stringify({ success: true, files: files.length, bytes: identity.evidence.bytes, tests: source.tests, uiGroups: allUi.groups, counts: formal.counts, sourceCommit: binding.sourceCommit }));