Skip to content

Commit abe9a4e

Browse files
committed
fix(pr-management): serialise findings in render's field names
Review fixups: - serializeFindingsForRender wrote body / rule / fixup, which render never reads, so every inline comment rendered from the file came out as a bare title. It now keeps every field of the original finding (explanation, rule_id, quoted_rule, excerpt, suggestion_block, side, reviewers, ...), drops the parser-only aliases, overrides the normalised file / line / severity, and maps body / rule to explanation / rule_id when the finding had only those. - Tests: a full Step-4 finding round-trips with every key render reads, and render's numbering over the serialised file matches formatKeepAnswer on the inputs where the raw keys diverge (lineNumber / line_number aliases, the string "0", a non-object item). - A numeric non-integer or negative line and a non-string severity are now recorded in errors, like their string counterparts. - The Codex manifest picks up the version main moved to. Generated-by: Claude Opus 5.5
1 parent 301e5eb commit abe9a4e

3 files changed

Lines changed: 122 additions & 14 deletions

File tree

‎plugins/magpie-pr-management/.codex-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "magpie-pr-management",
33
"description": "Apache Magpie \u2014 PR-queue management: triage, stats, deep code review, stack review, quick-merge, stale-sweep, reviewer routing, pre-first-PR checks.",
4-
"version": "0.9.0.dev202610280340",
4+
"version": "0.9.0.dev202611010039",
55
"author": {
66
"name": "Apache Magpie",
77
"url": "https://magpie.apache.org/"

‎plugins/magpie-pr-management/hooks/review-findings.test.ts‎

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,21 @@ describe('magpie-pr-management review findings mod (PR-1)', () => {
115115
assert(errors[0].includes("Malformed line number '12.5'"));
116116
});
117117

118+
test('numeric non-integer or negative lines and non-string severities are recorded', () => {
119+
const errors: string[] = [];
120+
assertStrictEqual(normalizeLine(12.5, errors), null);
121+
assertStrictEqual(normalizeLine(-3, errors), null);
122+
assertStrictEqual(normalizeLine(0, errors), null);
123+
assertStrictEqual(errors.length, 2);
124+
assert(errors[1].includes("Malformed line number '-3'"));
125+
126+
const sevErrors: string[] = [];
127+
assertStrictEqual(normalizeSeverity(3, sevErrors), 'minor');
128+
assertStrictEqual(normalizeSeverity(undefined, sevErrors), 'minor');
129+
assertStrictEqual(sevErrors.length, 1);
130+
assert(sevErrors[0].includes("Invalid severity type 'number'"));
131+
});
132+
118133
test('normalizeSource validates reviewer source attributes', () => {
119134
assertStrictEqual(normalizeSource('primary'), 'primary');
120135
assertStrictEqual(normalizeSource('adversarial'), 'adversarial');
@@ -281,7 +296,74 @@ describe('magpie-pr-management review findings mod (PR-1)', () => {
281296
assertStrictEqual(decoded[0].file, 'a.py');
282297
assertStrictEqual(decoded[0].line, 142);
283298
assertStrictEqual(decoded[0].severity, 'blocking');
284-
assertStrictEqual(decoded[0].body, 'Syntax flaw');
299+
assertStrictEqual(decoded[0].explanation, 'Syntax flaw');
300+
assertStrictEqual(decoded[0].rule_id, 'syntax');
301+
});
302+
303+
test('round-trips a full Step-4 finding with every key render reads', () => {
304+
const step4 = {
305+
file: './src/hook.py',
306+
line_number: '142',
307+
side: 'RIGHT',
308+
level: 'major',
309+
category: 'Code quality',
310+
rule_id: 'no in-function imports',
311+
quoted_rule: 'Flag any import inside a function body',
312+
excerpt: 'def f():\n import boto3',
313+
explanation: 'The import runs on every call.',
314+
suggestion: 'Move the import to module level.',
315+
suggestion_block: ' import boto3',
316+
reviewers: ['codex', 'copilot'],
317+
comment: 'edited comment text',
318+
action: 'edit',
319+
};
320+
const decoded = JSON.parse(serializeFindingsForRender(parseFindings([step4]).findings))[0];
321+
assertStrictEqual(decoded.file, 'src/hook.py');
322+
assertStrictEqual(decoded.line, 142);
323+
assertStrictEqual(decoded.severity, 'major');
324+
for (const key of [
325+
'side',
326+
'category',
327+
'rule_id',
328+
'quoted_rule',
329+
'excerpt',
330+
'explanation',
331+
'suggestion',
332+
'suggestion_block',
333+
'comment',
334+
]) {
335+
assertStrictEqual(decoded[key], (step4 as Record<string, unknown>)[key], `key ${key}`);
336+
}
337+
assertDeepStrictEqual(decoded.reviewers, ['codex', 'copilot']);
338+
for (const alias of ['line_number', 'level', 'action']) {
339+
assertStrictEqual(alias in decoded, false, `alias ${alias} dropped`);
340+
}
341+
});
342+
343+
test('render numbering over the serialised file matches formatKeepAnswer', () => {
344+
// Inputs where the raw keys and render's rule diverge: aliases render
345+
// never reads, the string "0" (truthy in Python), a non-object item.
346+
const rawDataset: unknown[] = [
347+
{ file: 'a.py', lineNumber: 12, body: 'alias lineNumber', action: 'accept' },
348+
{ file: 'b.py', line: '0', body: 'string zero', action: 'accept' },
349+
'not an object',
350+
{ file: 'c.py', line_number: 7, body: 'alias line_number', action: 'skip' },
351+
{ file: 'd.py', line: 30, body: 'plain line', action: 'edit' },
352+
{ file: 'e.py', line: null, body: 'unanchored', action: 'accept' },
353+
];
354+
const parsed = parseFindings(rawDataset);
355+
const serialised = JSON.parse(serializeFindingsForRender(parsed.findings)) as Array<
356+
Record<string, unknown>
357+
>;
358+
// render: anchored = [f for f in findings if f.get("line")]
359+
const renderAnchored = serialised.filter((f) => Boolean(f.line));
360+
const actions = parsed.findings.filter(isAnchored).map((f) => f.action);
361+
assertStrictEqual(renderAnchored.length, actions.length);
362+
const renderKept = renderAnchored
363+
.map((_, i) => i + 1)
364+
.filter((i) => actions[i - 1] === 'accept' || actions[i - 1] === 'edit');
365+
assertStrictEqual(formatKeepAnswer(parsed.findings), renderKept.join(','));
366+
assertStrictEqual(formatKeepAnswer(parsed.findings), '1,3');
285367
});
286368
});
287369

‎plugins/magpie-pr-management/hooks/review-findings.ts‎

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ import type {
3232
*/
3333
export function normalizeSeverity(raw: unknown, errors?: string[]): FindingSeverity {
3434
if (typeof raw !== 'string') {
35+
if (raw !== undefined && raw !== null && errors) {
36+
errors.push(`Invalid severity type '${typeof raw}'; defaulted to 'minor'`);
37+
}
3538
return 'minor';
3639
}
3740
const clean = raw.trim().toLowerCase();
@@ -80,7 +83,11 @@ export function normalizeFilePath(raw: unknown): string {
8083
*/
8184
export function normalizeLine(raw: unknown, errors?: string[]): number | null {
8285
if (typeof raw === 'number') {
83-
return Number.isInteger(raw) && raw >= 1 ? raw : null;
86+
if (Number.isInteger(raw) && raw >= 1) return raw;
87+
if (raw !== 0 && errors) {
88+
errors.push(`Malformed line number '${raw}'; treated as unanchored`);
89+
}
90+
return null;
8491
}
8592
if (typeof raw === 'string') {
8693
const trimmed = raw.trim();
@@ -219,20 +226,39 @@ export function formatKeepAnswer(findings: readonly ReviewFinding[]): string {
219226
return keptIndices.join(',');
220227
}
221228

229+
// Alias keys the parser accepts that render never reads; the serialised
230+
// file carries the canonical key instead, so the two cannot disagree.
231+
const ALIAS_KEYS = ['path', 'filename', 'lineNumber', 'line_number', 'level', 'action'];
232+
222233
/**
223-
* Serializes normalized review findings into the clean JSON structure
224-
* that code-review render consumes via its findings file parameter.
234+
* Serializes normalized review findings into the findings file that
235+
* code-review render reads, in render's own field names.
236+
*
237+
* Every field of the original finding is kept (explanation, rule_id,
238+
* quoted_rule, excerpt, suggestion_block, side, reviewers, ...), and only
239+
* the normalised file, line and severity override it. A finding that
240+
* arrived with only the parser's aliases (body, rule) gets render's names
241+
* for them. Render anchors on a truthy `line`, so with `line` normalised to
242+
* an integer >= 1 or null, its numbering over this file is formatKeepAnswer's.
225243
*/
226244
export function serializeFindingsForRender(findings: readonly ReviewFinding[]): string {
227-
const payload = findings.map((f) => ({
228-
file: f.file,
229-
line: f.line,
230-
severity: f.severity,
231-
body: f.body,
232-
rule: f.rule,
233-
source: f.source,
234-
fixup: f.fixup,
235-
}));
245+
const payload = findings.map((f) => {
246+
const raw = f.raw;
247+
const base: Record<string, unknown> =
248+
typeof raw === 'object' && raw !== null && !Array.isArray(raw)
249+
? { ...(raw as Record<string, unknown>) }
250+
: {};
251+
for (const key of ALIAS_KEYS) {
252+
delete base[key];
253+
}
254+
if (base.explanation === undefined && base.suggestion === undefined && f.body) {
255+
base.explanation = f.body;
256+
}
257+
if (base.rule_id === undefined && base.category === undefined && f.rule) {
258+
base.rule_id = f.rule;
259+
}
260+
return { ...base, file: f.file, line: f.line, severity: f.severity };
261+
});
236262
return JSON.stringify(payload, null, 2);
237263
}
238264

0 commit comments

Comments
 (0)