Skip to content

feat: refactor getDiffs for testability, boost reviewer coverage - #5

Merged
brucearctor merged 1 commit into
mainfrom
feat/test-coverage-reviewer-80
Jul 9, 2026
Merged

feat: refactor getDiffs for testability, boost reviewer coverage#5
brucearctor merged 1 commit into
mainfrom
feat/test-coverage-reviewer-80

Conversation

@brucearctor

@brucearctor brucearctor commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Adds DiffSource interface for testability. New tests for Run(), filterBySeverity, buildNumberedDiff.

Summary by CodeRabbit

  • Bug Fixes
    • Improved review execution so diff retrieval behaves correctly in edge cases (such as empty diffs) and properly surfaces errors instead of continuing with invalid inputs.
    • Enhanced consistency of review output across terminal, JSON, and CI comment modes.
  • Tests
    • Added extensive coverage for severity filtering, diff formatting/numbering, constructor wiring, and end-to-end review flow (including model and diff-source error handling).

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0e4e29a6-15d9-47ef-a38b-ce615424570e

📥 Commits

Reviewing files that changed from the base of the PR and between a8b55e8 and f96a446.

📒 Files selected for processing (2)
  • internal/reviewer/reviewer.go
  • internal/reviewer/reviewer_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/reviewer/reviewer.go
  • internal/reviewer/reviewer_test.go

📝 Walkthrough

Walkthrough

Adds a DiffSource interface and diffSource field to Reviewer, a NewWithDiffSource constructor for dependency injection, and modifies Run to use the injected diffSource when present, falling back to existing getDiffs otherwise. Adds corresponding test coverage.

Changes

Diff Source Injection

Layer / File(s) Summary
DiffSource interface, constructor, and Run wiring
internal/reviewer/reviewer.go
Adds DiffSource interface with GetDiffs, a diffSource field on Reviewer, NewWithDiffSource, and conditional diff loading in Run.
Tests for DiffSource wiring and Run behavior
internal/reviewer/reviewer_test.go
Adds mockDiffSource and tests for Run, filterBySeverity, buildNumberedDiff, constructor wiring, and output modes including CI notes and discussions.

Estimated code review effort: 2 (Simple) | ~15 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Reviewer
  participant DiffSource
  participant getDiffs

  Caller->>Reviewer: Run(ctx)
  alt diffSource is set
    Reviewer->>DiffSource: GetDiffs(ctx)
    DiffSource-->>Reviewer: diffs, title, description, error
  else diffSource is nil
    Reviewer->>getDiffs: getDiffs(ctx)
    getDiffs-->>Reviewer: diffs, title, description, error
  end
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: making getDiffs more testable and expanding reviewer test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/test-coverage-reviewer-80

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
internal/reviewer/reviewer.go (1)

19-22: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Optional: consider a richer return type instead of positional strings.

GetDiffs returns (diffs, title, desc, err) as four positional values, mirroring the existing getDiffs method. This is consistent with existing code, but a small struct (e.g. DiffContext{Diffs, Title, Desc}) would reduce the risk of accidentally swapping title/desc at call sites as more implementations are added.

🤖 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 `@internal/reviewer/reviewer.go` around lines 19 - 22, Replace the positional
string returns in DiffSource.GetDiffs with a small context struct so callers
don’t have to remember the order of title and desc. Update the DiffSource
interface and the existing getDiffs/GetDiffs implementation in reviewer.go to
return a single typed result like DiffContext containing Diffs, Title, and Desc,
and then adjust any call sites to use the named fields instead of unpacking
multiple values.
🤖 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 `@internal/reviewer/reviewer.go`:
- Around line 19-22: Replace the positional string returns in
DiffSource.GetDiffs with a small context struct so callers don’t have to
remember the order of title and desc. Update the DiffSource interface and the
existing getDiffs/GetDiffs implementation in reviewer.go to return a single
typed result like DiffContext containing Diffs, Title, and Desc, and then adjust
any call sites to use the named fields instead of unpacking multiple values.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 44f30b73-2958-4822-8fd4-db1bcc9b6531

📥 Commits

Reviewing files that changed from the base of the PR and between 8d5d4e7 and a8b55e8.

📒 Files selected for processing (2)
  • internal/reviewer/reviewer.go
  • internal/reviewer/reviewer_test.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant