@@ -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