claude-dev-env 8.116.3 → 8.116.4

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.
@@ -192,34 +192,20 @@ def _all_create_argument_lists(command: str) -> Iterator[list[str]]:
192
192
 
193
193
  def _arguments_draft(all_arguments: list[str], working_directory: str) -> PullRequestDraft | None:
194
194
  body = body_from_arguments(all_arguments, working_directory)
195
+ if body is None or followup_parent_number(body) is None:
196
+ return None
195
197
  repository = _repository_from_arguments(all_arguments, working_directory)
196
- if body is None or repository is None:
198
+ if repository is None:
197
199
  return None
198
200
  return PullRequestDraft(repository[0], repository[1], body)
199
201
 
200
202
 
201
- def _shell_draft(command: str, working_directory: str) -> PullRequestDraft | None:
203
+ def _shell_followup_drafts(command: str, working_directory: str) -> list[PullRequestDraft]:
202
204
  all_drafts = (
203
205
  _arguments_draft(all_arguments, working_directory)
204
206
  for all_arguments in _all_create_argument_lists(command)
205
207
  )
206
- return next((each_draft for each_draft in all_drafts if each_draft is not None), None)
207
-
208
-
209
- def _names_a_parent(all_payload_fields: Mapping[str, object]) -> bool:
210
- create_fields = create_tool_fields(all_payload_fields)
211
- if create_fields is not None:
212
- body = create_fields.get("body")
213
- return isinstance(body, str) and followup_parent_number(body) is not None
214
- command = shell_command(all_payload_fields)
215
- if command is None:
216
- return False
217
- working_directory = _working_directory(all_payload_fields)
218
- return any(
219
- (body := body_from_arguments(all_arguments, working_directory)) is not None
220
- and followup_parent_number(body) is not None
221
- for all_arguments in _all_create_argument_lists(command)
222
- )
208
+ return list(dict.fromkeys(each_draft for each_draft in all_drafts if each_draft is not None))
223
209
 
224
210
 
225
211
  def shell_command(all_payload_fields: Mapping[str, object]) -> str | None:
@@ -281,18 +267,50 @@ def create_tool_fields(all_payload_fields: Mapping[str, object]) -> Mapping[str,
281
267
  return _dispatch_fields(tool_input) if tool_name.endswith(WORKFLOW_DISPATCH_TOOL_SUFFIX) else None
282
268
 
283
269
 
284
- def pull_request_draft(all_payload_fields: Mapping[str, object]) -> PullRequestDraft | None:
285
- """Return the pull request a PreToolUse payload is about to open, or None."""
270
+ def followup_drafts(all_payload_fields: Mapping[str, object]) -> list[PullRequestDraft]:
271
+ """Return one draft per distinct repository and body among the creates whose body names a parent.
272
+
273
+ ::
274
+
275
+ create on o/r "Follow-up to #7" && create on o/r "Follow-up to #8" -> both drafts
276
+ create_pull_request {owner, repo, body "Follow-up to #7"} -> that one draft
277
+ create whose body names no parent, or any other tool -> []
278
+
279
+ A body that names no parent gives no draft before any repository or
280
+ origin read. A quoted create, which the command parser reads twice,
281
+ gives one draft.
282
+
283
+ Args:
284
+ all_payload_fields: The parsed PreToolUse input.
285
+
286
+ Returns:
287
+ The drafts, in command order.
288
+ """
286
289
  create_fields = create_tool_fields(all_payload_fields)
287
290
  if create_fields is not None:
288
291
  owner, repo, body = (create_fields.get(each_key) for each_key in ("owner", "repo", "body"))
289
- if isinstance(owner, str) and isinstance(repo, str) and isinstance(body, str):
290
- return PullRequestDraft(owner, repo, body)
291
- return None
292
+ if not isinstance(body, str) or followup_parent_number(body) is None:
293
+ return []
294
+ return [PullRequestDraft(owner, repo, body)] if isinstance(owner, str) and isinstance(repo, str) else []
292
295
  command = shell_command(all_payload_fields)
293
296
  if command is None:
297
+ return []
298
+ return _shell_followup_drafts(command, _working_directory(all_payload_fields))
299
+
300
+
301
+ def _open_pull_requests_once(
302
+ owner: str, repo: str, read_open: OpenPullRequestReader
303
+ ) -> list[Mapping[str, object]] | None:
304
+ return answer_once(("open pull requests", owner, repo), lambda: _open_pull_requests_or_none(owner, repo, read_open))
305
+
306
+
307
+ def _open_pull_requests_or_none(
308
+ owner: str, repo: str, read_open: OpenPullRequestReader
309
+ ) -> list[Mapping[str, object]] | None:
310
+ try:
311
+ return read_open(owner, repo)
312
+ except Exception:
294
313
  return None
295
- return _shell_draft(command, _working_directory(all_payload_fields))
296
314
 
297
315
 
298
316
  def _reason_for_parent(
@@ -318,25 +336,25 @@ def duplicate_followup_reason(
318
336
  ) -> str | None:
319
337
  """Return a deny reason when an open pull request already follows up the same parent.
320
338
 
321
- Any read failure returns None, so the pull request opens. When no create
322
- body carries a "Follow-up to #N" line, nothing is read, not even the
323
- origin remote.
339
+ Every create body that names a parent is checked, in command order, and
340
+ the first duplicate denies. A read that fails skips that create. When no
341
+ create body carries a "Follow-up to #N" line, nothing is read, not even
342
+ the origin remote.
324
343
 
325
344
  Args:
326
345
  all_payload_fields: The parsed PreToolUse input.
327
346
  read_open: Reads the open pull requests of an owner and repository;
328
347
  None reads them from the GitHub API.
329
348
  """
330
- if not _names_a_parent(all_payload_fields):
331
- return None
332
- draft = pull_request_draft(all_payload_fields)
333
- if draft is None:
334
- return None
335
- parent_number = followup_parent_number(draft.body)
336
- if parent_number is None:
337
- return None
338
- try:
339
- all_open_pull_requests = (read_open or read_open_pull_requests)(draft.owner, draft.repo)
340
- except Exception:
341
- return None
342
- return _reason_for_parent(parent_number, all_open_pull_requests)
349
+ reader = read_open or read_open_pull_requests
350
+ for each_draft in followup_drafts(all_payload_fields):
351
+ parent_number = followup_parent_number(each_draft.body)
352
+ if parent_number is None:
353
+ continue
354
+ all_open_pull_requests = _open_pull_requests_once(each_draft.owner, each_draft.repo, reader)
355
+ if all_open_pull_requests is None:
356
+ continue
357
+ reason = _reason_for_parent(parent_number, all_open_pull_requests)
358
+ if reason is not None:
359
+ return reason
360
+ return None
@@ -112,10 +112,17 @@ from hooks_constants.shell_command_wrappers import segment_program_and_arguments
112
112
 
113
113
 
114
114
  class CreateCall(NamedTuple):
115
- """The title and body one pull request create call passes; None marks a value this gate cannot read."""
115
+ """The title, body, head, base and repository one pull request create call passes.
116
+
117
+ None in title or body marks a value this gate cannot read. None in head,
118
+ base or repository marks a value the create does not name.
119
+ """
116
120
 
117
121
  title: str | None
118
122
  body: str | None
123
+ head: str | None
124
+ base: str | None
125
+ repository: str | None
119
126
 
120
127
 
121
128
  def _heading_level(line: str, heading_pattern: str) -> int | None:
@@ -235,6 +242,9 @@ def _shell_create_calls(command: str, working_directory: str) -> list[CreateCall
235
242
  CreateCall(
236
243
  title_from_arguments(all_create_arguments),
237
244
  body_from_arguments(all_create_arguments, working_directory),
245
+ _flag_value(all_create_arguments, ALL_HEAD_FLAGS, HEAD_FLAG_ASSIGNMENT_PREFIX) or None,
246
+ _flag_value(all_create_arguments, ALL_BASE_FLAGS, BASE_FLAG_ASSIGNMENT_PREFIX) or None,
247
+ _flag_value(all_create_arguments, ALL_REPOSITORY_FLAGS, REPOSITORY_FLAG_ASSIGNMENT_PREFIX) or None,
238
248
  )
239
249
  for all_create_arguments in _all_create_argument_lists(command)
240
250
  ]
@@ -249,59 +259,29 @@ def _flag_value(all_create_arguments: list[str], all_flags: frozenset[str], assi
249
259
  return None
250
260
 
251
261
 
252
- def _shell_flag_value(
253
- all_payload_fields: Mapping[str, object], all_flags: frozenset[str], assignment_prefix: str
254
- ) -> str | None:
255
- command = shell_command(all_payload_fields)
256
- if command is None:
257
- return None
258
- all_flag_values = [
259
- _flag_value(all_create_arguments, all_flags, assignment_prefix)
260
- for all_create_arguments in _all_create_argument_lists(command)
261
- ]
262
- return next((each_value for each_value in all_flag_values if each_value), None)
263
-
264
-
265
- def _named_create_field(
266
- all_payload_fields: Mapping[str, object], field_name: str, all_flags: frozenset[str], assignment_prefix: str
267
- ) -> str | None:
268
- create_fields = create_tool_fields(all_payload_fields)
269
- field_value = None if create_fields is None else create_fields.get(field_name)
270
- if isinstance(field_value, str) and field_value:
271
- return field_value
272
- return _shell_flag_value(all_payload_fields, all_flags, assignment_prefix)
273
-
274
-
275
- def _named_head_branch(all_payload_fields: Mapping[str, object]) -> str | None:
276
- return _named_create_field(all_payload_fields, "head", ALL_HEAD_FLAGS, HEAD_FLAG_ASSIGNMENT_PREFIX)
262
+ def _named_text(all_create_fields: Mapping[str, object], field_name: str) -> str | None:
263
+ field_value = all_create_fields.get(field_name)
264
+ return field_value if isinstance(field_value, str) and field_value else None
277
265
 
278
266
 
279
- def _named_base_branch(all_payload_fields: Mapping[str, object]) -> str | None:
280
- return _named_create_field(all_payload_fields, "base", ALL_BASE_FLAGS, BASE_FLAG_ASSIGNMENT_PREFIX)
281
-
282
-
283
- def _named_repository(all_payload_fields: Mapping[str, object]) -> str | None:
284
- create_fields = create_tool_fields(all_payload_fields)
285
- if create_fields is not None:
286
- owner = create_fields.get("owner")
287
- repository_name = create_fields.get("repo")
288
- if isinstance(owner, str) and owner and isinstance(repository_name, str) and repository_name:
289
- return f"{owner}/{repository_name}"
290
- return None
291
- return _shell_flag_value(all_payload_fields, ALL_REPOSITORY_FLAGS, REPOSITORY_FLAG_ASSIGNMENT_PREFIX)
267
+ def _mcp_create_call(all_create_fields: Mapping[str, object]) -> CreateCall:
268
+ title = all_create_fields.get("title")
269
+ body = all_create_fields.get("body")
270
+ owner = _named_text(all_create_fields, "owner")
271
+ repository_name = _named_text(all_create_fields, "repo")
272
+ return CreateCall(
273
+ title if isinstance(title, str) else None,
274
+ body if isinstance(body, str) else "",
275
+ _named_text(all_create_fields, "head"),
276
+ _named_text(all_create_fields, "base"),
277
+ f"{owner}/{repository_name}" if owner and repository_name else None,
278
+ )
292
279
 
293
280
 
294
281
  def _create_calls(all_payload_fields: Mapping[str, object]) -> list[CreateCall]:
295
282
  create_fields = create_tool_fields(all_payload_fields)
296
283
  if create_fields is not None:
297
- title = create_fields.get("title")
298
- body = create_fields.get("body")
299
- return [
300
- CreateCall(
301
- title if isinstance(title, str) else None,
302
- body if isinstance(body, str) else "",
303
- )
304
- ]
284
+ return [_mcp_create_call(create_fields)]
305
285
  command = shell_command(all_payload_fields)
306
286
  if command is None:
307
287
  return []
@@ -576,36 +556,38 @@ def missing_proof_reason(all_payload_fields: Mapping[str, object]) -> str | None
576
556
  the run, and the line uses the word run outside code spans and says workflow
577
557
  or GitHub Actions or names a covered workflow file; see
578
558
  _first_unwaived_admission. The same covered line is exempt from the merge word.
559
+ The waiver reads the head branch of the create whose body holds the admission.
579
560
 
580
561
  Args:
581
562
  all_payload_fields: The parsed PreToolUse input.
582
563
  """
583
- for each_body in _create_bodies(all_payload_fields):
584
- if each_body is None:
564
+ working_directory = str(all_payload_fields.get("cwd") or "")
565
+ for each_call in _create_calls(all_payload_fields):
566
+ if each_call.body is None:
585
567
  return MISSING_BODY_REASON
586
- section = proof_section(each_body)
568
+ section = proof_section(each_call.body)
587
569
  if not section:
588
570
  return MISSING_PROOF_REASON
589
- section_reason = _proof_section_reason(section, each_body, all_payload_fields)
571
+ section_reason = _proof_section_reason(section, each_call, working_directory)
590
572
  if section_reason is not None:
591
573
  return section_reason
592
574
  return None
593
575
 
594
576
 
595
577
  def _proof_section_reason(
596
- section: str, body: str | None = None, all_payload_fields: Mapping[str, object] | None = None
578
+ section: str, create_call: CreateCall | None = None, working_directory: str = ""
597
579
  ) -> str | None:
598
580
  if COMMAND_MARKER not in section:
599
581
  return MISSING_PROOF_REASON
600
582
  if _proof_runs_only_tests(section):
601
583
  return TEST_ONLY_PROOF_REASON
602
584
  all_admissions = unproven_admissions(section)
603
- if body is None or all_payload_fields is None:
585
+ if create_call is None or create_call.body is None:
604
586
  unwaived_admission = all_admissions[0] if all_admissions else None
605
587
  all_covered_names: list[str] = []
606
588
  else:
607
589
  needs_waiver = bool(all_admissions) or merge_word_line(section) is not None
608
- all_covered_names = _covered_workflow_names(body, all_payload_fields) if needs_waiver else []
590
+ all_covered_names = _covered_workflow_names(create_call, working_directory) if needs_waiver else []
609
591
  unwaived_admission = _first_unwaived_admission(all_admissions, all_covered_names)
610
592
  if unwaived_admission is not None:
611
593
  return UNPROVEN_PROOF_REASON.format(admission=unwaived_admission)
@@ -992,11 +974,8 @@ def remote_added_workflow_files(
992
974
  return None
993
975
 
994
976
 
995
- def _added_workflow_files_for_create(all_payload_fields: Mapping[str, object]) -> list[str]:
996
- working_directory = str(all_payload_fields.get("cwd") or "")
997
- head_branch = _named_head_branch(all_payload_fields)
998
- repository = _named_repository(all_payload_fields)
999
- base_branch = _named_base_branch(all_payload_fields)
977
+ def _added_workflow_files_for_create(create_call: CreateCall, working_directory: str) -> list[str]:
978
+ repository, base_branch, head_branch = create_call.repository, create_call.base, create_call.head
1000
979
  return answer_once(
1001
980
  ("added workflow files", working_directory, repository, base_branch, head_branch),
1002
981
  lambda: _read_added_workflow_files(working_directory, repository, base_branch, head_branch),
@@ -1067,7 +1046,7 @@ def _admission_is_about_a_first_run(admission: str, all_workflow_names: list[str
1067
1046
  )
1068
1047
 
1069
1048
 
1070
- def _covered_workflow_names(body: str, all_payload_fields: Mapping[str, object]) -> list[str]:
1049
+ def _covered_workflow_names(create_call: CreateCall, working_directory: str) -> list[str]:
1071
1050
  """Return the added workflow files whose first run the body plans for after the merge.
1072
1051
 
1073
1052
  ::
@@ -1082,17 +1061,17 @@ def _covered_workflow_names(body: str, all_payload_fields: Mapping[str, object])
1082
1061
  count as that prose. A sentence with a negation ahead of the verb does not count.
1083
1062
 
1084
1063
  Args:
1085
- body: The pull request body.
1086
- all_payload_fields: The parsed PreToolUse input.
1064
+ create_call: The create whose body and head branch are read.
1065
+ working_directory: The session directory the hook payload names.
1087
1066
  """
1088
- after_merge = _section_text(body, AFTER_MERGE_HEADING_PATTERN)
1067
+ after_merge = _section_text(create_call.body or "", AFTER_MERGE_HEADING_PATTERN)
1089
1068
  if not after_merge:
1090
1069
  return []
1091
1070
  outside_fence_text = _text_outside_fences(after_merge)
1092
1071
  if not _prose_names_a_recorder(re.sub(INLINE_CODE_SPAN_PATTERN, "", outside_fence_text)):
1093
1072
  return []
1094
1073
  all_names = []
1095
- for each_path in _added_workflow_files_for_create(all_payload_fields):
1074
+ for each_path in _added_workflow_files_for_create(create_call, working_directory):
1096
1075
  each_name = each_path.rsplit("/", 1)[-1]
1097
1076
  if f"`{each_path}`" in outside_fence_text or f"`{each_name}`" in outside_fence_text:
1098
1077
  all_names.append(each_name)
@@ -1124,29 +1103,48 @@ def missing_look_reason(all_payload_fields: Mapping[str, object]) -> str | None:
1124
1103
  git cannot read the branch, compare API lists only .py files -> None
1125
1104
  git cannot read the branch, compare API returns 300 .py files -> UNREADABLE_CHANGES_REASON
1126
1105
  neither git nor the compare API can read it, no picture -> UNREADABLE_CHANGES_REASON
1106
+ create --head a && create --head b, only b changes page.html -> MISSING_LOOK_REASON
1127
1107
 
1128
1108
  Every body is checked for a picture first. When each one shows a picture,
1129
- the check passes and reads neither git nor the compare API.
1109
+ the check passes and reads neither git nor the compare API. Each create
1110
+ is checked against its own head, base and repository, in command order,
1111
+ and the first deny wins.
1130
1112
 
1131
1113
  Args:
1132
1114
  all_payload_fields: The parsed PreToolUse input.
1133
1115
  """
1134
- all_bodies_without_picture = [
1135
- each_body
1136
- for each_body in _create_bodies(all_payload_fields)
1137
- if each_body is not None and not re.search(PROOF_IMAGE_PATTERN, proof_section(each_body) or "", re.IGNORECASE)
1116
+ working_directory = str(all_payload_fields.get("cwd") or "")
1117
+ all_calls_without_picture = [
1118
+ each_call
1119
+ for each_call in _create_calls(all_payload_fields)
1120
+ if each_call.body is not None
1121
+ and not re.search(PROOF_IMAGE_PATTERN, proof_section(each_call.body) or "", re.IGNORECASE)
1138
1122
  ]
1139
- if not all_bodies_without_picture:
1140
- return None
1141
- working_directory = all_payload_fields.get("cwd")
1142
- head_branch = _named_head_branch(all_payload_fields)
1143
- all_visible_files = visible_changed_files(str(working_directory or ""), head_branch)
1144
- if all_visible_files is None:
1145
- all_visible_files = remote_visible_changed_files(
1146
- _named_repository(all_payload_fields), _named_base_branch(all_payload_fields), head_branch
1147
- )
1123
+ all_reasons = (_look_reason_for_create(each_call, working_directory) for each_call in all_calls_without_picture)
1124
+ return next((each_reason for each_reason in all_reasons if each_reason is not None), None)
1125
+
1126
+
1127
+ def _look_reason_for_create(create_call: CreateCall, working_directory: str) -> str | None:
1128
+ all_visible_files = _visible_files_for_create(create_call, working_directory)
1148
1129
  if all_visible_files == []:
1149
1130
  return None
1150
1131
  if all_visible_files is None:
1151
1132
  return UNREADABLE_CHANGES_REASON
1152
1133
  return MISSING_LOOK_REASON.format(changed_files=CHANGED_FILES_SEPARATOR.join(all_visible_files))
1134
+
1135
+
1136
+ def _visible_files_for_create(create_call: CreateCall, working_directory: str) -> list[str] | None:
1137
+ repository, base_branch, head_branch = create_call.repository, create_call.base, create_call.head
1138
+ return answer_once(
1139
+ ("visible changed files", working_directory, repository, base_branch, head_branch),
1140
+ lambda: _read_visible_files(working_directory, repository, base_branch, head_branch),
1141
+ )
1142
+
1143
+
1144
+ def _read_visible_files(
1145
+ working_directory: str, repository: str | None, base_branch: str | None, head_branch: str | None
1146
+ ) -> list[str] | None:
1147
+ all_visible_files = visible_changed_files(working_directory, head_branch)
1148
+ if all_visible_files is None:
1149
+ return remote_visible_changed_files(repository, base_branch, head_branch)
1150
+ return all_visible_files
@@ -16,6 +16,8 @@ if str(HOOKS_DIRECTORY) not in sys.path:
16
16
  sys.path.insert(0, str(HOOKS_DIRECTORY))
17
17
 
18
18
  from blocking import followup_pr_dedupe as dedupe
19
+ from blocking.gate_run_reads import gate_run
20
+ from hooks_constants.followup_pr_dedupe_constants import DUPLICATE_FOLLOWUP_REASON_TEMPLATE
19
21
 
20
22
  OPEN_FOLLOWUP = {
21
23
  "number": 1769,
@@ -181,3 +183,82 @@ def test_create_tool_fields_should_read_a_pull_request_dispatch_as_a_create() ->
181
183
  def test_create_tool_fields_should_skip_a_call_that_opens_no_pull_request() -> None:
182
184
  assert dedupe.create_tool_fields(_dispatch_payload({"work_order": "wo-1"})) is None
183
185
  assert dedupe.create_tool_fields({"tool_name": "Bash", "tool_input": {"command": "gh pr list"}}) is None
186
+
187
+
188
+ def _open_followup(number: int, parent_number: int) -> dict[str, object]:
189
+ return {
190
+ "number": number,
191
+ "html_url": f"https://github.com/o/r/pull/{number}",
192
+ "body": f"Follow-up to #{parent_number}",
193
+ }
194
+
195
+
196
+ def _duplicate_reason(open_followup: Mapping[str, object], parent_number: int) -> str:
197
+ return DUPLICATE_FOLLOWUP_REASON_TEMPLATE.format(
198
+ open_number=open_followup["number"], parent_number=parent_number, open_url=open_followup["html_url"]
199
+ )
200
+
201
+
202
+ def _keyed_reader(
203
+ all_open_by_repository: Mapping[tuple[str, str], list[Mapping[str, object]] | Exception],
204
+ all_asked_repositories: list[tuple[str, str]],
205
+ ) -> dedupe.OpenPullRequestReader:
206
+ def read(owner: str, repo: str) -> list[Mapping[str, object]]:
207
+ all_asked_repositories.append((owner, repo))
208
+ answer = all_open_by_repository[(owner, repo)]
209
+ if isinstance(answer, Exception):
210
+ raise answer
211
+ return answer
212
+
213
+ return read
214
+
215
+
216
+ def _chained_inline_creates(all_repositories_and_bodies: list[tuple[str, str]]) -> dict[str, object]:
217
+ all_creates = [
218
+ f'gh pr create --repo {each_repository} --title "fix: {each_index}" --body "{each_body}"'
219
+ for each_index, (each_repository, each_body) in enumerate(all_repositories_and_bodies)
220
+ ]
221
+ return {"tool_name": "Bash", "tool_input": {"command": " && ".join(all_creates)}}
222
+
223
+
224
+ def test_chained_creates_should_deny_when_only_the_second_body_repeats_an_open_followup() -> None:
225
+ open_followup = _open_followup(9, 7)
226
+ all_asked_repositories: list[tuple[str, str]] = []
227
+ payload = _chained_inline_creates([("o/r", "Adds a hook."), ("o/r", "Follow-up to #7")])
228
+ reason = dedupe.duplicate_followup_reason(
229
+ payload, _keyed_reader({("o", "r"): [open_followup]}, all_asked_repositories)
230
+ )
231
+ assert reason == _duplicate_reason(open_followup, 7)
232
+
233
+
234
+ def test_followup_drafts_should_count_a_quoted_create_once() -> None:
235
+ payload = _chained_inline_creates([("o/r", "Follow-up to #7"), ("o/r", "Follow-up to #8")])
236
+ assert dedupe.followup_drafts(payload) == [
237
+ dedupe.PullRequestDraft("o", "r", "Follow-up to #7"),
238
+ dedupe.PullRequestDraft("o", "r", "Follow-up to #8"),
239
+ ]
240
+
241
+
242
+ def test_chained_followups_should_read_one_open_list_per_repository() -> None:
243
+ open_followup = _open_followup(11, 8)
244
+ all_asked_repositories: list[tuple[str, str]] = []
245
+ payload = _chained_inline_creates([("o/r", "Follow-up to #7"), ("o/r", "Follow-up to #8")])
246
+ with gate_run():
247
+ reason = dedupe.duplicate_followup_reason(
248
+ payload, _keyed_reader({("o", "r"): [open_followup]}, all_asked_repositories)
249
+ )
250
+ assert reason == _duplicate_reason(open_followup, 8)
251
+ assert all_asked_repositories == [("o", "r")]
252
+
253
+
254
+ def test_followup_read_failure_should_skip_only_that_create() -> None:
255
+ open_followup = _open_followup(9, 7)
256
+ all_asked_repositories: list[tuple[str, str]] = []
257
+ all_open_by_repository: dict[tuple[str, str], list[Mapping[str, object]] | Exception] = {
258
+ ("a", "r"): OSError("network down"),
259
+ ("b", "r"): [open_followup],
260
+ }
261
+ payload = _chained_inline_creates([("a/r", "Follow-up to #5"), ("b/r", "Follow-up to #7")])
262
+ reason = dedupe.duplicate_followup_reason(payload, _keyed_reader(all_open_by_repository, all_asked_repositories))
263
+ assert reason == _duplicate_reason(open_followup, 7)
264
+ assert all_asked_repositories == [("a", "r"), ("b", "r")]
@@ -436,6 +436,44 @@ def test_deny_should_add_the_reads_ran_out_sentence_when_the_deadline_cut_a_read
436
436
  assert decision["hookSpecificOutput"]["permissionDecisionReason"] == UNREADABLE_CHANGES_REASON + READS_RAN_OUT_SENTENCE
437
437
 
438
438
 
439
+ class SettableClock:
440
+ """Reads the seconds it was last set to, starting at zero."""
441
+
442
+ def __init__(self) -> None:
443
+ self.seconds = 0.0
444
+
445
+ def __call__(self) -> float:
446
+ return self.seconds
447
+
448
+
449
+ def test_deny_should_add_the_reads_ran_out_sentence_when_the_deadline_cuts_the_second_head(
450
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
451
+ ) -> None:
452
+ all_asked_commands = _unstarted_children(monkeypatch)
453
+ clock = SettableClock()
454
+ original_gh_api_lines = gate.proof._gh_api_lines
455
+
456
+ def compare_that_spends_the_slice(endpoint: str, query: str) -> list[str] | None:
457
+ if endpoint.endswith("...x"):
458
+ clock.seconds = PROOF_AND_LOOK_READS_SECONDS + 1.0
459
+ return [json.dumps(["M", "", "tool.py"])]
460
+ return original_gh_api_lines(endpoint, query)
461
+
462
+ monkeypatch.setattr(gate.proof, "_gh_api_lines", compare_that_spends_the_slice)
463
+ body = PROVEN_FOLLOWUP_BODY.replace("Follow-up to #1731", "Adds a guard.")
464
+ (tmp_path / "body.md").write_text(body, encoding="utf-8")
465
+ all_creates = [
466
+ CREATE_WORDS + f' --title "fix: {each_head}" --body-file body.md --repo o/r --base main --head {each_head}'
467
+ for each_head in ("x", "y")
468
+ ]
469
+ payload = {"tool_name": "Bash", "tool_input": {"command": " && ".join(all_creates)}, "cwd": str(tmp_path)}
470
+ with read_deadlines_started(clock):
471
+ decision = gate.decision_for(payload)
472
+ assert decision is not None
473
+ assert decision["hookSpecificOutput"]["permissionDecisionReason"] == UNREADABLE_CHANGES_REASON + READS_RAN_OUT_SENTENCE
474
+ assert not any(each_command[:1] == ["gh"] for each_command in all_asked_commands)
475
+
476
+
439
477
  def test_deny_should_keep_its_reason_when_every_read_had_time(tmp_path: Path) -> None:
440
478
  decision = gate.decision_for(_mcp_create_without_repository(tmp_path))
441
479
  assert decision is not None
@@ -12,6 +12,7 @@ if str(HOOKS_DIRECTORY) not in sys.path:
12
12
  sys.path.insert(0, str(HOOKS_DIRECTORY))
13
13
 
14
14
  from blocking import pull_request_proof as gate
15
+ from blocking.gate_run_reads import gate_run
15
16
  from blocking.pr_lifecycle_skill_gate import decision_for
16
17
  from hooks_constants.pull_request_proof_constants import (
17
18
  COMPARE_FILE_LIST_LIMIT,
@@ -21,6 +22,7 @@ from hooks_constants.pull_request_proof_constants import (
21
22
  MISSING_EVAL_SECTION_REASON,
22
23
  MISSING_EXISTING_WORK_REASON,
23
24
  MISSING_FLOWCHART_REASON,
25
+ MISSING_LOOK_REASON,
24
26
  MISSING_PROOF_REASON,
25
27
  TEST_ONLY_PROOF_REASON,
26
28
  UNPROVEN_PROOF_REASON,
@@ -1662,3 +1664,68 @@ def test_create_calls_and_other_tools_should_pass_the_edit_check(tmp_path: Path)
1662
1664
  unrun_body = "## Proof in practice\nRan `python run.py`.\nNot run: x.\n"
1663
1665
  assert gate.edit_proof_reason(_mcp_create(unrun_body)) is None
1664
1666
  assert gate.edit_proof_reason(_shell("git push -u origin b", tmp_path)) is None
1667
+
1668
+
1669
+ def _chained_creates(tmp_path: Path, all_flags_and_bodies: list[tuple[str, str]]) -> str:
1670
+ all_creates = []
1671
+ for each_index, (each_flags, each_body) in enumerate(all_flags_and_bodies):
1672
+ body_path = tmp_path / f"body_{each_index}.md"
1673
+ body_path.write_text(each_body, encoding="utf-8")
1674
+ all_creates.append(f'gh pr create --title "fix: {each_index}" --body-file "{body_path}" {each_flags}')
1675
+ return " && ".join(all_creates)
1676
+
1677
+
1678
+ def _clone_with_quiet_branch(tmp_path: Path) -> Path:
1679
+ clone_path = _repository_with_change(tmp_path / "repository", "page.html")
1680
+ subprocess.run(["git", "-C", str(clone_path), "branch", "quiet", "main"], check=True)
1681
+ return clone_path
1682
+
1683
+
1684
+ def test_chained_creates_should_deny_when_only_the_second_branch_changes_a_page(tmp_path: Path) -> None:
1685
+ clone_path = _clone_with_quiet_branch(tmp_path)
1686
+ subprocess.run(["git", "-C", str(clone_path), "checkout", "-q", "main"], check=True)
1687
+ command = _chained_creates(tmp_path, [("--head quiet", PROVEN_BODY), ("--head feature", PROVEN_BODY)])
1688
+ reason = gate.missing_look_reason(_shell(command, clone_path))
1689
+ assert reason == MISSING_LOOK_REASON.format(changed_files="page.html")
1690
+
1691
+
1692
+ def test_chained_create_without_a_head_should_read_its_own_checkout(tmp_path: Path) -> None:
1693
+ clone_path = _clone_with_quiet_branch(tmp_path)
1694
+ picture_body = PROVEN_BODY + "![after](https://example.com/after.png)\n"
1695
+ command = _chained_creates(tmp_path, [("", PROVEN_BODY), ("--head quiet", picture_body)])
1696
+ reason = gate.missing_look_reason(_shell(command, clone_path))
1697
+ assert reason == MISSING_LOOK_REASON.format(changed_files="page.html")
1698
+
1699
+
1700
+ def test_chained_creates_should_check_each_waiver_against_its_own_head(
1701
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
1702
+ ) -> None:
1703
+ all_endpoints: list[str] = []
1704
+ all_responses = {
1705
+ "repos/o/r/compare/main...x": _workflow_compare_lines(1, ["tool.py"]),
1706
+ "repos/o/r/compare/main...y": _workflow_compare_lines(1, [f"{WORKFLOW_DIRECTORY}/new.yml"]),
1707
+ }
1708
+ monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api(all_responses, all_endpoints))
1709
+ shared_flags = "--repo o/r --base main"
1710
+ command = _chained_creates(
1711
+ tmp_path, [(f"--head x {shared_flags}", PROVEN_BODY), (f"--head y {shared_flags}", WAIVER_BODY)]
1712
+ )
1713
+ assert gate.missing_proof_reason(_shell(command, tmp_path)) is None
1714
+ assert all_endpoints == ["repos/o/r/compare/main...y"]
1715
+
1716
+
1717
+ def test_chained_creates_should_read_the_compare_api_once_per_distinct_head(
1718
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
1719
+ ) -> None:
1720
+ all_endpoints: list[str] = []
1721
+ python_only = [_compare_line("M", "", "tool.py")]
1722
+ all_responses = {"repos/o/r/compare/main...x": python_only, "repos/o/r/compare/main...y": python_only}
1723
+ monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api(all_responses, all_endpoints))
1724
+ shared_flags = "--repo o/r --base main"
1725
+ command = _chained_creates(
1726
+ tmp_path,
1727
+ [(f"--head {each_head} {shared_flags}", PROVEN_BODY) for each_head in ("x", "y", "x")],
1728
+ )
1729
+ with gate_run():
1730
+ assert gate.missing_look_reason(_shell(command, tmp_path)) is None
1731
+ assert all_endpoints == ["repos/o/r/compare/main...x", "repos/o/r/compare/main...y"]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-dev-env",
3
- "version": "8.116.3",
3
+ "version": "8.116.4",
4
4
  "description": "Claude Code development standards — rules, hooks, agents, commands, and skills",
5
5
  "type": "module",
6
6
  "bin": {