Skip to content

chore: show line diff count#1042

Open
adityachoudhari26 wants to merge 1 commit intomainfrom
line-diff-count
Open

chore: show line diff count#1042
adityachoudhari26 wants to merge 1 commit intomainfrom
line-diff-count

Conversation

@adityachoudhari26
Copy link
Copy Markdown
Member

@adityachoudhari26 adityachoudhari26 commented Apr 22, 2026

fixes #1033

Summary by CodeRabbit

  • New Features

    • GitHub check titles now display cumulative line addition and deletion statistics from deployment plan changes, replacing previous count-based summaries for improved visibility.
  • Tests

    • Updated test cases to validate new GitHub check title format incorporating diff statistics.

Copilot AI review requested due to automatic review settings April 22, 2026 23:52
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 22, 2026

📝 Walkthrough

Walkthrough

The changes modify GitHub check title generation for deployment plans to report added and deleted line counts derived from unified diffs of proposed changes, replacing the previous format that summarized counts of changed, unchanged, and unsupported resources.

Changes

Cohort / File(s) Summary
Diff-based Title Generation
apps/workspace-engine/svc/controllers/deploymentplanresult/github_check.go
Adds logic to compute unified diffs between current and proposed agent states, counts additions and deletions per agent, aggregates totals, and updates check title generation to display +<additions> -<deletions> format (with errored count appended when errors exist).
Test Assertion Updates
apps/workspace-engine/svc/controllers/deploymentplanresult/github_check_test.go
Updates TestAggregate_CheckTitle test cases to expect GitHub check titles in new diff-line format (e.g., "+7 -3 (1 errored)", "+12 -4", "+0 -0") instead of previous human-readable count format.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 With diffs now counted, line by line,
The checks grow clearer, oh so fine!
No more "unsupported" in sight,
Just + and - shining bright!
Plan summaries hop left and right! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: implementing line diff count display in GitHub check summaries instead of agent status counts.
Linked Issues check ✅ Passed The code changes implement the core requirement from issue #1033: replacing agent status summaries with total line additions and deletions across all agents [#1033].
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the diff-line counting feature; no unrelated modifications detected in the modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 line-diff-count

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
apps/workspace-engine/svc/controllers/deploymentplanresult/github_check_test.go (1)

57-74: Coverage gap: the new diff-counting logic isn't directly tested.

The updated TestAggregate_CheckTitle cases only assert on already-populated Additions/Deletions values; countDiffLines and the aggregateResults path that populates those fields from Current/Proposed aren't exercised. Consider extending TestAggregateResults_Counts to assert agg.Additions/agg.Deletions for the completedResult("a", true, "old", "new") case, and/or adding a focused TestCountDiffLines with table cases (identical input → 0/0, pure additions, pure deletions, mixed, empty strings, content lines that happen to start with --- or +++ — which in a unified diff would appear as +--- / -+++ and must still be counted correctly).

