import test from 'node:test'; import assert from 'node:assert/strict'; import { spawnSync } from 'node:child_process'; import { readFileSync } from 'node:fs'; import path from 'node:path'; const treeRoot = path.join(import.meta.dirname, '..'); const cli = path.join(treeRoot, 'src', 'cli.ts'); const specRoot = path.join(import.meta.dirname, 'fixtures', 'synthetic-spec'); function runCli(...args) { const proc = spawnSync(process.execPath, [cli, ...args], { encoding: 'utf8', cwd: treeRoot }); return { code: proc.status, stdout: proc.stdout, envelope: JSON.parse(proc.stdout) }; } test('синтетическая спецификация проходит bhl validate без диагностик', () => { const result = runCli('validate', specRoot); assert.equal(result.code, 0); assert.deepEqual(result.envelope.data.errors, []); // 8 файлов ядра + profiles/×2 + presets/×1 — факультативные каталоги тоже валидируются (BHL-041) assert.equal(result.envelope.data.files, 11); }); test('пресет разворачивается в Effective Specification со всеми связями', () => { const result = runCli('profile', 'resolve', specRoot, '--preset', 'preset-synth-all'); assert.equal(result.code, 0); const { profiles, effective } = result.envelope.data; assert.deepEqual(profiles, ['prof-synth-light', 'prof-synth-strict']); assert.deepEqual( effective.map((item) => [item.requirement, item.level, item.parameters]), [ [ 'req-synth-alpha', 'SHOULD', [{ parameter: 'param-synth-budget', value: 4, source: 'prof-synth-light' }], ], [ 'req-synth-beta', 'SHOULD', [{ parameter: 'param-synth-mode', value: 'plain', source: 'prof-synth-strict' }], ], ['req-synth-gamma', 'MUST NOT', []], ], ); const gamma = effective.find((item) => item.requirement === 'req-synth-gamma'); assert.deepEqual(gamma.sources, ['prof-synth-strict']); }); test('разрешение пресета не зависит от порядка явных профилей', () => { const first = runCli( 'profile', 'resolve', specRoot, '--profile', 'prof-synth-light', '--profile', 'prof-synth-strict', ); const second = runCli( 'profile', 'resolve', specRoot, '--profile', 'prof-synth-strict', '--profile', 'prof-synth-light', ); assert.equal(first.code, 0); assert.equal(second.stdout, first.stdout); }); test('фикстура явно отмечена как инфраструктурная, а не BHS 0.1.0', () => { const readme = readFileSync(path.join(specRoot, 'README.md'), 'utf8'); assert.ok(readme.includes('не является'), 'отметка о не-стандартности'); assert.ok(readme.includes('BHS 0.1.0'), 'ссылка на содержательную редакцию'); }); test('spec list и spec show работают на синтетической спецификации', () => { const list = runCli('spec', 'list', '--spec-root', specRoot); assert.equal(list.code, 0); assert.deepEqual( list.envelope.data.requirements.map((item) => item.id), ['req-synth-alpha', 'req-synth-beta', 'req-synth-gamma'], ); const byDomain = runCli('spec', 'list', '--spec-root', specRoot, '--domain', 'dom-synth-build'); assert.equal(byDomain.envelope.data.requirements.length, 3); const shown = runCli('spec', 'show', 'req-synth-alpha', '--spec-root', specRoot); assert.equal(shown.code, 0); assert.equal(shown.envelope.data.requirement.level, 'MUST'); const ghost = runCli('spec', 'show', 'req-ghost', '--spec-root', specRoot); assert.equal(ghost.code, 1); assert.equal(ghost.envelope.error.code, 'NOT_FOUND'); });