import test from 'node:test'; import assert from 'node:assert/strict'; import { existsSync, readFileSync } from 'node:fs'; import path from 'node:path'; import { parseDocument } from 'yaml'; const treeRoot = path.join(import.meta.dirname, '..'); const labRoot = path.join(treeRoot, '..', '..'); const copyFile = path.join( import.meta.dirname, 'fixtures', 'normative', 'req-single-quality-command.yaml', ); // Transitional fallback for the migration only: until BHL-066 creates products/bhs-spec/, // the normative tree lives in spec/. Remove this constant together with the transition // entry in products.yaml — the declared tree is the intended source of truth (D-054). const LEGACY_SPEC_TREE = 'spec'; function normativeTree() { const registry = path.join(labRoot, 'products.yaml'); if (existsSync(registry)) { const products = parseDocument(readFileSync(registry, 'utf8')).toJS()?.products ?? []; const declared = products.find((product) => product?.id === 'bhs-spec')?.tree; if (typeof declared === 'string' && existsSync(path.join(labRoot, declared))) { return declared; } } return existsSync(path.join(labRoot, LEGACY_SPEC_TREE)) ? LEGACY_SPEC_TREE : null; } test('копия нормативного требования свежа: байты совпадают с деревом bhs-spec', (t) => { const tree = normativeTree(); if (tree === null) { t.skip('нормативное дерево лаборатории недоступно за пределами дерева продукта'); return; } const original = path.join(labRoot, tree, 'requirements', 'req-single-quality-command.yaml'); assert.ok(existsSync(original), `нормативный файл не найден в ${tree}/requirements/`); assert.equal( readFileSync(copyFile, 'utf8'), readFileSync(original, 'utf8'), `копия расходится с ${tree}/requirements/req-single-quality-command.yaml: обновите её целиком по tests/fixtures/normative/README.md`, ); });