#!/usr/bin/env node // scripts/verify-phase-3.test.mjs // Source: Phase 3 SDOC-01..06 composite verify gate smoke test. // // Spawns `node scripts/verify-phase-3.mjs` end-to-end against committed Phase 3 // artifacts. Asserts: // - exit 0 // - stdout matches /OK \(\d+ steps green\)/ // - all 14 canonical step labels appear in stdout in order // // Usage: node scripts/verify-phase-3.test.mjs // OR: pnpm test:verify-phase-3 // Exit: 0 on success, 1 on any assertion failure. import { spawnSync } from 'node:child_process'; const expectedLabels = [ 'Plan 01: wiki errata', 'Plan 02: protocol-doc verify', 'Plan 02: lint:protocol', 'Plan 03: save-format-doc verify', 'Plan 03: lint:save-formats', 'Plan 10: tsc strict — protocol.ts', 'Plan 11: tsc strict — save-formats.ts', 'Plan 04: catalog:verify:server', 'Plan 04: lint:subsystem-mds', 'Plan 05: lint:parity-checklist', 'Plan 06: db:emit-check', 'Plan 06: lint:schema-sync', 'Plan 06: db:test', 'Plan 07/08: lint:adrs', ]; const r = spawnSync('node', ['scripts/verify-phase-3.mjs'], { encoding: 'utf-8' }); if (r.status !== 0) { console.error('FAIL: verify-phase-3 exited non-zero', { status: r.status }); console.error('--- stdout ---\n' + (r.stdout ?? '')); console.error('--- stderr ---\n' + (r.stderr ?? '')); process.exit(1); } const stdout = r.stdout ?? ''; if (!/OK \(\d+ steps green\)/.test(stdout)) { console.error('FAIL: expected /OK \\(\\d+ steps green\\)/ in stdout'); console.error('--- stdout ---\n' + stdout); process.exit(1); } // Strict count assertion: must equal expectedLabels.length (14). const countMatch = stdout.match(/OK \((\d+) steps green\)/); const stepCount = countMatch ? Number(countMatch[1]) : -1; if (stepCount !== expectedLabels.length) { console.error(`FAIL: expected ${expectedLabels.length} steps green, got ${stepCount}`); process.exit(1); } // Order-preserving label check: each label must appear after the previous. let cursor = 0; for (const label of expectedLabels) { const idx = stdout.indexOf(`=== ${label} ===`, cursor); if (idx === -1) { console.error(`FAIL: step label not found in expected order: "${label}"`); console.error(`(searching from offset ${cursor})`); process.exit(1); } cursor = idx + label.length; } console.log(`verify-phase-3.test: OK (${stepCount} steps, ${expectedLabels.length} labels in order)`); process.exit(0);