Repository navigation
fix(azure): render /improve suggestions as a diff block - #2718
IsmaelMartinez wants to merge 3 commits into
Conversation
Azure DevOps has no committable suggestion blocks, so the fence /improve emits was published verbatim and rendered as a raw, uneditable block. Rewrite it as a diff block, matching what the Bitbucket providers already do. Refs: The-PR-Agent#2110 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
PR Summary by QodoRender Azure /improve Suggestions as Diff Blocks
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1. Regex suggestions stay unrendered
|
| patch = "\n".join(patch_orig.splitlines()[5:]).strip('\n') | ||
| diff_code = f"\n\n```diff\n{patch.rstrip()}\n```" |
There was a problem hiding this comment.
4. Diff conversion drops changed lines 🐞 Bug ≡ Correctness
The renderer removes the first five splitlines() entries, but existing_code and improved_code are each forced to end in a newline and then split on \n, so difflib.unified_diff includes a sixth blank-context line after the -/+ lines. Consequently the slice keeps only that blank line and Azure receives an empty diff block instead of showing the old and new code.
Agent Prompt
## Issue description
The generated unified diff contains a trailing empty-line context entry because both snippets are appended with `\n` and split using `split('\\n')`. Slicing from index 5 therefore discards the `-` and `+` lines, producing an empty diff block.
## Issue Context
The regression test expects `-values = []` and `+values = set()` in the Azure comment, but the current slicing removes them. Build the patch from the actual unified-diff hunk lines (or change the input splitting/slicing) while preserving the existing fallback behavior when the original suggestion is unusable.
## Fix Focus Areas
- pr_agent/git_providers/azuredevops_provider.py[116-123]
- tests/unittest/test_azure_devops_provider.py[482-492]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Hi @naorpeled, last of this batch, ready for review. Azure DevOps has no committable suggestions, but |
Resolves the two conflicts left by The-PR-Agent#2724 and later main: the import block (main added json/SimpleNamespace, this branch adds difflib) and the tail of test_azure_devops_provider.py, where both sides appended a test class. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016uEfquYG4H96b9DjhLi7VT
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LpThzLDt7pgLathoucBkcL
| diff_code = f"\n\n```diff\n{patch.rstrip()}\n```" | ||
| return re.sub(r'```suggestion.*?```', diff_code, body, flags=re.DOTALL) |
There was a problem hiding this comment.
1. Regex suggestions stay unrendered 🐞 Bug ≡ Correctness
_render_suggestion_as_diff passes arbitrary generated diff text directly to re.sub as a replacement template, causing backslash sequences to be interpreted rather than inserted literally. Suggestions containing regular expressions, escaped strings, or Windows paths can therefore be altered or raise re.error, after which the exception handler restores the raw unsupported suggestion fence.
Agent Prompt
## Issue description
Generated code containing backslashes is interpreted as regular-expression replacement syntax, which can corrupt the displayed diff or prevent conversion entirely.
## Fix Focus Areas
- pr_agent/git_providers/azuredevops_provider.py[223-224]
## Recommended Fix
Pass a callable replacement such as `lambda _: diff_code` to `re.sub` so the generated diff is returned verbatim, and add tests covering valid and invalid replacement-string escape sequences.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| existing_code = original_suggestion['existing_code'].rstrip() + "\n" | ||
| improved_code = original_suggestion['improved_code'].rstrip() + "\n" | ||
| diff = difflib.unified_diff(existing_code.split('\n'), | ||
| improved_code.split('\n'), n=999) |
There was a problem hiding this comment.
2. Rendered fixes show wrong indentation 🐞 Bug ≡ Correctness
_render_suggestion_as_diff builds its improved side from the original model dictionary rather than the normalized new_code_snippet embedded in the suggestion body. When dedent_code aligns unindented model output to an indented target, the substituted diff advertises the unaligned code instead of the replacement prepared by the suggestion pipeline.
Agent Prompt
## Issue description
Azure constructs the displayed diff from the unnormalized model response even though the published suggestion body contains an indentation-aligned replacement.
## Fix Focus Areas
- pr_agent/git_providers/azuredevops_provider.py[217-224]
- pr_agent/tools/pr_code_suggestions.py[1203-1252]
## Recommended Fix
Build the improved side of the Azure diff from the normalized code stored in the suggestion fence, or store that normalized value in the rendered suggestion data and pass it explicitly to the renderer.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Code review by qodo was updated up to the latest commit 278cd0e |
|
Closing in favour of a community pick-up: main needs an approving review from a second maintainer and I cannot approve my own PR, so this has sat green since 19 August. The change and its tests stay on |
Azure DevOps has no committable suggestion blocks, but
/improveemits GitHub's suggestion fence unconditionally and the Azure provider posts that body verbatim, so it renders as a raw uneditable block. Every other platform without native support rewrites the fence first: both Bitbucket providers swap in a diff block, GitLab rewrites the info string, Gerrit special-cases it.This applies the Bitbucket treatment to Azure, including the PR-level fallback path. When
original_suggestionis missing or unusable the body is left exactly as it is today. Four regression tests, two of which fail onmain.Refs #2110.