|
| 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 assertCheck(failures, condition, message) { |
| 25 | + if (!condition) failures.push(message); |
| 26 | +} |
| 27 | + |
| 28 | +function normalize(content) { |
| 29 | + return content.replace(/\s+/gu, ' ').trim(); |
| 30 | +} |
| 31 | + |
| 32 | +function parseArgs(argv) { |
| 33 | + const args = { repoRoot: defaultRepoRoot, skipBranchCheck: false }; |
| 34 | + for (let index = 0; index < argv.length; index += 1) { |
| 35 | + const arg = argv[index]; |
| 36 | + if (arg === '--repo-root') args.repoRoot = path.resolve(argv[++index]); |
| 37 | + else if (arg === '--skip-branch-check') args.skipBranchCheck = true; |
| 38 | + else if (arg === '--help' || arg === '-h') args.help = true; |
| 39 | + else throw new Error(`Unknown argument ${arg}`); |
| 40 | + } |
| 41 | + return args; |
| 42 | +} |
| 43 | + |
| 44 | +function printHelp() { |
| 45 | + process.stdout.write( |
| 46 | + [ |
| 47 | + 'Usage: node scripts/check-v45-gate9-gate-taxonomy-formal-spec-readiness.mjs [--skip-branch-check] [--repo-root <path>]', |
| 48 | + '', |
| 49 | + 'Checks the V45 gate taxonomy and formal specification readiness atom.', |
| 50 | + ].join('\n'), |
| 51 | + ); |
| 52 | + process.stdout.write('\n'); |
| 53 | +} |
| 54 | + |
| 55 | +function main() { |
| 56 | + const args = parseArgs(process.argv.slice(2)); |
| 57 | + if (args.help) { |
| 58 | + printHelp(); |
| 59 | + return; |
| 60 | + } |
| 61 | + |
| 62 | + const root = args.repoRoot; |
| 63 | + const failures = []; |
| 64 | + const pointer = read(root, 'BITCODE_SPEC.txt').trim(); |
| 65 | + |
| 66 | + assertCheck(failures, pointer === 'V44', `BITCODE_SPEC.txt must remain V44 during V45 atom work. Observed ${pointer || 'empty'}.`); |
| 67 | + |
| 68 | + if (!args.skipBranchCheck) { |
| 69 | + const branch = git(root, ['branch', '--show-current']); |
| 70 | + assertCheck( |
| 71 | + failures, |
| 72 | + branch === 'version/v45' || /^v45\/gate-\d+-[a-z0-9][a-z0-9-]*$/u.test(branch), |
| 73 | + `V45 work must occur on version/v45 or v45/gate-N-* branches. Observed ${branch || 'detached HEAD'}.`, |
| 74 | + ); |
| 75 | + } |
| 76 | + |
| 77 | + for (const relativePath of [ |
| 78 | + 'BITCODE_SPEC_V45_NOTES.md', |
| 79 | + 'BITCODE_SPEC_V44.md', |
| 80 | + 'BITCODE_SPEC.txt', |
| 81 | + 'package.json', |
| 82 | + 'scripts/check-v45-gate8-proof-readback-operational-boundaries.mjs', |
| 83 | + ]) { |
| 84 | + assertCheck(failures, exists(root, relativePath), `Missing required V45 Gate 9 file: ${relativePath}`); |
| 85 | + } |
| 86 | + |
| 87 | + const notes = read(root, 'BITCODE_SPEC_V45_NOTES.md'); |
| 88 | + const normalizedNotes = normalize(notes); |
| 89 | + const packageJson = read(root, 'package.json'); |
| 90 | + |
| 91 | + for (const phrase of [ |
| 92 | + 'V45 protocol-development atom 8: gate taxonomy and formal spec readiness', |
| 93 | + 'The remaining opening question is process taxonomy', |
| 94 | + 'V45 gates must be classified before the formal specification consolidation begins', |
| 95 | + 'No gate may claim a stronger class than its accepted artifacts prove', |
| 96 | + 'Notes-level atom gates are discussion-to-law preparation', |
| 97 | + 'formal specification gates are draft canon authoring', |
| 98 | + 'parity gates are implementation audit', |
| 99 | + 'proof-only gates harden validation', |
| 100 | + 'interface-only gates adjust protocol windows', |
| 101 | + 'implementation gates close audited parity gaps', |
| 102 | + 'rehearsal gates prove whole-system behavior', |
| 103 | + 'promotion gates alone may advance `BITCODE_SPEC.txt`', |
| 104 | + 'The canonical V45 gate taxonomy is', |
| 105 | + 'notes-specification-atom', |
| 106 | + 'formal-specification-consolidation', |
| 107 | + 'specification-parity-matrix', |
| 108 | + 'proof-only', |
| 109 | + 'interface-only', |
| 110 | + 'implementation', |
| 111 | + 'rehearsal', |
| 112 | + 'promotion', |
| 113 | + 'source-safe UX/UI', |
| 114 | + 'entitlement/disclosure trace to formal spec', |
| 115 | + 'using PR discussion, memory, or notes as primary implementation authority', |
| 116 | + 'Readiness law', |
| 117 | + 'The notes-specification atom set for the V45 opening is complete enough to begin formal specification consolidation', |
| 118 | + 'Formal consolidation must preserve the accepted semantics of all notes atoms', |
| 119 | + 'AssetPack as commodity, Need-relative BTD scalar-volume, BTC settlement finality', |
| 120 | + 'After consolidation, the parity matrix gate must treat the formal V45 specification family as the only implementation-audit authority', |
| 121 | + 'Promotion remains prohibited until formal specification, parity, grouped implementation, proof, interface, rehearsal, and promotion-readiness gates are accepted', |
| 122 | + 'Acceptance for this atom', |
| 123 | + 'formal-specification consolidation as the next movement after accepted notes', |
| 124 | + 'parity auditing from the formal V45 specification', |
| 125 | + 'implementation only from accepted parity gaps', |
| 126 | + '`BITCODE_SPEC.txt` promotion only through the promotion gate', |
| 127 | + ]) { |
| 128 | + assertCheck(failures, normalizedNotes.includes(phrase), `V45 Gate 9 notes must include phrase: ${phrase}`); |
| 129 | + } |
| 130 | + |
| 131 | + assertCheck( |
| 132 | + failures, |
| 133 | + packageJson.includes('"check:v45-gate9": "node scripts/check-v45-gate9-gate-taxonomy-formal-spec-readiness.mjs"'), |
| 134 | + 'package.json must expose check:v45-gate9.', |
| 135 | + ); |
| 136 | + |
| 137 | + if (failures.length > 0) { |
| 138 | + process.stderr.write('V45 Gate 9 gate taxonomy and formal spec readiness check failed:\n'); |
| 139 | + for (const failure of failures) process.stderr.write(`- ${failure}\n`); |
| 140 | + process.exitCode = 1; |
| 141 | + return; |
| 142 | + } |
| 143 | + |
| 144 | + process.stdout.write('V45 Gate 9 gate taxonomy and formal spec readiness check passed.\n'); |
| 145 | +} |
| 146 | + |
| 147 | +try { |
| 148 | + main(); |
| 149 | +} catch (error) { |
| 150 | + const detail = error instanceof Error ? error.message : String(error); |
| 151 | + process.stderr.write(`${detail}\n`); |
| 152 | + process.exitCode = 1; |
| 153 | +} |
0 commit comments