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 { publicSnapshot, compareOriginalState } from './cache-f-state.mjs'; const hash = bytes => createHash('sha256').update(bytes).digest('hex'); const git = args => execFileSync('git', args, { windowsHide: true, maxBuffer: 30000000 }); const identity = JSON.parse(fs.readFileSync('docs/project-cache-release-identity.json', 'utf8')); const baseline = JSON.parse(fs.readFileSync('docs/project-cache-release-code-baseline.json', 'utf8')); assert.equal(identity.success, true); assert.equal(identity.version, '1.19.0'); assert.equal(identity.codeCommit, baseline.codeCommit); assert.equal(git(['status', '--porcelain']).toString('utf8').trim(), ''); const commit = git(['rev-parse', 'HEAD']).toString('utf8').trim(), records = []; const check = (file, expected) => { const bytes = fs.readFileSync(file); assert.equal(bytes.length, expected.bytes, file); assert.equal(hash(bytes), expected.sha256, file); return bytes; }; for (const file of ['docs/project-cache-e-evidence/manifest.json', 'docs/project-cache-f-release-evidence/manifest.json']) { const value = JSON.parse(fs.readFileSync(file, 'utf8')); assert.equal(value.success, true); for (const row of value.files) { const target = row.archived ?? path.join(path.dirname(file), row.file), bytes = check(target, row); assert.deepEqual(git(['show', commit + ':' + target.replaceAll('\\', '/')]), bytes, 'Committed evidence original bytes: ' + target); records.push({ path: target, bytes: row.bytes, sha256: row.sha256 }); } } for (const row of [...baseline.inputs, ...baseline.builds, ...baseline.benchmarks]) check(row.path, row); for (const kind of ['portable', 'source', 'installer']) check(identity.release[kind].path, identity.release[kind]); const before = JSON.parse(fs.readFileSync(identity.formal.baseline.before, 'utf8')); const current = await publicSnapshot('http://127.0.0.1:4318', identity.formal.dataRoot), retained = compareOriginalState(before, current); assert.equal(current.version, '1.19.0'); assert.equal(current.pid, identity.formal.pid); assert.equal(current.runtimeRoot, identity.formal.runtimeRoot); const docs = ['README.md', 'AGENTS.md', 'CHANGELOG.md', 'docs/QA-1.19.md', 'docs/RETROSPECTIVE-1.19.md', 'docs/PLAN-1.20.md', 'docs/NEXT-STEPS.md', 'docs/CAPABILITIES.md', 'docs/MILESTONE-AUDIT.md']; for (const file of docs) assert.match(fs.readFileSync(file, 'utf8'), /1\.19|1\.20/); assert.doesNotMatch(fs.readFileSync('docs/PRODUCT-PLAN.md', 'utf8'), /当前模型协议仍使用stream:false/); const output = '.qa/cache-f-final-audit.json'; assert.equal(fs.existsSync(output), false); fs.writeFileSync(output, JSON.stringify({ success: true, at: new Date().toISOString(), finalGitCommit: commit, codeCommit: baseline.codeCommit, retained, version: current.version, pid: current.pid, exactEvidence: records.length, evidenceBytes: records.reduce((sum, row) => sum + row.bytes, 0), frozenInputs: baseline.inputs.length, frozenBuilds: baseline.builds.length, realModelRequests: 0, scope: 'Committed original E/F evidence, all frozen executable inputs/builds/benchmarks, immutable artifacts and final original formal state rechecked; docs-only finalization never rewrites executable packages.' }, null, 2) + '\n', { flag: 'wx' }); console.log(JSON.stringify({ success: true, output, commit, exactEvidence: records.length, retained }));