|
15 | 15 | edit_pr_body, |
16 | 16 | extract_codecov_summary, |
17 | 17 | extract_linked_issue_number, |
| 18 | + fetch_linked_issue_bundle, |
18 | 19 | format_issue_context, |
19 | 20 | post_pr_comment, |
20 | 21 | parse_args, |
@@ -88,6 +89,87 @@ def test_extract_linked_issue_number_falls_back_to_title(self) -> None: |
88 | 89 | ) |
89 | 90 | self.assertEqual(linked_issue, 117) |
90 | 91 |
|
| 92 | + @mock.patch("pipeline_pr.fetch_issue_data") |
| 93 | + def test_fetch_linked_issue_bundle_prefers_closing_issue_references( |
| 94 | + self, |
| 95 | + fetch_issue_data: mock.Mock, |
| 96 | + ) -> None: |
| 97 | + fetch_issue_data.return_value = { |
| 98 | + "number": 210, |
| 99 | + "title": "[Model] Partition", |
| 100 | + } |
| 101 | + |
| 102 | + issue_number, issue = fetch_linked_issue_bundle( |
| 103 | + "CodingThrust/problem-reductions", |
| 104 | + { |
| 105 | + "title": "Fix #19: stale title reference", |
| 106 | + "body": "This PR still mentions Fixes #19 in copied text.", |
| 107 | + "closingIssuesReferences": [ |
| 108 | + {"number": 210, "title": "[Model] Partition"}, |
| 109 | + ], |
| 110 | + }, |
| 111 | + ) |
| 112 | + |
| 113 | + self.assertEqual(issue_number, 210) |
| 114 | + self.assertEqual(issue, {"number": 210, "title": "[Model] Partition"}) |
| 115 | + fetch_issue_data.assert_called_once_with("CodingThrust/problem-reductions", 210) |
| 116 | + |
| 117 | + @mock.patch("pipeline_pr.fetch_issue_data") |
| 118 | + def test_fetch_linked_issue_bundle_checks_all_candidates_and_prefers_title_match( |
| 119 | + self, |
| 120 | + fetch_issue_data: mock.Mock, |
| 121 | + ) -> None: |
| 122 | + issues = { |
| 123 | + 19: {"number": 19, "title": "[Rule] Coloring -> ILP"}, |
| 124 | + 210: {"number": 210, "title": "[Model] Partition"}, |
| 125 | + } |
| 126 | + fetch_issue_data.side_effect = lambda repo, number: issues[number] |
| 127 | + |
| 128 | + issue_number, issue = fetch_linked_issue_bundle( |
| 129 | + "CodingThrust/problem-reductions", |
| 130 | + { |
| 131 | + "title": "Fix #19: [Model] Partition", |
| 132 | + "body": "Also closes #210.", |
| 133 | + "closingIssuesReferences": [ |
| 134 | + {"number": 19}, |
| 135 | + {"number": 210}, |
| 136 | + ], |
| 137 | + }, |
| 138 | + ) |
| 139 | + |
| 140 | + self.assertEqual(issue_number, 210) |
| 141 | + self.assertEqual(issue, {"number": 210, "title": "[Model] Partition"}) |
| 142 | + self.assertEqual(fetch_issue_data.call_args_list, [ |
| 143 | + mock.call("CodingThrust/problem-reductions", 19), |
| 144 | + mock.call("CodingThrust/problem-reductions", 210), |
| 145 | + ]) |
| 146 | + |
| 147 | + @mock.patch("pipeline_pr.fetch_issue_data") |
| 148 | + def test_fetch_linked_issue_bundle_uses_latest_issue_when_scores_tie( |
| 149 | + self, |
| 150 | + fetch_issue_data: mock.Mock, |
| 151 | + ) -> None: |
| 152 | + issues = { |
| 153 | + 19: {"number": 19, "title": "[Model] Old"}, |
| 154 | + 210: {"number": 210, "title": "[Model] Newer"}, |
| 155 | + } |
| 156 | + fetch_issue_data.side_effect = lambda repo, number: issues[number] |
| 157 | + |
| 158 | + issue_number, issue = fetch_linked_issue_bundle( |
| 159 | + "CodingThrust/problem-reductions", |
| 160 | + { |
| 161 | + "title": "Refresh implementation", |
| 162 | + "body": "Touches multiple linked issues.", |
| 163 | + "closingIssuesReferences": [ |
| 164 | + {"number": 19}, |
| 165 | + {"number": 210}, |
| 166 | + ], |
| 167 | + }, |
| 168 | + ) |
| 169 | + |
| 170 | + self.assertEqual(issue_number, 210) |
| 171 | + self.assertEqual(issue, {"number": 210, "title": "[Model] Newer"}) |
| 172 | + |
91 | 173 | def test_summarize_comments_splits_human_copilot_and_codecov_sources(self) -> None: |
92 | 174 | summary = summarize_comments( |
93 | 175 | inline_comments=[ |
@@ -205,6 +287,48 @@ def test_build_snapshot_includes_linked_issue_ci_and_codecov(self) -> None: |
205 | 287 | self.assertEqual(snapshot["counts"]["files"], 1) |
206 | 288 | self.assertEqual(snapshot["counts"]["commits"], 2) |
207 | 289 |
|
| 290 | + def test_build_snapshot_prefers_closing_issue_references_when_inferring_link(self) -> None: |
| 291 | + snapshot = build_snapshot( |
| 292 | + { |
| 293 | + "number": 664, |
| 294 | + "title": "Fix #19: stale title reference", |
| 295 | + "body": "Copied text still says Fixes #19.", |
| 296 | + "state": "OPEN", |
| 297 | + "url": "https://github.com/CodingThrust/problem-reductions/pull/664", |
| 298 | + "headRefName": "issue-210-partition-v2", |
| 299 | + "baseRefName": "main", |
| 300 | + "mergeable": "CONFLICTING", |
| 301 | + "headRefOid": "abc123", |
| 302 | + "labels": [], |
| 303 | + "files": [], |
| 304 | + "commits": [], |
| 305 | + "closingIssuesReferences": [{"number": 210}], |
| 306 | + } |
| 307 | + ) |
| 308 | + |
| 309 | + self.assertEqual(snapshot["linked_issue_number"], 210) |
| 310 | + |
| 311 | + def test_build_snapshot_uses_latest_linked_issue_number_when_multiple_candidates_exist(self) -> None: |
| 312 | + snapshot = build_snapshot( |
| 313 | + { |
| 314 | + "number": 700, |
| 315 | + "title": "Refresh implementation", |
| 316 | + "body": "References multiple issues.", |
| 317 | + "state": "OPEN", |
| 318 | + "url": "https://github.com/CodingThrust/problem-reductions/pull/700", |
| 319 | + "headRefName": "refresh-linked-issues", |
| 320 | + "baseRefName": "main", |
| 321 | + "mergeable": "MERGEABLE", |
| 322 | + "headRefOid": "def456", |
| 323 | + "labels": [], |
| 324 | + "files": [], |
| 325 | + "commits": [], |
| 326 | + "closingIssuesReferences": [{"number": 19}, {"number": 210}], |
| 327 | + } |
| 328 | + ) |
| 329 | + |
| 330 | + self.assertEqual(snapshot["linked_issue_number"], 210) |
| 331 | + |
208 | 332 | def test_build_current_pr_context_includes_repo_and_pr_fields(self) -> None: |
209 | 333 | current = build_current_pr_context( |
210 | 334 | "CodingThrust/problem-reductions", |
@@ -406,7 +530,11 @@ def test_build_pr_context_assembles_existing_helper_results( |
406 | 530 | context = build_pr_context("CodingThrust/problem-reductions", 570) |
407 | 531 |
|
408 | 532 | build_pr_snapshot.assert_called_once_with("CodingThrust/problem-reductions", 570) |
409 | | - build_comments_summary.assert_called_once_with("CodingThrust/problem-reductions", 570) |
| 533 | + build_comments_summary.assert_called_once_with( |
| 534 | + "CodingThrust/problem-reductions", |
| 535 | + 570, |
| 536 | + linked_issue_number=117, |
| 537 | + ) |
410 | 538 | build_linked_issue_context.assert_called_once() |
411 | 539 | self.assertEqual(context["pr_number"], 570) |
412 | 540 | self.assertEqual(context["issue_context_text"], "# [Model] GraphPartitioning") |
|
0 commit comments