Skip to content

Commit cd8b970

Browse files
sahrizviclaude
andcommitted
fix(review): [R20 S4] context-line indent measurement in changedLinesForScan (cubic P2)
cubic P2 bot review — the scalar-state tracker measured indent inconsistently between context and changed diff lines. Context lines start with a leading SPACE (the diff marker) and my earlier code left it in place; changed lines had their `+`/`-` marker stripped before indent measurement. Result: a valid `|1` block scalar opened in the context with a body indented exactly one space beyond the header wasn't masked, because the context-side `scalarIndent` counted one extra space and the changed-side body's indent then failed the `indent > scalarIndent` check. Fix strips the leading diff marker (`+`/`-`/space) on ALL lines before indent measurement, so context and changed lines live in the same coordinate system. New regression test: `|1` block scalar opened in context with body containing `data_tests:` / `constraints:` prose stays trivial. Full altimate review suite: 3808 pass / 640 skip / 0 fail (was 3807 baseline — 1 new test). Co-Authored-By: Claude Opus 4.7 <[email protected]> Claude-Session: https://claude.ai/code/session_017zXDXMiNFh4qDPxPCfa2of
1 parent e52c863 commit cd8b970

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎packages/opencode/src/altimate/review/risk-tier.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,13 @@ function changedLinesForScan(diff: string | undefined): string {
153153
if (raw.startsWith("+++") || raw.startsWith("---") || raw.startsWith("@@")) continue
154154
// Distinguish added / removed / context so we can update scalar state
155155
// from context lines too but only include +/- in the output.
156-
const marker = raw.startsWith("+") || raw.startsWith("-") ? raw[0] : " "
157-
const stripped = marker === " " ? raw : raw.slice(1)
156+
// Unified-diff context lines start with a leading SPACE (the diff
157+
// marker), so we must strip that space too — otherwise a context line
158+
// like " description: |1" is measured as 1-deeper indent than an
159+
// otherwise-equivalent "+ data_tests: ..." changed line, and the
160+
// scalar body fails the `indent > scalarIndent` check (cubic P2).
161+
const marker = raw.startsWith("+") || raw.startsWith("-") ? raw[0] : raw.startsWith(" ") ? " " : ""
162+
const stripped = marker === "" ? raw : raw.slice(1)
158163
const indent = stripped.length - stripped.replace(/^[ \t]+/, "").length
159164
const contentEmpty = stripped.trim() === ""
160165
// Close the current scalar when we hit a non-empty line at ≤ scalarIndent.

‎packages/opencode/test/altimate/review.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,27 @@ describe("risk-tier", () => {
609609
}
610610
})
611611

612+
test("R20 S4: `|1` block scalar in context — body indent measured consistently (cubic P2 bot review)", () => {
613+
// Cubic P2 — the diff-marker vs indentation calculation was
614+
// inconsistent between context lines (retained their leading space)
615+
// and changed lines (whose `+`/`-` marker was stripped). A valid `|1`
616+
// block scalar opened in context with a body indented exactly one
617+
// space beyond the header wasn't masked because the context
618+
// scalarIndent counted one extra space. Now BOTH context and changed
619+
// lines have their leading diff marker stripped before indent
620+
// measurement.
621+
const diff =
622+
"@@ -1,8 +1,9 @@\n" +
623+
" models:\n" +
624+
" - name: mrt_x\n" +
625+
" description: |1\n" +
626+
" Existing body line stays put.\n" +
627+
"+ data_tests: are still in the sibling schema.yml, not here.\n" +
628+
"+ constraints: too.\n"
629+
const r = classifyPR([file("models/intermediate/int_x.yml", diff)])
630+
expect(r.tier).toBe("trivial")
631+
})
632+
612633
test("R20 S4: block-scalar OPENED IN CONTEXT (not changed) still suppresses body (codex round-6 HIGH)", () => {
613634
// Codex R20 round-6 HIGH — an earlier version stripped only the
614635
// filtered +/- slice, so a pre-existing `description: |` in the

0 commit comments

Comments
 (0)