claude-dev-env 8.109.5 → 8.109.7

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.
@@ -1,14 +1,19 @@
1
1
  """Behavioral tests for reading a pull request open from a PreToolUse payload.
2
2
 
3
3
  gh pr create --repo acme/tools --title "--head evil" -> acme/tools, quoted option ignored
4
- mcp create_pull_request {owner, repo} -> acme/tools, no head
4
+ mcp create_pull_request {owner, repo, head} -> acme/tools, head listed by GitHub
5
+ mcp create_pull_request {owner, repo, head: u:b} -> acme/tools, head listed for u
5
6
  gh pr merge 12 -> no open
6
7
  """
7
8
 
8
9
  from __future__ import annotations
9
10
 
11
+ import subprocess
10
12
  from pathlib import Path
11
13
 
14
+ import pytest
15
+
16
+ from blocking.merge_review_gate_parts import open_request
12
17
  from blocking.merge_review_gate_parts.open_request import OpenRequest, open_request_from
13
18
 
14
19
 
@@ -16,6 +21,57 @@ def _shell_payload(command: str, folder: Path) -> dict[str, object]:
16
21
  return {"tool_name": "Bash", "tool_input": {"command": command}, "cwd": str(folder)}
17
22
 
18
23
 
24
+ def _create_payload(head: str, folder: Path, owner: str = "acme") -> dict[str, object]:
25
+ return {
26
+ "tool_name": "mcp__github__create_pull_request",
27
+ "tool_input": {"owner": owner, "repo": "tools", "head": head},
28
+ "cwd": str(folder),
29
+ }
30
+
31
+
32
+ def _git(folder: Path, *all_arguments: str) -> str:
33
+ completed = subprocess.run(
34
+ ["git", "-C", str(folder), *all_arguments], capture_output=True, text=True, check=True
35
+ )
36
+ return completed.stdout.strip()
37
+
38
+
39
+ def _commit(folder: Path, message: str) -> str:
40
+ _git(
41
+ folder,
42
+ "-c",
43
+ "user.name=t",
44
+ "-c",
45
+ "user.email=t@example.com",
46
+ "commit",
47
+ "--quiet",
48
+ "--allow-empty",
49
+ "-m",
50
+ message,
51
+ )
52
+ return _git(folder, "rev-parse", "HEAD")
53
+
54
+
55
+ def _checkout_on(tmp_path: Path, branch: str) -> Path:
56
+ checkout = tmp_path / "checkout"
57
+ checkout.mkdir()
58
+ _git(checkout, "init", "--quiet", "--initial-branch", branch)
59
+ return checkout
60
+
61
+
62
+ def _bare_remote(github: Path, owner: str) -> Path:
63
+ remote = github / owner / "tools.git"
64
+ remote.mkdir(parents=True)
65
+ _git(remote, "init", "--quiet", "--bare")
66
+ return remote
67
+
68
+
69
+ def _redirect_github(monkeypatch: pytest.MonkeyPatch, github: Path) -> None:
70
+ monkeypatch.setenv("GIT_CONFIG_COUNT", "1")
71
+ monkeypatch.setenv("GIT_CONFIG_KEY_0", f"url.{github}/.insteadOf")
72
+ monkeypatch.setenv("GIT_CONFIG_VALUE_0", "https://github.com/")
73
+
74
+
19
75
  def test_should_read_the_repository_and_ignore_options_quoted_in_the_title(tmp_path: Path) -> None:
20
76
  payload = _shell_payload('gh pr create --repo acme/tools --title "--head evil"', tmp_path)
21
77
  assert open_request_from(payload) == OpenRequest(owner="acme", repo="tools", head=None)
@@ -30,9 +86,143 @@ def test_should_read_the_create_tool_with_no_head_branch(tmp_path: Path) -> None
30
86
  assert open_request_from(payload) == OpenRequest(owner="acme", repo="tools", head=None)
31
87
 
32
88
 
33
- def test_should_return_none_for_a_command_that_opens_nothing(tmp_path: Path) -> None:
34
- assert open_request_from(_shell_payload("gh pr merge 12", tmp_path)) is None
89
+ def test_should_read_a_pushed_branch_from_outside_any_checkout(
90
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
91
+ ) -> None:
92
+ checkout = _checkout_on(tmp_path, "feature")
93
+ head = _commit(checkout, "first")
94
+ github = tmp_path / "github.com"
95
+ _git(checkout, "push", "--quiet", str(_bare_remote(github, "acme")), "feature")
96
+ _redirect_github(monkeypatch, github)
97
+ assert open_request_from(_create_payload("feature", tmp_path)) == OpenRequest(
98
+ owner="acme", repo="tools", head=head
99
+ )
100
+
101
+
102
+ def test_should_read_a_fork_branch_from_the_fork_owner(
103
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
104
+ ) -> None:
105
+ checkout = _checkout_on(tmp_path, "feature")
106
+ base_head = _commit(checkout, "base")
107
+ github = tmp_path / "github.com"
108
+ _git(checkout, "push", "--quiet", str(_bare_remote(github, "acme")), "feature")
109
+ fork_head = _commit(checkout, "fork")
110
+ _git(checkout, "push", "--quiet", str(_bare_remote(github, "someone")), "feature")
111
+ _redirect_github(monkeypatch, github)
112
+ assert base_head != fork_head
113
+ assert open_request_from(_create_payload("someone:feature", tmp_path)).head == fork_head
114
+
115
+
116
+ def test_should_read_no_head_for_a_branch_the_repository_does_not_list(
117
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
118
+ ) -> None:
119
+ github = tmp_path / "github.com"
120
+ _bare_remote(github, "acme")
121
+ _redirect_github(monkeypatch, github)
122
+ assert open_request_from(_create_payload("feature", tmp_path)).head is None
123
+
124
+
125
+ def test_should_list_in_an_empty_folder_so_the_checkout_config_never_applies(
126
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
127
+ ) -> None:
128
+ checkout = _checkout_on(tmp_path, "feature")
129
+ head = _commit(checkout, "first")
130
+ github = tmp_path / "github.com"
131
+ _git(checkout, "push", "--quiet", str(_bare_remote(github, "acme")), "feature")
132
+ _redirect_github(monkeypatch, github)
133
+ decoy = tmp_path / "decoy"
134
+ _commit(checkout, "decoy")
135
+ _git(checkout, "push", "--quiet", str(_bare_remote(decoy, "acme")), "feature")
136
+ _git(checkout, "config", f"url.{decoy}/acme/.insteadOf", "https://github.com/acme/")
137
+ monkeypatch.chdir(checkout)
138
+ assert open_request_from(_create_payload("feature", tmp_path)).head == head
35
139
 
36
140
 
37
- def test_should_name_the_slug_from_owner_and_repo() -> None:
38
- assert OpenRequest(owner="acme", repo="tools", head=None).slug == "acme/tools"
141
+ def test_should_read_no_head_when_the_listing_times_out(monkeypatch: pytest.MonkeyPatch) -> None:
142
+ def time_out(all_arguments: list[str], **_all_keyword_arguments: object) -> None:
143
+ raise subprocess.TimeoutExpired(all_arguments, 1)
144
+
145
+ monkeypatch.setattr(open_request.subprocess, "run", time_out)
146
+ assert open_request_from(_create_payload("feature", Path("."))).head is None
147
+
148
+
149
+ def test_should_run_the_listing_without_a_terminal_prompt(monkeypatch: pytest.MonkeyPatch) -> None:
150
+ monkeypatch.delenv("GIT_TERMINAL_PROMPT", raising=False)
151
+ monkeypatch.delenv("GCM_INTERACTIVE", raising=False)
152
+ all_environments: list[dict[str, str]] = []
153
+
154
+ def record_environment(
155
+ all_arguments: list[str], **all_keyword_arguments: dict[str, str]
156
+ ) -> subprocess.CompletedProcess[bytes]:
157
+ if "env" in all_keyword_arguments:
158
+ all_environments.append(all_keyword_arguments["env"])
159
+ return subprocess.CompletedProcess(all_arguments, 1)
160
+
161
+ monkeypatch.setattr(open_request.subprocess, "run", record_environment)
162
+ open_request_from(_create_payload("feature", Path(".")))
163
+ assert all_environments[0]["GIT_TERMINAL_PROMPT"] == "0"
164
+ assert all_environments[0]["GCM_INTERACTIVE"] == "never"
165
+
166
+
167
+ def test_should_pick_the_listed_line_that_names_the_branch_exactly(
168
+ monkeypatch: pytest.MonkeyPatch,
169
+ ) -> None:
170
+ listing = f"{'1' * 40}\trefs/heads/feature-two\n{'2' * 40}\trefs/heads/feature\n"
171
+
172
+ def list_branches(
173
+ all_arguments: list[str], **all_keyword_arguments: object
174
+ ) -> subprocess.CompletedProcess[bytes]:
175
+ all_keyword_arguments["stdout"].write(listing.encode())
176
+ return subprocess.CompletedProcess(all_arguments, 0)
177
+
178
+ monkeypatch.setattr(open_request.subprocess, "run", list_branches)
179
+ assert open_request_from(_create_payload("feature", Path("."))).head == "2" * 40
180
+
181
+
182
+ def test_should_run_no_listing_for_a_call_that_names_no_owner(
183
+ monkeypatch: pytest.MonkeyPatch,
184
+ ) -> None:
185
+ all_commands: list[list[str]] = []
186
+
187
+ def record_command(
188
+ all_arguments: list[str], **_all_keyword_arguments: object
189
+ ) -> subprocess.CompletedProcess[bytes]:
190
+ all_commands.append(all_arguments)
191
+ return subprocess.CompletedProcess(all_arguments, 1)
192
+
193
+ monkeypatch.setattr(open_request.subprocess, "run", record_command)
194
+ assert open_request_from(_create_payload("feature", Path("."), owner="")).head is None
195
+ assert not any("ls-remote" in each_command for each_command in all_commands)
196
+
197
+
198
+ def test_should_read_the_checkout_branch_when_github_lists_none(
199
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
200
+ ) -> None:
201
+ checkout = _checkout_on(tmp_path, "feature")
202
+ head = _commit(checkout, "first")
203
+ github = tmp_path / "github.com"
204
+ _bare_remote(github, "acme")
205
+ _redirect_github(monkeypatch, github)
206
+ assert open_request_from(_create_payload("feature", checkout)).head == head
207
+
208
+
209
+ def test_should_read_a_fork_branch_from_the_checkout_when_github_lists_none(
210
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
211
+ ) -> None:
212
+ checkout = _checkout_on(tmp_path, "feature")
213
+ head = _commit(checkout, "first")
214
+ github = tmp_path / "github.com"
215
+ _bare_remote(github, "someone")
216
+ _redirect_github(monkeypatch, github)
217
+ assert open_request_from(_create_payload("someone:feature", checkout)).head == head
218
+
219
+
220
+ def test_should_read_a_shell_open_branch_from_the_checkout(tmp_path: Path) -> None:
221
+ checkout = _checkout_on(tmp_path, "feature")
222
+ head = _commit(checkout, "first")
223
+ payload = _shell_payload("gh pr create --repo acme/tools --head feature", checkout)
224
+ assert open_request_from(payload) == OpenRequest(owner="acme", repo="tools", head=head)
225
+
226
+
227
+ def test_should_read_no_open_from_a_merge_command(tmp_path: Path) -> None:
228
+ assert open_request_from(_shell_payload("gh pr merge 12", tmp_path)) is None
@@ -13,12 +13,15 @@ from pathlib import Path
13
13
  import pytest
