Files
harness-lab/tests/synthetic-spec.test.mjs
T
Suslov-MD 24eb332f2d feat: подключение лаборатории к BHS 0.1.0 (BHL-041)
- bhl.yaml: манифест потребителя (spec 0.1.0, профиль prof-core, без
  предварительных исключений)
- spec/profiles/prof-core.yaml: 15 требований без ослаблений; профили и
  пресеты валидируются bhl validate как факультативные каталоги
- конвейер release→sha256→fetch(lock)→verify→manifest→resolve закреплён
  интеграционным тестом; артефакты .artifacts/ вне Git
- инвентарь исключений и классификация отклонений (5.2) —
  results/dogfooding/2026-11-29-lab-connection.md
- check.mjs не сканирует .artifacts (локальное состояние сборки)
2026-11-29 11:46:56 +03:00

83 lines
4.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import test from 'node:test';
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
import { readFileSync, readdirSync } from 'node:fs';
import path from 'node:path';
const repoRoot = path.dirname(import.meta.dirname);
const cli = path.join(repoRoot, 'packages', 'bhl', 'src', 'cli.ts');
const specRoot = path.join(repoRoot, 'examples', 'synthetic-spec');
function runCli(...args) {
const proc = spawnSync(process.execPath, [cli, ...args], { encoding: 'utf8', cwd: repoRoot });
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('копия схем в примере синхронна с spec/schemas', () => {
const canonical = new Set(readdirSync(path.join(repoRoot, 'spec', 'schemas')));
const copy = new Set(readdirSync(path.join(specRoot, 'schemas')));
assert.deepEqual([...copy].sort(), [...canonical].sort());
for (const name of canonical) {
assert.equal(
readFileSync(path.join(specRoot, 'schemas', name), 'utf8'),
readFileSync(path.join(repoRoot, 'spec', 'schemas', name), 'utf8'),
`расхождение копии схемы ${name}`,
);
}
});
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');
});