fix(gate): part 2 verifier findings — non-object findings, carried backed copy, rule_keys, marks, approval prose, brief_path, engine put-back once
1. plan-review-dedup skips only a null or undefined finding; any other entry that is not an object (a string, a number, an array) goes on as before E, a finding with no valid severity that the plan gate counts as a blocker (it was dropped, so a string blocker recorded PASS). 2. plan-gate --record: a previous finding that rule A carried as counted and whose id is backed this round leaves the counted set, the counts, the verdict and the stop rule's summary (it was counted and listed in known_outside at once: BLOCK, not-fewer, and --accept-open refused). 3. A known_outside entry keeps rule_keys; extractVerdict accepts it (a list of strings), and the bare gate re-checks with the same keys the recorder used, so a merged finding whose security key is only in rule_keys is a WARN, not a STOP. 4. plan-critic, scope-guardian and /trekplan Phase 9's round-2 sentences say the Critic Verdict also lists known_outside and each is marked by id in previous. Code already accepts such a mark (dedup passes it; countRound ignores ids it does not carry; --record removes the entry on true); pinned in diff mode and full count. 5. The approval prose names ## Threat Model where it named only ## Intent + ## Goal: skills/annotating/SKILL.md (description, step 4, guard list), docs/command-modes.md, Handover 1's intent_approved_hash row, README (approval, Approve row, intent approval gate) and CLAUDE.md's /trekbrief row. 6. threat-model.mjs gains usableInRepo (a brief path relative to the repo top level) and repoRelativeBrief; --record stores brief_path relative to the top level, never absolute, and both gates read it from there, so the gate run from a subdirectory reads the same brief. reviewThreatModel uses usableInRepo. Handover 4 and the gate header say so. 7. review-finalize's outside pass puts an entry back only when no finding carries its row yet (engine-compare rowOf): an engine finding listed in known_outside while its payload is saved went back twice. 8. A test runs scripts/release-check.mjs on a review whose known_outside entry the brief does not back: exit 2 (control: backed passes the review check). Existing tests changed: plan-gate-threat-model's entry-keys assertion now expects rule_keys (item 3), and its planted non-security entry drops the security key from rule_keys too, since the gate reads rule_keys (item 3). Part 2 fix round of the E plan. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c47061191c
commit
1be961aab1
17 changed files with 298 additions and 52 deletions
|
|
@ -23,7 +23,7 @@ import { test } from 'node:test';
|
|||
import { strict as assert } from 'node:assert';
|
||||
import { resolve, join } from 'node:path';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { mkdtempSync, writeFileSync, readFileSync, rmSync, realpathSync } from 'node:fs';
|
||||
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, realpathSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { gatePlan, recordVerdict, planHash, operativeText, extractVerdict } from '../../lib/validators/plan-gate.mjs';
|
||||
|
|
@ -122,9 +122,10 @@ test('record: a backed security finding leaves the counted set and goes to known
|
|||
assert.deepEqual(v.findings, []);
|
||||
assert.equal(v.known_outside?.length, 1, JSON.stringify(v));
|
||||
const e = v.known_outside[0];
|
||||
assert.deepEqual(Object.keys(e).sort(), ['id', 'line', 'rule_key', 'text']);
|
||||
assert.deepEqual(Object.keys(e).sort(), ['id', 'line', 'rule_key', 'rule_keys', 'text']);
|
||||
assert.match(e.id, /^[0-9a-f]{40}$/);
|
||||
assert.equal(e.rule_key, 'SECURITY_RISK');
|
||||
assert.deepEqual(e.rule_keys, ['SECURITY_RISK']);
|
||||
assert.equal(e.text, S1);
|
||||
assert.equal(e.line, OUTSIDE);
|
||||
assert.equal(v.brief_path, 'brief.md');
|
||||
|
|
@ -246,7 +247,7 @@ test('gate guard: a planted known_outside entry that is not a Voyage security fi
|
|||
assert.equal(r.verdict.known_outside?.length, 1, 'round 1 lists the backed finding');
|
||||
const planted = r.text.replace(/```json\n[\s\S]*?\n```/, () => {
|
||||
const v = extractVerdict(r.text).verdict;
|
||||
return '```json\n' + JSON.stringify({ ...v, known_outside: [{ ...v.known_outside[0], rule_key: 'MISSING_TEST' }] }, null, 2) + '\n```';
|
||||
return '```json\n' + JSON.stringify({ ...v, known_outside: [{ ...v.known_outside[0], rule_key: 'MISSING_TEST', rule_keys: ['MISSING_TEST'] }] }, null, 2) + '\n```';
|
||||
});
|
||||
assert.equal(extractVerdict(planted).error, null);
|
||||
const g = gatePlan(planted, { threatModel: TM });
|
||||
|
|
@ -313,6 +314,35 @@ test('CLI: --record --brief lists a backed finding as a known issue; the gate wa
|
|||
}
|
||||
});
|
||||
|
||||
test('fix 6: brief_path is stored relative to the repo top level, and the gate run from a subdirectory reads the same brief', () => {
|
||||
const dir = realpathSync(mkdtempSync(join(tmpdir(), 'plan-gate-tm-')));
|
||||
try {
|
||||
assert.equal(spawnSync('git', ['init', '-q'], { cwd: dir, env: childEnv(GIT_CLEAN) }).status, 0);
|
||||
const b = join(dir, 'brief.md');
|
||||
const s = stampIntentApproval(BRIEF, new Date(NOW));
|
||||
writeFileSync(b, s.text);
|
||||
const repo = resolveRepo(dir);
|
||||
assert.equal(appendApproval({ repo, kind: 'intent', subject: normalizeSubject(repo, b), sha: normalizeHex(s.hash) }).appended, true);
|
||||
const sub = join(dir, 'sub');
|
||||
mkdirSync(sub);
|
||||
const p = join(dir, 'plan.md');
|
||||
for (const [cwd, briefArg] of [[dir, 'brief.md'], [sub, '../brief.md'], [sub, b]]) {
|
||||
writeFileSync(p, buildPlan());
|
||||
const t1 = readFileSync(p, 'utf-8');
|
||||
const payload = dd({ pc: [{ ...f('blocker', at(t1, R1_CHANGES), S1, 'SECURITY_RISK', { threat_model_ref: OUTSIDE }), file: p }] });
|
||||
const c1 = run(cwd, ['--record', p, '--brief', briefArg, '--reviewed', planHash(t1)], JSON.stringify(payload));
|
||||
assert.equal(c1.code, 0, c1.out + c1.err);
|
||||
assert.equal(lastJson(c1.out).known_outside, 1, `${cwd} ${briefArg}: ${c1.out}`);
|
||||
assert.equal(extractVerdict(readFileSync(p, 'utf-8')).verdict.brief_path, 'brief.md', `stored relative to the top level (${briefArg})`);
|
||||
const g = run(sub, [p]);
|
||||
assert.equal(g.code, 0, `the gate from a subdirectory: ${g.out}`);
|
||||
assert.match(g.out, /WARN {2}\[PLAN_GATE_KNOWN_OUTSIDE\]/);
|
||||
}
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('CLI: --brief without a value is a usage error; a threat model that is not usable is said in the output', () => {
|
||||
const dir = realpathSync(mkdtempSync(join(tmpdir(), 'plan-gate-tm-')));
|
||||
try {
|
||||
|
|
@ -337,6 +367,73 @@ test('CLI: --brief without a value is a usage error; a threat model that is not
|
|||
}
|
||||
});
|
||||
|
||||
// ---- Part 2 fix round ---------------------------------------------------------------
|
||||
|
||||
test('fix 1: a string entry in a reviewer\'s findings still counts as a blocker through dedup and --record', () => {
|
||||
const t1 = buildPlan();
|
||||
const d = dedupFindings([
|
||||
{ agent: 'plan-critic', payload: { findings: ['BLOCKER: step 2 runs rm -rf on an unquoted user path'] } },
|
||||
{ agent: 'scope-guardian', payload: { findings: [] } },
|
||||
]);
|
||||
assert.equal(d.findings.length, 1, 'the string entry is kept as a finding with no valid severity');
|
||||
const r = rec(t1, d);
|
||||
assert.equal(r.verdict.counts.blocker, 1);
|
||||
assert.equal(r.verdict.verdict, 'BLOCK');
|
||||
});
|
||||
|
||||
test('fix 2: a finding counted in round 1 and backed in round 2 (same id, marked resolved: false) is listed once and counts nowhere', () => {
|
||||
const t1 = buildPlan();
|
||||
const r1 = rec(t1, dd({ pc: [f('blocker', at(t1, R1_CHANGES), S1, 'SECURITY_RISK')] }));
|
||||
const id = r1.verdict.findings[0].id;
|
||||
const t2 = editA(r1.text);
|
||||
const r2 = rec(t2, dd({
|
||||
pc: [f('blocker', at(t2, R1_CHANGES), S1, 'SECURITY_RISK', { threat_model_ref: OUTSIDE })],
|
||||
pcPrev: [{ id, resolved: false }], sgPrev: [{ id, resolved: false }],
|
||||
}), { base: baseOf(r1.text), threatModel: TM, briefPath: 'brief.md' });
|
||||
const v = r2.verdict;
|
||||
assert.deepEqual(v.findings.map(x => x.id), [], 'the carried copy left the counted set');
|
||||
assert.deepEqual(v.counts, { blocker: 0, major: 0, minor: 0 });
|
||||
assert.equal(v.verdict, 'PASS');
|
||||
assert.deepEqual((v.known_outside ?? []).map(e => e.id), [id]);
|
||||
assert.equal(v.rounds.at(-1).blocking, 0, 'it left the stop-rule summary');
|
||||
assert.equal(v.stop_rule.fired, false, JSON.stringify(v.stop_rule));
|
||||
assert.equal(gatePlan(r2.text, { threatModel: TM }).code, 0);
|
||||
});
|
||||
|
||||
test('fix 3: a merged finding whose security key is only in rule_keys is backed at record and in the bare gate alike', () => {
|
||||
const t1 = buildPlan();
|
||||
const l = at(t1, R1_CHANGES);
|
||||
const d = dd({
|
||||
pc: [f('blocker', l, S1, 'injection/shell', { threat_model_ref: OUTSIDE })],
|
||||
sg: [f('blocker', l, S1, 'SECURITY_RISK', { threat_model_ref: OUTSIDE })],
|
||||
});
|
||||
assert.equal(d.findings.length, 1, 'dedup merged the two');
|
||||
const r = rec(t1, d, { threatModel: TM, briefPath: 'brief.md' });
|
||||
assert.equal(r.verdict.known_outside?.length, 1);
|
||||
assert.deepEqual(r.verdict.known_outside[0].rule_keys, ['injection/shell', 'SECURITY_RISK']);
|
||||
const g = gatePlan(r.text, { threatModel: TM });
|
||||
assert.equal(g.code, 0, JSON.stringify(g.reasons));
|
||||
assert.ok(g.warnings.some(w => w.code === 'PLAN_GATE_KNOWN_OUTSIDE'), JSON.stringify(g.warnings));
|
||||
// extractVerdict accepts rule_keys and refuses a malformed one.
|
||||
const v = extractVerdict(r.text).verdict;
|
||||
const bad = r.text.replace(/```json\n[\s\S]*?\n```/, () => '```json\n' + JSON.stringify({ ...v, known_outside: [{ ...v.known_outside[0], rule_keys: [7] }] }, null, 2) + '\n```');
|
||||
assert.ok(extractVerdict(bad).error, 'a rule_keys that is not a list of strings is malformed');
|
||||
});
|
||||
|
||||
test('fix 4: a reviewer\'s mark on a known_outside id passes dedup and the count, and resolved: true removes the entry (diff mode and full count)', () => {
|
||||
const r1 = backedRound1();
|
||||
const id = r1.verdict.known_outside?.[0]?.id;
|
||||
assert.ok(id, 'round 1 lists the backed finding');
|
||||
const t2 = editA(r1.text);
|
||||
const d = dd({ pcPrev: [{ id, resolved: true }], sgPrev: [{ id, resolved: true }] });
|
||||
assert.deepEqual(d.marks, [{ agent: 'plan-critic', id, resolved: true }, { agent: 'scope-guardian', id, resolved: true }]);
|
||||
for (const opts of [{ base: baseOf(r1.text) }, { baseNote: 'no snapshot; full counting' }]) {
|
||||
const r2 = recordVerdict(t2, d, { reviewed: planHash(t2), planPaths: PATHS, now: NOW, ...opts });
|
||||
assert.equal(r2.code, 0, r2.message);
|
||||
assert.equal(r2.verdict.known_outside, undefined, JSON.stringify(opts));
|
||||
}
|
||||
});
|
||||
|
||||
// ---- Handover 4 ---------------------------------------------------------------------
|
||||
|
||||
test('Handover 4 names --brief, known_outside, brief_path and the two new codes', () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue