|
6 | 6 | import unittest |
7 | 7 | from pathlib import Path |
8 | 8 |
|
9 | | -from scripts.render_upstream import check, load_templates, sync, write_report |
| 9 | +from scripts.render_upstream import ( |
| 10 | + check, |
| 11 | + load_templates, |
| 12 | + render_pull_request_body, |
| 13 | + sync, |
| 14 | + write_pull_request_body, |
| 15 | + write_report, |
| 16 | +) |
10 | 17 |
|
11 | 18 |
|
12 | 19 | class RenderUpstreamTest(unittest.TestCase): |
@@ -168,6 +175,71 @@ def test_rejects_unsafe_paths(self) -> None: |
168 | 175 | with self.assertRaisesRegex(ValueError, "unsafe path"): |
169 | 176 | load_templates(manifest) |
170 | 177 |
|
| 178 | + def test_render_pull_request_body_for_successful_report(self) -> None: |
| 179 | + body = render_pull_request_body( |
| 180 | + { |
| 181 | + "ok": True, |
| 182 | + "updated": 1, |
| 183 | + "unchanged": 1, |
| 184 | + "failed": 0, |
| 185 | + "templates": [ |
| 186 | + { |
| 187 | + "name": "updated", |
| 188 | + "status": "updated", |
| 189 | + "destination": "workflow-templates/updated.yml", |
| 190 | + "patches": ["patches/updated.patch"], |
| 191 | + }, |
| 192 | + { |
| 193 | + "name": "unchanged", |
| 194 | + "status": "unchanged", |
| 195 | + "destination": "workflow-templates/unchanged.yml", |
| 196 | + "patches": [], |
| 197 | + }, |
| 198 | + ], |
| 199 | + } |
| 200 | + ) |
| 201 | + |
| 202 | + self.assertIn("Updated templates: 1", body) |
| 203 | + self.assertIn("✅ updated — updated", body) |
| 204 | + self.assertIn("➖ unchanged — unchanged", body) |
| 205 | + self.assertIn("- patches/updated.patch", body) |
| 206 | + |
| 207 | + def test_render_pull_request_body_for_failed_patch(self) -> None: |
| 208 | + body = render_pull_request_body( |
| 209 | + { |
| 210 | + "ok": False, |
| 211 | + "updated": 0, |
| 212 | + "unchanged": 0, |
| 213 | + "failed": 1, |
| 214 | + "templates": [ |
| 215 | + { |
| 216 | + "name": "broken", |
| 217 | + "status": "failed", |
| 218 | + "destination": "workflow-templates/broken.yml", |
| 219 | + "patches": ["patches/broken.patch"], |
| 220 | + "error": "failed to apply patches/broken.patch", |
| 221 | + } |
| 222 | + ], |
| 223 | + } |
| 224 | + ) |
| 225 | + |
| 226 | + self.assertIn("Failed templates: 1", body) |
| 227 | + self.assertIn("❌ broken — failed", body) |
| 228 | + self.assertIn("failed to apply patches/broken.patch", body) |
| 229 | + self.assertIn("left unchanged", body) |
| 230 | + |
| 231 | + def test_write_pull_request_body_without_report(self) -> None: |
| 232 | + with tempfile.TemporaryDirectory() as directory: |
| 233 | + report = Path(directory) / "missing.json" |
| 234 | + output = Path(directory) / "body.md" |
| 235 | + |
| 236 | + write_pull_request_body(report, output) |
| 237 | + |
| 238 | + self.assertIn( |
| 239 | + "No patch report was produced", |
| 240 | + output.read_text(encoding="utf-8"), |
| 241 | + ) |
| 242 | + |
171 | 243 |
|
172 | 244 | if __name__ == "__main__": |
173 | 245 | unittest.main() |
0 commit comments