14
14
  from blocking.merge_review_gate_parts.receipts import (
15
15
  has_clean_open_review,
16
+ has_zero_finding_open_review,
17
+ is_clean_open_pass,
16
18
  open_receipt_path,
17
19
  receipt_path,
18
20
  same_commit,
19
21
  )
20
22
 
21
23
  HEAD = "abc1234def5678abc1234def5678abc1234def56"
24
+ RULINGS_LINK = "https://github.com/acme/tools/pull/12#issuecomment-1"
22
25
 
23
26
 
24
27
  @pytest.fixture(autouse=True)
@@ -27,10 +30,11 @@ def receipt_folder(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
27
30
  return tmp_path
28
31
 
29
32
 
30
- def _write_open_receipt(finding_count: int) -> None:
33
+ def _write_open_receipt(finding_count: int, all_extra_fields: dict[str, object] | None = None) -> None:
31
34
  path = open_receipt_path("acme", "tools", HEAD)
32
35
  path.parent.mkdir(parents=True, exist_ok=True)
33
- path.write_text(json.dumps({"head": HEAD, "findings": finding_count}), encoding="utf-8")
36
+ all_receipt_fields = {"head": HEAD, "findings": finding_count, **(all_extra_fields or {})}
37
+ path.write_text(json.dumps(all_receipt_fields), encoding="utf-8")
34
38
 
35
39
 
36
40
  def test_should_find_a_clean_open_review_by_short_head_under_any_owner() -> None:
@@ -48,6 +52,95 @@ def test_should_reject_a_head_that_is_not_a_commit() -> None:
48
52
  assert has_clean_open_review("tools", "main") is False
49
53
 
50
54
 
55
+ def test_should_find_an_open_review_whose_findings_are_ruled_out_at_file_and_line() -> None:
56
+ _write_open_receipt(2, {"ruled_out": 2, "ruling_lines": ["a.py:1", "b.py:20"]})
57
+ assert has_clean_open_review("tools", HEAD[:7]) is True
58
+
59
+
60
+ def test_should_reject_an_open_review_whose_rulings_cover_fewer_findings() -> None:
61
+ _write_open_receipt(2, {"ruled_out": 2, "ruling_lines": ["a.py:1"]})
62
+ assert has_clean_open_review("tools", HEAD[:7]) is False
63
+
64
+
65
+ def test_should_find_a_zero_finding_open_review_by_short_head() -> None:
66
+ _write_open_receipt(0)
67
+ assert has_zero_finding_open_review("tools", HEAD[:7]) is True
68
+
69
+
70
+ @pytest.mark.parametrize(
71
+ "extra_fields",
72
+ [{}, {"ruled_out": 2, "ruling_lines": ["a.py:1", "b.py:20"]}],
73
+ )
74
+ def test_should_reject_a_zero_finding_open_review_when_findings_were_reported(
75
+ extra_fields: dict[str, object],
76
+ ) -> None:
77
+ _write_open_receipt(2, extra_fields)
78
+ assert has_zero_finding_open_review("tools", HEAD[:7]) is False
79
+
80
+
81
+ def test_should_reject_a_zero_finding_open_review_for_a_head_that_is_not_a_commit() -> None:
82
+ _write_open_receipt(0)
83
+ assert has_zero_finding_open_review("tools", "main") is False
84
+
85
+
86
+ def test_should_count_an_open_pass_with_no_findings_as_clean() -> None:
87
+ assert is_clean_open_pass({"head": HEAD, "findings": 0}) is True
88
+
89
+
90
+ def test_should_count_an_open_pass_with_every_finding_ruled_out_as_clean() -> None:
91
+ all_receipt_fields = {
92
+ "head": HEAD,
93
+ "findings": 3,
94
+ "ruled_out": 3,
95
+ "ruling_lines": ["a.py:1", "src/b.py:20", "docs/c.md:7"],
96
+ }
97
+ assert is_clean_open_pass(all_receipt_fields) is True
98
+
99
+
100
+ def test_should_count_an_open_pass_ruled_out_at_paths_with_spaces_and_dots_as_clean() -> None:
101
+ all_receipt_fields = {
102
+ "head": HEAD,
103
+ "findings": 3,
104
+ "ruled_out": 3,
105
+ "ruling_lines": ["docs/My Notes.md:4", ".github/ci.yml:2", "src/..hidden/a.py:9"],
106
+ }
107
+ assert is_clean_open_pass(all_receipt_fields) is True
108
+
109
+
110
+ @pytest.mark.parametrize(
111
+ "extra_fields",
112
+ [
113
+ {},
114
+ {"ruled_out": 1, "ruling_lines": ["a.py:1", "b.py:2"]},
115
+ {"ruled_out": 2, "ruling_lines": ["a.py:1"]},
116
+ {"ruled_out": 2, "ruling_lines": ["a.py:1", "b.py:2", "c.py:3"]},
117
+ {"ruled_out": 2, "rulings": RULINGS_LINK},
118
+ {"ruled_out": 2, "ruling_lines": ["a.py:1", "see the thread"]},
119
+ {"ruled_out": 2, "ruling_lines": ["a.py:1", "b.py:0"]},
120
+ {"ruled_out": 2, "ruling_lines": ["a.py:1", 7]},
121
+ {"ruled_out": 2, "ruling_lines": ["a.py:1", "a.py:1"]},
122
+ {"ruled_out": 2, "ruling_lines": ["a.py:1", "b.py:2", "a.py:1"]},
123
+ {"ruled_out": 2, "ruling_lines": ["a.py:1", "./a.py:1"]},
124
+ {"ruled_out": 2, "ruling_lines": ["a.py:1", "docs/../a.py:2"]},
125
+ {"ruled_out": 2, "ruling_lines": ["a.py:1", "/a.py:2"]},
126
+ {"ruled_out": 2, "ruling_lines": ["a.py:1", "docs//notes.txt:1"]},
127
+ {"ruled_out": 2, "ruling_lines": ["a.py:1", "docs/:1"]},
128
+ {"ruled_out": True, "ruling_lines": ["a.py:1", "b.py:2"]},
129
+ ],
130
+ )
131
+ def test_should_reject_an_open_pass_whose_rulings_do_not_prove_each_finding(
132
+ extra_fields: dict[str, object],
133
+ ) -> None:
134
+ assert is_clean_open_pass({"head": HEAD, "findings": 2, **extra_fields}) is False
135
+
136
+
137
+ @pytest.mark.parametrize("finding_count", [-1, True, "0", None])
138
+ def test_should_reject_an_open_pass_whose_finding_count_is_not_a_count(
139
+ finding_count: object,
140
+ ) -> None:
141
+ assert is_clean_open_pass({"head": HEAD, "findings": finding_count}) is False
142
+
143
+
51
144
  def test_should_lowercase_owner_and_repo_in_the_numbered_receipt_path(receipt_folder: Path) -> None:
52
145
  assert receipt_path("Acme", "Tools", 12) == receipt_folder / "acme__tools__12.json"
53
146
 
@@ -21,7 +21,7 @@ This family stops a chat reply, edited message, or tool call when its payload br
21
21
  - `blocking/resolve_thread_reply_gate.py` denies a review thread resolve until the agent's own transcript shows a reply on that same thread that posted after the last user prompt and that no successful resolve of the thread has spent. A resolve is a `resolve_review_thread` call, which names the thread by `threadID`; a `pull_request_review_write` call with method `resolve_thread`, which names it by `threadId`; a shell command with a `gh api graphql` `resolveReviewThread` mutation, which names it by a literal `PRRT_` id; or a shell call to `pulls/<n>/ccr/comments/<id>/resolve`, which names it by a comment id. A graphql resolve that names no `PRRT_` id is denied. A reply is an `add_reply_to_pull_request_comment` call, or a `gh api` call to a comment's `replies` endpoint or to `addPullRequestReviewThreadReply`, which names its thread by `PRRT_` id. A reply and a resolve by comment id match when they name the same comment, or when a successful tool result in the transcript, such as `pull_request_read` `get_review_comments`, lists the comment under the thread by its `discussion_r` anchor or `databaseId`. A reply whose result is an error, such as a refusal from `blocking/reply_length_gate.py`, does not count. With no readable transcript, the resolve passes.
22
22
  - `blocking/verify_before_commit_gate.py` denies a `git commit` in a repository with a `.claude/skills/verify` or `.agents/skills/verify` directory until the `verify` skill loads after the last user prompt, through a Skill call whose result comes back without an error, or the `/verify` command in that prompt. It reads the committed paths from the staged diff, the tracked changes for `-a`, and the paths of each `git add` earlier in the same command, and passes a commit whose paths are all docs, images, test files, or `.json`, `.jsonl`, `.yaml`, `.yml`, or `.csv` files under a `docs` folder.
23
23
  - `blocking/build_eval_before_eval_write_gate.py` denies a write to an eval file until a Skill call named exactly `claude-api` with args `build-eval`, or the `/claude-api build-eval` command, appears in the transcript.
24
- - `blocking/merge_review_gate.py` denies an agent's merge until a review pass on the merged head reported zero findings, or ruled out every finding and linked the posted rulings. It reads the receipt `scripts/merge_review_receipt.py` writes, requires the merge, auto-merge or merge-queue entry to be pinned to that head, and skips repositories listed in `CLAUDE_MERGE_REVIEW_EXEMPT_REPOSITORIES`. Its deny reason names the review command `CLAUDE_MERGE_REVIEW_COMMAND` sets. The reason tells the agent to run that command for the first three passes and `/code-review low --fix <number>` for each later pass; the gate itself counts no passes. It also denies a pull request open, through `gh pr create`, `pull_request.py create` or a `create_pull_request` tool, until a pass recorded as `merge_review_receipt.py <owner/name> open <head> 0` covers the head the pull request opens with. A merge pinned to that same head passes on the open receipt.
24
+ - `blocking/merge_review_gate.py` denies an agent's merge until a review pass on the merged head reported zero findings, or ruled out every finding and linked the posted rulings. It reads the receipt `scripts/merge_review_receipt.py` writes, requires the merge, auto-merge or merge-queue entry to be pinned to that head, and skips repositories listed in `CLAUDE_MERGE_REVIEW_EXEMPT_REPOSITORIES`. Its deny reason names the review command `CLAUDE_MERGE_REVIEW_COMMAND` sets. The reason tells the agent to run that command for the first three passes and `/code-review low --fix <number>` for each later pass; the gate itself counts no passes. It also denies a pull request open, through `gh pr create`, `pull_request.py create` or a `create_pull_request` tool, until a pass recorded as `merge_review_receipt.py <owner/name> open <head> 0` covers the head the pull request opens with. An open pass also counts when every finding is ruled out: `merge_review_receipt.py <owner/name> open <head> <count> --ruled-out <count> --rulings <path:line,...>`, with a different `path:line` for each finding, checked against the file at that head when the pass is recorded. A merge pinned to that same head passes on the open receipt only when the pass found zero findings.
25
25
  - `blocking/merge_over_review_offer_gate.py` denies a decision card or question that offers a merge while it names open review findings, a red check, unaddressed review comments, or an override. It reads the whole card as one text: every question, header, context, reason, and option, whether the option is a string or a label with a consequence or description.
26
26
  - `blocking/artifact_dark_mode_gate.py` denies an Artifact page publish when the page, inside the publish wrapper, keeps a light body or shows text under 4.5:1 contrast in dark mode. `blocking/artifact_dark_mode_render.cjs` renders the page in headless Chromium for it.
27
27
  - `blocking/send_user_file_worktree_root_gate.py` denies a `SendUserFile` call that names a file outside the session's working directory, the `cwd` in the hook payload. The desktop file pane opens a sent file only under that folder and shows "Couldn't find this file" for any other path. The reason lists each outside file and names `<cwd>\.scratch\` as the folder to copy it into.
@@ -46,7 +46,7 @@ This family stops a chat reply, edited message, or tool call when its payload br
46
46
  - `blocking/resolve_thread_reply_gate.py` runs on `PreToolUse`, matcher `Bash|PowerShell|mcp__.*__resolve_review_thread|mcp__.*__pull_request_review_write`, timeout `10` seconds in `hooks.json`.
47
47
  - `blocking/verify_before_commit_gate.py` runs on `PreToolUse`, matcher `Bash|PowerShell`, timeout `30` seconds in `hooks.json`.
48
48
  - `blocking/build_eval_before_eval_write_gate.py` runs on `PreToolUse`, matcher `Write|Edit|MultiEdit|NotebookEdit|apply_patch`, timeout `10` seconds in `hooks.json`.
49
- - `blocking/merge_review_gate.py` runs on `PreToolUse`, matcher `Bash|PowerShell|mcp__.*__(create_pull_request|merge_pull_request|enable_pr_auto_merge)`, timeout `10` seconds in `hooks.json`.
49
+ - `blocking/merge_review_gate.py` runs on `PreToolUse`, matcher `Bash|PowerShell|mcp__.*__(create_pull_request|merge_pull_request|enable_pr_auto_merge)`, timeout `30` seconds in `hooks.json`. A `create_pull_request` call reads its head branch from GitHub with `git ls-remote` over https, so the working folder does not matter. The lookup runs in an empty folder, so no checkout's git config applies, takes no terminal prompt, and gets 5 seconds. A fork head `user:branch` reads the repository of `user`. A branch GitHub does not list, or a lookup that fails, resolves in the working folder as a shell open does, as `origin/<branch>` first. The timeout covers the lookup beside those local git calls.
50
50
  - `blocking/merge_over_review_offer_gate.py` runs on `PreToolUse`, matcher `AskUserQuestion|mcp__.*__ask_decision`, timeout `10` seconds in `hooks.json`.
51
51
  - `blocking/artifact_dark_mode_gate.py` runs on `PreToolUse`, matcher `Artifact`, timeout `60` seconds in `hooks.json`.
52
52
  - `blocking/send_user_file_worktree_root_gate.py` runs on `PreToolUse`, matcher `SendUserFile`, timeout `10` seconds in `hooks.json`.
@@ -75,7 +75,7 @@ Preconditions:
75
75
  - **Lifecycle skill.** Input is a `git commit` or `gh pr create` command with no `pr-lifecycle` invocation in the transcript. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_pr_lifecycle_skill_gate.py -q`. The adjacent test observes a denial, then a silent allow once the skill or its slash command appears.
76
76
  - **Verify before commit.** Input is `git add app.py; git commit -m change` in a temporary repository with `.agents/skills/verify`, and a transcript with no `verify` load after its last prompt. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_verify_before_commit_gate.py -q`. The adjacent test observes a denial, then a silent allow after a `verify` Skill call or a `/verify` prompt. A load before the last prompt still denies. A docs-only commit, a commit of data files under a `docs` folder, a tests-only commit, and a repository with no verify skill pass. A `.py` file under `docs` and a `.json` file outside `docs` still deny.
77
77
  - **Eval write.** Input is a Write to `evals/cases.json` with no build-eval call in the transcript. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_build_eval_before_eval_write_gate.py -q`. The adjacent test observes a denial, then an allow once the call appears; a write outside an eval path passes.
78
- - **Clean review.** Input is a merge with no receipt, a receipt with findings, a merge pinned to a newer head, an unpinned merge, or auto-merge with no head. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_merge_review_gate.py -q`. The adjacent test observes a denial for each; a merge or auto-merge pinned to the clean head and a merge in an exempt repository pass. An open with no clean open receipt at its head is denied; an open reviewed clean at its head, and a merge pinned to that head, pass.
78
+ - **Clean review.** Input is a merge with no receipt, a receipt with findings, a merge pinned to a newer head, an unpinned merge, or auto-merge with no head. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_merge_review_gate.py -q`. The adjacent test observes a denial for each; a merge or auto-merge pinned to the clean head and a merge in an exempt repository pass. An open with no clean open receipt at its head is denied; an open reviewed clean at its head, and a merge pinned to that head, pass. An open pass whose every finding has its own `path:line` ruling lets the open through; a merge pinned to that head is denied, since only a zero-finding open pass carries to the merge. An open whose branch neither GitHub nor the working folder holds is denied as unreadable.
79
79
  - **Merge offer.** Input is a decision card or AskUserQuestion that offers "Merge now", the merge queue, or a yes to "Merge it now?" while any part of the card names open findings or unaddressed review comments. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_merge_over_review_offer_gate.py -q`. The adjacent test observes a denial for each, including an offer and findings in separate questions; a card with no merge offer, a card about the merge review check itself, a card about shipping a docs change, and a merge offer after a clean review pass.
80
80
  - **Dark mode page.** Input is an Artifact publish of a page that themes `html` but leaves `body` to the publish wrapper. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_artifact_dark_mode_gate.py -q`. The adjacent test observes a denial that names the text and its contrast; a page that themes `body` passes. The render tests skip on a host with no Node Playwright and Chromium.
81
81
  - **Sent file root.** Input is a `SendUserFile` call for a file on `Y:\` or in the session scratchpad, with `cwd` set to a worktree. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_send_user_file_worktree_root_gate.py -q`. The adjacent test observes a denial that names the file and `<cwd>\.scratch\`; a file under `<cwd>\.scratch\` passes.
package/hooks/hooks.json CHANGED
@@ -138,7 +138,7 @@
138
138
  {
139
139
  "type": "command",
140
140
  "command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/blocking/merge_review_gate.py",
141
- "timeout": 10
141
+ "timeout": 30
142
142
  }
143
143
  ]
144
144
  },
@@ -37,6 +37,11 @@ ORIGIN_URL_PATTERN = re.compile(
37
37
  r"github\.com[:/](?P<owner>[\w.-]+)/(?P<repo>[\w.-]+?)(?:\.git)?/?$"
38
38
  )
39
39
  GIT_TIMEOUT_SECONDS = 3
40
+ REMOTE_LOOKUP_TIMEOUT_SECONDS = 5
41
+ GITHUB_REMOTE_URL_TEMPLATE = "https://github.com/{owner}/{repo}.git"
42
+ REMOTE_BRANCH_REFERENCE_TEMPLATE = "refs/heads/{branch}"
43
+ LS_REMOTE_FIELD_SEPARATOR = "\t"
44
+ ALL_NON_INTERACTIVE_GIT_SETTINGS = {"GIT_TERMINAL_PROMPT": "0", "GCM_INTERACTIVE": "never"}
40
45
  ALL_ORIGIN_URL_ARGUMENTS = ("remote", "get-url", "origin")
41
46
  OPEN_HEAD_PATTERN = re.compile(r"[0-9a-fA-F]{7,40}")
42
47
  OPEN_RECEIPT_HEAD_PATTERN = re.compile(r"[0-9a-fA-F]{40}")
@@ -56,6 +61,12 @@ RULINGS_LINK_PATTERN = re.compile(
56
61
  r"https://github\.com/(?P<owner>[\w.-]+)/(?P<repo>[\w.-]+)/pull/(?P<number>\d+)"
57
62
  r"#issuecomment-\d+"
58
63
  )
64
+ RULING_PATH_SEGMENT = r"(?!\.{1,2}(?![^\x00-\x1f:,/\\]))[^\x00-\x1f:,/\\]+"
65
+ RULING_REFERENCE_PATTERN = re.compile(
66
+ r"(?P<path>" + RULING_PATH_SEGMENT + r"(?:/" + RULING_PATH_SEGMENT + r")*):(?P<line>[1-9]\d*)"
67
+ )
68
+ RULING_SEPARATOR = ","
69
+ RULING_LOOKUP_TIMEOUT_SECONDS = 10
59
70
  REPO_OPTION_PATTERN = re.compile(r"(?:-R|--repo)[\s=](?P<owner>[\w.-]+)/(?P<repo>[\w.-]+)")
60
71
  MATCH_HEAD_PATTERN = re.compile(r"--match-head-commit[\s=](?P<sha>[0-9a-fA-F]{7,40})")
61
72
  API_SHA_FIELD_PATTERN = re.compile(r"(?:-f|-F|--field|--raw-field)[\s=]sha=(?P<sha>[0-9a-fA-F]{7,40})")
@@ -80,6 +91,7 @@ RECEIPT_HEAD_KEY = "head"
80
91
  RECEIPT_FINDINGS_KEY = "findings"
81
92
  RECEIPT_RULED_OUT_KEY = "ruled_out"
82
93
  RECEIPT_RULINGS_KEY = "rulings"
94
+ RECEIPT_RULING_LINES_KEY = "ruling_lines"
83
95
  RECORD_COMMAND = "python3 ~/.claude/scripts/merge_review_receipt.py"
84
96
 
85
97
  NO_CLEAN_REVIEW_REASON_TEMPLATE = (
@@ -118,14 +130,21 @@ UNKNOWN_TARGET_REASON = (
118
130
  NO_CLEAN_OPEN_REVIEW_REASON_TEMPLATE = (
119
131
  "{slug} has no clean review for head {head}, which this pull request would open with. "
120
132
  "Review the branch diff with `{review_command}`, fix and push every finding, and review "
121
- "again until a pass reports zero findings. Record that pass with `"
133
+ "again until a pass reports zero findings or every finding is ruled out with file:line "
134
+ "evidence. Record a pass with zero findings with `"
135
+ + RECORD_COMMAND
136
+ + " {slug} "
137
+ + OPEN_TARGET_WORD
138
+ + " {head} 0`. Record a pass whose every finding is ruled out with `"
122
139
  + RECORD_COMMAND
123
140
  + " {slug} "
124
141
  + OPEN_TARGET_WORD
125
- + " {head} 0`, then open the pull request. The merge accepts that receipt while the "
126
- "head stays {head}."
142
+ + " {head} <finding count> --ruled-out <finding count> --rulings <path:line for each "
143
+ "finding, comma separated>`, each path:line a line this head holds. Then open the pull "
144
+ "request. A merge pinned to {head} accepts an open pass only at zero findings."
127
145
  )
