Skip to content

Added regression test for issue #4643 #4893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions tests/test_code_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,39 @@ def test_find_comment_scope():

for line_number, expected_scope in target_hunks.items():
assert find_comment_scope(patched_file, line_number) == expected_scope


def test_generate_processed_output_attaches_comment_to_correct_line():
# Regression test for https://github.com/mozilla/bugbug/issues/4643
Copy link
Member

Choose a reason for hiding this comment

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

The issue was not a bug; it was a feature request. Looking at the test again, it does not seem to test the changed code.

import json

from unidiff import PatchSet

from bugbug.tools.code_review import InlineComment, generate_processed_output

# Mock output from the model
output = json.dumps(
[{"file": "example.py", "code_line": 10, "comment": "This is a test comment."}]
)

# Create a mock patch set
patch_content = """\
diff --git a/example.py b/example.py
--- a/example.py
+++ b/example.py
@@ -8,0 +9,2 @@
+def example_function():
+ pass
"""
patch = PatchSet(patch_content)

# Generate processed output
comments = list(generate_processed_output(output, patch))

# Check that the comment is attached to the correct line
assert len(comments) == 1
assert isinstance(comments[0], InlineComment)
assert comments[0].filename == "example.py"
assert comments[0].start_line == 10
assert comments[0].end_line == 10
assert comments[0].content == "This is a test comment."