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 './task-control-j-state.mjs'; const hash = bytes => createHash('sha256').update(bytes).digest('hex'); const git = (args, options = {}) => execFileSync('git', args, { windowsHide: true, maxBuffer: 512 * 1024 * 1024, ...options }); const read = file => JSON.parse(fs.readFileSync(file, 'utf8')); assert.equal(git(['status', '--porcelain']).toString().trim(), ''); const identity = read('docs/task-control-release-identity.json'), baseline = read('docs/task-control-release-code-baseline.json'); assert.equal(identity.success, true); assert.equal(identity.version, '1.20.1'); assert.equal(identity.codeCommit, baseline.codeCommit); const commit = git(['rev-parse', 'HEAD']).toString().trim(), manifest = read(identity.evidence.manifest); assert.equal(hash(fs.readFileSync(identity.evidence.manifest)), identity.evidence.sha256); 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 row of manifest.files) check(row.archived, row); const objects = git(['cat-file', '--batch'], { input: manifest.files.map(row => commit + ':' + row.archived + '\n').join('') }); let offset = 0; for (const row of manifest.files) { const newline = objects.indexOf(10, offset), header = objects.subarray(offset, newline).toString(); assert.match(header, /^[a-f0-9]+ blob \d+$/); const length = Number(header.split(' ').at(-1)), bytes = objects.subarray(newline + 1, newline + 1 + length); offset = newline + 2 + length; assert.equal(length, row.bytes); assert.equal(hash(bytes), row.sha256); assert.deepEqual(bytes, fs.readFileSync(row.archived)); } assert.equal(offset, objects.length); 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 = read(read('.qa/task-control-j-formal-baseline-location.json').before); const current = await publicSnapshot('http://127.0.0.1:4318', identity.formal.pointer.dataRoot), retained = compareOriginalState(before, current); assert.equal(current.version, '1.20.1'); assert.equal(current.pid, identity.formal.pid); assert.equal(current.runtimeRoot, identity.formal.runtimeRoot); assert.deepEqual(current.active, []); let links = 0; for (const file of ['README.md', 'AGENTS.md', 'CHANGELOG.md', 'task_plan.md', 'findings.md', 'progress.md', 'docs/QA-1.20.1.md', 'docs/RETROSPECTIVE-1.20.1.md', 'docs/CASE-REACT-SOURCE-2026-11-01.md', 'docs/VALIDATION.md', 'docs/MILESTONE-AUDIT.md', 'docs/NEXT-STEPS.md', 'docs/PRODUCT-PLAN.md', 'docs/CAPABILITIES.md', 'docs/PLAN-1.21.md']) { for (const match of fs.readFileSync(file, 'utf8').matchAll(/\[[^\]\r\n]*\]\(([^)\r\n]+)\)/g)) { const target = match[1].replace(/^<|>$/g, '').split(/[#?]/)[0]; if (!target || /^[a-z][a-z0-9+.-]*:/i.test(target)) continue; assert.ok(fs.existsSync(path.resolve(path.dirname(file), decodeURIComponent(target))), file + ': ' + target); links++; } } const output = '.qa/task-control-j-final-audit.json'; assert.equal(fs.existsSync(output), false); const result = { success: true, at: new Date().toISOString(), finalGitCommit: commit, codeCommit: baseline.codeCommit, retained, version: current.version, pid: current.pid, exactEvidence: manifest.files.length, evidenceBytes: manifest.bytes, frozenInputs: baseline.inputs.length, frozenBuilds: baseline.builds.length, localLinks: links, realModelRequests: 0, scope: 'Committed original scoped evidence, frozen executable source/builds, immutable artifacts and fresh original formal state. No remote push, credential read or user-project execution.' }; fs.writeFileSync(output, JSON.stringify(result, null, 2) + '\n', { flag: 'wx' }); console.log(JSON.stringify(result));