testbot: trim the coverage section and render it in one place - #1292
Conversation
#1290 trimmed verify_coverage.render_markdown(), but that is not what builds the PR body. The workflow writes coverage_report.md and only cats it into the run log; the PR body comes from create_pr.py's _build_coverage_section(), a second renderer of the same section that reads the JSON sidecar. So #1291 still shipped ~300 lines of per-range bullets. Apply the same trim there: keep the per-target summary line, name only the ranges still missing coverage, cap at MAX_REPORTED_RANGES with an "and N more" tail. The constant is imported from verify_coverage rather than redeclared, matching the existing guardrails import. On a #1291-shaped report the section goes from 308 lines to 9. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughCoverage JSON is parsed into verifier report objects and rendered by shared Markdown helpers. Coverage output omits covered-range details, formats single-line uncovered ranges as ChangesCoverage reporting
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/scripts/testbot/tests/test_create_pr.py (1)
1251-1270: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMake the overflow fixture depend on
MAX_REPORTED_RANGES.
misseshas 14 entries. IfMAX_REPORTED_RANGESis 14 or greater, correct output includesline 14and has no overflow suffix. The test then fails without a renderer defect.Proposed fix
- misses = [[n, n] for n in range(1, 15)] + misses = [ + [line_number, line_number] + for line_number in range(1, MAX_REPORTED_RANGES + 2) + ] ... - self.assertNotIn("line 14", section) + self.assertNotIn( + f"line {MAX_REPORTED_RANGES + 1}", section + )🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/scripts/testbot/tests/test_create_pr.py` around lines 1251 - 1270, Update test_still_uncovered_ranges_are_capped so the misses fixture contains more entries than MAX_REPORTED_RANGES, while preserving the assertion that the overflow suffix reports the remaining count and the capped output excludes the final range.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/scripts/testbot/tests/test_create_pr.py`:
- Around line 1251-1270: Update test_still_uncovered_ranges_are_capped so the
misses fixture contains more entries than MAX_REPORTED_RANGES, while preserving
the assertion that the overflow suffix reports the remaining count and the
capped output excludes the final range.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: f7133c00-8612-45bf-a39a-63c322f0f0e9
📒 Files selected for processing (2)
src/scripts/testbot/create_pr.pysrc/scripts/testbot/tests/test_create_pr.py
_build_coverage_section re-implemented what verify_coverage already renders, so trimming one left the other unchanged. Replace it with a call: parse the JSON back into TargetReports, then render_markdown. create_pr.py loses 59 lines and there is one renderer to change. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/scripts/testbot/create_pr.py`:
- Around line 335-340: Update the coverage report loading block around
reports_from_json to also catch UnicodeDecodeError from Path.read_text,
alongside the existing OSError and json.JSONDecodeError handling. Preserve the
current warning and empty-string return so invalid UTF-8 reports omit the
coverage section without aborting PR creation.
In `@src/scripts/testbot/verify_coverage.py`:
- Around line 275-287: Add validation while constructing RangeResult and
TargetReport: normalize or reject nonpositive or reversed range coordinates,
constrain range hit counts to their totals, and ensure each target’s hit_lines
does not exceed listed_lines. Apply these checks before reports reach rendering
or pass/fail evaluation, preserving valid metrics unchanged.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: a1dab59f-437e-4756-b0a0-43c6fd9b2b28
📒 Files selected for processing (3)
src/scripts/testbot/create_pr.pysrc/scripts/testbot/tests/test_create_pr.pysrc/scripts/testbot/verify_coverage.py
🚧 Files skipped from review as they are similar to previous changes (1)
- src/scripts/testbot/tests/test_create_pr.py
int() has no overload for a bare object, so the fail-soft helper failed CI's mypy aspect. Narrow to (int, float, str) before converting. Caught by `bazel test -- //src/scripts/testbot/...`; the package-scoped `:all` pattern used earlier does not run mypy on the library target. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Description
#1290 trimmed the per-range checklist out of
verify_coverage.render_markdown(), but #1291 still shipped ~300 lines of it. That fix was on the wrong code path.There were two renderers of the same section:
verify_coverage.render_markdown()→coverage_report.md, which the workflow onlycats into the run log.create_pr._build_coverage_section()→ read the JSON sidecar and re-rendered the section independently. This is what builds the PR body.Changes
MAX_REPORTED_RANGESwith an "and N more" tail._build_coverage_sectionnow parses the JSON back intoTargetReports via a newverify_coverage.reports_from_json()and callsrender_markdown(). One renderer, so this cannot drift again.create_pr.pyloses 59 lines.Before (#1291, 308 lines)
After (6 lines)
Verification
bazel test //src/scripts/testbot:all //src/scripts/testbot/tests:all— 19/19 pass, includingtestbot-pylintandtest_create_pr-pylint(10.00/10). Rendered a #1291-shaped report through the real_build_coverage_sectionto confirm 308 → 6 lines.reports_from_jsonkeeps the fail-soft coercion the old renderer had, so a malformed field still degrades the body instead of blocking PR creation.Issue - None
Checklist
🤖 Generated with Claude Code
Summary by CodeRabbit