fix(tooling): marker guard false-positives on changes deep inside a pre-existing block

Merged
AN
6mo ago
+152-4

What does this PR do?

Fixes the Marker Guard CI job, which went red on main (commit 89699f6919, the #895 merge) by false-positiving on packages/opencode/src/cli/cmd/tui/worker.ts:183 — a line that is correctly wrapped in an altimate_change block.

Root cause: parseDiffForMarkerWarnings derived marker state only from the lines visible in each diff hunk (git diff -U5 → ±5 context lines). When a line is modified deep inside a large pre-existing altimate_change block, the block's start marker sits outside the context window and never appears in the hunk, so inMarkerBlock stays false and the change is mis-flagged as unmarked. The per-hunk marker-state reset compounded it.

Fix: compute marker coverage from the full post-change file and pass it into the parser:

  • computeMarkedLines(content) — full-file, depth-counted coverage set (handles nested start/end pairs, which a single openBlock would miss).
  • parseDiffForMarkerWarnings(file, diff, markedLines?) — a changed line is covered if the in-hunk tracker saw its start or the full-file map says it's inside a marked block. The map can only suppress false positives, never add new ones — so all existing warning behavior is preserved.
  • checkFileForMarkers reads git show HEAD:<file> (or the working tree for base-less runs) and feeds the map in.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Issue for this PR

Closes #876

How did you verify your code works?

  • 11 new unit tests in script/upstream/analyze.test.ts: nesting, unbalanced markers, and the exact context-window false positive (with/without coverage map, plus an end-to-end reconstruction). Full file: 29/29 pass.
  • Reproduced the real failure: analyze.ts --markers --base 7e909a9777 --strict (the exact base the CI job used) flags worker.ts:183 with the original code and passes with the fix. Reverting the fix reproduces the failure.

Checklist

  • My code follows the style guidelines of this project
  • I have added tests that prove my fix is effective
  • New and existing unit tests pass locally with my changes
  • I have made corresponding changes to the documentation (n/a — internal tooling)

Summary by cubic

Fix Marker Guard false positives when editing lines deep inside a pre-existing altimate_change block. CI no longer misflags valid changes, and genuine warnings are unchanged.

  • Bug Fixes
    • Added computeMarkedLines for full-file, nesting-aware marker coverage.
    • Updated parseDiffForMarkerWarnings to take a coverage map; a line is covered if seen in-hunk or in the map.
    • checkFileForMarkers now reads the post-change file to supply coverage; added tests for the context-window case and nested markers. Closes #876.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed false positive warnings for code changes occurring within pre-existing marked regions when the corresponding start marker is outside the diff context window.
  • Tests

    • Added comprehensive unit tests for marker coverage computation, including validation of nested marker pairs, edge cases, and integration testing to ensure marked regions are properly recognized across file contexts.