BREAKING CHANGE: the {NNN} in CA-{SCANNER}-{NNN} identifies the check that
produced the finding. It used to be the finding's position in that scanner's
output for that run, which made it unstable across CONFIGURATIONS, not just
across releases as STATE framed it. Measured on two fixtures: "No custom
subagents" was CA-GAP-007 on minimal-project and CA-GAP-004 on healthy-project.
A user who fixed an unrelated earlier gap silently renumbered every later one,
so a .config-audit-ignore pin retargeted to a neighbouring finding with no
version change at all.
Second measured arm: README already documented the opposite scheme. It and the
scanner headers describe ~20 numbers as check codes (CA-SKL-003 = oversized
body, CA-PLH-015 = folder shadowing, CA-TOK-006 = schema deferral), and the
counter could only produce those in the all-fire case -- source-order positions
are 4, 3 and 8. The documentation described the scheme; the implementation was
what was wrong. Every published number is preserved by construction and pinned
exhaustively in tests/lib/finding-codes.test.mjs.
scanners/lib/finding-codes.mjs is the single authority. Every finding() call
passes a `code`; an undeclared or missing one THROWS. No counter fallback --
that would reproduce D1's findGapId -> 'unknown' silent degradation and let a
half-converted scanner ship IDs that look valid. findingCounter/resetCounter
are deleted outright, not left as no-ops. Retirement is now a mechanism:
RETIRED_CODES tombstones a withdrawn key so its number is never reissued,
seeded with GAP t3_8 -- the D1 removal that opened this chunk.
IDs are consequently NOT unique per finding: one check failing in three files
emits three findings sharing an ID. That inverts which consumer is correct, so
every f.id/findingId site was classified before the change. diff-engine and
most of fix-engine already keyed on scanner+title+file (drift was never lying);
fix-engine's verification did not, and keyed on the ID alone -- fixing one of
two sibling instances marked both fixed, and the untouched one, still present
in the re-scan, was reported as a REGRESSION. Red test first, then keyed on
(findingId, file), which both planFixes and applyFixes already carry.
plugin-health's crossIds Set was measured and is a clean negative: cross
findings are allFindings.slice(crossPluginStart) and codes 18/19 are emitted
only in that tail, so the partition holds by construction.
unknownSuppressions() reports a pin that names no declared check, in the
--output-file payload (ux-rules rule 2 -- a stderr-only warning is invisible to
the commands) and only when one exists, so a clean config is byte-identical.
That is what makes the break safe: a stale pin goes loud instead of dying quiet.
Frozen tests/snapshots/v5.0.0/ untouched on disk. IDs are masked out of that
comparison (mask-finding-ids.mjs) rather than re-derived -- re-deriving
positional IDs would assert the retired scheme against itself, and #58's
isGapEntry off-by-one is the measured example of that misfiring. The dead
re-derivation is removed from strip-retired-gap.mjs. default-output snapshots
re-approved after confirming the diff is IDs and nothing else.
Guards, each seen red against its own defect: a missing code (scanner errors
out mid-sweep), an orphan declaration, a resurrected retired key, and a
documented ID naming no check. The sweep asserts the union across all 16
scanners, never per scanner -- a per-scanner assertion goes green on a partial
conversion.
Fasit written before implementation: docs/mbug28-id-semantics-fasit.local.md,
including one correction made before running (CML has 12 checks over 13 call
sites -- the anchored and calibrated char-budget arms are one check, which a
repeated-title sweep found and my call-site count had missed).
Suite 1535 -> 1573, 0 failing.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MyqCQKK2ornJ1jFWwqx17E
157 lines
6.6 KiB
JavaScript
157 lines
6.6 KiB
JavaScript
import { describe, it } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { resolve, dirname } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { execFile } from 'node:child_process';
|
|
import { promisify } from 'node:util';
|
|
import { readFile, unlink } from 'node:fs/promises';
|
|
import { hermeticEnv } from '../helpers/hermetic-home.mjs';
|
|
import { stripHotspotLoadPattern } from '../helpers/strip-hotspot-load-pattern.mjs';
|
|
import { stripAddedScanners } from '../helpers/strip-added-scanner.mjs';
|
|
import { stripRetiredGap } from '../helpers/strip-retired-gap.mjs';
|
|
import { maskFindingIds } from '../helpers/mask-finding-ids.mjs';
|
|
|
|
const exec = promisify(execFile);
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const REPO = resolve(__dirname, '../..');
|
|
const CLI = resolve(REPO, 'scanners/scan-orchestrator.mjs');
|
|
const FIXTURE = resolve(REPO, 'tests/fixtures/marketplace-medium');
|
|
const SNAPSHOT_PATH = resolve(REPO, 'tests/snapshots/v5.0.0/scan-orchestrator.json');
|
|
|
|
/**
|
|
* Normalize a scan-orchestrator envelope for snapshot comparison by
|
|
* blanking out time-varying fields (timestamp, durations, target path)
|
|
* and ancestor-cascade-derived counts. `claudeMdEstimatedTokens` reflects
|
|
* walkClaudeMdCascade walking upward from the fixture; any docs edit to
|
|
* this plugin's own CLAUDE.md ripples into it even when scanner behavior
|
|
* is unchanged. Returns a NEW object — does not mutate input.
|
|
*/
|
|
function normalizeEnvelope(env) {
|
|
const out = JSON.parse(JSON.stringify(env));
|
|
if (out.meta) {
|
|
out.meta.target = '<TARGET>';
|
|
out.meta.timestamp = '<TIMESTAMP>';
|
|
}
|
|
if (Array.isArray(out.scanners)) {
|
|
for (const s of out.scanners) {
|
|
s.duration_ms = 0;
|
|
if (s.activeConfig && 'claudeMdEstimatedTokens' in s.activeConfig) {
|
|
s.activeConfig.claudeMdEstimatedTokens = '<ANCESTOR_DERIVED>';
|
|
}
|
|
}
|
|
}
|
|
return maskFindingIds(stripRetiredGap(stripAddedScanners(stripHotspotLoadPattern(out))));
|
|
}
|
|
|
|
async function runOrchestrator(flags) {
|
|
const out = `/tmp/scan-orch-humanizer-${process.pid}-${Date.now()}-${Math.random()}.json`;
|
|
try {
|
|
await exec('node', [CLI, FIXTURE, '--output-file', out, ...flags], {
|
|
timeout: 60000,
|
|
cwd: REPO,
|
|
env: hermeticEnv(),
|
|
});
|
|
const written = await readFile(out, 'utf-8');
|
|
return JSON.parse(written);
|
|
} finally {
|
|
await unlink(out).catch(() => {});
|
|
}
|
|
}
|
|
|
|
describe('scan-orchestrator humanizer wiring (Step 5)', () => {
|
|
describe('--json mode (SC-6: byte-equal v5.0.0)', () => {
|
|
it('produces envelope structurally equal to v5.0.0 snapshot', async () => {
|
|
const actual = await runOrchestrator(['--json']);
|
|
const expected = JSON.parse(await readFile(SNAPSHOT_PATH, 'utf-8'));
|
|
assert.deepStrictEqual(normalizeEnvelope(actual), normalizeEnvelope(expected));
|
|
});
|
|
|
|
it('does NOT add humanizer fields to findings', async () => {
|
|
const actual = await runOrchestrator(['--json']);
|
|
for (const s of actual.scanners) {
|
|
for (const f of s.findings) {
|
|
assert.equal(f.userImpactCategory, undefined,
|
|
`${f.id}: --json findings must not have userImpactCategory`);
|
|
assert.equal(f.userActionLanguage, undefined,
|
|
`${f.id}: --json findings must not have userActionLanguage`);
|
|
assert.equal(f.relevanceContext, undefined,
|
|
`${f.id}: --json findings must not have relevanceContext`);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('--raw mode (SC-7: byte-equal v5.0.0)', () => {
|
|
it('produces envelope structurally equal to v5.0.0 snapshot', async () => {
|
|
const actual = await runOrchestrator(['--raw']);
|
|
const expected = JSON.parse(await readFile(SNAPSHOT_PATH, 'utf-8'));
|
|
assert.deepStrictEqual(normalizeEnvelope(actual), normalizeEnvelope(expected));
|
|
});
|
|
|
|
it('does NOT add humanizer fields to findings', async () => {
|
|
const actual = await runOrchestrator(['--raw']);
|
|
for (const s of actual.scanners) {
|
|
for (const f of s.findings) {
|
|
assert.equal(f.userImpactCategory, undefined,
|
|
`${f.id}: --raw findings must not have userImpactCategory`);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('default mode (humanized)', () => {
|
|
it('preserves envelope-level shape', async () => {
|
|
const actual = await runOrchestrator([]);
|
|
assert.ok(actual.meta, 'meta present');
|
|
assert.ok(Array.isArray(actual.scanners), 'scanners array present');
|
|
assert.ok(actual.aggregate, 'aggregate present');
|
|
assert.equal(actual.scanners.length, 16, 'all 16 scanners present');
|
|
});
|
|
|
|
it('preserves scanner shape (scanner/status/findings/counts)', async () => {
|
|
const actual = await runOrchestrator([]);
|
|
for (const s of actual.scanners) {
|
|
assert.ok(typeof s.scanner === 'string', 'scanner name string');
|
|
assert.ok(typeof s.status === 'string', 'status string');
|
|
assert.ok(Array.isArray(s.findings), 'findings array');
|
|
assert.ok(s.counts, 'counts object');
|
|
}
|
|
});
|
|
|
|
it('adds humanizer fields to every finding', async () => {
|
|
const actual = await runOrchestrator([]);
|
|
let totalFindings = 0;
|
|
for (const s of actual.scanners) {
|
|
for (const f of s.findings) {
|
|
totalFindings++;
|
|
assert.equal(typeof f.userImpactCategory, 'string',
|
|
`${f.id}: userImpactCategory must be string`);
|
|
assert.equal(typeof f.userActionLanguage, 'string',
|
|
`${f.id}: userActionLanguage must be string`);
|
|
assert.equal(typeof f.relevanceContext, 'string',
|
|
`${f.id}: relevanceContext must be string`);
|
|
assert.ok(['test-fixture-no-impact', 'affects-this-machine-only', 'affects-everyone'].includes(f.relevanceContext),
|
|
`${f.id}: relevanceContext must be one of allowed values, got ${f.relevanceContext}`);
|
|
}
|
|
}
|
|
assert.ok(totalFindings > 0, 'expected at least one finding to assert against');
|
|
});
|
|
|
|
it('preserves stable identifiers (id, scanner, severity)', async () => {
|
|
const actualHumanized = await runOrchestrator([]);
|
|
const actualRaw = await runOrchestrator(['--raw']);
|
|
|
|
const flatHumanized = actualHumanized.scanners.flatMap(s => s.findings);
|
|
const flatRaw = actualRaw.scanners.flatMap(s => s.findings);
|
|
assert.equal(flatHumanized.length, flatRaw.length, 'finding count matches');
|
|
|
|
for (let i = 0; i < flatHumanized.length; i++) {
|
|
const h = flatHumanized[i];
|
|
const r = flatRaw[i];
|
|
assert.equal(h.id, r.id, `finding ${i} id matches`);
|
|
assert.equal(h.scanner, r.scanner, `finding ${i} scanner matches`);
|
|
assert.equal(h.severity, r.severity, `finding ${i} severity matches`);
|
|
}
|
|
});
|
|
});
|
|
});
|