feat: синтетическая спецификация для сквозных прогонов (BHL-018)
- examples/synthetic-spec: полный набор сущностей, профилей, пресета и антипаттерна - bhl validate и profile resolve проходят пример без диагностик - тест сверяет копию схем с spec/schemas и порядок разрешения - README карты лаборатории дополнен spec/ и examples/
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
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, []);
|
||||
assert.equal(result.envelope.data.files, 8);
|
||||
});
|
||||
|
||||
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'), 'ссылка на содержательную редакцию');
|
||||
});
|
||||
Reference in New Issue
Block a user