Also applies to: 140-187

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@apps/workspace-engine/svc/controllers/deploymentplanresult/github_check_test.go`
around lines 57 - 74, Extend TestAggregateResults_Counts to assert that
aggregateResults populates Additions and Deletions for the completedResult("a",
true, "old", "new") case (use agg.Additions and agg.Deletions) so countDiffLines
is exercised, and/or add a new focused TestCountDiffLines table-driven test that
calls countDiffLines with cases: identical inputs -> 0/0, pure additions, pure
deletions, mixed changes, empty strings, and lines that begin with diff markers
like "+---" or "-+++" to ensure those are counted correctly; locate the logic in
aggregateResults and the countDiffLines function to wire inputs via
completedResult helpers and assert expected numeric results.
apps/workspace-engine/svc/controllers/deploymentplanresult/github_check.go (1)

157-182: Redundant unified-diff computation per changed agent.

For every result with HasChanges=true, difflib.GetUnifiedDiffString is now invoked twice against the same Current/Proposed inputs: once here with Context: 0 to count lines, and again in formatAgentSection (line 295) with Context: 3 to render the markdown diff. For large manifests this doubles the diff work. Consider counting +/- lines directly from the Context: 3 diff that's already produced in formatAgentSection and caching the totals on agentResult, or sharing a single diff through the aggregate pipeline.

Also applies to: 295-304

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/workspace-engine/svc/controllers/deploymentplanresult/github_check.go`
around lines 157 - 182, The countDiffLines function is redundantly recomputing a
unified diff (Context:0) while formatAgentSection already generates a unified
diff (Context:3); refactor so the unified diff is computed once and its +/− line
counts are reused: have formatAgentSection (or the diff-producing step) return
or attach the unified-diff string and computed adds/dels to the agentResult
(e.g., add fields like AddedLines/DeletedLines or a CachedDiff string), compute
adds/dels by scanning the already-produced Context:3 diff instead of calling
difflib.GetUnifiedDiffString again, and update callers that currently call
countDiffLines to read the cached totals; remove the duplicate
GetUnifiedDiffString invocation in countDiffLines or inline its logic to use the
cached diff.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/workspace-engine/svc/controllers/deploymentplanresult/github_check.go`:
- Around line 264-269: The diff summary currently returns "+0 -0" when there are
no changes; update the logic in the formatting function that produces
diffSummary (the block using a.Additions, a.Deletions, a.Errored) to first
detect the all-clean case (a.Additions == 0 && a.Deletions == 0 && a.Changed ==
0) and return "No changes" in that case, otherwise build the "+%d -%d" summary
as before and still append the "(%d errored)" suffix when a.Errored > 0; keep
references to the same variables (a.Additions, a.Deletions, a.Changed,
a.Errored) so the change is a simple conditional early-return.

---

Nitpick comments:
In
`@apps/workspace-engine/svc/controllers/deploymentplanresult/github_check_test.go`:
- Around line 57-74: Extend TestAggregateResults_Counts to assert that
aggregateResults populates Additions and Deletions for the completedResult("a",
true, "old", "new") case (use agg.Additions and agg.Deletions) so countDiffLines
is exercised, and/or add a new focused TestCountDiffLines table-driven test that
calls countDiffLines with cases: identical inputs -> 0/0, pure additions, pure
deletions, mixed changes, empty strings, and lines that begin with diff markers
like "+---" or "-+++" to ensure those are counted correctly; locate the logic in
aggregateResults and the countDiffLines function to wire inputs via
completedResult helpers and assert expected numeric results.

In `@apps/workspace-engine/svc/controllers/deploymentplanresult/github_check.go`:
- Around line 157-182: The countDiffLines function is redundantly recomputing a
unified diff (Context:0) while formatAgentSection already generates a unified
diff (Context:3); refactor so the unified diff is computed once and its +/− line
counts are reused: have formatAgentSection (or the diff-producing step) return
or attach the unified-diff string and computed adds/dels to the agentResult
(e.g., add fields like AddedLines/DeletedLines or a CachedDiff string), compute
adds/dels by scanning the already-produced Context:3 diff instead of calling
difflib.GetUnifiedDiffString again, and update callers that currently call
countDiffLines to read the cached totals; remove the duplicate
GetUnifiedDiffString invocation in countDiffLines or inline its logic to use the
cached diff.
🪄 Autofix (Beta)

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: Pro

Run ID: 6a1aec19-417f-4c96-83c3-f7d414e2bb70

📥 Commits

Reviewing files that changed from the base of the PR and between 6e43752 and 60f2d2c.

📒 Files selected for processing (2)
  • apps/workspace-engine/svc/controllers/deploymentplanresult/github_check.go
  • apps/workspace-engine/svc/controllers/deploymentplanresult/github_check_test.go

Comment on lines +264 to +269

diffSummary := fmt.Sprintf("+%d -%d", a.Additions, a.Deletions)
if a.Errored > 0 {
return fmt.Sprintf(
"%d errored, %d changed, %d unchanged, %d unsupported",
a.Errored, a.Changed, a.Unchanged, a.Unsupported,
)
return fmt.Sprintf("%s (%d errored)", diffSummary, a.Errored)
}
if a.Changed > 0 {
return fmt.Sprintf(
"%d changed, %d unchanged, %d unsupported",
a.Changed, a.Unchanged, a.Unsupported,
)
}
if a.Unsupported > 0 {
return fmt.Sprintf(
"No changes (%d unsupported)",
a.Unsupported,
)
}
return "No changes"
return diffSummary
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

UX: "+0 -0" replaces the old "No changes" summary.

When every agent reports HasChanges=false, the title now reads +0 -0 (confirmed by the "final no changes shows zero diff counts" and "final all clean" test cases). That's technically correct, but arguably less informative than the prior "No changes" / human-readable summary. If intentional per the linked issue (#1033 asks specifically for line totals), feel free to ignore; otherwise consider falling back to "No changes" when a.Additions == 0 && a.Deletions == 0 && a.Changed == 0.

Optional fallback
 	diffSummary := fmt.Sprintf("+%d -%d", a.Additions, a.Deletions)
 	if a.Errored > 0 {
 		return fmt.Sprintf("%s (%d errored)", diffSummary, a.Errored)
 	}
+	if a.Additions == 0 && a.Deletions == 0 && a.Changed == 0 {
+		return "No changes"
+	}
 	return diffSummary
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
diffSummary := fmt.Sprintf("+%d -%d", a.Additions, a.Deletions)
if a.Errored > 0 {
return fmt.Sprintf(
"%d errored, %d changed, %d unchanged, %d unsupported",
a.Errored, a.Changed, a.Unchanged, a.Unsupported,
)
return fmt.Sprintf("%s (%d errored)", diffSummary, a.Errored)
}
if a.Changed > 0 {
return fmt.Sprintf(
"%d changed, %d unchanged, %d unsupported",
a.Changed, a.Unchanged, a.Unsupported,
)
}
if a.Unsupported > 0 {
return fmt.Sprintf(
"No changes (%d unsupported)",
a.Unsupported,
)
}
return "No changes"
return diffSummary
diffSummary := fmt.Sprintf("+%d -%d", a.Additions, a.Deletions)
if a.Errored > 0 {
return fmt.Sprintf("%s (%d errored)", diffSummary, a.Errored)
}
if a.Additions == 0 && a.Deletions == 0 && a.Changed == 0 {
return "No changes"
}
return diffSummary
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/workspace-engine/svc/controllers/deploymentplanresult/github_check.go`
around lines 264 - 269, The diff summary currently returns "+0 -0" when there
are no changes; update the logic in the formatting function that produces
diffSummary (the block using a.Additions, a.Deletions, a.Errored) to first
detect the all-clean case (a.Additions == 0 && a.Deletions == 0 && a.Changed ==
0) and return "No changes" in that case, otherwise build the "+%d -%d" summary
as before and still append the "(%d errored)" suffix when a.Errored > 0; keep
references to the same variables (a.Additions, a.Deletions, a.Changed,
a.Errored) so the change is a simple conditional early-return.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the GitHub check run title for deployment plan results to show total line additions/deletions (per issue #1033) instead of changed/unchanged/unsupported counts.

Changes:

  • Add diff line aggregation fields (Additions, Deletions) to the result aggregate.
  • Compute total added/deleted line counts across agents with changes and render as +A -D in checkTitle().
  • Update unit tests to assert the new title formatting.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
apps/workspace-engine/svc/controllers/deploymentplanresult/github_check.go Adds diff line counting and updates check title formatting to show +additions -deletions.
apps/workspace-engine/svc/controllers/deploymentplanresult/github_check_test.go Updates checkTitle test cases to match the new diff-count-based summary.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +158 to +180
diff, err := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
A: difflib.SplitLines(current),
B: difflib.SplitLines(proposed),
FromFile: "current",
ToFile: "proposed",
Context: 0,
})
if err != nil {
return 0, 0
}
var adds, dels int
for line := range strings.SplitSeq(diff, "\n") {
if strings.HasPrefix(line, "+++") || strings.HasPrefix(line, "---") {
continue
}
if strings.HasPrefix(line, "+") {
adds++
continue
}
if strings.HasPrefix(line, "-") {
dels++
}
}
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

