fix: ремедиация аудита лаборатории — решения и исправления (BHL-043)
- решения владельца: D-039 принято (SemVer), D-044 (BLOCKED — седьмой статус), D-045 (у param-coverage-threshold нет глобального default), D-046 (уточнение D-040: обезличенные производные выводы разрешены) - chg-018 STRENGTHENED + migration: значение задаёт профиль/манифест - C1: bhl audit --spec-version (fallback на lock.json кеша, иначе ошибка) - C2: UNKNOWN-находки валидны по схеме evidence (review-note, locator, дата) - C3: treeFingerprint игнорирует .pi/.artifacts/.cache/.tmp - C4: req-single-quality-command — детерминированная проверка - L1: порог длины id вынесен в именованную константу MAX_ID_LENGTH - пакет: 48/48 тестов, корень зелёный
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
||||
import { mkdirSync, mkdtempSync, cpSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
|
||||
@@ -39,6 +39,8 @@ function runAudit(t, projectFiles) {
|
||||
specRoot,
|
||||
'--preset',
|
||||
'preset-synth-all',
|
||||
'--spec-version',
|
||||
'0.1.0',
|
||||
'--generated-at',
|
||||
GENERATED_AT,
|
||||
],
|
||||
@@ -115,3 +117,118 @@ test('audit: usage-ошибки и нечитаемый spec-root дают по
|
||||
assert.equal(badSpec.status, 1);
|
||||
assert.equal(JSON.parse(badSpec.stdout).error.code, 'VALIDATION_FAILED');
|
||||
});
|
||||
|
||||
function makeFixtureSpec(t) {
|
||||
const dir = makeDir();
|
||||
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
||||
const spec = path.join(dir, 'spec');
|
||||
cpSync(specRoot, spec, { recursive: true });
|
||||
return { dir, spec };
|
||||
}
|
||||
|
||||
function auditRun(spec, projectDir, out, extraArgs) {
|
||||
return spawnSync(
|
||||
process.execPath,
|
||||
[
|
||||
cli,
|
||||
'audit',
|
||||
projectDir,
|
||||
'--out',
|
||||
out,
|
||||
'--spec-root',
|
||||
spec,
|
||||
'--generated-at',
|
||||
GENERATED_AT,
|
||||
...extraArgs,
|
||||
],
|
||||
{ encoding: 'utf8' },
|
||||
);
|
||||
}
|
||||
|
||||
test('audit: версия спецификации из флага, из lock.json или ошибка (C1/BHL-043)', (t) => {
|
||||
const { dir, spec } = makeFixtureSpec(t);
|
||||
const project = path.join(dir, 'project');
|
||||
writeProject(project, GOOD_PROJECT);
|
||||
const noVersion = auditRun(spec, project, path.join(dir, 'r1.json'), []);
|
||||
assert.equal(noVersion.status, 1);
|
||||
assert.equal(JSON.parse(noVersion.stdout).error.code, 'VALIDATION_FAILED');
|
||||
assert.match(noVersion.stdout, /spec-version-unknown/);
|
||||
writeProject(dir, { 'lock.json': JSON.stringify({ version: '9.9.9' }) });
|
||||
const fromLock = auditRun(spec, project, path.join(dir, 'r2.json'), []);
|
||||
assert.equal(fromLock.status, 0, fromLock.stdout);
|
||||
const report = JSON.parse(readFileSync(path.join(dir, 'r2.json'), 'utf8'));
|
||||
assert.equal(report.spec_version, '9.9.9');
|
||||
const flagged = auditRun(spec, project, path.join(dir, 'r3.json'), ['--spec-version', '8.8.8']);
|
||||
assert.equal(flagged.status, 0);
|
||||
assert.equal(JSON.parse(readFileSync(path.join(dir, 'r3.json'), 'utf8')).spec_version, '8.8.8');
|
||||
});
|
||||
|
||||
test('audit: UNKNOWN-находки валидны по схеме отчёта (C2/BHL-043)', (t) => {
|
||||
const { dir, spec } = makeFixtureSpec(t);
|
||||
const alpha = readFileSync(path.join(spec, 'requirements', 'req-synth-alpha.yaml'), 'utf8');
|
||||
writeProject(spec, {
|
||||
'requirements/req-plain-no-check.yaml': alpha.replace('req-synth-alpha', 'req-plain-no-check'),
|
||||
'profiles/prof-plain.yaml':
|
||||
'id: prof-plain\ntitle: Только без проверки\ndescription: Профиль фикстуры с требованием без детерминированной проверки.\nrequirements:\n - requirement: req-plain-no-check\n',
|
||||
});
|
||||
const project = path.join(dir, 'project');
|
||||
writeProject(project, GOOD_PROJECT);
|
||||
const out = path.join(dir, 'r.json');
|
||||
const run = auditRun(spec, project, out, ['--spec-version', '0.1.0', '--profile', 'prof-plain']);
|
||||
assert.equal(run.status, 0, run.stdout);
|
||||
const report = JSON.parse(readFileSync(out, 'utf8'));
|
||||
assert.equal(report.findings[0].status, 'UNKNOWN');
|
||||
const validate = spawnSync(
|
||||
process.execPath,
|
||||
[cli, 'report', 'validate', out, '--spec-root', spec],
|
||||
{
|
||||
encoding: 'utf8',
|
||||
},
|
||||
);
|
||||
assert.equal(validate.status, 0, validate.stdout);
|
||||
});
|
||||
|
||||
test('audit: отпечаток не зависит от изменчивого локального состояния .pi/.artifacts (C3/BHL-043)', (t) => {
|
||||
const { dir, spec } = makeFixtureSpec(t);
|
||||
const project = path.join(dir, 'project');
|
||||
writeProject(project, GOOD_PROJECT);
|
||||
const first = auditRun(spec, project, path.join(dir, 'r1.json'), ['--spec-version', '0.1.0']);
|
||||
assert.equal(first.status, 0, first.stdout);
|
||||
writeProject(project, {
|
||||
'.pi/transcript.jsonl': '{"turn":1}\n',
|
||||
'.artifacts/tmp.bin': 'volatile',
|
||||
});
|
||||
const second = auditRun(spec, project, path.join(dir, 'r2.json'), ['--spec-version', '0.1.0']);
|
||||
assert.equal(second.status, 0, second.stdout);
|
||||
assert.equal(
|
||||
readFileSync(path.join(dir, 'r2.json'), 'utf8'),
|
||||
readFileSync(path.join(dir, 'r1.json'), 'utf8'),
|
||||
);
|
||||
});
|
||||
|
||||
test('audit: req-single-quality-command проверяется детерминированно (C4/BHL-043)', (t) => {
|
||||
const { dir, spec } = makeFixtureSpec(t);
|
||||
const realReq = path.join(
|
||||
import.meta.dirname,
|
||||
'..',
|
||||
'..',
|
||||
'..',
|
||||
'spec',
|
||||
'requirements',
|
||||
'req-single-quality-command.yaml',
|
||||
);
|
||||
cpSync(realReq, path.join(spec, 'requirements', 'req-single-quality-command.yaml'));
|
||||
writeProject(spec, {
|
||||
'profiles/prof-real.yaml':
|
||||
'id: prof-real\ntitle: Реальное требование\ndescription: Профиль фикстуры с реальным требованием единой команды качества.\nrequirements:\n - requirement: req-single-quality-command\n',
|
||||
});
|
||||
const project = path.join(dir, 'project');
|
||||
writeProject(project, GOOD_PROJECT);
|
||||
const out = path.join(dir, 'r.json');
|
||||
const run = auditRun(spec, project, out, ['--spec-version', '0.1.0', '--profile', 'prof-real']);
|
||||
assert.equal(run.status, 0, run.stdout);
|
||||
const report = JSON.parse(readFileSync(out, 'utf8'));
|
||||
const finding = report.findings.find((f) => f.requirement === 'req-single-quality-command');
|
||||
assert.equal(finding.method, 'deterministic');
|
||||
assert.equal(finding.status, 'PASS');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user