Files
Agent-Workbench/docs/project-cache-f-release-evidence/0132-seal-cache-release.mjs
T
2026-11-01 09:31:00 +08:00

129 lines
16 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert/strict';
import { createHash } from 'node:crypto';
import { publicSnapshot, compareOriginalState } from './cache-f-state.mjs';
const read = file => JSON.parse(fs.readFileSync(file, 'utf8'));
const hash = bytes => createHash('sha256').update(bytes).digest('hex');
const baseline = read('docs/project-cache-release-code-baseline.json'), release = read('releases/latest.json');
assert.equal(baseline.version, '1.19.0'); assert.equal(release.installer.version, '1.19.0');
const phases = ['archives', 'source', 'portable', 'portable-companion', 'portable-protocols', 'portable-vision', 'portable-cache', 'prepare-install', 'install', 'formal-stage', 'formal-upgrade', 'formal-activate', 'formal-ui', 'formal-verify', 'formal-artifacts'];
const receipts = phases.map(phase => { const file = '.qa/cache-f-' + phase + '-result.json', value = read(file); assert.equal(value.success, true, phase); assert.equal(value.unchangedInputs, true); assert.equal(value.release.setupSha256, release.installer.sha256); return { file, value }; });
const source = read('.qa/cache-f-source-original-validation.json'), portable = read('.qa/cache-f-portable-original-validation.json');
assert.equal(source.success, true); assert.equal(source.tests.tests, 590); assert.equal(source.tests.pass, 590);
for (const key of ['fail', 'cancelled', 'skipped', 'todo']) assert.equal(source.tests[key], 0);
const sorted = rows => rows.slice().sort((a, b) => a.path.localeCompare(b.path));
assert.deepEqual(sorted(source.inputs), sorted(baseline.inputs));
assert.deepEqual(sorted(source.buildFiles), sorted(baseline.builds.map(({ path, sha256 }) => ({ path, sha256 }))));
assert.equal(source.actualDesktop.window.results.length, 7); assert.equal(source.actualDesktop.ui.assertions.length, 9); assert.equal(source.actualDesktop.projects.cases.length, 16);
for (const projects of [source.actualDesktop.projects, source.actualProtocolEngineering]) assert.deepEqual(projects.results.map(value => value.parentCheck.results[0].tests.passed), [8, 9, 10]);
assert.deepEqual(source.actualVisionEngineering.results.map(value => value.check.results[0].tests.passed), [8, 9, 10]);
assert.equal(source.actualCompanion.passed.length, 7); assert.equal(source.actualProtocols.passed.length, 5); assert.equal(source.actualVision.passed.length, 5);
assert.equal(source.actualProjectCache.success, true); assert.equal(source.actualProjectCache.passed.length, 7);
assert.equal(source.actualCacheEngineering.success, true); assert.equal(source.actualCacheEngineering.cases.length, 9);
assert.deepEqual(source.actualCacheEngineering.results.map(value => value.check.results[0].tests.passed), [8, 9, 10]);
assert.equal(source.actualVisionEngineering.cases.length, 7); assert.equal(source.actualProtocolEngineering.cases.length, 13);
assert.equal(portable.appRoot, release.portableRoot); assert.equal(portable.actualControlled.success, true);
const ui = read('docs/project-cache-all-ui-validation.json'); assert.equal(ui.success, true); assert.equal(ui.results.length, 27); assert.equal(ui.groups, 203);
const installLocation = read('.qa/cache-f-install-location.json'), install = read(installLocation.result);
assert.equal(install.success, true); assert.equal(install.cases.length, 7); assert.equal(install.installer.productSetup.sha256, release.installer.sha256);
assert.equal(install.installer.samePayloadManifestSha256, hash(fs.readFileSync(path.join(release.portableRoot, 'MANIFEST.json'))));
const baselineLocation=read('.qa/cache-f-formal-baseline-location.json');
assert.equal(read('.qa/cache-f-formal-stage-result.json').success,true); assert.equal(baselineLocation.staged,'.qa/cache-f-formal-stage.json');
const formal = read('.qa/cache-f-formal-verify.json'), before = read(baselineLocation.before);
assert.equal(formal.success, true); assert.equal(formal.identity.pid, 36552); assert.equal(formal.currentProviderPreserved, true); assert.equal(formal.inspectorClosed, true);
const current = await publicSnapshot('http://127.0.0.1:4318', formal.dataRoot), retained = compareOriginalState(before, current);
assert.equal(current.version, '1.19.0'); assert.equal(current.runtimeRoot, formal.candidate);
const smoke = read('.qa/cache-f-formal-ui-validation.json'), artifacts = read('.qa/cache-f-formal-artifacts.json'), native = read('.qa/cache-f-formal-native.json');
assert.equal(smoke.success, true); assert.equal(smoke.results.length, 24); assert.equal(artifacts.success, true); assert.equal(artifacts.checked, artifacts.total);
assert.equal(native.success, true); assert.equal(native.version, '1.19.0'); assert.equal(native.hostPid, 36552);
for (const key of ['pageErrors', 'requestFailures', 'httpErrors', 'blockedWrites']) assert.deepEqual(smoke[key], []);
for (const item of [...baseline.inputs, ...baseline.builds, ...baseline.benchmarks]) { const bytes = fs.readFileSync(item.path); assert.equal(bytes.length, item.bytes); assert.equal(hash(bytes), item.sha256, item.path); }
for (const item of [release.portable, release.source, release.installer]) assert.equal(hash(fs.readFileSync(item.path)), item.sha256);
const gitAudit = read('.qa/cache-f-code-git-audit.json'), licenses = read('.qa/cache-f-license-audit.json'), completed = read('.qa/cache-f-log-completions/index.json');
assert.equal(gitAudit.success, true); assert.equal(gitAudit.codeCommit, baseline.codeCommit); assert.equal(gitAudit.inputFiles, baseline.inputs.length); assert.equal(licenses.success, true); assert.equal(completed.success, true);
assert.ok(licenses.records.some(row => /jpeg-js-0\.4\.4/.test(row.archived))); assert.ok(licenses.records.some(row => /pngjs-7\.0\.0/.test(row.archived)));
const directory = 'docs/project-cache-f-release-evidence'; assert.equal(fs.existsSync(directory), false);
const queue = [], seen = new Map();
function copy(file, expected = {}) {
const absolute = path.resolve(file), old = seen.get(absolute); if (old) { if (expected.sha256) assert.equal(old.sha256, expected.sha256); return old; }
assert.doesNotMatch(file, /(?:\.sqlite(?:-(?:wal|shm))?|\.(?:db|key|pem|pfx|p12))$/i, 'No private databases, credentials or certificates');
const stat = fs.lstatSync(file); assert.equal(stat.isSymbolicLink(), false); assert.equal(stat.isFile(), true);
const bytes = fs.readFileSync(file), sha256 = hash(bytes); if (expected.sha256) assert.equal(sha256, expected.sha256, file); if (expected.bytes !== undefined) assert.equal(bytes.length, expected.bytes, file);
const name = String(queue.length + 1).padStart(4, '0') + '-' + path.basename(file).replace(/\.log$/, '-log.txt');
const row = { original: absolute, archived: directory + '/' + name, bytes: bytes.length, sha256 }; queue.push({ row, bytes }); seen.set(absolute, row); return row;
}
function logCopy(file, sha256) {
if (hash(fs.readFileSync(file)) === sha256) return copy(file, { sha256 });
const item = completed.completions.find(value => value.source === path.resolve(file)); assert.ok(item); assert.equal(item.original.sha256, sha256); copy(item.original.path, item.original); return copy(file, item.completed);
}
function surface(root) {
if (!root || !fs.existsSync(root)) return;
for (const entry of fs.readdirSync(root, { withFileTypes: true })) if (entry.isFile() && /\.(?:json|png|jpg|html|txt|log|tap|mjs|cjs|sse)$/.test(entry.name)) copy(path.join(root, entry.name));
}
function projectTree(root) {
if (!root || !fs.existsSync(root)) return;
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
if (['.git', 'node_modules', '__pycache__', '.pytest_cache', '.venv'].includes(entry.name)) continue;
const file = path.join(root, entry.name); if (entry.isDirectory()) projectTree(file); else copy(file);
}
}
function screenshots(value, bases=[]) {
if (!value || typeof value !== 'object') return; if (Array.isArray(value)) { value.forEach(item=>screenshots(item,bases)); return; }
const ownedBases=['root','directory'].map(key=>value[key]).filter(item=>typeof item==='string'&&fs.existsSync(item)&&fs.statSync(item).isDirectory());
if(ownedBases.length)bases=ownedBases;
const resolved=file=>{
if(path.isAbsolute(file)||fs.existsSync(file))return file;
const candidates=[...new Set(bases.map(root=>path.resolve(root,file)).filter(file=>fs.existsSync(file)))];
assert.equal(candidates.length,1,'Resolve a relative screenshot only within its declared original EVIDENCE directory: '+file);
return candidates[0];
};
if (typeof value.file === 'string' && /\.(png|jpg)$/.test(value.file)) copy(resolved(value.file), value.sha256 ? { sha256: value.sha256 } : {});
for (const [key, item] of Object.entries(value)) {
if (typeof item === 'string' && /screenshot$/i.test(key) && /\.(png|jpg)$/.test(item)) copy(resolved(item), value.screenshotSha256 ? { sha256: value.screenshotSha256 } : {});
if (key === 'screenshots' && Array.isArray(item)) for (const file of item) if (typeof file === 'string') copy(resolved(file));
if (item && typeof item === 'object') screenshots(item,bases);
}
}
for (const { file, value } of receipts) { copy(file); copy(value.logPath, { bytes: value.logBytes, sha256: value.logSha256 }); }
for (const name of fs.readdirSync('.qa')) {
// The parent closes this attempt's log only after this process exits. Archive
// completed attempts, but do not mislabel this still-open log as final evidence.
if (/^cache-f-seal(?:-retry)?\.log$/.test(name) && !fs.existsSync(path.join('.qa', name.replace(/\.log$/, '-result.json')))) continue;
if (/^(?:(?:cache-f-|project-cache-).*\.(?:json|log|tap|mjs)|(?:prepare|freeze|package|run|shorten|deploy|verify|audit|seal|record|finalize|write)-cache-.*\.mjs)$/.test(name)) copy(path.join('.qa', name));
}
for (const name of fs.readdirSync('docs')) if (/^project-cache-.*\.(?:json|txt)$/.test(name)) copy(path.join('docs', name));
copy('.qa/cache-f-state.mjs'); copy('.qa/desktop-f-state.mjs'); copy('.qa/prepare-cache-seal.mjs');
copy('.qa/inspect-cache-ui-failure.mjs'); copy('.qa/cache-ui-failure-runtime-observation.json'); copy('.qa/cache-ui-failure-runtime-followup.json');
copy('releases/latest.json'); copy(path.join(release.portableRoot, 'MANIFEST.json')); copy(path.join(release.sourceRoot, 'MANIFEST.json'));
for (const row of source.logs) { copy(row.path, row); const text = fs.readFileSync(row.path, 'utf8'); for (const match of text.matchAll(/^EVIDENCE (.+)\r?$/gm)) surface(match[1].trim()); }
copy(path.join(source.directory, 'inputs.json')); copy(path.join(source.directory, 'result.json'));
for (const row of ui.results) {
copy(row.evidence); copy(row.log); const text = fs.readFileSync(row.log, 'utf8'); const roots=[...text.matchAll(/^EVIDENCE (.+)\r?$/gm)].map(match=>match[1].trim()); for(const root of roots)surface(root);
screenshots(read(row.evidence),roots);
}
for (const row of install.cases) { if (row.processLog) copy(row.processLog, { sha256: row.processLogSha256 }); if (row.setupLog) logCopy(row.setupLog, row.setupLogSha256); if (row.uninstallLog) logCopy(row.uninstallLog, row.uninstallLogSha256); }
copy(installLocation.result); copy(release.installer.source); copy(path.join(path.dirname(release.installer.source), 'compile.txt')); copy(install.installer.source); copy(path.join(path.dirname(install.installer.source), 'compile.txt'));
copy('.qa/cache-f-formal-setup.log', { sha256: read(baselineLocation.staged).setupLogSha256 });
for (const root of ['.qa/cache-native-before', '.qa/cache-native-after', '.qa/cache-all-ui-first-failure', '.qa/cache-f-log-completions']) surface(root);
for (const entry of fs.readdirSync('.qa', { withFileTypes: true })) if (entry.isDirectory() && /^(?:project-cache-ui-|project-cache-projects-)/.test(entry.name)) { const root = path.join('.qa', entry.name); surface(root); for (const kind of ['node', 'react', 'python']) { surface(path.join(root, kind)); projectTree(path.join(root, kind, 'original-fixture/project')); } }
surface(source.actualDesktop.window.root); projectTree(path.join(source.actualDesktop.window.root, 'owned-project'));
for (const name of ['desktop-controlled-ui', 'desktop-projects', 'responses-engineering', 'vision-engineering', 'project-cache-engineering']) {
const file = path.join(source.sourceRoot, '.qa', name + '-location.json'), location = read(file); copy(file); copy(location.result); surface(location.directory);
if (name === 'desktop-controlled-ui') projectTree(path.join(location.directory, 'original-fixture/project'));
else for (const kind of ['node', 'react', 'python']) { const root = path.join(location.directory, kind); surface(root); projectTree(path.join(root, 'original-fixture/project')); }
}
for (const value of [source.actualDesktop, source.actualCompanion, source.actualProtocols, source.actualVision, source.actualProjectCache, smoke, native]) screenshots(value);
for (const phase of ['portable-companion', 'portable-protocols', 'portable-vision', 'portable-cache']) { const text = fs.readFileSync('.qa/cache-f-' + phase + '.log', 'utf8'), root = text.match(/EVIDENCE ([^\r\n]+)/)?.[1]; assert.ok(root); surface(root); }
const manifest = { success: true, version: '1.19.0', codeCommit: baseline.codeCommit, sealedAt: new Date().toISOString(), files: queue.map(value => value.row), bytes: queue.reduce((sum, value) => sum + value.bytes.length, 0), sourceTests: source.tests, ui: { classes: 27, groups: 203 }, scope: 'Original release/failure/success bytes. Formal snapshots contain public hashes; no private SQLite, model Key, certificate or QA device identity.' };
fs.mkdirSync(directory); fs.writeFileSync(directory + '/.gitattributes', '* -text -whitespace\n', { flag: 'wx' });
for (const { row, bytes } of queue) fs.writeFileSync(row.archived, bytes, { flag: 'wx' }); fs.writeFileSync(directory + '/manifest.json', JSON.stringify(manifest, null, 2) + '\n', { flag: 'wx' });
const identity = { success: true, version: '1.19.0', codeCommit: baseline.codeCommit, immutableRelease: path.basename(release.portableRoot), release,
frozen: { inputs: baseline.inputs.length, builds: baseline.builds.length, benchmarks: baseline.benchmarks.length, gitAudit },
independentSource: { sourceRoot: source.sourceRoot, tests: source.tests, inputs: source.inputFiles, buildMatchedFiles: source.buildMatchedFiles, desktopWindow: 7, desktopUi: 9, desktopEngineering: 16, responsesEngineering: 13, screenshotEngineering: 7, cacheEngineering: 9, cacheUi: 7, parentTests: [8, 9, 10], containedCompanion: 7, containedProtocols: 5, containedVision: 5 },
ui: { classes: 27, groups: 203, formalPanels: 24 }, samePayloadInstall: { cases: 7, setupSha256: install.installer.sha256, productSetupSha256: release.installer.sha256 },
formal: { pid: formal.identity.pid, runtimeRoot: formal.candidate, dataRoot: formal.dataRoot, counts: formal.counts, artifactRecords: artifacts.artifactRecords, blobFiles: artifacts.blobFiles, currentProviderPreserved: true, retained, inspectorClosed: true, companion: formal.companion, native, baseline: { before: baselineLocation.before, staged: baselineLocation.staged, freshCompleteSnapshot: true, installerRerun: false } },
evidence: { manifest: directory + '/manifest.json', files: queue.length, bytes: manifest.bytes }, realModelRequests: 0,
limitations: ['Cache has measured cross-instance AST benefit only; cold/warm/invalidation closure adds overhead, Python shows no stable improvement, no token savings inferred.', 'Real configured-model visual engineering and Purge benefit remain separately deferred.', 'No new iPhone screenshot/stream result; Edge/TLS viewports are separate from user-confirmed 1.16 iPhone evidence.', 'Image token values are local reservations, not provider billing or a universal capacity guarantee.', 'Mobile input remains read-only observe access; uploads and budget changes use desktop.', 'Audio, general computer control, unknown WorkBuddy formats and controlled self-improvement remain later work.'], sealedAt: manifest.sealedAt };
fs.writeFileSync('docs/project-cache-release-identity.json', JSON.stringify(identity, null, 2) + '\n', { flag: 'wx' }); console.log(JSON.stringify({ success: true, files: queue.length, bytes: manifest.bytes, identity: 'docs/project-cache-release-identity.json' }));