claude-dev-env 8.119.0 → 8.119.2

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.
Files changed (41) hide show
  1. package/bin/git_hooks_installer.mjs +26 -2
  2. package/bin/git_hooks_installer.test.mjs +36 -0
  3. package/bin/install-transaction.mjs +3 -1
  4. package/bin/install.mjs +12 -8
  5. package/bin/install.test.mjs +89 -0
  6. package/bin/install.transaction.test.mjs +34 -0
  7. package/bin/merge_profile_settings.mjs +3 -2
  8. package/bin/merge_profile_settings.test.mjs +25 -1
  9. package/bin/profile-stop-gate.mjs +2 -1
  10. package/bin/profile-stop-gate.test.mjs +26 -1
  11. package/bin/write-file-atomically.mjs +148 -0
  12. package/bin/write-file-atomically.test.mjs +263 -0
  13. package/hooks/blocking/followup_pr_dedupe.py +71 -13
  14. package/hooks/blocking/merge_review_gate.py +4 -0
  15. package/hooks/blocking/merge_review_gate_parts/create_folders.py +6 -2
  16. package/hooks/blocking/merge_review_gate_parts/open_request.py +40 -15
  17. package/hooks/blocking/resolve_thread_reply_gate.py +116 -1
  18. package/hooks/blocking/test_cloud_graphql_gate.py +4 -0
  19. package/hooks/blocking/test_followup_pr_dedupe.py +99 -0
  20. package/hooks/blocking/test_gh_global_account_switch_gate.py +4 -0
  21. package/hooks/blocking/test_headless_claude_broker_gate.py +4 -0
  22. package/hooks/blocking/test_merge_review_gate.py +133 -0
  23. package/hooks/blocking/test_python_windows_invocation_gate.py +4 -0
  24. package/hooks/blocking/test_resolve_thread_reply_gate.py +430 -0
  25. package/hooks/blocking/tests/test_create_folders.py +7 -0
  26. package/hooks/blocking/tests/test_open_request.py +21 -0
  27. package/hooks/features/conduct-gates.md +3 -3
  28. package/hooks/hooks_constants/followup_pr_dedupe_constants.py +5 -0
  29. package/hooks/hooks_constants/merge_review_gate_constants.py +5 -0
  30. package/hooks/hooks_constants/pytest_invocation.py +24 -9
  31. package/hooks/hooks_constants/resolve_thread_reply_gate_constants.py +21 -1
  32. package/hooks/hooks_constants/test_pytest_invocation.py +25 -0
  33. package/hooks/hooks_constants/test_shell_command_mutation.py +11 -0
  34. package/hooks/hooks_constants/transcript_skill_scan_constants.py +22 -0
  35. package/hooks/session/test_npx_pele_guidance.py +4 -0
  36. package/hooks/test_transcript_skill_scan.py +72 -0
  37. package/hooks/transcript_skill_scan.py +138 -4
  38. package/hooks/validators/config/security_checks_constants.py +88 -0
  39. package/hooks/validators/security_checks.py +186 -1
  40. package/hooks/validators/test_security_checks.py +149 -0
  41. package/package.json +1 -1
@@ -3,6 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import json
6
+ import shlex
6
7
  import sys
7
8
  from collections.abc import Iterable, Iterator
8
9
  from pathlib import Path
@@ -15,16 +16,28 @@ from blocking.pr_lifecycle_skill_gate import deny_decision, transcript_paths
15
16
  from hooks_constants.pr_lifecycle_skill_gate_constants import SHELL_TOOL_NAMES
16
17
  from hooks_constants.pre_tool_use_stdin import print_decision_from_stdin
17
18
  from hooks_constants.resolve_thread_reply_gate_constants import (
19
+ ALL_REPLY_SCRIPT_FLAG_OPTIONS,
20
+ ALL_REPLY_SCRIPT_VALUE_OPTIONS,
21
+ ABSOLUTE_LAUNCHER_FOLDER_PATTERN,
18
22
  ALL_REPLY_TOOL_NAME_SUFFIXES,
23
+ REPLY_SCRIPT_LAUNCHER_NAME_PATTERN,
19
24
  ALL_THREAD_ID_INPUT_KEYS,
20
25
  COMMENT_ANCHOR_PATTERN,
21
26
  COMMENT_ID_INPUT_KEY,
22
27
  MISSING_REPLY_REASON,
28
+ REPLY_SCRIPT_COMMENT_ID_OPTION,
29
+ REPLY_SCRIPT_FILE_NAME,
30
+ REPLY_SCRIPT_REQUEST_SUBCOMMAND,
31
+ REPLY_SCRIPT_THREAD_ID_OPTION,
23
32
  RESOLVE_TOOL_NAME_PATTERN,
24
33
  RESOLVE_THREAD_METHOD,
25
34
  REVIEW_WRITE_METHOD_KEY,
26
35
  REVIEW_WRITE_TOOL_NAME_PATTERN,
27
36
  SHELL_COMMAND_KEY,
37
+ SHELL_OPTION_PREFIX,
38
+ SHELL_OPTION_VALUE_SEPARATOR,
39
+ SHELL_PATH_SEPARATOR,
40
+ SHELL_UNREADABLE_CHARACTER_PATTERN,
28
41
  SHELL_REPLY_COMMAND_PATTERN,
29
42
  SHELL_REPLY_COMMENT_ID_PATTERN,
30
43
  SHELL_RESOLVE_COMMAND_PATTERN,
@@ -100,15 +113,114 @@ def is_reply_call(tool_call: TranscriptToolCall) -> bool:
100
113
  mcp__github__add_reply_to_pull_request_comment -> True
101
114
  Bash "gh api repos/o/r/pulls/7/comments/99/replies -f body=x" -> True
102
115
  Bash "gh api graphql" with addPullRequestReviewThreadReply -> True
116
+ Bash "python review_reply_post.py request --comment-id 99" -> True
117
+ Bash "python review_reply_post.py post --request r.json" -> False
103
118
  mcp__github__add_issue_comment -> False
104
119
 
120
+ The reply script exits 0 only once its reply is on the thread, so one
121
+ plain call of it counts when its result, or its background task notice,
122
+ shows no error. ``reply_script_targets`` gives the forms that count.
123
+
105
124
  Args:
106
125
  tool_call: One tool call read from the transcript.
107
126
  """
108
127
  if tool_call.name.endswith(ALL_REPLY_TOOL_NAME_SUFFIXES):
109
128
  return True
110
129
  command = _shell_command(tool_call.name, tool_call.tool_input)
111
- return command is not None and SHELL_REPLY_COMMAND_PATTERN.search(command) is not None
130
+ return command is not None and (
131
+ SHELL_REPLY_COMMAND_PATTERN.search(command) is not None or reply_script_targets(command) is not None
132
+ )
133
+
134
+
135
+ def _is_reply_script_launcher(word: str) -> bool:
136
+ folder, separator, name = word.rpartition(SHELL_PATH_SEPARATOR)
137
+ return REPLY_SCRIPT_LAUNCHER_NAME_PATTERN.fullmatch(name) is not None and (
138
+ not separator or ABSOLUTE_LAUNCHER_FOLDER_PATTERN.match(folder + separator) is not None
139
+ )
140
+
141
+
142
+ def _reply_script_request_words(command: str) -> list[str] | None:
143
+ if SHELL_UNREADABLE_CHARACTER_PATTERN.search(command) is not None:
144
+ return None
145
+ try:
146
+ all_words = shlex.split(command)
147
+ except ValueError:
148
+ return None
149
+ if all_words and _is_reply_script_launcher(all_words[0]):
150
+ all_words = all_words[1:]
151
+ if not all_words or all_words[0].rpartition(SHELL_PATH_SEPARATOR)[2] != REPLY_SCRIPT_FILE_NAME:
152
+ return None
153
+ all_script_words = all_words[1:]
154
+ if not all_script_words or all_script_words[0] != REPLY_SCRIPT_REQUEST_SUBCOMMAND:
155
+ return None
156
+ return all_script_words[1:]
157
+
158
+
159
+ def _reply_script_option_values(all_request_words: list[str]) -> dict[str, str] | None:
160
+ value_by_option: dict[str, str] = {}
161
+ all_pending_words = list(reversed(all_request_words))
162
+ while all_pending_words:
163
+ option, separator, attached_value = all_pending_words.pop().partition(SHELL_OPTION_VALUE_SEPARATOR)
164
+ if option in value_by_option:
165
+ return None
166
+ if option in ALL_REPLY_SCRIPT_FLAG_OPTIONS and not separator:
167
+ value_by_option[option] = ""
168
+ continue
169
+ if option not in ALL_REPLY_SCRIPT_VALUE_OPTIONS:
170
+ return None
171
+ option_value = attached_value if separator else (all_pending_words.pop() if all_pending_words else "")
172
+ if not option_value or option_value.startswith(SHELL_OPTION_PREFIX):
173
+ return None
174
+ value_by_option[option] = option_value
175
+ return value_by_option
176
+
177
+
178
+ def reply_script_targets(command: str) -> tuple[frozenset[str], frozenset[str]] | None:
179
+ """Return the thread ids and comment ids one reply script call answers, or None for any other command.
180
+
181
+ ::
182
+
183
+ python ci/review_reply_post.py request --pull 7 --comment-id 9 --thread-id PRRT_a -> ({"PRRT_a"}, {"9"})
184
+ /usr/bin/python3 review_reply_post.py request --comment-id=9 --supersede -> ({}, {"9"})
185
+ python review_reply_post.py request --comment-id 9 || true -> None
186
+ python review_reply_post.py request --comment-id 9 --he -> None
187
+ python review_reply_post.py request --comment-id 9 --comment 5 -> None
188
+ python review_reply_post.py request --comment-id 9 --comment-id 5 -> None
189
+ python review_reply_post.py request --comment-id 9 --hel{p,p} -> None
190
+ ./python review_reply_post.py request --comment-id 9 -> None
191
+ python -u review_reply_post.py request --comment-id 9 -> None
192
+ python review_reply_post.py post --request r.json -> None
193
+ echo review_reply_post.py request --comment-id 9 -> None
194
+
195
+ The command must be one plain call: an optional launcher, the script, then
196
+ ``request``. The launcher is ``python``, ``python3``, ``python3.<n>`` or
197
+ ``py``, with or without ``.exe``, bare or by an absolute path, which
198
+ starts with ``/`` or with a drive letter and ``:/``. The script's parser accepts any prefix of an option
199
+ name, so every word after ``request`` must be an option the gate knows by
200
+ its full name, each given once, with its value: ``--pull``,
201
+ ``--comment-id``, ``--thread-id``, ``--body-file``, ``--wait-seconds``, or
202
+ the bare ``--supersede``. A value that starts with ``-`` is refused. A
203
+ command that holds ``;``, ``&``, ``|``, a redirect, a subshell, a
204
+ substitution, a variable, a ``#``, a brace, a glob, ``~``, ``!``, a
205
+ backslash or a line break is no reply, since the words bash runs, or the
206
+ exit code it reports, can differ from the text.
207
+
208
+ Args:
209
+ command: The shell command text.
210
+ """
211
+ all_request_words = _reply_script_request_words(command)
212
+ value_by_option = None if all_request_words is None else _reply_script_option_values(all_request_words)
213
+ if value_by_option is None:
214
+ return None
215
+ comment_id = value_by_option.get(REPLY_SCRIPT_COMMENT_ID_OPTION, "")
216
+ if not (comment_id.isascii() and comment_id.isdigit()):
217
+ return None
218
+ thread_id = value_by_option.get(REPLY_SCRIPT_THREAD_ID_OPTION)
219
+ if thread_id is None:
220
+ return frozenset(), frozenset({comment_id})
221
+ if THREAD_ID_PATTERN.fullmatch(thread_id) is None:
222
+ return None
223
+ return frozenset({thread_id}), frozenset({comment_id})
112
224
 
113
225
 
114
226
  def _reply_comment_ids(all_tool_input_fields: dict[str, object]) -> frozenset[str]:
@@ -124,6 +236,9 @@ def _reply_targets(tool_call: TranscriptToolCall) -> tuple[frozenset[str], froze
124
236
  command = _shell_command(tool_call.name, tool_call.tool_input)
125
237
  if command is None:
126
238
  return frozenset(), _reply_comment_ids(tool_call.tool_input)
239
+ script_targets = reply_script_targets(command)
240
+ if script_targets is not None:
241
+ return script_targets
127
242
  return frozenset(THREAD_ID_PATTERN.findall(command)), frozenset(SHELL_REPLY_COMMENT_ID_PATTERN.findall(command))
128
243
 
129
244
 
@@ -116,6 +116,10 @@ def test_should_detect_a_github_graphql_call(command: str) -> None:
116
116
  assert gate.calls_github_graphql(command) is True
117
117
 
118
118
 
119
+ def test_should_detect_a_graphql_call_behind_a_launcher_and_env_unset() -> None:
120
+ assert gate.calls_github_graphql("nohup env -u FOO gh api graphql -f query=x") is True
121
+
122
+
119
123
  @pytest.mark.parametrize(
120
124
  "command",
121
125
  [
@@ -536,6 +536,105 @@ def test_gh_repo_environment_should_name_the_repository_when_the_origin_is_unrea
536
536
  assert all_asked_repositories == [("o", "r")]
537
537
 
538
538
 
539
+ @pytest.mark.parametrize(
540
+ "command",
541
+ [
542
+ 'GH_REPO=o/r env -u GH_REPO gh pr create --title "fix: a" --body "Follow-up to #7"',
543
+ 'GH_REPO=o/r env -i gh pr create --title "fix: a" --body "Follow-up to #7"',
544
+ 'GH_REPO=o/r nohup env -u GH_REPO gh pr create --title "fix: a" --body "Follow-up to #7"',
545
+ 'GH_REPO=o/r nice -n 5 env -u GH_REPO stdbuf -o0 gh pr create --title "fix: a" --body "Follow-up to #7"',
546
+ 'gh pr create --repo o/r --title "fix: a" --body "Follow-up to #7" ; '
547
+ 'GH_REPO=o/r gh pr create --title "fix: a" --body "Follow-up to #7"',
548
+ ],
549
+ )
550
+ def test_should_find_an_origin_duplicate_for_a_create_behind_a_gh_repo_prefix(
551
+ tmp_path: Path, command: str
552
+ ) -> None:
553
+ checkout_path = _checkout_with_origin(tmp_path, "https://github.com/acme/tools.git")
554
+ open_followup = _open_followup(9, 7)
555
+ all_asked_repositories: list[tuple[str, str]] = []
556
+ payload = {"tool_name": "Bash", "cwd": str(checkout_path), "tool_input": {"command": command}}
557
+ reader = _keyed_reader({("o", "r"): [], ("acme", "tools"): [open_followup]}, all_asked_repositories)
558
+ reason = dedupe.duplicate_followup_reason(payload, reader)
559
+ assert reason is not None
560
+ assert _duplicate_reason(open_followup, 7) in reason
561
+ assert ("acme", "tools") in all_asked_repositories
562
+
563
+
564
+ def test_should_tell_a_create_behind_a_gh_repo_prefix_with_an_origin_duplicate_to_name_its_repository_with_the_repo_flag(
565
+ tmp_path: Path,
566
+ ) -> None:
567
+ checkout_path = _checkout_with_origin(tmp_path, "https://github.com/acme/tools.git")
568
+ command = 'GH_REPO=acme/other env -u GH_REPO gh pr create --title "fix: a" --body "Follow-up to #7"'
569
+ payload = {"tool_name": "Bash", "cwd": str(checkout_path), "tool_input": {"command": command}}
570
+ reader = _keyed_reader({("acme", "other"): [], ("acme", "tools"): [_open_followup(9, 7)]}, [])
571
+ reason = dedupe.duplicate_followup_reason(payload, reader)
572
+ assert reason is not None
573
+ assert "GH_REPO=" in reason
574
+ assert "--repo owner/name" in reason
575
+
576
+
577
+ @pytest.mark.parametrize(
578
+ "command",
579
+ [
580
+ 'GH_REPO=nonsense env -u GH_REPO gh pr create --title "fix: a" --body "Follow-up to #7"',
581
+ 'GH_REPO=nonsense gh pr create --title "fix: a" --body "Follow-up to #7"',
582
+ 'gh pr create --repo o/r --title x --body y ; GH_REPO=nonsense env -u GH_REPO gh pr create --title "fix: a" --body "Follow-up to #7"',
583
+ ],
584
+ )
585
+ def test_should_find_an_origin_duplicate_for_a_create_behind_a_gh_repo_prefix_the_gate_cannot_parse(
586
+ tmp_path: Path, command: str
587
+ ) -> None:
588
+ checkout_path = _checkout_with_origin(tmp_path, "https://github.com/acme/tools.git")
589
+ open_followup = _open_followup(9, 7)
590
+ all_asked_repositories: list[tuple[str, str]] = []
591
+ payload = {"tool_name": "Bash", "cwd": str(checkout_path), "tool_input": {"command": command}}
592
+ reader = _keyed_reader({("o", "r"): [], ("acme", "tools"): [open_followup]}, all_asked_repositories)
593
+ reason = dedupe.duplicate_followup_reason(payload, reader)
594
+ assert reason is not None
595
+ assert _duplicate_reason(open_followup, 7) in reason
596
+ assert ("acme", "tools") in all_asked_repositories
597
+
598
+
599
+ def test_should_lead_the_origin_duplicate_reason_for_a_gh_repo_prefix_with_the_repo_flag_way_out(
600
+ tmp_path: Path,
601
+ ) -> None:
602
+ checkout_path = _checkout_with_origin(tmp_path, "https://github.com/acme/tools.git")
603
+ open_followup = _open_followup(9, 7)
604
+ command = 'GH_REPO=acme/other env -u GH_REPO gh pr create --title "fix: a" --body "Follow-up to #7"'
605
+ payload = {"tool_name": "Bash", "cwd": str(checkout_path), "tool_input": {"command": command}}
606
+ reader = _keyed_reader({("acme", "other"): [], ("acme", "tools"): [open_followup]}, [])
607
+ reason = dedupe.duplicate_followup_reason(payload, reader)
608
+ assert reason is not None
609
+ assert reason.index("--repo owner/name") < reason.index(_duplicate_reason(open_followup, 7))
610
+
611
+
612
+ def test_should_allow_a_create_that_names_acme_other_with_its_own_repo_flag_when_only_origin_holds_the_followup(
613
+ tmp_path: Path,
614
+ ) -> None:
615
+ checkout_path = _checkout_with_origin(tmp_path, "https://github.com/acme/tools.git")
616
+ command = 'GH_REPO=acme/other gh pr create --repo acme/other --title "fix: a" --body "Follow-up to #7"'
617
+ payload = {"tool_name": "Bash", "cwd": str(checkout_path), "tool_input": {"command": command}}
618
+ all_asked_repositories: list[tuple[str, str]] = []
619
+ reader = _keyed_reader(
620
+ {("acme", "other"): [], ("acme", "tools"): [_open_followup(9, 7)]}, all_asked_repositories
621
+ )
622
+ assert dedupe.duplicate_followup_reason(payload, reader) is None
623
+ assert all_asked_repositories == [("acme", "other")]
624
+
625
+
626
+ def test_should_allow_a_create_that_names_its_repository_with_its_own_repo_flag_when_origin_holds_a_duplicate(
627
+ tmp_path: Path,
628
+ ) -> None:
629
+ checkout_path = _checkout_with_origin(tmp_path, "https://github.com/acme/tools.git")
630
+ all_asked_repositories: list[tuple[str, str]] = []
631
+ command = 'gh pr create --repo o/r --title "fix: a" --body "Follow-up to #7"'
632
+ payload = {"tool_name": "Bash", "cwd": str(checkout_path), "tool_input": {"command": command}}
633
+ reader = _keyed_reader({("o", "r"): [], ("acme", "tools"): [_open_followup(9, 7)]}, all_asked_repositories)
634
+ assert dedupe.duplicate_followup_reason(payload, reader) is None
635
+ assert all_asked_repositories == [("o", "r")]
636
+
637
+
539
638
  def test_all_pull_request_argument_lists_should_list_the_named_action_only() -> None:
540
639
  command = "gh pr edit 7 --body x && python pull_request.py edit --number 8 && gh pr create --body y"
541
640
  all_argument_lists = list(dedupe.all_pull_request_argument_lists(command, ["pr", "edit"], "edit"))
@@ -45,6 +45,10 @@ def test_global_account_change_is_detected(command: str) -> None:
45
45
  assert gate.changes_global_gh_account(command) is True
46
46
 
47
47
 
48
+ def test_should_detect_an_account_switch_behind_a_launcher_and_env_unset() -> None:
49
+ assert gate.changes_global_gh_account("time -p env -u FOO gh auth switch --user account-b") is True
50
+
51
+
48
52
  @pytest.mark.parametrize(
49
53
  "command",
50
54
  [
@@ -48,6 +48,10 @@ def test_headless_claude_without_the_broker_is_detected(command: str) -> None:
48
48
  assert gate.starts_unbrokered_headless_claude(command) is True
49
49
 
50
50
 
51
+ def test_should_detect_headless_claude_behind_a_launcher_and_env_unset() -> None:
52
+ assert gate.starts_unbrokered_headless_claude("nohup env -u CLAUDECODE claude -p task") is True
53
+
54
+
51
55
  @pytest.mark.parametrize(
52
56
  "command",
53
57
  [
@@ -1070,6 +1070,139 @@ def test_should_ask_for_an_origin_review_of_a_first_create_behind_a_gh_repo_pref
1070
1070
  )
1071
1071
 
1072
1072
 
1073
+ ALL_LATER_PREFIXED_CREATES = [
1074
+ 'gh pr create --head feature --label "see gh pr create" --repo acme/other ; '
1075
+ "GH_REPO=acme/other env -u GH_REPO gh pr create --head feature",
1076
+ *(
1077
+ f"gh pr create --head feature --repo acme/other {separator} "
1078
+ f"GH_REPO=acme/other {wrapper} gh pr create --head feature"
1079
+ for separator in (";", "&&")
1080
+ for wrapper in (
1081
+ "env -u GH_REPO",
1082
+ "env -i",
1083
+ "sudo",
1084
+ "env --unset=GH_REPO",
1085
+ "env -uGH_REPO",
1086
+ "env -",
1087
+ "env --ignore-environment",
1088
+ "sudo --preserve-env",
1089
+ "nohup env -u GH_REPO",
1090
+ "nice env -u GH_REPO",
1091
+ "nice -n 5 env -u GH_REPO",
1092
+ "stdbuf -o0 env -u GH_REPO",
1093
+ "time env -u GH_REPO",
1094
+ "setsid env -u GH_REPO",
1095
+ "env nice env -u GH_REPO",
1096
+ "nohup nice env -i env -u GH_REPO",
1097
+ "nice -n 5 env -u GH_REPO stdbuf -o0",
1098
+ "time nohup env --unset GH_REPO nice",
1099
+ "nohup timeout -s KILL 60",
1100
+ )
1101
+ ),
1102
+ "echo 'gh pr create --head feature --label \"see gh pr create\" --repo acme/other' ; "
1103
+ "GH_REPO=acme/other env -u GH_REPO gh pr create --head feature",
1104
+ "gh pr create --head feature --repo acme/other ; GH_REPO=acme/other gh pr create --head feature",
1105
+ "gh pr create --head feature --repo acme/other ; env GH_REPO=acme/other gh pr create --head feature",
1106
+ "gh pr create --head feature --repo acme/other ; "
1107
+ "env -u GH_REPO GH_REPO=acme/other gh pr create --head feature",
1108
+ "gh pr create --head feature --repo acme/other ; "
1109
+ "GH_REPO=acme/other env -u GH_REPO python3 pull_request.py create --head feature",
1110
+ ]
1111
+
1112
+
1113
+ @pytest.mark.parametrize("command", ALL_LATER_PREFIXED_CREATES)
1114
+ def test_should_ask_for_an_origin_review_of_any_create_behind_a_gh_repo_prefix_with_the_prefix_repository_exempt(
1115
+ branch_checkout: tuple[Path, str], monkeypatch: pytest.MonkeyPatch, command: str
1116
+ ) -> None:
1117
+ folder, head = branch_checkout
1118
+ monkeypatch.setenv("CLAUDE_MERGE_REVIEW_EXEMPT_REPOSITORIES", "acme/other")
1119
+ assert f"acme/tools has no clean review for head {head}" in _deny_reason(
1120
+ _bash_in(folder, command)
1121
+ )
1122
+
1123
+
1124
+ @pytest.mark.parametrize("command", ALL_LATER_PREFIXED_CREATES)
1125
+ def test_should_ask_for_an_origin_review_of_any_create_behind_a_gh_repo_prefix_with_the_prefix_repository_reviewed(
1126
+ branch_checkout: tuple[Path, str], command: str
1127
+ ) -> None:
1128
+ folder, head = branch_checkout
1129
+ merge_review_receipt.main(["acme/other", "open", head, "0"], io.StringIO())
1130
+ assert f"acme/tools has no clean review for head {head}" in _deny_reason(
1131
+ _bash_in(folder, command)
1132
+ )
1133
+
1134
+
1135
+ ALL_ORIGIN_CREATES_BESIDE_AN_OTHER_REPOSITORY = [
1136
+ "GH_REPO=acme/other sudo gh pr create --head feature",
1137
+ "gh pr create --head feature --repo acme/other ; gh pr create --head feature --repo acme/tools",
1138
+ "gh pr create --head feature --repo acme/other && gh pr create --head feature",
1139
+ "gh pr create --head feature --repo acme/other ; gh pr create --head feature",
1140
+ "gh pr create --head feature --repo acme/other ; nohup env -u FOO gh pr create --head feature",
1141
+ "gh pr create --head feature --repo acme/other ; "
1142
+ "nice -n 5 env -u FOO stdbuf -o0 gh pr create --head feature",
1143
+ ]
1144
+
1145
+
1146
+ @pytest.mark.parametrize("command", ALL_ORIGIN_CREATES_BESIDE_AN_OTHER_REPOSITORY)
1147
+ def test_should_ask_for_an_origin_review_beside_an_exempt_other_repository(
1148
+ branch_checkout: tuple[Path, str], monkeypatch: pytest.MonkeyPatch, command: str
1149
+ ) -> None:
1150
+ folder, head = branch_checkout
1151
+ monkeypatch.setenv("CLAUDE_MERGE_REVIEW_EXEMPT_REPOSITORIES", "acme/other")
1152
+ assert f"acme/tools has no clean review for head {head}" in _deny_reason(
1153
+ _bash_in(folder, command)
1154
+ )
1155
+
1156
+
1157
+ @pytest.mark.parametrize("command", ALL_ORIGIN_CREATES_BESIDE_AN_OTHER_REPOSITORY)
1158
+ def test_should_ask_for_an_origin_review_beside_a_reviewed_other_repository(
1159
+ branch_checkout: tuple[Path, str], command: str
1160
+ ) -> None:
1161
+ folder, head = branch_checkout
1162
+ merge_review_receipt.main(["acme/other", "open", head, "0"], io.StringIO())
1163
+ assert f"acme/tools has no clean review for head {head}" in _deny_reason(
1164
+ _bash_in(folder, command)
1165
+ )
1166
+
1167
+
1168
+ def test_should_tell_a_create_behind_a_gh_repo_prefix_to_name_its_repository_with_the_repo_flag(
1169
+ branch_checkout: tuple[Path, str], monkeypatch: pytest.MonkeyPatch
1170
+ ) -> None:
1171
+ folder, _head = branch_checkout
1172
+ monkeypatch.setenv("CLAUDE_MERGE_REVIEW_EXEMPT_REPOSITORIES", "acme/other")
1173
+ reason = _deny_reason(
1174
+ _bash_in(folder, "GH_REPO=acme/other env -u GH_REPO gh pr create --head feature")
1175
+ )
1176
+ assert "GH_REPO=" in reason
1177
+ assert "--repo owner/name" in reason
1178
+
1179
+
1180
+ @pytest.mark.parametrize(
1181
+ "command",
1182
+ [
1183
+ "GH_REPO=nonsense gh pr create --head feature",
1184
+ "gh pr create --head feature --repo acme/other ; "
1185
+ "GH_REPO=nonsense env -u GH_REPO gh pr create --head feature",
1186
+ ],
1187
+ )
1188
+ def test_should_tell_a_create_behind_an_unreadable_gh_repo_prefix_to_name_its_repository_with_the_repo_flag(
1189
+ branch_checkout: tuple[Path, str], monkeypatch: pytest.MonkeyPatch, command: str
1190
+ ) -> None:
1191
+ folder, head = branch_checkout
1192
+ monkeypatch.setenv("CLAUDE_MERGE_REVIEW_EXEMPT_REPOSITORIES", "acme/other")
1193
+ reason = _deny_reason(_bash_in(folder, command))
1194
+ assert f"acme/tools has no clean review for head {head}" in reason
1195
+ assert "--repo owner/name" in reason
1196
+
1197
+
1198
+ def test_should_allow_a_create_that_names_an_exempt_repository_with_its_own_repo_flag(
1199
+ branch_checkout: tuple[Path, str], monkeypatch: pytest.MonkeyPatch
1200
+ ) -> None:
1201
+ folder, _head = branch_checkout
1202
+ monkeypatch.setenv("CLAUDE_MERGE_REVIEW_EXEMPT_REPOSITORIES", "acme/other")
1203
+ assert _reason(_bash_in(folder, "gh pr create --head feature --repo acme/other")) is None
1204
+
1205
+
1073
1206
  def _git_on_path(tmp_path: Path, monkeypatch: pytest.MonkeyPatch, script_body: str) -> None:
1074
1207
  bin_folder = tmp_path / "fake-bin"
1075
1208
  bin_folder.mkdir()
@@ -56,6 +56,10 @@ def test_should_flag_isolated_python_without_utf8_mode(command: str) -> None:
56
56
  assert gate.runs_isolated_python_without_utf8_mode(command) is True
57
57
 
58
58
 
59
+ def test_should_flag_isolated_python_behind_a_launcher_and_env_unset() -> None:
60
+ assert gate.runs_isolated_python_without_utf8_mode("time -p env -u FOO python -I script.py") is True
61
+
62
+
59
63
  @pytest.mark.parametrize(
60
64
  "command",
61
65
  [