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 cli = path.join(import.meta.dirname, '..', 'src', 'cli.ts'); const pkg = JSON.parse(readFileSync(path.join(import.meta.dirname, '..', 'package.json'), 'utf8')); function run(...args) { const proc = spawnSync(process.execPath, [cli, ...args], { encoding: 'utf8' }); return { code: proc.status, stdout: proc.stdout, envelope: JSON.parse(proc.stdout) }; } test('version: стабильный JSON-конверт и код 0', () => { const first = run('version'); assert.equal(first.code, 0); assert.equal(first.envelope.ok, true); assert.equal(first.envelope.command, 'version'); assert.equal(first.envelope.data.version, pkg.version); assert.equal(first.envelope.data.name, '@baseline-harness/bhl'); const again = run('version'); assert.equal(again.stdout, first.stdout, 'повторный прогон даёт идентичный JSON'); }); test('использование: пустой запуск, --help и неизвестная команда — код 2', () => { assert.equal(run().code, 2); assert.equal(run('--help').code, 2); const unknown = run('nope'); assert.equal(unknown.code, 2); assert.equal(unknown.envelope.ok, false); assert.equal(unknown.envelope.error.code, 'USAGE'); }); test('известные команды Wave D/E пока возвращают NOT_IMPLEMENTED и код 3', () => { for (const command of ['spec', 'audit']) { const result = run(command); assert.equal(result.code, 3, command); assert.equal(result.envelope.ok, false, command); assert.equal(result.envelope.error.code, 'NOT_IMPLEMENTED', command); } });