|
3 | 3 | import importlib.util |
4 | 4 | import json |
5 | 5 | import os |
| 6 | +import subprocess |
6 | 7 | import unittest |
7 | 8 | from unittest import mock |
8 | 9 |
|
@@ -71,6 +72,50 @@ def test_post_verdict_never_approves(self): |
71 | 72 | self.assertIn("--comment", command) |
72 | 73 | self.assertNotIn("--approve", command) |
73 | 74 |
|
| 75 | + def test_verify_head_stops_before_posting_when_stale(self): |
| 76 | + context = { |
| 77 | + "repository": "ConductorOne/example", |
| 78 | + "pr_number": 42, |
| 79 | + "current_sha": "old-sha", |
| 80 | + } |
| 81 | + result = subprocess.CompletedProcess( |
| 82 | + ["gh"], |
| 83 | + 0, |
| 84 | + stdout=json.dumps({"head": {"sha": "new-sha"}}), |
| 85 | + stderr="", |
| 86 | + ) |
| 87 | + with mock.patch.object(pro, "gh", return_value=result): |
| 88 | + with self.assertRaises(SystemExit) as exit_info: |
| 89 | + pro.verify_head(context) |
| 90 | + |
| 91 | + self.assertEqual(exit_info.exception.code, 3) |
| 92 | + |
| 93 | + def test_post_inline_comment_uses_fixed_pull_comment_endpoint(self): |
| 94 | + context = { |
| 95 | + "repository": "ConductorOne/example", |
| 96 | + "pr_number": 42, |
| 97 | + "current_sha": "head-sha", |
| 98 | + } |
| 99 | + entry = { |
| 100 | + "path": "internal/foo.go", |
| 101 | + "line": 7, |
| 102 | + "confidence": "high", |
| 103 | + "summary": "Summary.", |
| 104 | + "details": "Details.", |
| 105 | + } |
| 106 | + with mock.patch.object(pro, "gh") as gh: |
| 107 | + pro.post_inline_comment(context, entry, "🟠 Bug:") |
| 108 | + |
| 109 | + command = gh.call_args.args[0] |
| 110 | + self.assertEqual( |
| 111 | + command[:2], |
| 112 | + ["api", "repos/ConductorOne/example/pulls/42/comments"], |
| 113 | + ) |
| 114 | + self.assertIn("-f", command) |
| 115 | + self.assertIn("commit_id=head-sha", command) |
| 116 | + self.assertIn("path=internal/foo.go", command) |
| 117 | + self.assertIn("side=RIGHT", command) |
| 118 | + |
74 | 119 | def test_load_review_output_requires_json_object(self): |
75 | 120 | with mock.patch.dict(os.environ, {"CLAUDE_REVIEW_OUTPUT": json.dumps([])}): |
76 | 121 | with self.assertRaises(SystemExit) as exit_info: |
|
0 commit comments