Skip to content

Commit beeb470

Browse files
committed
Cover structured review publisher writes
1 parent 22c9169 commit beeb470

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

.github/actions/pr-review/scripts/test_publish_review_output.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import importlib.util
44
import json
55
import os
6+
import subprocess
67
import unittest
78
from unittest import mock
89

@@ -71,6 +72,50 @@ def test_post_verdict_never_approves(self):
7172
self.assertIn("--comment", command)
7273
self.assertNotIn("--approve", command)
7374

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+
74119
def test_load_review_output_requires_json_object(self):
75120
with mock.patch.dict(os.environ, {"CLAUDE_REVIEW_OUTPUT": json.dumps([])}):
76121
with self.assertRaises(SystemExit) as exit_info:

0 commit comments

Comments
 (0)