Skip to content

Commit 554bc16

Browse files
test(improve): cover persistent history updates
1 parent 9a7f3fe commit 554bc16

3 files changed

Lines changed: 35 additions & 4 deletions

File tree

.pr_agent.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
enable_review_labels_effort = true
88
enable_auto_approval = true
99

10-
[pr_code_suggestions]
11-
suggestions_heading = "PR Code Suggestions"
12-
1310
[github_app]
1411
pr_commands = [
1512
"/describe --pr_description.publish_description_as_comment=true",

tests/e2e_tests/e2e_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FILE_PATH: str = "pr_agent/cli_pip.py"
22

33
PR_HEADER_START_WITH = '### **User description**\nupdate cli_pip.py\n\n\n___\n\n### **PR Type**'
4-
REVIEW_START_WITH = '## PR Reviewer Guide 🔍\n\n<table>\n<tr><td>⏱️&nbsp;<strong>Estimated effort to review</strong>:'
4+
REVIEW_START_WITH = '## PR Reviewer Guide 🔍\n\n<!-- pr-agent:review:full -->\n\n<table>\n<tr><td>⏱️&nbsp;<strong>Estimated effort to review</strong>:'
55
IMPROVE_START_WITH_REGEX_PATTERN = (
66
r"^## PR Code Suggestions ✨\n\n"
77
r"<!-- pr-agent:improve:summary -->\n\n"

tests/unittest/test_pr_code_suggestions_core.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,3 +762,37 @@ def test_legacy_heading_without_generated_shape_is_not_adopted():
762762
provider.edit_comment.assert_not_called()
763763
published = provider.publish_comment.call_args.args[0]
764764
assert PRCodeSuggestionsIdentity.SUMMARY.value in published
765+
766+
767+
def test_custom_heading_is_kept_when_a_history_section_already_exists():
768+
existing = MagicMock()
769+
existing.body = (
770+
"## Previous Custom Heading ✨\n\n"
771+
f"{PRCodeSuggestionsIdentity.SUMMARY.value}\n\n"
772+
"<!-- aaa1111 -->\n\n"
773+
"Latest suggestions up to commit aaa1111\n\n"
774+
"<table>latest</table>\n\n___\n\n"
775+
"#### Previous suggestions\n"
776+
"<details><summary>Suggestions up to commit 0000000</summary>\n"
777+
"<br><table>older</table>\n\n</details>\n"
778+
)
779+
provider = _persistent_provider([existing])
780+
custom_header = "## Latest Custom Heading ✨"
781+
782+
result = PRCodeSuggestions.publish_persistent_comment_with_history(
783+
provider,
784+
f"{custom_header}\n\n<table>new suggestions</table>",
785+
initial_header=custom_header,
786+
name="suggestions",
787+
identity_marker=PRCodeSuggestionsIdentity.SUMMARY.value,
788+
legacy_initial_header=PRCodeSuggestionsHeader.SUMMARY.value,
789+
)
790+
791+
assert result is existing
792+
updated = provider.edit_comment.call_args.args[1]
793+
assert updated.startswith(
794+
f"{custom_header}\n\n{PRCodeSuggestionsIdentity.SUMMARY.value}\n\n<!-- deadbee -->"
795+
)
796+
assert "Suggestions up to commit aaa1111" in updated
797+
assert "Suggestions up to commit 0000000" in updated
798+
provider.publish_comment.assert_not_called()

0 commit comments

Comments
 (0)