128
146
  UNKNOWN_OPEN_TARGET_REASON = (
129
- "This pull request names no repository or head commit the review gate can read. Run it "
130
- "from the branch checkout, or pass `--repo owner/name` and `--head <pushed branch>`."
147
+ "This pull request names no repository or head commit the review gate can read. Check that "
148
+ "the head branch is on GitHub and this session can reach it, or run it from the branch "
149
+ "checkout, or pass `--repo owner/name` and `--head <pushed branch>`."
131
150
  )
@@ -84,7 +84,25 @@ UNPROVEN_PROOF_REASON = (
84
84
  " Do not open the pull request, or ask for review of an open one, until that output"
85
85
  " is there. When it is a condition the change does not"
86
86
  " target, move the line under a 'Not covered' heading at the same level as the proof"
87
- " heading. Read " + PROOF_GUIDE_PATH + " for the full rule."
87
+ " heading. When the pull request adds a workflow file the default branch lacks, its first"
88
+ " run waits for the merge: add an 'After merge' heading that names the workflow file in"
89
+ " backticks and says who records the run link. Read " + PROOF_GUIDE_PATH + " for the full rule."
90
+ )
91
+ AFTER_MERGE_HEADING_PATTERN = r"^(#{1,6})[ \t]+after merge[ \t]*#*[ \t]*$"
92
+ AFTER_MERGE_RECORDER_PATTERN = r"\brecord(?:s|ed)?\b[^.;\n]{0,30}\b(?:run|link|url|result)s?\b"
93
+ AFTER_MERGE_NO_RECORDER_PATTERN = (
94
+ r"\b(?:nobody|no[ -]?one|not|never|cannot|can't|won't|doesn't)\b[^.;,\n]{0,60}\brecord(?:s|ed)?\b"
95
+ r"|\brecord(?:s|ed)?\s+(?:nothing|none|no)\b|\bno\s+records?\b"
96
+ )
97
+ AFTER_MERGE_SENTENCE_SEPARATOR_PATTERN = r"[;\n]|\.(?=\s|$)"
98
+ WORKFLOW_SUBJECT_PATTERN = r"\b(?:github actions|workflow)\b"
99
+ RUN_WORD_PATTERN = r"\bruns?\b"
100
+ GIT_URL_SUFFIX = ".git"
101
+ REMOTE_LINE_FIELD_COUNT = 2
102
+ WORKFLOW_NAME_MATCH_TEMPLATE = r"(?<![\w.-]){workflow_name}(?![\w-]|\.\w)"
103
+ NEW_WORKFLOW_PATH_PATTERN = r"^\.github/workflows/[^/]+\.ya?ml$"
104
+ ADDED_FILE_NAMES_QUERY = (
105
+ '(.files | length | tostring), (.files[] | select(.status == "added" or .status == "renamed" or .status == "copied") | .filename)'
88
106
  )
