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'; import { DatabaseSync } from 'node:sqlite'; const read = file => JSON.parse(fs.readFileSync(file, 'utf8')); const hash = bytes => createHash('sha256').update(bytes).digest('hex'); const canonical = value => Array.isArray(value) ? value.map(canonical) : value && typeof value === 'object' ? Object.fromEntries(Object.keys(value).sort().map(key => [key, canonical(value[key])])) : value; const digest = value => hash(JSON.stringify(canonical(value))); const source = read('.qa/source-package-validation.json'), compared = read('.qa/workers-final-inputs-comparison.json'), baseline = read('docs/workers-code-baseline.json'); const release = read('releases/latest.json'), archive = read('.qa/archives-validation.json'), portable = read('.qa/release-validation.json'); const ui = read('docs/workers-all-ui-validation.json'), projects = read('docs/workers-projects-validation.json'), workerUi = read('docs/workers-ui-validation.json'); const deployed = read('docs/workers-upgrade-live-validation.json'), smoke = read('.qa/workers-deployed-ui-validation.json'); for (const [name, report] of Object.entries({ source, compared, baseline, archive, portable, ui, projects, deployed, smoke })) { assert.equal(report.success, true, name); assert.equal(report.version, '1.13.0', name); } assert.equal(workerUi.passed, true); assert.equal(workerUi.version, '1.13.0'); assert.equal(workerUi.assertions.length, 10); assert.equal(source.tests.tests, 404); assert.equal(source.tests.pass, source.tests.tests); for (const name of ['fail', 'cancelled', 'skipped', 'todo']) assert.equal(source.tests[name], 0); assert.deepEqual(source.inputs, baseline.inputs); assert.equal(source.inputFiles, baseline.inputs.length); assert.equal(source.buildMatchedFiles, 6); assert.equal(ui.groups, 160); assert.equal(ui.results.length, 21); assert.equal(projects.results.length, 3); assert.equal(projects.cases.length, 13); for (const sample of projects.results) { assert.equal(sample.success, true); assert.equal(sample.realModelRequests, 0); assert.equal(sample.parentChecks.status, 'passed'); assert.ok(sample.commit); } assert.deepEqual(projects.results.map(value => value.parentChecks.results[0].tests.passed), [8, 9, 10]); for (const sample of projects.results.filter(value => value.kind === 'react')) { assert.equal(sample.browserJobs.length, 2); for (const job of sample.browserJobs) { assert.equal(job.status, 'passed'); assert.equal(job.cleanup.exited, true); assert.equal(job.assertions.passed, 10); } } assert.equal(smoke.results.length, 10); assert.equal(smoke.pid, deployed.pid); assert.equal(deployed.preservesCurrentObservedProcess, true); assert.equal(deployed.allRowsAndExportsPreserved, true); assert.equal(deployed.connectionPreserved, true); assert.equal(deployed.modelCenterPreserved, true); assert.equal(deployed.realModelRequests, 0); assert.equal(smoke.modelRequests, 0); for (const field of ['pageErrors', 'requestFailures', 'httpErrors', 'blockedWrites']) assert.deepEqual(smoke[field], []); for (const row of [...baseline.inputs, ...baseline.builds, ...baseline.benchmarks]) assert.equal(hash(fs.readFileSync(row.path)), row.sha256, row.path); for (const row of projects.inputs) assert.equal(hash(fs.readFileSync(row.path)), row.sha256, row.path); for (const row of workerUi.inputs) assert.equal(hash(fs.readFileSync(row.path)), row.sha256, row.path); for (const native of [source.actualRea, source.actualEngine, source.actualBrowser]) assert.equal(native.success, true); for (const kind of ['source', 'portable']) { const item = archive.archives.find(value => value.kind === kind); assert.equal(item.sha256, release[kind].sha256); assert.equal(hash(fs.readFileSync(release[kind].path)), item.sha256); } const logs = [...source.logs.map(row => ({ path: row.path, bytes: row.bytes, sha256: row.sha256 })), ...ui.results.map(row => { const bytes = fs.readFileSync(row.log); return { path: row.log, bytes: bytes.length, sha256: hash(bytes) }; })]; for (const row of logs) { const bytes = fs.readFileSync(row.path); assert.equal(bytes.length, row.bytes); assert.equal(hash(bytes), row.sha256); } const images = [...smoke.results.map(row => ({ path: row.screenshot, sha256: row.screenshotSha256 })), ...workerUi.screenshots.map(row => ({ path: row.file, sha256: row.sha256 })), ...projects.results.flatMap(row => (row.screenshots ?? []).map(image => ({ path: image.file, sha256: image.sha256 })))]; for (const row of images) { const bytes = fs.readFileSync(row.path); assert.equal(hash(bytes), row.sha256); assert.ok(bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))); } const db = new DatabaseSync(path.join(deployed.dataRoot, 'workbench.sqlite'), { readOnly: true }); db.exec('BEGIN'); try { for (const [table, order] of [['projects', 'id'], ['sessions', 'id'], ['records', 'kind,id'], ['events', 'seq']]) { const rows = db.prepare('SELECT * FROM ' + table + ' ORDER BY ' + order).all(); assert.equal(rows.length, deployed.database[table].count); assert.equal(digest(rows), deployed.database[table].sha256); } } finally { db.exec('ROLLBACK'); db.close(); } const bootstrap = await (await fetch('http://127.0.0.1:4318/api/bootstrap')).json(); assert.equal(bootstrap.version, '1.13.0'); assert.equal((await (await fetch('http://127.0.0.1:4318/api/health')).json()).pid, deployed.pid); for (const row of deployed.preservedSessionSnapshots) { const value = await (await fetch('http://127.0.0.1:4318/api/sessions/' + row.id + '/export', { headers: { 'X-Workbench-Token': bootstrap.token } })).json(); for (const kind of ['project', 'session', 'execution']) assert.equal(digest(value[kind]), row[kind]); } await assert.rejects(fetch('http://127.0.0.1:9229/json/list', { signal: AbortSignal.timeout(1000) })); const historicalLogCopies = fs.readdirSync('docs').filter(name => name.startsWith('workers-') && name.endsWith('.log')).sort() .map(name => ['docs/' + name, 'docs/' + name.replace(/\.log$/, '-log.txt')]); for (const [from, to] of historicalLogCopies) { if (fs.existsSync(to)) assert.ok(fs.readFileSync(from).equals(fs.readFileSync(to)), to + ': existing original log copy must be identical'); } const copies = [ ['.qa/archives-validation.json', 'docs/workers-archives-validation.json'], ['.qa/release-validation.json', 'docs/workers-release-validation.json'], ['.qa/source-package-validation.json', 'docs/workers-source-package-validation.json'], ['.qa/workers-final-inputs-comparison.json', 'docs/workers-git-inputs.json'], ['.qa/workers-source-tested-candidate.json', 'docs/workers-source-tested-candidate.json'], ['.qa/workers-source-candidate-archives-validation.json', 'docs/workers-source-candidate-archives-validation.json'], ['.qa/workers-deployed-ui-validation.json', 'docs/workers-deployed-ui-validation.json'], ...source.logs.map(row => [row.path, 'docs/workers-source-' + path.basename(row.path).replace(/\.log$/, '-log.txt')]), ...ui.results.map(row => [row.log, 'docs/workers-ui-' + row.script.replace('.mjs', '') + '-log.txt']), ['.qa/finish-workers-deployment.mjs', 'docs/workers-deployment-verifier.mjs'], ['.qa/smoke-workers-deployed.mjs', 'docs/workers-deployed-ui-verifier.mjs'], ['.qa/compare-workers-final-candidate.mjs', 'docs/workers-final-candidate-verifier.mjs'], ['.qa/seal-workers-evidence.mjs', 'docs/workers-evidence-seal-verifier.mjs'], ...historicalLogCopies, ]; for (const [from, to] of copies) { const bytes = fs.readFileSync(from); fs.writeFileSync(to, bytes); assert.equal(hash(fs.readFileSync(to)), hash(bytes)); } const names = [...new Set([...fs.readdirSync('docs').filter(name => name.startsWith('workers-') && name !== 'workers-release-identity.json' && !name.endsWith('.log')).map(name => 'docs/' + name), 'docs/QA-1.13.md', 'docs/WORKERS.md', 'docs/RETROSPECTIVE-1.13.md', 'docs/PLAN-1.13.md', 'docs/PLAN-1.14.md', 'docs/NEXT-STEPS.md', 'docs/PRODUCT-PLAN.md', 'docs/RESEARCH-ROADMAP.md', 'docs/CAPABILITIES.md', 'docs/VALIDATION.md', 'docs/deployment.json'])].sort(); const identity = { success: true, version: '1.13.0', releaseId: path.basename(release.portableRoot).match(/(\d{17})$/)[1], sealedAt: new Date().toISOString(), codeCommit: baseline.codeCommit, release, independentlyTestedCandidate: read('.qa/workers-source-tested-candidate.json'), independentSourceRoot: source.sourceRoot, sourceInputs: baseline.inputs, benchmarkInputs: baseline.benchmarks, builds: baseline.builds, tests: source.tests, uiGroups: ui.groups, functionalProjects: projects.results.length, projectAssertions: projects.cases.length, realModelRequests: 0, currentPid: deployed.pid, allRowsAndExportsPreserved: true, postSmokeDatabaseUnchanged: true, inspectorClosed: true, gitExactInputs: compared.exactBytes, gitLfOnlyInputs: compared.normalized, originalLogs: logs, originalImages: images, originalReportLogs: historicalLogCopies.map(([sourcePath, file]) => { const bytes = fs.readFileSync(sourcePath); return { sourcePath, path: file, bytes: bytes.length, sha256: hash(bytes) }; }), reports: names.map(file => { const bytes = fs.readFileSync(file); return { path: file, bytes: bytes.length, sha256: hash(bytes) }; }), scope: 'Two isolated workers, verified parent integration and recovery, three owned functional projects, complete independent source/portable/UI and state-preserving deployment. Fixed Provider fixtures are distinct from real-model reasoning or autonomous success.' }; fs.writeFileSync('docs/workers-release-identity.json', JSON.stringify(identity, null, 2)); console.log(JSON.stringify({ success: true, tests: source.tests.tests, uiGroups: ui.groups, projects: projects.results.length, reports: identity.reports.length, logs: logs.length, images: images.length, pid: deployed.pid }));