claude-dev-env 8.109.5 → 8.109.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,4 +9,6 @@ A pull request the agent made merges only after a code review of its head comes
9
9
  5. Repeat until a pass records `CLEAN`. A pass whose every finding is ruled out records `CLEAN` with `--ruled-out <finding count> --rulings <link to the rulings comment on this pull request>`.
10
10
  6. Merge pinned to that head: `expectedHeadSha` on the merge tool, or `--match-head-commit` on `gh pr merge`.
11
11
 
12
+ A pass run before the pull request opens names `open` in place of the number and the full 40 character head: `python3 ~/.claude/scripts/merge_review_receipt.py <owner>/<name> open <head sha> <finding count>`. A pass whose every finding is ruled out adds `--ruled-out <finding count> --rulings <path:line for each finding, comma separated>`. Run it in the checkout that holds the head. It checks that each `path:line` exists at that head, and each finding needs a different one. A merge pinned to that head passes on an open pass only at zero findings. Rulings for the merge go on the pull request, as in step 5.
13
+
12
14
  `hooks/blocking/merge_review_gate.py` denies any other merge. In a merge-queue repository, enqueue with `gh pr merge <number> --repo <owner>/<name> --auto --match-head-commit <head sha>`; auto-merge that names no head is denied. A repository whose own CI and merge queue review and merge its pull requests is listed in `CLAUDE_MERGE_REVIEW_EXEMPT_REPOSITORIES`, comma separated as `owner/name`, and skips the gate.
@@ -38,6 +38,7 @@ if hooks_directory not in sys.path:
38
38
  from blocking.merge_review_gate_parts.open_request import OpenRequest, open_request_from
