fix(review): the workflow review floors an illegally lowered brief-conflict finding
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ce7700b71b
commit
8cc6ba0181
2 changed files with 331 additions and 5 deletions
|
|
@ -43,6 +43,20 @@ const RULE_KEYS = [
|
|||
'CODE_REVIEW_DEFECT', 'CODE_REVIEW_IMPROVEMENT', 'SECURITY_REVIEW_VULNERABILITY',
|
||||
];
|
||||
const SEVERITIES = ['BLOCKER', 'MAJOR', 'MINOR', 'SUGGESTION'];
|
||||
// Every catalogue rule_key -> its tier (lib/review/rule-catalogue.mjs; scripts
|
||||
// cannot import, so it is inlined and pinned equal by the workflow test).
|
||||
const RULE_TIERS = {
|
||||
MISSING_BRIEF_REF: 'MAJOR', UNIMPLEMENTED_CRITERION: 'BLOCKER', SCOPE_CREEP_BUILT: 'MAJOR',
|
||||
NON_GOAL_VIOLATED: 'BLOCKER', MISSING_TEST: 'MAJOR', SECURITY_INJECTION: 'BLOCKER',
|
||||
PLACEHOLDER_IN_CODE: 'MAJOR', MISSING_ERROR_HANDLING: 'MINOR', UNDECLARED_DEPENDENCY: 'MAJOR',
|
||||
PLAN_EXECUTE_DRIFT: 'MAJOR', BROKEN_SUCCESS_CRITERION: 'BLOCKER', COVERAGE_SILENT_SKIP: 'MAJOR',
|
||||
CODE_REVIEW_DEFECT: 'MAJOR', CODE_REVIEW_IMPROVEMENT: 'MINOR', SECURITY_REVIEW_VULNERABILITY: 'BLOCKER',
|
||||
};
|
||||
// Lower number = higher severity; an unknown severity ranks last (as
|
||||
// lib/review/coordinator-contract.mjs severityRank does).
|
||||
const sevRank = (s) => (SEVERITIES.includes(s) ? SEVERITIES.indexOf(s) : SEVERITIES.length);
|
||||
// The catalogue tier of a rule_key, or null when the key is missing or unknown.
|
||||
const tierOf = (key) => (typeof key === 'string' && Object.prototype.hasOwnProperty.call(RULE_TIERS, key) ? RULE_TIERS[key] : null);
|
||||
|
||||
// Findings schema — mirrors lib/review/findings-schema.mjs (NW1). The enum on
|
||||
// rule_key enforces the catalogue at the StructuredOutput layer (stronger than
|
||||
|
|
@ -94,6 +108,9 @@ const VERDICT_SCHEMA = {
|
|||
line: { type: 'integer', minimum: 0 },
|
||||
title: { type: 'string' },
|
||||
detail: { type: 'string' },
|
||||
engine: { type: 'string', enum: ['code-review', 'security-review'] },
|
||||
contradicts_brief: { type: 'string' },
|
||||
brief_lowered_from: { type: 'string', enum: ['MAJOR'] },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -102,12 +119,18 @@ const VERDICT_SCHEMA = {
|
|||
|
||||
// Inlined dedup by (file,line,rule_key) — the JS-side replacement for the
|
||||
// coordinator's pass-1 triplet dedup (T2 §5 / lib/review/plan-review-dedup.mjs
|
||||
// pattern; scripts cannot import, so the triplet key is inlined).
|
||||
// pattern; scripts cannot import, so the triplet key is inlined). On a
|
||||
// repeated triplet the higher severity stays; at equal severity the finding
|
||||
// with an `engine` stays; otherwise the first-seen one stays.
|
||||
function dedupByTriplet(findings) {
|
||||
const seen = new Map();
|
||||
for (const f of findings) {
|
||||
const key = `${f.file}\u0000${f.line}\u0000${f.rule_key}`;
|
||||
if (!seen.has(key)) seen.set(key, f);
|
||||
if (!seen.has(key)) { seen.set(key, f); continue; }
|
||||
const kept = seen.get(key);
|
||||
const higher = sevRank(f.severity) < sevRank(kept.severity);
|
||||
const tieToEngine = sevRank(f.severity) === sevRank(kept.severity) && Boolean(f.engine) && !kept.engine;
|
||||
if (higher || tieToEngine) seen.set(key, f);
|
||||
}
|
||||
return [...seen.values()];
|
||||
}
|
||||
|
|
@ -137,6 +160,16 @@ function coordinatorPrompt(merged, a) {
|
|||
'Return {verdict, findings} via StructuredOutput. Synthesis across files is forbidden.',
|
||||
`The brief (the contract) is at: ${a.briefPath} — Read it if needed for context.`,
|
||||
'',
|
||||
'=== BRIEF CHOICES (the brief-conflict rule) ===',
|
||||
`Read the brief's choices at ${a.briefPath}: \`## Non-Goals\`, \`## Constraints\`, \`## Preferences\`,`,
|
||||
'and the operator decisions in `## Open Questions / Assumptions`.',
|
||||
'Only an engine finding (`engine`: code-review or security-review) whose recommended action',
|
||||
'contradicts one of those choices is marked, with `contradicts_brief: "<the Non-Goal or choice, verbatim>"`.',
|
||||
'Only a /code-review finding at the MAJOR tier and at severity MAJOR then drops to MINOR, with',
|
||||
"`brief_lowered_from: 'MAJOR'`. Every other marked finding keeps its severity. A reviewer-agent finding",
|
||||
'(no `engine`) and a finding whose rule_key is not in the catalogue are never marked. A brief-conflicting',
|
||||
'finding is kept and marked, never removed. Each returned finding keeps its `engine` and `rule_key`.',
|
||||
'',
|
||||
'=== PRE-DEDUPED FINDINGS (JSON) ===',
|
||||
JSON.stringify(merged, null, 2),
|
||||
].join('\n');
|
||||
|
|
@ -171,8 +204,22 @@ const expectedEngines = a.quick ? ['claude-code-review'] : ['claude-code-review'
|
|||
const arrivedEngines = new Set(enginePayloads.map((p) => p.reviewer));
|
||||
const missingEngines = expectedEngines.filter((name) => !arrivedEngines.has(name));
|
||||
const missingReviewers = (rawResults.length - reviewerResults.length) + missingEngines.length;
|
||||
const allFindings = [...reviewerResults, ...enginePayloads]
|
||||
.flatMap((r) => (Array.isArray(r?.findings) ? r.findings : []));
|
||||
// Provenance, before dedup: "came from an engine" is read from the source,
|
||||
// never from an `engine` field. A reviewer finding loses any `engine` it
|
||||
// carries; an engine payload's findings get `engine` from its `reviewer`
|
||||
// (the names lib/review/engine-findings.mjs writes); any other payload gives
|
||||
// its findings no `engine`. So an `engine` in `merged` means an engine payload.
|
||||
const engineOf = (reviewer) => (reviewer === 'claude-code-review' ? 'code-review'
|
||||
: reviewer === 'claude-security-review' ? 'security-review' : null);
|
||||
const withEngine = (f, eng) => {
|
||||
if (!f || typeof f !== 'object') return f;
|
||||
const { engine: _dropped, ...rest } = f;
|
||||
return eng ? { ...rest, engine: eng } : rest;
|
||||
};
|
||||
const allFindings = [
|
||||
...reviewerResults.flatMap((r) => (Array.isArray(r?.findings) ? r.findings : []).map((f) => withEngine(f, null))),
|
||||
...enginePayloads.flatMap((p) => (Array.isArray(p?.findings) ? p.findings : []).map((f) => withEngine(f, engineOf(p?.reviewer)))),
|
||||
];
|
||||
const merged = dedupByTriplet(allFindings);
|
||||
log(`Arm B: ${reviewerResults.length} reviewer(s); ${allFindings.length} raw → ${merged.length} after triplet-dedup`);
|
||||
|
||||
|
|
@ -190,6 +237,33 @@ if (merged.length === 0) {
|
|||
// The verdict is mechanical: recompute its floor from the findings the
|
||||
// coordinator returned, so an LLM-written ALLOW over a BLOCKER cannot pass.
|
||||
const returned = Array.isArray(coord?.findings) ? coord.findings : merged;
|
||||
// The brief-conflict floor: every returned finding is judged from its
|
||||
// counterpart in the coordinator's input (`merged`, same file/line/rule_key),
|
||||
// never from the labels the coordinator wrote. The raise is written into
|
||||
// `returned`, the mark kept, so the rendered review.md carries it.
|
||||
const counterparts = new Map(merged
|
||||
.filter((m) => m && typeof m === 'object')
|
||||
.map((m) => [`${m.file}\u0000${m.line}\u0000${m.rule_key}`, m]));
|
||||
const present = (f, field) => f[field] !== undefined && f[field] !== null;
|
||||
const raiseTo = (f, sev) => { if (sevRank(sev) < sevRank(f.severity)) f.severity = sev; };
|
||||
for (const f of returned) {
|
||||
if (!f || typeof f !== 'object') continue;
|
||||
const c = counterparts.get(`${f.file}\u0000${f.line}\u0000${f.rule_key}`);
|
||||
const labelled = present(f, 'engine') || present(f, 'contradicts_brief') || present(f, 'brief_lowered_from');
|
||||
if (c && c.engine) {
|
||||
// (1) an engine counterpart: raised to its severity, unless the one legal lowering.
|
||||
const legal = c.engine === 'code-review' && c.severity === 'MAJOR' && tierOf(c.rule_key) === 'MAJOR' &&
|
||||
f.severity === 'MINOR' && typeof f.contradicts_brief === 'string' && f.contradicts_brief.trim().length > 0 &&
|
||||
f.brief_lowered_from === 'MAJOR';
|
||||
if (!legal) raiseTo(f, c.severity);
|
||||
f.engine = c.engine;
|
||||
} else if (labelled) {
|
||||
// (2) a reviewer counterpart, (3) no counterpart: an unknown key raises to BLOCKER.
|
||||
raiseTo(f, tierOf(f.rule_key) ?? 'BLOCKER');
|
||||
if (c) raiseTo(f, c.severity);
|
||||
delete f.engine;
|
||||
}
|
||||
}
|
||||
const has = (sev) => returned.some((f) => f && f.severity === sev);
|
||||
let verdict = coord?.verdict ?? null;
|
||||
if (has('BLOCKER')) verdict = 'BLOCK';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue