Skip to content

Commit 846cf24

Browse files
anandgupta42claude
andcommitted
fix: round-6 review polish — alias preference + grade nested findings
- `review/runner.ts`: when a PII column has `query_targets`, report ONLY the output aliases — the source column name is not present in the model output, so including it flagged a column that isn't there (`SELECT email AS contact` now reports `contact`, not `email` + `contact`). - `check --checks grade`: findings now come from all nested EvalResult sections (lint.findings + validation.errors + safety.threats) — a failing grade with clean lint no longer yields an empty, passing finding list. - Regression test for the nested-findings case. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 3974e35 commit 846cf24

3 files changed

Lines changed: 48 additions & 6 deletions

File tree

‎packages/opencode/src/altimate/review/runner.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,11 @@ export function createDispatcherRunner(opts: DispatcherRunnerOptions): ReviewRun
222222
// legacy array shape is kept as a fallback. Each entry names the
223223
// SOURCE column; query_targets carries the exposed OUTPUT aliases
224224
// (e.g. `SELECT email AS contact` → column "email", targets ["contact"]).
225-
...asArray<any>((data.pii as any)?.pii_columns ?? data.pii).flatMap((p: any) => [
226-
piiColumnOf(p),
227-
...(Array.isArray(p?.query_targets) ? p.query_targets : []),
228-
]),
225+
// Prefer the aliases when present — the source name is not in the
226+
// model output, so reporting it would flag a column that isn't there.
227+
...asArray<any>((data.pii as any)?.pii_columns ?? data.pii).flatMap((p: any) =>
228+
Array.isArray(p?.query_targets) && p.query_targets.length ? p.query_targets : [piiColumnOf(p)],
229+
),
229230
...rawIssues
230231
.filter((i: any) => /pii|sensitive/i.test(String(i.category ?? i.rule ?? i.code ?? i.kind ?? "")))
231232
.map(piiColumnOf),

‎packages/opencode/src/cli/cmd/check.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,28 @@ async function runGrade(
289289
}
290290
// Engine EvalResult: { explain, lint, overall_grade, safety, scores, sql,
291291
// total_time_ms, validation } — the grade is `overall_grade`, the numeric
292-
// score is `scores.overall`, and actionable findings live in `lint.findings`.
292+
// score is `scores.overall`. Findings come from ALL nested sections:
293+
// lint.findings, validation.errors, and safety.threats — a failing grade
294+
// with clean lint must not produce an empty (passing) finding list.
293295
const lint = result.data.lint as Record<string, unknown> | undefined
296+
const validation = result.data.validation as Record<string, unknown> | undefined
297+
const safety = result.data.safety as Record<string, unknown> | undefined
298+
const nested = [
299+
...((lint?.findings as Array<Record<string, unknown>> | undefined) ?? []),
300+
...(((validation?.errors as Array<Record<string, unknown>> | undefined) ?? []).map((e) => ({
301+
...e,
302+
rule: "validate",
303+
severity: "error",
304+
})) as Array<Record<string, unknown>>),
305+
...(((safety?.threats as Array<Record<string, unknown>> | undefined) ?? []).map((t) => ({
306+
...t,
307+
rule: (t.rule as string) ?? "safety",
308+
})) as Array<Record<string, unknown>>),
309+
]
294310
const issues = (result.data.issues ??
295311
result.data.findings ??
296312
result.data.recommendations ??
297-
lint?.findings ??
313+
(nested.length ? nested : undefined) ??
298314
[]) as Array<Record<string, unknown>>
299315
const findings = issues.map((f) => ({
300316
file,

‎packages/opencode/test/cli/check-e2e.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,31 @@ describe("check command E2E", () => {
782782
expect(j.results.grade.score).toBe(0.72)
783783
})
784784

785+
test("grade check surfaces validation/safety findings when lint is clean", async () => {
786+
// EvalResult can carry validation errors or safety threats with zero lint
787+
// findings — the grade check must not present an empty (passing) list.
788+
const file = await writeSql(tmpDir.dir, "grade-nested.sql", "SELECT zzz FROM t;")
789+
setDispatcherResponse("altimate_core.grade", () => ({
790+
success: true,
791+
data: {
792+
overall_grade: "D",
793+
scores: { overall: 0.4 },
794+
lint: { clean: true, findings: [] },
795+
validation: { valid: false, errors: [{ code: "E002", message: "Column 'zzz' not found" }] },
796+
safety: { safe: false, threats: [{ rule: "tautology_attack", severity: "high", message: "OR 1=1 detected" }] },
797+
},
798+
}))
799+
installDispatcherMocks()
800+
801+
const r = await runHandler(baseArgs({ files: [file], checks: "grade" }))
802+
const j = parseJson(r.stdout)
803+
expect(j.results.grade.findings.length).toBe(2)
804+
const rules = j.results.grade.findings.map((f: any) => f.rule)
805+
expect(rules).toContain("validate")
806+
expect(rules).toContain("tautology_attack")
807+
expect(j.results.grade.findings.some((f: any) => f.severity === "error")).toBe(true)
808+
})
809+
785810
test("grade check fails closed on engine failure envelope", async () => {
786811
// Native handlers report failures via {success:false}, not by throwing —
787812
// a failed grade run must not pass silently with zero findings.

0 commit comments

Comments
 (0)