39
39
  from blocking.merge_review_gate_parts.receipts import (
40
40
  has_clean_open_review,
41
+ has_zero_finding_open_review,
41
42
  is_clean_receipt,
42
43
  receipt_path,
43
44
  same_commit,
@@ -275,7 +276,7 @@ def deny_reason(request: MergeRequest) -> str | None:
275
276
  if (
276
277
  request.pinned_head
277
278
  and not pass_on_pinned_head
278
- and has_clean_open_review(request.repo, request.pinned_head)
279
+ and has_zero_finding_open_review(request.repo, request.pinned_head)
279
280
  ):
280
281
  return None
281
282
  fields = {"slug": request.slug, "number": request.number}
@@ -5,6 +5,7 @@ from __future__ import annotations
5
5
  import os
6
6
  import subprocess
7
7
  import sys
8
+ import tempfile
8
9
  from dataclasses import dataclass
9
10
  from pathlib import Path
10
11
 
@@ -13,6 +14,7 @@ if hooks_directory not in sys.path:
13
14
  sys.path.insert(0, hooks_directory)
14
15
 
15
16
  from hooks_constants.merge_review_gate_constants import (
17
+ ALL_NON_INTERACTIVE_GIT_SETTINGS,
16
18
  ALL_ORIGIN_URL_ARGUMENTS,
17
19
  ALL_SHELL_TOOL_NAMES,
18
20
  CHANGE_FOLDER_PATTERN,
@@ -21,13 +23,17 @@ from hooks_constants.merge_review_gate_constants import (
21
23
  CURRENT_HEAD_REFERENCE,
22
24
  CWD_FIELD,
23
25
  GH_PR_CREATE_PATTERN,
26
+ GITHUB_REMOTE_URL_TEMPLATE,
24
27
  GIT_TIMEOUT_SECONDS,
25
28
  HEAD_BRANCH_FIELD,
26
29
  HEAD_OPTION_PATTERN,
30
+ LS_REMOTE_FIELD_SEPARATOR,
27
31
  ORIGIN_URL_PATTERN,
28
32
  OWNER_FIELD,
29
33
  PULL_REQUEST_SCRIPT_CREATE_PATTERN,
30
34
  REMOTE_BRANCH_PREFIX,
35
+ REMOTE_BRANCH_REFERENCE_TEMPLATE,
36
+ REMOTE_LOOKUP_TIMEOUT_SECONDS,
31
37
  REPO_FIELD,
32
38
  REPO_OPTION_PATTERN,
33
39
  )
@@ -62,8 +68,11 @@ def open_request_from(all_payload_fields: dict[str, object]) -> OpenRequest | No
62
68
  gh pr create --repo o/r --head branch
63
69
  python pull_request.py create --repo o/r --head branch
64
70
 
65
- A branch resolves in the payload's folder or a ``cd`` target, as
66
- ``origin/<branch>`` first. No head means ``HEAD``; no repository, ``origin``.
71
+ A tool call reads its head branch from GitHub first. A fork head
72
+ ``user:branch`` reads the repository of ``user``. A branch GitHub does not
73
+ list, and every branch of a shell command, resolves in the payload's folder
74
+ as ``origin/<branch>`` first. A ``cd`` target names the folder. No head
75
+ means ``HEAD``; no repository, ``origin``.
67
76
 
68
77
  Args:
69
78
  all_payload_fields: The parsed PreToolUse input.
@@ -86,12 +95,15 @@ def open_request_from(all_payload_fields: dict[str, object]) -> OpenRequest | No
86
95
 
87
96
 
88
97
  def _tool_open_request(all_tool_input: dict[object, object], folder: str | None) -> OpenRequest:
98
+ owner = str(all_tool_input.get(OWNER_FIELD, ""))
99
+ repo = str(all_tool_input.get(REPO_FIELD, ""))
89
100
  branch = all_tool_input.get(HEAD_BRANCH_FIELD)
90
- return OpenRequest(
91
- owner=str(all_tool_input.get(OWNER_FIELD, "")),
92
- repo=str(all_tool_input.get(REPO_FIELD, "")),
93
- head=_branch_commit(branch, folder) if isinstance(branch, str) and branch else None,
101
+ head = (
102
+ _pushed_commit(owner, repo, branch) or _branch_commit(branch, folder)
103
+ if isinstance(branch, str) and branch
104
+ else None
94
105
  )
106
+ return OpenRequest(owner=owner, repo=repo, head=head)
95
107
 
96
108
 
97
109
  def _shell_open_request(command: str, folder: str | None) -> OpenRequest | None:
@@ -155,6 +167,40 @@ def _branch_commit(branch: str, folder: str | None) -> str | None:
155
167
  return None
156
168
 
157
169
 
170
+ def _pushed_commit(owner: str, repo: str, branch: str) -> str | None:
171
+ head_owner, separator, head_branch = branch.partition(":")
172
+ if not separator:
173
+ head_owner, head_branch = owner, branch
174
+ if not head_owner or not repo or not head_branch:
175
+ return None
176
+ reference = REMOTE_BRANCH_REFERENCE_TEMPLATE.format(branch=head_branch)
177
+ remote_url = GITHUB_REMOTE_URL_TEMPLATE.format(owner=head_owner, repo=repo)
178
+ with tempfile.TemporaryDirectory() as empty_folder, tempfile.TemporaryFile() as listing:
179
+ try:
180
+ subprocess.run(
181
+ ["git", "ls-remote", remote_url, reference],
182
+ cwd=empty_folder,
183
+ stdin=subprocess.DEVNULL,
184
+ stdout=listing,
185
+ stderr=subprocess.DEVNULL,
186
+ timeout=REMOTE_LOOKUP_TIMEOUT_SECONDS,
187
+ check=False,
188
+ env={**os.environ, **ALL_NON_INTERACTIVE_GIT_SETTINGS},
189
+ )
190
+ except (OSError, subprocess.SubprocessError):
191
+ return None
192
+ listing.seek(0)
193
+ return _listed_commit(listing.read().decode("utf-8", "replace"), reference)
194
+
195
+
196
+ def _listed_commit(listing: str, reference: str) -> str | None:
197
+ for each_line in listing.splitlines():
198
+ commit, separator, listed_reference = each_line.partition(LS_REMOTE_FIELD_SEPARATOR)
199
+ if separator and listed_reference == reference:
200
+ return commit
201
+ return None
202
+
203
+
158
204
  def _origin_repository(folder: str | None) -> tuple[str, str]:
159
205
  origin_url = _run_git(list(ALL_ORIGIN_URL_ARGUMENTS), folder)
160
206
  origin_match = ORIGIN_URL_PATTERN.search(origin_url) if origin_url else None
@@ -9,6 +9,7 @@ from __future__ import annotations
9
9
  import json
10
10
  import os
11
11
  import sys
12
+ from collections.abc import Callable
12
13
  from pathlib import Path
13
14
 
14
15
  hooks_directory = str(Path(__file__).resolve().parent.parent.parent)
@@ -27,7 +28,9 @@ from hooks_constants.merge_review_gate_constants import (
27
28
  RECEIPT_FINDINGS_KEY,
28
29
  RECEIPT_HEAD_KEY,
29
30
  RECEIPT_RULED_OUT_KEY,
31
+ RECEIPT_RULING_LINES_KEY,
30
32
  RECEIPT_RULINGS_KEY,
33
+ RULING_REFERENCE_PATTERN,
31
34
  RULINGS_LINK_PATTERN,
32
35
  )
33
36
 
@@ -81,32 +84,71 @@ def open_receipt_path(owner: str, repo: str, head: str) -> Path:
81
84
 
82
85
 
83
86
  def has_clean_open_review(repo: str, head: str) -> bool:
84
- """Return whether a pass recorded before the pull request opened found zero findings at a head.
87
+ """Return whether a pass recorded before the pull request opened lets it open at a head.
85
88
 
86
- The head may be a full or an abbreviated commit, matched against each
87
- recorded head by prefix. The owner is left out of the match, since a
88
- checkout whose origin still names a transferred repository's old owner
89
- opens against the new one::
89
+ The pass is clean when it found zero findings, or when each finding has a
90
+ ``path:line`` ruling. The head may be a full or an abbreviated commit,
91
+ matched against each recorded head by prefix. The owner is left out of the
92
+ match, since a checkout whose origin still names a transferred
93
+ repository's old owner opens against the new one::
90
94
 
91
95
  open receipt {head: abc1234..., findings: 0}, head abc1234 -> True
96
+ open receipt {head: abc1234..., findings: 2, ruled out 2,
97
+ ruling_lines [a.py:1, b.py:20]}, head abc1234 -> True
92
98
  open receipt {head: abc1234..., findings: 2}, head abc1234 -> False
93
99
  no open receipt for the repository -> False
94
100
 
95
101
  Args:
96
102
  repo: Repository name.
97
- head: The commit the open or merge names.
103
+ head: The commit the open names.
98
104
 
99
105
  Returns:
100
106
  True when a clean open receipt covers that head.
101
107
  """
108
+ return _has_open_review(repo, head, is_clean_open_pass)
109
+
110
+
111
+ def has_zero_finding_open_review(repo: str, head: str) -> bool:
112
+ """Return whether a pass recorded before the pull request opened found zero findings at a head.
113
+
114
+ A merge accepts the open pass only at zero findings. Ruled-out findings
115
+ need the rulings comment a numbered pass links on the pull request::
116
+
117
+ open receipt {head: abc1234..., findings: 0}, head abc1234 -> True
118
+ open receipt {head: abc1234..., findings: 2, ruled out 2,
119
+ ruling_lines [a.py:1, b.py:20]}, head abc1234 -> False
120
+
121
+ Args:
122
+ repo: Repository name.
123
+ head: The commit the merge pins.
124
+
125
+ Returns:
126
+ True when an open receipt with zero findings covers that head.
127
+ """
128
+ return _has_open_review(repo, head, _reports_no_findings)
129
+
130
+
131
+ def _has_open_review(
132
+ repo: str, head: str, is_acceptable_pass: Callable[[dict[str, object]], bool]
133
+ ) -> bool:
102
134
  if not OPEN_HEAD_PATTERN.fullmatch(head):
103
135
  return False
104
136
  folder = receipt_directory() / OPEN_RECEIPT_DIRECTORY_NAME
105
137
  pattern = OPEN_RECEIPT_GLOB_TEMPLATE.format(repo=repo.casefold())
106
- return any(_is_clean_open_receipt(each_path, head) for each_path in folder.glob(pattern))
138
+ return any(
139
+ _is_open_receipt_for(each_path, head, is_acceptable_pass)
140
+ for each_path in folder.glob(pattern)
141
+ )
107
142
 
108
143
 
109
- def _is_clean_open_receipt(path: Path, head: str) -> bool:
144
+ def _reports_no_findings(all_receipt_fields: dict[str, object]) -> bool:
145
+ finding_count = all_receipt_fields.get(RECEIPT_FINDINGS_KEY)
146
+ return _is_count(finding_count) and finding_count == 0
147
+
148
+
149
+ def _is_open_receipt_for(
150
+ path: Path, head: str, is_acceptable_pass: Callable[[dict[str, object]], bool]
151
+ ) -> bool:
110
152
  try:
111
153
  all_receipt_fields = json.loads(path.read_text(encoding="utf-8"))
112
154
  except (OSError, ValueError):
@@ -118,8 +160,50 @@ def _is_clean_open_receipt(path: Path, head: str) -> bool:
118
160
  isinstance(recorded_head, str)
119
161
  and OPEN_RECEIPT_HEAD_PATTERN.fullmatch(recorded_head) is not None
120
162
  and same_commit(recorded_head, head)
121
- and _is_count(all_receipt_fields.get(RECEIPT_FINDINGS_KEY))
122
- and all_receipt_fields.get(RECEIPT_FINDINGS_KEY) == 0
163
+ and is_acceptable_pass(all_receipt_fields)
164
+ )
165
+
166
+
167
+ def is_clean_open_pass(all_receipt_fields: dict[str, object]) -> bool:
168
+ """Return whether a pass recorded before the pull request opened lets it open.
169
+
170
+ The pull request has no number yet, so no rulings comment exists to link.
171
+ A pass is clean when it reported zero findings, or when each finding it
172
+ reported has its own ``path:line`` ruling beside it::
173
+
174
+ findings 0 -> clean
175
+ findings 2, ruled out 2, ruling_lines [a.py:1, src/b.py:20] -> clean
176
+ findings 2, ruled out 2, ruling_lines [a.py:1] -> not clean
177
+ findings 2, ruled out 2, ruling_lines [a.py:1, a.py:1] -> not clean
178
+ findings 2, ruled out 2, ruling_lines [a.py:1, see the thread] -> not clean
179
+
180
+ Args:
181
+ all_receipt_fields: The parsed receipt of one review pass.
182
+
183
+ Returns:
184
+ True when the pass counts as clean.
185
+ """
186
+ finding_count = all_receipt_fields.get(RECEIPT_FINDINGS_KEY)
187
+ return _reports_no_findings(all_receipt_fields) or (
188
+ _is_count(finding_count)
189
+ and _rules_out_every_finding_at_file_and_line(all_receipt_fields, finding_count)
190
+ )
191
+
192
+
193
+ def _rules_out_every_finding_at_file_and_line(
194
+ all_receipt_fields: dict[str, object], finding_count: object
195
+ ) -> bool:
196
+ all_ruling_lines = all_receipt_fields.get(RECEIPT_RULING_LINES_KEY)
197
+ return (
198
+ _ruled_out_count_matches(all_receipt_fields, finding_count)
199
+ and isinstance(all_ruling_lines, list)
200
+ and len(all_ruling_lines) == finding_count
201
+ and len(set(map(str, all_ruling_lines))) == finding_count
202
+ and all(
203
+ isinstance(each_ruling, str)
204
+ and RULING_REFERENCE_PATTERN.fullmatch(each_ruling) is not None
205
+ for each_ruling in all_ruling_lines
206
+ )
123
207
  )
124
208
 
125
209
 
@@ -174,14 +258,16 @@ def _is_count(candidate: object) -> bool:
174
258
  def _rules_out_every_finding(
175
259
  all_receipt_fields: dict[str, object], finding_count: object, owner: str, repo: str, number: int
176
260
  ) -> bool:
177
- ruled_out_count = all_receipt_fields.get(RECEIPT_RULED_OUT_KEY)
178
- return (
179
- _is_count(ruled_out_count)
180
- and ruled_out_count == finding_count
181
- and _links_rulings_on(all_receipt_fields.get(RECEIPT_RULINGS_KEY), owner, repo, number)
261
+ return _ruled_out_count_matches(all_receipt_fields, finding_count) and _links_rulings_on(
262
+ all_receipt_fields.get(RECEIPT_RULINGS_KEY), owner, repo, number
182
263
  )
183
264
 
184
265
 
266
+ def _ruled_out_count_matches(all_receipt_fields: dict[str, object], finding_count: object) -> bool:
267
+ ruled_out_count = all_receipt_fields.get(RECEIPT_RULED_OUT_KEY)
268
+ return _is_count(ruled_out_count) and ruled_out_count == finding_count
269
+
270
+
185
271
  def _links_rulings_on(rulings: object, owner: str, repo: str, number: int) -> bool:
186
272
  rulings_match = RULINGS_LINK_PATTERN.fullmatch(rulings) if isinstance(rulings, str) else None
187
273
  return (
@@ -1,5 +1,7 @@
1
1
  """Behavior tests for the clean-review merge gate."""
2
2
 
3
+ import io
4
+ import os
3
5
  import subprocess
4
6
  import sys
5
7
  from pathlib import Path
@@ -25,9 +27,22 @@ def receipt_folder(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
25
27
  monkeypatch.setenv("CLAUDE_MERGE_REVIEW_RECEIPT_DIR", str(tmp_path))
26
28
  monkeypatch.delenv("CLAUDE_MERGE_REVIEW_EXEMPT_REPOSITORIES", raising=False)
27
29
  monkeypatch.delenv("CLAUDE_MERGE_REVIEW_COMMAND", raising=False)
30
+ remotes = tmp_path / "github.com"
31
+ subprocess.run(
32
+ ["git", "init", "--quiet", "--bare", str(remotes / "acme" / "tools.git")], check=True
33
+ )
34
+ index = int(os.environ.get("GIT_CONFIG_COUNT", "0"))
35
+ monkeypatch.setenv("GIT_CONFIG_COUNT", str(index + 1))
36
+ monkeypatch.setenv(f"GIT_CONFIG_KEY_{index}", f"url.{remotes}/.insteadOf")
37
+ monkeypatch.setenv(f"GIT_CONFIG_VALUE_{index}", "https://github.com/")
28
38
  return tmp_path
29
39
 
30
40
 
41
+ @pytest.fixture
42
+ def github_repository(receipt_folder: Path) -> Path:
43
+ return receipt_folder / "github.com" / "acme" / "tools.git"
44
+
45
+
31
46
  def _merge_tool(head: str | None = None) -> dict[str, object]:
32
47
  tool_input: dict[str, object] = {"owner": "acme", "repo": "tools", "pullNumber": 12}
33
48
  if head is not None:
@@ -210,7 +225,7 @@ def _git(folder: Path, *all_arguments: str) -> str:
210
225
 
211
226
 
212
227
  @pytest.fixture
213
- def branch_checkout(tmp_path: Path) -> tuple[Path, str]:
228
+ def branch_checkout(tmp_path: Path, github_repository: Path) -> tuple[Path, str]:
214
229
  folder = tmp_path / "checkout"
215
230
  folder.mkdir()
216
231
  _git(folder, "init", "--quiet", "--initial-branch", "main")
@@ -228,9 +243,50 @@ def branch_checkout(tmp_path: Path) -> tuple[Path, str]:
228
243
  "-m",
229
244
  "first",
230
245
  )
246
+ _git(folder, "push", "--quiet", str(github_repository), "feature")
231
247
  return folder, _git(folder, "rev-parse", "HEAD")
232
248
 
233
249
 
250
+ @pytest.fixture
251
+ def ruled_checkout(
252
+ branch_checkout: tuple[Path, str], github_repository: Path, monkeypatch: pytest.MonkeyPatch
253
+ ) -> tuple[Path, str]:
254
+ folder, _head = branch_checkout
255
+ (folder / "a.py").write_text("one\n", encoding="utf-8")
256
+ (folder / "b.py").write_text("one\ntwo\n", encoding="utf-8")
257
+ _git(folder, "add", "a.py", "b.py")
258
+ _git(
259
+ folder,
260
+ "-c",
261
+ "user.name=t",
262
+ "-c",
263
+ "user.email=t@example.com",
264
+ "commit",
265
+ "--quiet",
266
+ "-m",
267
+ "files",
268
+ )
269
+ _git(folder, "push", "--quiet", str(github_repository), "feature")
270
+ monkeypatch.chdir(folder)
271
+ return folder, _git(folder, "rev-parse", "HEAD")
272
+
273
+
274
+ def _record_open_pass(head: str, findings: int, ruled_out: int, rulings: str) -> None:
275
+ merge_review_receipt.main(
276
+ [
277
+ "acme/tools",
278
+ "open",
279
+ head,
280
+ str(findings),
281
+ "--ruled-out",
282
+ str(ruled_out),
283
+ "--rulings",
284
+ rulings,
285
+ ],
286
+ io.StringIO(),
287
+ )
288
+
289
+
234
290
  def _create_tool(folder: Path, head: str = "feature") -> dict[str, object]:
235
291
  return {
236
292
  "tool_name": "mcp__github__create_pull_request",
@@ -248,6 +304,24 @@ def test_should_deny_a_pull_request_open_with_no_review(branch_checkout: tuple[P
248
304
  reason = _reason(_create_tool(folder))
249
305
  assert f"no clean review for head {head}" in reason
250
306
  assert f"acme/tools open {head} 0" in reason
307
+ assert "--ruled-out" in reason
308
+ assert "--rulings" in reason
309
+
310
+
311
+ def test_should_allow_a_pull_request_open_whose_findings_are_ruled_out_at_file_and_line(
312
+ ruled_checkout: tuple[Path, str],
313
+ ) -> None:
314
+ folder, head = ruled_checkout
315
+ _record_open_pass(head, 2, 2, "a.py:1,b.py:2")
316
+ assert _reason(_create_tool(folder)) is None
317
+
318
+
319
+ def test_should_deny_a_pull_request_open_whose_rulings_leave_a_finding_unproven(
320
+ ruled_checkout: tuple[Path, str],
321
+ ) -> None:
322
+ folder, head = ruled_checkout
323
+ _record_open_pass(head, 3, 2, "a.py:1,b.py:2")
324
+ assert "no clean review" in _reason(_create_tool(folder))
251
325
 
252
326
 
253
327
  def test_should_allow_a_pull_request_open_reviewed_clean_at_its_head(
@@ -299,6 +373,27 @@ def test_should_deny_a_pull_request_open_whose_head_cannot_be_read(tmp_path: Pat
299
373
  assert "names no repository or head commit" in reason
300
374
 
301
375
 
376
+ def test_should_read_the_pushed_head_of_a_branch_outside_any_checkout(
377
+ branch_checkout: tuple[Path, str], tmp_path: Path
378
+ ) -> None:
379
+ _folder, head = branch_checkout
380
+ outside = tmp_path / "outside"
381
+ outside.mkdir()
382
+ assert f"no clean review for head {head}" in _reason(_create_tool(outside))
383
+ merge_review_receipt.record_open_review("acme/tools", head, 0)
384
+ assert _reason(_create_tool(outside)) is None
385
+
386
+
387
+ def test_should_read_the_checkout_head_when_github_lists_no_such_repository(
388
+ branch_checkout: tuple[Path, str],
389
+ ) -> None:
390
+ folder, head = branch_checkout
391
+ merge_review_receipt.record_open_review("acme/ghost", head, 0)
392
+ unlisted_create = _create_tool(folder)
393
+ unlisted_create["tool_input"]["repo"] = "ghost"
394
+ assert _reason(unlisted_create) is None
395
+
396
+
302
397
  def test_should_allow_a_pull_request_open_in_an_exempt_repository(
303
398
  branch_checkout: tuple[Path, str], monkeypatch: pytest.MonkeyPatch
304
399
  ) -> None:
@@ -314,6 +409,14 @@ def test_should_allow_a_merge_pinned_to_the_head_reviewed_clean_before_open() ->
314
409
  assert _reason(_bash(command)) is None
315
410
 
316
411
 
412
+ def test_should_deny_a_merge_pinned_to_a_head_whose_open_pass_only_ruled_findings_out(
413
+ ruled_checkout: tuple[Path, str],
414
+ ) -> None:
415
+ _folder, head = ruled_checkout
416
+ _record_open_pass(head, 2, 2, "a.py:1,b.py:2")
417
+ assert "no clean review" in _reason(_merge_tool(head))
418
+
419
+
317
420
  def test_should_deny_a_merge_pinned_past_the_head_reviewed_before_open() -> None:
318
421
  merge_review_receipt.record_open_review("acme/tools", CLEAN_HEAD, 0)
319
422
  assert "no clean review" in _reason(_merge_tool(NEW_HEAD))
@@ -360,7 +463,7 @@ def test_should_check_a_merge_chained_after_a_reviewed_open(
360
463
 
361
464
 
362
465
  def test_should_read_the_pushed_branch_before_the_local_one(
363
- branch_checkout: tuple[Path, str],
466
+ branch_checkout: tuple[Path, str], github_repository: Path
364
467
  ) -> None:
365
468
  folder, local_head = branch_checkout
366
469
  _git(
@@ -376,12 +479,36 @@ def test_should_read_the_pushed_branch_before_the_local_one(
376
479
  "pushed",
377
480
  )
378
481
  pushed_head = _git(folder, "rev-parse", "HEAD")
379
- _git(folder, "update-ref", "refs/remotes/origin/feature", pushed_head)
482
+ _git(folder, "push", "--quiet", str(github_repository), "HEAD:feature")
380
483
  _git(folder, "reset", "--quiet", "--hard", local_head)
381
484
  merge_review_receipt.record_open_review("acme/tools", local_head, 0)
382
485
  assert f"head {pushed_head}" in _reason(_create_tool(folder))
383
486
 
384
487
 
488
+ def test_should_read_the_fetched_branch_before_the_local_one_for_a_shell_open(
489
+ branch_checkout: tuple[Path, str],
490
+ ) -> None:
491
+ folder, local_head = branch_checkout
492
+ _git(
493
+ folder,
494
+ "-c",
495
+ "user.name=t",
496
+ "-c",
497
+ "user.email=t@example.com",
498
+ "commit",
499
+ "--quiet",
500
+ "--allow-empty",
501
+ "-m",
502
+ "fetched",
503
+ )
504
+ fetched_head = _git(folder, "rev-parse", "HEAD")
505
+ _git(folder, "update-ref", "refs/remotes/origin/feature", fetched_head)
506
+ _git(folder, "reset", "--quiet", "--hard", local_head)
507
+ merge_review_receipt.record_open_review("acme/tools", local_head, 0)
508
+ command = "gh pr create --repo acme/tools --head feature"
509
+ assert f"head {fetched_head}" in _reason(_bash_in(folder, command))
510
+
511
+
385
512
  def test_should_not_match_an_open_receipt_on_a_short_pinned_head() -> None:
386
513
  merge_review_receipt.record_open_review("acme/tools", CLEAN_HEAD, 0)
387
514
  assert "no clean review" in _reason(_merge_tool(CLEAN_HEAD[:3]))