|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +import { execFileSync } from 'node:child_process'; |
| 4 | +import { existsSync, readFileSync } from 'node:fs'; |
| 5 | +import path from 'node:path'; |
| 6 | +import { fileURLToPath } from 'node:url'; |
| 7 | + |
| 8 | +const __filename = fileURLToPath(import.meta.url); |
| 9 | +const __dirname = path.dirname(__filename); |
| 10 | +const defaultRepoRoot = path.resolve(__dirname, '..'); |
| 11 | + |
| 12 | +function read(root, relativePath) { |
| 13 | + return readFileSync(path.join(root, relativePath), 'utf8'); |
| 14 | +} |
| 15 | + |
| 16 | +function exists(root, relativePath) { |
| 17 | + return existsSync(path.join(root, relativePath)); |
| 18 | +} |
| 19 | + |
| 20 | +function git(root, args) { |
| 21 | + return execFileSync('git', args, { cwd: root, encoding: 'utf8' }).trim(); |
| 22 | +} |
| 23 | + |
| 24 | +function run(root, args) { |
| 25 | + return execFileSync(process.execPath, args, { cwd: root, encoding: 'utf8' }).trim(); |
| 26 | +} |
| 27 | + |
| 28 | +function assertCheck(failures, condition, message) { |
| 29 | + if (!condition) failures.push(message); |
| 30 | +} |
| 31 | + |
| 32 | +function normalize(content) { |
| 33 | + return content.replace(/\s+/gu, ' ').trim(); |
| 34 | +} |
| 35 | + |
| 36 | +function parseArgs(argv) { |
| 37 | + const args = { repoRoot: defaultRepoRoot, skipBranchCheck: false }; |
| 38 | + for (let index = 0; index < argv.length; index += 1) { |
| 39 | + const arg = argv[index]; |
| 40 | + if (arg === '--repo-root') args.repoRoot = path.resolve(argv[++index]); |
| 41 | + else if (arg === '--skip-branch-check') args.skipBranchCheck = true; |
| 42 | + else if (arg === '--help' || arg === '-h') args.help = true; |
| 43 | + else throw new Error(`Unknown argument ${arg}`); |
| 44 | + } |
| 45 | + return args; |
| 46 | +} |
| 47 | + |
| 48 | +function printHelp() { |
| 49 | + process.stdout.write( |
| 50 | + [ |
| 51 | + 'Usage: node scripts/check-v45-gate10-formal-spec-consolidation.mjs [--skip-branch-check] [--repo-root <path>]', |
| 52 | + '', |
| 53 | + 'Checks the V45 formal specification consolidation gate.', |
| 54 | + ].join('\n'), |
| 55 | + ); |
| 56 | + process.stdout.write('\n'); |
| 57 | +} |
| 58 | + |
| 59 | +function main() { |
| 60 | + const args = parseArgs(process.argv.slice(2)); |
| 61 | + if (args.help) { |
| 62 | + printHelp(); |
| 63 | + return; |
| 64 | + } |
| 65 | + |
| 66 | + const root = args.repoRoot; |
| 67 | + const failures = []; |
| 68 | + const pointer = read(root, 'BITCODE_SPEC.txt').trim(); |
| 69 | + |
| 70 | + assertCheck(failures, pointer === 'V44', `BITCODE_SPEC.txt must remain V44 during V45 formal draft work. Observed ${pointer || 'empty'}.`); |
| 71 | + |
| 72 | + if (!args.skipBranchCheck) { |
| 73 | + const branch = git(root, ['branch', '--show-current']); |
| 74 | + assertCheck( |
| 75 | + failures, |
| 76 | + branch === 'version/v45' || /^v45\/gate-\d+-[a-z0-9][a-z0-9-]*$/u.test(branch), |
| 77 | + `V45 work must occur on version/v45 or v45/gate-N-* branches. Observed ${branch || 'detached HEAD'}.`, |
| 78 | + ); |
| 79 | + } |
| 80 | + |
| 81 | + for (const relativePath of [ |
| 82 | + 'BITCODE_SPEC_V45.md', |
| 83 | + 'BITCODE_SPEC_V45_DELTA.md', |
| 84 | + 'BITCODE_SPEC_V45_NOTES.md', |
| 85 | + 'BITCODE_SPEC_V45_PARITY_MATRIX.md', |
| 86 | + 'BITCODE_SPEC_V44.md', |
| 87 | + 'BITCODE_SPEC_V44_PROVEN.md', |
| 88 | + 'BITCODE_SPEC.txt', |
| 89 | + 'package.json', |
| 90 | + 'scripts/check-v45-gate9-gate-taxonomy-formal-spec-readiness.mjs', |
| 91 | + ]) { |
| 92 | + assertCheck(failures, exists(root, relativePath), `Missing required V45 Gate 10 file: ${relativePath}`); |
| 93 | + } |
| 94 | + |
| 95 | + const spec = read(root, 'BITCODE_SPEC_V45.md'); |
| 96 | + const delta = read(root, 'BITCODE_SPEC_V45_DELTA.md'); |
| 97 | + const notes = read(root, 'BITCODE_SPEC_V45_NOTES.md'); |
| 98 | + const parity = read(root, 'BITCODE_SPEC_V45_PARITY_MATRIX.md'); |
| 99 | + const packageJson = read(root, 'package.json'); |
| 100 | + const combined = normalize([spec, delta, notes, parity].join('\n')); |
| 101 | + |
| 102 | + for (const phrase of [ |
| 103 | + 'formal draft specification consolidated from accepted V45 notes atoms', |
| 104 | + 'V44 remains active canon until V45 promotion', |
| 105 | + 'Bitcode is the knowledge commoditization protocol and commercial system', |
| 106 | + 'AssetPack is the traded commodity', |
| 107 | + 'BTD is the non-fungible, proof-addressed scalar unit of technical knowledge volume', |
| 108 | + 'final BTD size is computed only after a reviewed Need, selected Fit set, synthesized Need-Fit AssetPack', |
| 109 | + 'BTC is Bitcode settlement money and payment truth', |
| 110 | + 'Prepared, signed, broadcast, and observed states are not final settlement', |
| 111 | + 'All Bitcode interfaces are protocol windows', |
| 112 | + 'Bitcode state advances only by proof-backed readback', |
| 113 | + 'Telemetry is observability only', |
| 114 | + 'V45 gates are classified as', |
| 115 | + 'formal-specification-consolidation', |
| 116 | + 'specification-parity-matrix', |
| 117 | + 'Implementation follows accepted parity gaps', |
| 118 | + 'Promotion alone may advance `BITCODE_SPEC.txt`', |
| 119 | + 'implementation parity is not yet audited', |
| 120 | + 'This parity matrix is the formal shell for the next V45 gate', |
| 121 | + ]) { |
| 122 | + assertCheck(failures, combined.includes(phrase), `V45 formal family must include phrase: ${phrase}`); |
| 123 | + } |
| 124 | + |
| 125 | + assertCheck( |
| 126 | + failures, |
| 127 | + packageJson.includes('"check:v45-gate10": "node scripts/check-v45-gate10-formal-spec-consolidation.mjs"'), |
| 128 | + 'package.json must expose check:v45-gate10.', |
| 129 | + ); |
| 130 | + |
| 131 | + try { |
| 132 | + const output = run(root, [ |
| 133 | + 'scripts/check-bitcode-spec-family.mjs', |
| 134 | + '--version', |
| 135 | + 'V45', |
| 136 | + '--mode', |
| 137 | + 'draft', |
| 138 | + '--current-target', |
| 139 | + 'V44', |
| 140 | + ]); |
| 141 | + assertCheck(failures, output.includes('Bitcode spec family ok for V45'), 'V45 draft spec-family check did not report success.'); |
| 142 | + } catch (error) { |
| 143 | + const detail = error instanceof Error ? error.message : String(error); |
| 144 | + failures.push(`V45 draft spec-family check failed: ${detail}`); |
| 145 | + } |
| 146 | + |
| 147 | + if (failures.length > 0) { |
| 148 | + process.stderr.write('V45 Gate 10 formal specification consolidation check failed:\n'); |
| 149 | + for (const failure of failures) process.stderr.write(`- ${failure}\n`); |
| 150 | + process.exitCode = 1; |
| 151 | + return; |
| 152 | + } |
| 153 | + |
| 154 | + process.stdout.write('V45 Gate 10 formal specification consolidation check passed.\n'); |
| 155 | +} |
| 156 | + |
| 157 | +try { |
| 158 | + main(); |
| 159 | +} catch (error) { |
| 160 | + const detail = error instanceof Error ? error.message : String(error); |
| 161 | + process.stderr.write(`${detail}\n`); |
| 162 | + process.exitCode = 1; |
| 163 | +} |
0 commit comments