89
107
  DEFERRED_PROOF_REASON = (
90
108
  "This pull request's 'Proof in practice' section mentions a merge: \"{deferral}\". Run that"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-dev-env",
3
- "version": "8.109.5",
3
+ "version": "8.109.7",
4
4
  "description": "Claude Code development standards — rules, hooks, agents, commands, and skills",
5
5
  "type": "module",
6
6
  "bin": {
@@ -64,6 +64,7 @@ if _hooks_directory not in sys.path:
64
64
  sys.path.insert(0, _hooks_directory)
65
65
 
66
66
  from blocking.pull_request_proof import (
67
+ checkout_is_for,
67
68
  missing_eval_section_reason,
68
69
  missing_existing_work_reason,
69
70
  missing_proof_reason,
@@ -159,12 +160,32 @@ def _description_heading_findings(body_text: str) -> list[DurablePostFinding]:
159
160
  ]
160
161
 
161
162
 
163
+ def _checkout_directory(head_branch: str | None, repository: str | None) -> str:
164
+ current_directory = str(Path.cwd())
165
+ if head_branch and repository and checkout_is_for(current_directory, repository):
166
+ return current_directory
167
+ return ""
168
+
169
+
162
170
  def _pull_request_proof_findings(
163
- title: str | None, body_text: str
171
+ title: str | None,
172
+ body_text: str,
173
+ head_branch: str | None = None,
174
+ repository: str | None = None,
164
175
  ) -> list[DurablePostFinding]:
176
+ owner, _separator, repository_name = (repository or "").partition(
177
+ REPOSITORY_OWNER_SEPARATOR
178
+ )
165
179
  create_payload = {
166
180
  "tool_name": PROOF_GATE_CREATE_TOOL_NAME,
167
- "tool_input": {"title": title, "body": body_text},
181
+ "tool_input": {
182
+ "title": title,
183
+ "body": body_text,
184
+ "head": head_branch,
185
+ "owner": owner,
186
+ "repo": repository_name,
187
+ },
188
+ "cwd": _checkout_directory(head_branch, repository),
168
189
  }
169
190
  all_reasons = (
170
191
  missing_proof_reason(create_payload),
@@ -251,6 +272,7 @@ def _body_findings(
251
272
  body_text: str | None,
252
273
  head_branch: str | None = None,
253
274
  title: str | None = None,
275
+ repository: str | None = None,
254
276
  ) -> list[DurablePostFinding]:
255
277
  if body_text is None:
256
278
  return []
@@ -267,7 +289,9 @@ def _body_findings(
267
289
  else:
268
290
  if action == ACTION_PR_CREATE:
269
291
  all_findings.extend(_description_heading_findings(body_text))
270
- all_findings.extend(_pull_request_proof_findings(title, body_text))
292
+ all_findings.extend(
293
+ _pull_request_proof_findings(title, body_text, head_branch, repository)
294
+ )
271
295
  if action == ACTION_GITHUB_MCP_COMMENT:
272
296
  all_findings.extend(_comment_length_findings(body_text))
273
297
  all_findings.extend(_contrast_framing_findings(body_text))
@@ -307,7 +331,7 @@ def lint_durable_post(
307
331
  return (
308
332
  *_title_findings(title),
309
333
  *_private_term_findings(title, repository),
310
- *_body_findings(action, body_text, head_branch, title),
334
+ *_body_findings(action, body_text, head_branch, title, repository),
311
335
  *_private_term_findings(body_text, repository),
312
336
  )
313
337