countDiffLines generates a full unified diff string and then scans it to count additions/deletions. This introduces a second diff computation per changed agent (the diff is already computed again in formatAgentSection when rendering output), which can materially increase CPU/memory use for large plans. Consider counting via difflib opcodes (without building a unified diff string), or computing the diff once per agent and reusing it for both the rendered diff and the line counts.

Suggested change
diff, err := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
A: difflib.SplitLines(current),
B: difflib.SplitLines(proposed),
FromFile: "current",
ToFile: "proposed",
Context: 0,
})
if err != nil {
return 0, 0
}
var adds, dels int
for line := range strings.SplitSeq(diff, "\n") {
if strings.HasPrefix(line, "+++") || strings.HasPrefix(line, "---") {
continue
}
if strings.HasPrefix(line, "+") {
adds++
continue
}
if strings.HasPrefix(line, "-") {
dels++
}
}
currentLines := difflib.SplitLines(current)
proposedLines := difflib.SplitLines(proposed)
if len(currentLines) == 0 {
return len(proposedLines), 0
}
if len(proposedLines) == 0 {
return 0, len(currentLines)
}
// Count additions/deletions without building a unified diff string.
// The number of deleted lines is the number of lines in current that are
// not part of the longest common subsequence (LCS); similarly for added
// lines in proposed. This preserves line-based counting semantics while
// avoiding the extra allocation and scan of a rendered diff.
prev := make([]int, len(proposedLines)+1)
curr := make([]int, len(proposedLines)+1)
for i := 1; i <= len(currentLines); i++ {
for j := 1; j <= len(proposedLines); j++ {
if currentLines[i-1] == proposedLines[j-1] {
curr[j] = prev[j-1] + 1
} else if prev[j] >= curr[j-1] {
curr[j] = prev[j]
} else {
curr[j] = curr[j-1]
}
}
prev, curr = curr, prev
clear(curr)
}
lcs := prev[len(proposedLines)]
adds := len(proposedLines) - lcs
dels := len(currentLines) - lcs

Copilot uses AI. Check for mistakes.
Comment on lines +198 to +200
adds, dels := countDiffLines(r.Current, r.Proposed)
a.Additions += adds
a.Deletions += dels
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

New behavior aggregates Additions/Deletions based on diffs, but the tests currently only assert the final title string and do not verify that aggregateResults computes Additions/Deletions correctly across multiple agents / multi-line changes. Add a focused unit test (and/or tests for countDiffLines) that asserts expected additions/deletions counts for representative diffs and ensures unchanged/unsupported/errored agents don’t affect the totals.

Suggested change
adds, dels := countDiffLines(r.Current, r.Proposed)
a.Additions += adds
a.Deletions += dels
if r.Status == db.DeploymentPlanTargetStatusCompleted {
adds, dels := countDiffLines(r.Current, r.Proposed)
a.Additions += adds
a.Deletions += dels
}

Copilot uses AI. Check for mistakes.
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.

Plan Summary on Github Actions

2 participants