claude-dev-env 8.128.0 → 8.128.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.
@@ -28,19 +28,14 @@ from blocking.gate_run_reads import answer_once
28
28
  from blocking.pull_request_proof import (
29
29
  CreateCall,
30
30
  _all_section_texts,
31
- _cached_head_reference,
32
31
  _compare_lines,
33
32
  _create_calls,
34
- _first_merge_base,
35
33
  _git_lines,
36
34
  _git_output,
37
35
  _merge_base_and_head,
38
- checkout_is_for,
39
- )
40
- from hooks_constants.pull_request_proof_constants import (
41
- COMPARE_FILE_LIST_LIMIT,
42
- REMOTE_BRANCH_PREFIX,
36
+ read_named_base_first,
43
37
  )
38
+ from hooks_constants.pull_request_proof_constants import COMPARE_FILE_LIST_LIMIT
44
39
  from hooks_constants.oversized_change_constants import (
45
40
  ALL_GENERATED_ATTRIBUTE_VALUES,
46
41
  ALL_LOCKFILE_NAMES,
@@ -65,6 +60,7 @@ def oversized_pull_request_reason(all_payload_fields: Mapping[str, object]) -> s
65
60
  create, 1,500 changed lines, no 'Why one pull request' section -> OVERSIZED_PULL_REQUEST_REASON
66
61
  create, 1,500 changed lines, the section states a reason -> None
67
62
  create, 900 changed lines -> None
63
+ named base neither origin/<base> nor the compare API can read -> measured against main
68
64
  create whose size git and the compare API cannot read -> None
69
65
  a body edit, a merge, any other tool -> None
70
66
 
@@ -103,12 +99,14 @@ def _measured_line_count_for_create(create_call: CreateCall, working_directory:
103
99
  def _read_measured_line_count(
104
100
  working_directory: str, repository: str | None, base_branch: str | None, head_branch: str | None
105
101
  ) -> int | None:
106
- measured_line_count = None
107
- if working_directory and checkout_is_for(working_directory, repository):
108
- measured_line_count = local_measured_line_count(working_directory, base_branch, head_branch)
109
- if measured_line_count is None:
110
- measured_line_count = remote_measured_line_count(repository, base_branch, head_branch)
111
- return measured_line_count
102
+ return read_named_base_first(
103
+ working_directory,
104
+ repository,
105
+ head_branch,
106
+ base_branch,
107
+ lambda each_base_branch: local_measured_line_count(working_directory, each_base_branch, head_branch),
108
+ lambda: remote_measured_line_count(repository, base_branch, head_branch),
109
+ )
112
110
 
113
111
 
114
112
  def local_measured_line_count(
@@ -124,15 +122,16 @@ def local_measured_line_count(
124
122
  base names a branch the clone does not hold -> None
125
123
 
126
124
  The head is the checked-out branch, or the named branch or its origin copy.
127
- The base is ``origin/<base>`` or ``<base>``, else the first of origin/HEAD,
128
- origin/main and main. A rename counts only its edited lines.
125
+ A named base is read only as ``origin/<base>``. With no base named, it is
126
+ the first of origin/HEAD, origin/main and main. A rename counts only its
127
+ edited lines.
129
128
 
130
129
  Args:
131
130
  working_directory: The session directory the hook payload names.
132
131
  base_branch: The base branch the create call names, or None.
133
132
  head_branch: The head branch the create call names, or None.
134
133
  """
135
- merge_base_and_head = _merge_base_and_head_for_base(working_directory, base_branch, head_branch)
134
+ merge_base_and_head = _merge_base_and_head(working_directory, head_branch, base_branch)
136
135
  if merge_base_and_head is None:
137
136
  return None
138
137
  merge_base, head_reference = merge_base_and_head
@@ -179,20 +178,6 @@ def _counts_without_lockfiles(numstat_output: str) -> dict[str, int] | None:
179
178
  }
180
179
 
181
180
 
182
- def _merge_base_and_head_for_base(
183
- working_directory: str, base_branch: str | None, head_branch: str | None
184
- ) -> tuple[str, str] | None:
185
- if not base_branch:
186
- return _merge_base_and_head(working_directory, head_branch)
187
- head_reference = _cached_head_reference(working_directory, head_branch)
188
- if head_reference is None:
189
- return None
190
- merge_base = _first_merge_base(
191
- working_directory, head_reference, (REMOTE_BRANCH_PREFIX + base_branch, base_branch)
192
- )
193
- return None if merge_base is None else (merge_base, head_reference)
194
-
195
-
196
181
  def _numstat_counts(numstat_output: str) -> dict[str, int] | None:
197
182
  count_by_path: dict[str, int] = {}
198
183
  all_fields = iter(numstat_output.split("\0"))
@@ -5,7 +5,7 @@ from __future__ import annotations
5
5
  import json
6
6
  import re
7
7
  import sys
8
- from collections.abc import Iterator, Mapping, Sequence
8
+ from collections.abc import Callable, Iterator, Mapping, Sequence
9
9
  from typing import NamedTuple
10
10
  from pathlib import Path
11
11
 
@@ -19,15 +19,17 @@ from blocking.followup_pr_dedupe import (
19
19
  all_pull_request_argument_lists,
20
20
  body_from_arguments,
21
21
  create_tool_fields,
22
+ named_repository,
22
23
  shell_command,
23
24
  title_from_arguments,
24
25
  )
25
- from blocking.gate_run_reads import ReadSlice, answer_once, child_stdout
26
+ from blocking.gate_run_reads import AnswerType, ReadSlice, answer_once, child_stdout
26
27
  from hooks_constants.pr_lifecycle_skill_gate_constants import UPDATE_PULL_REQUEST_TOOL_SUFFIX
27
28
  from hooks_constants.pull_request_proof_constants import (
28
29
  ADDED_FILE_NAMES_QUERY,
29
30
  GIT_URL_SUFFIX,
30
31
  REMOTE_LINE_FIELD_COUNT,
32
+ REPOSITORY_PATH_SEPARATOR,
31
33
  RUN_WORD_PATTERN,
32
34
  WORKFLOW_NAME_MATCH_TEMPLATE,
33
35
  WORKFLOW_SUBJECT_PATTERN,
@@ -201,12 +203,19 @@ def _shell_create_calls(command: str, working_directory: str) -> list[CreateCall
201
203
  body_from_arguments(all_create_arguments, working_directory),
202
204
  _flag_value(all_create_arguments, ALL_HEAD_FLAGS, HEAD_FLAG_ASSIGNMENT_PREFIX) or None,
203
205
  _flag_value(all_create_arguments, ALL_BASE_FLAGS, BASE_FLAG_ASSIGNMENT_PREFIX) or None,
204
- _flag_value(all_create_arguments, ALL_REPOSITORY_FLAGS, REPOSITORY_FLAG_ASSIGNMENT_PREFIX) or None,
206
+ _owner_and_name(_flag_value(all_create_arguments, ALL_REPOSITORY_FLAGS, REPOSITORY_FLAG_ASSIGNMENT_PREFIX)),
205
207
  )
206
208
  for all_create_arguments in all_create_argument_lists(command)
207
209
  ]
208
210
 
209
211
 
212
+ def _owner_and_name(repository_flag_value: str | None) -> str | None:
213
+ if not repository_flag_value:
214
+ return None
215
+ owner_and_name = named_repository(repository_flag_value.rstrip(REPOSITORY_PATH_SEPARATOR).removesuffix(GIT_URL_SUFFIX))
216
+ return None if owner_and_name is None else REPOSITORY_PATH_SEPARATOR.join(owner_and_name)
217
+
218
+
210
219
  def _flag_value(all_create_arguments: list[str], all_flags: frozenset[str], assignment_prefix: str) -> str | None:
211
220
  for each_position, each_argument in enumerate(all_create_arguments):
212
221
  if each_argument in all_flags and each_position + 1 < len(all_create_arguments):
@@ -690,7 +699,7 @@ def _git_lines(working_directory: str, *all_git_arguments: str) -> list[str] | N
690
699
  def _first_merge_base(
691
700
  working_directory: str,
692
701
  head_reference: str,
693
- all_base_references: Sequence[str] = ALL_DEFAULT_BRANCH_REFERENCES,
702
+ all_base_references: Sequence[str],
694
703
  ) -> str | None:
695
704
  for each_base_reference in all_base_references:
696
705
  all_merge_base_lines = _git_lines(working_directory, "merge-base", head_reference, each_base_reference)
@@ -718,18 +727,25 @@ def _head_reference(working_directory: str, head_branch: object) -> str | None:
718
727
  return None
719
728
 
720
729
 
721
- def visible_changed_files(working_directory: str, head_branch: object) -> list[str] | None:
730
+ def visible_changed_files(
731
+ working_directory: str, head_branch: object, base_branch: str | None
732
+ ) -> list[str] | None:
722
733
  """Return the changed files people see on the head branch, or None when git cannot tell.
723
734
 
724
735
  The head is the checked-out branch, or the named branch or its origin copy
725
- when the checkout holds another branch. The base is the first of
726
- origin/HEAD, origin/main and main that git can reach::
736
+ when the checkout holds another branch. A named base is read only as
737
+ origin/<base>, the copy GitHub compares against, so a stack level counts
738
+ only its own files. A missing origin/<base> gives None, and the caller asks
739
+ the compare API. With no base named, the base is the first of origin/HEAD,
740
+ origin/main and main that git can reach::
727
741
 
728
742
  checkout on feature, page.html changed -> ["page.html"]
729
743
  page.html renamed with no edit -> []
730
744
  page.html renamed and edited -> ["page.html"]
731
745
  named head exists nowhere in the clone -> None
732
746
  no base reference reachable -> None
747
+ --base parent, parent holds page.html -> []
748
+ --base parent, no origin/parent -> None
733
749
 
734
750
  A rename whose old and new blob ids match and whose old and new names end the
735
751
  same way, such as a.html to b/a.html, changes nothing people see. One that
@@ -739,11 +755,12 @@ def visible_changed_files(working_directory: str, head_branch: object) -> list[s
739
755
  Args:
740
756
  working_directory: The session directory the hook payload names.
741
757
  head_branch: The head branch a create call names, or None.
758
+ base_branch: The base branch a create call names, or None.
742
759
  """
743
- merge_base_and_head = _merge_base_and_head(working_directory, head_branch)
760
+ merge_base_and_head = _merge_base_and_head(working_directory, head_branch, base_branch)
744
761
  if merge_base_and_head is None:
745
762
  return None
746
- raw_output = _git_output(working_directory, "diff", "--raw", "--no-abbrev", "-M", "-z", *merge_base_and_head)
763
+ raw_output = _raw_diff_output(working_directory, *merge_base_and_head)
747
764
  if raw_output is None:
748
765
  return None
749
766
  all_changes = _git_changes(raw_output.split("\0"))
@@ -752,21 +769,30 @@ def visible_changed_files(working_directory: str, head_branch: object) -> list[s
752
769
  return _visible_paths(all_changes)
753
770
 
754
771
 
755
- def _merge_base_and_head(working_directory: str, head_branch: object) -> tuple[str, str] | None:
772
+ def _raw_diff_output(working_directory: str, merge_base: str, head_reference: str) -> str | None:
773
+ return _git_output(working_directory, "diff", "--raw", "--no-abbrev", "-M", "-z", merge_base, head_reference)
774
+
775
+
776
+ def _merge_base_and_head(
777
+ working_directory: str, head_branch: object, base_branch: str | None
778
+ ) -> tuple[str, str] | None:
756
779
  named_head = head_branch if isinstance(head_branch, str) else None
757
780
  return answer_once(
758
- ("merge base and head", working_directory, named_head),
759
- lambda: _read_merge_base_and_head(working_directory, named_head),
781
+ ("merge base and head", working_directory, named_head, base_branch),
782
+ lambda: _read_merge_base_and_head(working_directory, named_head, base_branch),
760
783
  )
761
784
 
762
785
 
763
- def _read_merge_base_and_head(working_directory: str, head_branch: str | None) -> tuple[str, str] | None:
786
+ def _read_merge_base_and_head(
787
+ working_directory: str, head_branch: str | None, base_branch: str | None
788
+ ) -> tuple[str, str] | None:
764
789
  if not working_directory:
765
790
  return None
766
791
  head_reference = _cached_head_reference(working_directory, head_branch)
767
792
  if head_reference is None:
768
793
  return None
769
- merge_base = _first_merge_base(working_directory, head_reference)
794
+ all_base_references = (REMOTE_BRANCH_PREFIX + base_branch,) if base_branch else ALL_DEFAULT_BRANCH_REFERENCES
795
+ merge_base = _first_merge_base(working_directory, head_reference, all_base_references)
770
796
  return None if merge_base is None else (merge_base, head_reference)
771
797
 
772
798
 
@@ -825,7 +851,9 @@ def _workflow_paths(all_added_paths: list[str]) -> list[str]:
825
851
  return [each_path for each_path in all_added_paths if re.match(NEW_WORKFLOW_PATH_PATTERN, each_path)]
826
852
 
827
853
 
828
- def added_workflow_files(working_directory: str, head_branch: object) -> list[str] | None:
854
+ def added_workflow_files(
855
+ working_directory: str, head_branch: object, base_branch: str | None
856
+ ) -> list[str] | None:
829
857
  """Return the workflow files the head branch adds, or None when git cannot tell.
830
858
 
831
859
  The head and base are chosen as in visible_changed_files. Only a file git
@@ -839,8 +867,9 @@ def added_workflow_files(working_directory: str, head_branch: object) -> list[st
839
867
  Args:
840
868
  working_directory: The session directory the hook payload names.
841
869
  head_branch: The head branch a create call names, or None.
870
+ base_branch: The base branch a create call names, or None.
842
871
  """
843
- merge_base_and_head = _merge_base_and_head(working_directory, head_branch)
872
+ merge_base_and_head = _merge_base_and_head(working_directory, head_branch, base_branch)
844
873
  if merge_base_and_head is None:
845
874
  return None
846
875
  all_added_paths = _git_lines(
@@ -957,23 +986,67 @@ def _added_workflow_files_for_create(create_call: CreateCall, working_directory:
957
986
  def _read_added_workflow_files(
958
987
  working_directory: str, repository: str | None, base_branch: str | None, head_branch: str | None
959
988
  ) -> list[str]:
960
- all_workflow_paths = None
961
- if _local_checkout_may_answer(working_directory, repository, head_branch):
962
- all_workflow_paths = added_workflow_files(working_directory, head_branch)
963
- if all_workflow_paths is None:
964
- all_workflow_paths = remote_added_workflow_files(repository, base_branch, head_branch)
989
+ all_workflow_paths = read_named_base_first(
990
+ working_directory,
991
+ repository,
992
+ head_branch,
993
+ base_branch,
994
+ lambda each_base_branch: added_workflow_files(working_directory, head_branch, each_base_branch),
995
+ lambda: remote_added_workflow_files(repository, base_branch, head_branch),
996
+ )
965
997
  return all_workflow_paths or []
966
998
 
967
999
 
968
- def _local_checkout_may_answer(
969
- working_directory: str, repository: str | None, head_branch: str | None
970
- ) -> bool:
971
- return not head_branch or checkout_is_for(working_directory, repository)
1000
+ def read_named_base_first(
1001
+ working_directory: str,
1002
+ repository: str | None,
1003
+ head_branch: str | None,
1004
+ base_branch: str | None,
1005
+ read_local: Callable[[str | None], AnswerType | None],
1006
+ read_remote: Callable[[], AnswerType | None],
1007
+ ) -> AnswerType | None:
1008
+ """Return the first answer of the clone at the base, the compare API, and the clone at main.
1009
+
1010
+ ::
1011
+
1012
+ clone reads origin/parent -> the clone's answer
1013
+ clone lacks origin/parent, compare API answers -> the compare API's answer
1014
+ neither answers, base named, clone may answer -> the clone's answer, default base
1015
+ clone is for another repository, API is silent -> None
1016
+
1017
+ The clone may answer when it is for the named repository, or when no head
1018
+ is named, since gh then proposes the clone's own branch. The default base is
1019
+ the first of origin/HEAD, origin/main and main that git can reach.
1020
+
1021
+ Args:
1022
+ working_directory: The session directory the hook payload names.
1023
+ repository: The repository a create call names, or None.
1024
+ head_branch: The head branch a create call names, or None.
1025
+ base_branch: The base branch a create call names, or None.
1026
+ read_local: Reads the clone against a base, or against the defaults for None.
1027
+ read_remote: Reads the compare API against the named base.
1028
+ """
1029
+ local_may_answer = bool(working_directory) and (
1030
+ not head_branch or checkout_is_for(working_directory, repository)
1031
+ )
1032
+ answer = read_local(base_branch) if local_may_answer else None
1033
+ if answer is None:
1034
+ answer = read_remote()
1035
+ if answer is None and base_branch and local_may_answer:
1036
+ answer = read_local(None)
1037
+ return answer
972
1038
 
973
1039
 
974
1040
  def checkout_is_for(working_directory: str, repository: str | None) -> bool:
975
1041
  if repository is None:
976
1042
  return True
1043
+ return answer_once(
1044
+ ("checkout is for", working_directory, repository),
1045
+ lambda: _read_checkout_is_for(working_directory, repository),
1046
+ )
1047
+
1048
+
1049
+ def _read_checkout_is_for(working_directory: str, repository: str) -> bool:
977
1050
  all_remote_lines = _git_lines(working_directory, "remote", "-v") if working_directory else None
978
1051
  all_repository_endings = ("/" + repository.lower(), ":" + repository.lower())
979
1052
  for each_line in all_remote_lines or []:
@@ -1116,7 +1189,11 @@ def _visible_files_for_create(create_call: CreateCall, working_directory: str) -
1116
1189
  def _read_visible_files(
1117
1190
  working_directory: str, repository: str | None, base_branch: str | None, head_branch: str | None
1118
1191
  ) -> list[str] | None:
1119
- all_visible_files = visible_changed_files(working_directory, head_branch)
1120
- if all_visible_files is None:
1121
- return remote_visible_changed_files(repository, base_branch, head_branch)
1122
- return all_visible_files
1192
+ return read_named_base_first(
1193
+ working_directory,
1194
+ repository,
1195
+ head_branch,
1196
+ base_branch,
1197
+ lambda each_base_branch: visible_changed_files(working_directory, head_branch, each_base_branch),
1198
+ lambda: remote_visible_changed_files(repository, base_branch, head_branch),
1199
+ )
@@ -137,13 +137,17 @@ def test_should_pass_a_body_edit(large_branch: Path) -> None:
137
137
  assert size.oversized_pull_request_reason(payload) is None
138
138
 
139
139
 
140
- def test_should_pass_when_no_base_can_be_resolved(large_branch: Path) -> None:
140
+ def test_should_measure_against_main_when_neither_the_named_base_nor_the_compare_api_answers(
141
+ large_branch: Path,
142
+ ) -> None:
143
+ subprocess.run(["git", "-C", str(large_branch), "branch", "local-only"], check=True)
141
144
  assert size.local_measured_line_count(str(large_branch), "no-such-branch", None) is None
145
+ assert size.local_measured_line_count(str(large_branch), "local-only", None) is None
142
146
  assert (
143
147
  size.oversized_pull_request_reason(
144
- _create(large_branch, PLAIN_BODY, "--base no-such-branch")
148
+ _create(large_branch, PLAIN_BODY, "--base local-only")
145
149
  )
146
- is None
150
+ is not None
147
151
  )
148
152
 
149
153
 
@@ -224,7 +228,7 @@ def test_should_ask_git_for_the_head_once_when_the_proof_check_already_did(
224
228
 
225
229
  monkeypatch.setattr(gate_run_reads, "started_child", recording_start)
226
230
  with gate_run_reads.gate_run():
227
- assert proof.visible_changed_files(str(large_branch), "feature") == []
231
+ assert proof.visible_changed_files(str(large_branch), "feature", None) == []
228
232
  assert size.local_measured_line_count(str(large_branch), None, "feature") == 1500
229
233
  assert sum("--show-current" in each_command for each_command in all_started_commands) == 1
230
234
 
@@ -250,7 +254,7 @@ def test_should_measure_remotely_when_the_create_names_another_repository(
250
254
  large_branch: Path, monkeypatch: pytest.MonkeyPatch
251
255
  ) -> None:
252
256
  monkeypatch.setattr(size, "remote_measured_line_count", lambda *all_arguments: None)
253
- payload = _create(large_branch, PLAIN_BODY, "--repo other-owner/other-repository")
257
+ payload = _create(large_branch, PLAIN_BODY, "--repo other-owner/other-repository --head feature")
254
258
  assert size.oversized_pull_request_reason(payload) is None
255
259
 
256
260
 
@@ -266,7 +270,7 @@ def test_should_find_the_merge_base_once_when_the_proof_check_already_did(
266
270
 
267
271
  monkeypatch.setattr(gate_run_reads, "started_child", recording_start)
268
272
  with gate_run_reads.gate_run():
269
- assert proof.visible_changed_files(str(large_branch), None) == []
273
+ assert proof.visible_changed_files(str(large_branch), None, None) == []
270
274
  assert size.local_measured_line_count(str(large_branch), None, None) == 1500
271
275
  assert sum("merge-base" in each_command for each_command in all_started_commands) == 1
272
276
 
@@ -305,3 +309,12 @@ def test_should_count_the_whole_branch_when_git_diffs_relative_to_the_session_fo
305
309
  clone_path = _generated_schema_branch(tmp_path)
306
310
  _git(clone_path, "config", "diff.relative", "true")
307
311
  assert size.local_measured_line_count(str(clone_path / "sub"), None, None) == 41
312
+
313
+
314
+ def test_should_not_measure_the_clone_for_a_create_aimed_at_another_repository(
315
+ large_branch: Path, monkeypatch: pytest.MonkeyPatch
316
+ ) -> None:
317
+ monkeypatch.setattr(size, "remote_measured_line_count", lambda *all_arguments: None)
318
+
319
+ assert size._read_measured_line_count(str(large_branch), "o/r", "main", "feature") is None
320
+ assert size._read_measured_line_count(str(large_branch), "o/r", "main", None) == 1500
@@ -633,6 +633,8 @@ def test_build_eval_invocation_in_the_agent_transcript_should_pass(tmp_path: Pat
633
633
 
634
634
 
635
635
  def _dispatch_payload(tmp_path: Path, all_inputs: dict[str, object], transcript_path: Path) -> dict[str, object]:
636
+ checkout_path = _checkout_without_visible_changes(tmp_path)
637
+ subprocess.run(["git", "-C", checkout_path, "remote", "add", "origin", "https://github.com/o/r.git"], check=True)
636
638
  return {
637
639
  "tool_name": "mcp__github__actions_run_trigger",
638
640
  "tool_input": {
@@ -644,7 +646,7 @@ def _dispatch_payload(tmp_path: Path, all_inputs: dict[str, object], transcript_
644
646
  "inputs": all_inputs,
645
647
  },
646
648
  "transcript_path": str(transcript_path),
647
- "cwd": _checkout_without_visible_changes(tmp_path),
649
+ "cwd": checkout_path,
648
650
  }
649
651
 
650
652
 
@@ -15,6 +15,7 @@ from blocking import pull_request_proof as gate
15
15
  from blocking.gate_run_reads import gate_run
16
16
  from blocking.pr_lifecycle_skill_gate import decision_for
17
17
  from hooks_constants.pull_request_proof_constants import (
18
+ ALL_DEFAULT_BRANCH_REFERENCES,
18
19
  COMPARE_FILE_LIST_LIMIT,
19
20
  COMPARE_FILE_STATUS_QUERY,
20
21
  DEFERRED_PROOF_REASON,
@@ -463,10 +464,13 @@ def _repository_with_change(tmp_path: Path, changed_file_name: str) -> Path:
463
464
  return clone_path
464
465
 
465
466
 
466
- def _mcp_create_on_branch(body: str, working_directory: Path) -> dict[str, object]:
467
+ def _mcp_create_on_branch(body: str, working_directory: Path, base: str | None = None) -> dict[str, object]:
468
+ tool_input = {"body": body, "head": "feature"}
469
+ if base is not None:
470
+ tool_input["base"] = base
467
471
  return {
468
472
  "tool_name": "mcp__github__create_pull_request",
469
- "tool_input": {"body": body, "head": "feature"},
473
+ "tool_input": tool_input,
470
474
  "cwd": str(working_directory),
471
475
  }
472
476
 
@@ -504,8 +508,8 @@ def test_should_allow_a_python_only_change_without_a_picture(tmp_path: Path) ->
504
508
 
505
509
  def test_visible_changed_files_skips_a_different_head_branch(tmp_path: Path) -> None:
506
510
  clone_path = _repository_with_change(tmp_path, "page.html")
507
- assert gate.visible_changed_files(str(clone_path), "feature") == ["page.html"]
508
- assert gate.visible_changed_files(str(clone_path), "other-branch") is None
511
+ assert gate.visible_changed_files(str(clone_path), "feature", None) == ["page.html"]
512
+ assert gate.visible_changed_files(str(clone_path), "other-branch", None) is None
509
513
 
510
514
 
511
515
  def test_should_deny_when_git_cannot_read_the_branch_and_proof_shows_no_picture(tmp_path: Path) -> None:
@@ -587,13 +591,13 @@ def _repository_with_rename(
587
591
 
588
592
  def test_should_allow_a_pure_html_rename_without_a_picture(tmp_path: Path) -> None:
589
593
  clone_path = _repository_with_rename(tmp_path, None)
590
- assert gate.visible_changed_files(str(clone_path), "feature") == []
594
+ assert gate.visible_changed_files(str(clone_path), "feature", None) == []
591
595
  assert gate.missing_look_reason(_mcp_create_on_branch(PROVEN_BODY, clone_path)) is None
592
596
 
593
597
 
594
598
  def test_should_deny_an_html_rename_that_also_edits_the_page(tmp_path: Path) -> None:
595
599
  clone_path = _repository_with_rename(tmp_path, "<p>new line</p>\n")
596
- assert gate.visible_changed_files(str(clone_path), "feature") == ["references/asset-specs.html"]
600
+ assert gate.visible_changed_files(str(clone_path), "feature", None) == ["references/asset-specs.html"]
597
601
  reason = gate.missing_look_reason(_mcp_create_on_branch(PROVEN_BODY, clone_path))
598
602
  assert reason is not None
599
603
  assert "references/asset-specs.html" in reason
@@ -672,18 +676,18 @@ def test_should_report_an_unparseable_compare_line_as_unknown(monkeypatch: pytes
672
676
 
673
677
  def test_should_deny_a_byte_identical_rename_from_a_hidden_suffix_to_a_page(tmp_path: Path) -> None:
674
678
  clone_path = _repository_with_rename(tmp_path, None, "notes.txt", "site/notes.html")
675
- assert gate.visible_changed_files(str(clone_path), "feature") == ["site/notes.html"]
679
+ assert gate.visible_changed_files(str(clone_path), "feature", None) == ["site/notes.html"]
676
680
  assert gate.missing_look_reason(_mcp_create_on_branch(PROVEN_BODY, clone_path)) is not None
677
681
 
678
682
 
679
683
  def test_should_deny_a_rename_whose_lines_were_reordered(tmp_path: Path) -> None:
680
684
  clone_path = _repository_with_rename(tmp_path, None, reorder_lines=True)
681
- assert gate.visible_changed_files(str(clone_path), "feature") == ["references/asset-specs.html"]
685
+ assert gate.visible_changed_files(str(clone_path), "feature", None) == ["references/asset-specs.html"]
682
686
 
683
687
 
684
688
  def test_should_deny_a_byte_identical_rename_from_one_page_type_to_another(tmp_path: Path) -> None:
685
689
  clone_path = _repository_with_rename(tmp_path, None, "Widget.tsx", "site/widget.html")
686
- assert gate.visible_changed_files(str(clone_path), "feature") == ["site/widget.html"]
690
+ assert gate.visible_changed_files(str(clone_path), "feature", None) == ["site/widget.html"]
687
691
 
688
692
 
689
693
  def test_should_report_unreadable_git_output_as_unknown() -> None:
@@ -694,12 +698,12 @@ def test_should_report_unreadable_git_output_as_unknown() -> None:
694
698
 
695
699
  def test_should_keep_a_page_whose_name_holds_an_apostrophe(tmp_path: Path) -> None:
696
700
  clone_path = _repository_with_change(tmp_path, "q't.html")
697
- assert gate.visible_changed_files(str(clone_path), "feature") == ["q't.html"]
701
+ assert gate.visible_changed_files(str(clone_path), "feature", None) == ["q't.html"]
698
702
 
699
703
 
700
704
  def test_should_keep_a_page_whose_name_has_non_ascii_letters(tmp_path: Path) -> None:
701
705
  clone_path = _repository_with_change(tmp_path, "página.html")
702
- assert gate.visible_changed_files(str(clone_path), "feature") == ["página.html"]
706
+ assert gate.visible_changed_files(str(clone_path), "feature", None) == ["página.html"]
703
707
 
704
708
 
705
709
  def test_should_deny_as_unreadable_when_the_compare_api_fails(
@@ -809,7 +813,7 @@ def test_visible_changed_files_falls_back_to_origin_main_without_origin_head(tmp
809
813
  clone_path = _repository_with_change(tmp_path, "page.html")
810
814
  subprocess.run(["git", "-C", str(clone_path), "remote", "set-head", "origin", "-d"], check=True)
811
815
  subprocess.run(["git", "-C", str(clone_path), "checkout", "-q", "main"], check=True)
812
- assert gate.visible_changed_files(str(clone_path), "feature") == ["page.html"]
816
+ assert gate.visible_changed_files(str(clone_path), "feature", None) == ["page.html"]
813
817
 
814
818
 
815
819
  def test_should_read_the_head_flag_of_a_shell_create(tmp_path: Path) -> None:
@@ -1083,11 +1087,11 @@ def test_added_workflow_files_should_list_only_files_the_branch_adds(
1083
1087
  tmp_path / "added", NEW_WORKFLOW_NAME
1084
1088
  )
1085
1089
  edited_clone = _repository_with_workflow_change(tmp_path / "edited", "ci.yml")
1086
- assert gate.added_workflow_files(str(added_clone), "feature") == [
1090
+ assert gate.added_workflow_files(str(added_clone), "feature", None) == [
1087
1091
  f"{WORKFLOW_DIRECTORY}/{NEW_WORKFLOW_NAME}"
1088
1092
  ]
1089
- assert gate.added_workflow_files(str(edited_clone), "feature") == []
1090
- assert gate.added_workflow_files(str(added_clone), "other-branch") is None
1093
+ assert gate.added_workflow_files(str(edited_clone), "feature", None) == []
1094
+ assert gate.added_workflow_files(str(added_clone), "other-branch", None) is None
1091
1095
 
1092
1096
 
1093
1097
  def _workflow_compare_lines(count: int, all_added_paths: list[str]) -> list[str]:
@@ -1179,9 +1183,11 @@ def test_one_gate_run_should_resolve_the_merge_base_once_for_the_waiver_and_look
1179
1183
  all_head_references: list[str] = []
1180
1184
  original_first_merge_base = gate._first_merge_base
1181
1185
 
1182
- def counted_first_merge_base(working_directory: str, head_reference: str) -> str | None:
1186
+ def counted_first_merge_base(
1187
+ working_directory: str, head_reference: str, all_base_references: tuple[str, ...]
1188
+ ) -> str | None:
1183
1189
  all_head_references.append(head_reference)
1184
- return original_first_merge_base(working_directory, head_reference)
1190
+ return original_first_merge_base(working_directory, head_reference, all_base_references)
1185
1191
 
1186
1192
  monkeypatch.setattr(gate, "_first_merge_base", counted_first_merge_base)
1187
1193
  payload = _mcp_create_on_branch(WAIVER_BODY, clone_path)
@@ -1261,7 +1267,7 @@ def test_added_workflow_files_should_count_a_renamed_workflow_as_added(
1261
1267
  check=True,
1262
1268
  )
1263
1269
  assert f"{WORKFLOW_DIRECTORY}/renamed.yml" in gate.added_workflow_files(
1264
- str(clone_path), "feature"
1270
+ str(clone_path), "feature", None
1265
1271
  )
1266
1272
 
1267
1273
 
@@ -1753,6 +1759,7 @@ def _run_git(repository_path: Path, *all_arguments: str) -> None:
1753
1759
 
1754
1760
 
1755
1761
  def _commit_file(repository_path: Path, file_name: str) -> None:
1762
+ (repository_path / file_name).parent.mkdir(parents=True, exist_ok=True)
1756
1763
  (repository_path / file_name).write_text("x\n", encoding="utf-8")
1757
1764
  _run_git(repository_path, "add", ".")
1758
1765
  _run_git(repository_path, "commit", "-q", "-m", f"add {file_name}")
@@ -1785,4 +1792,109 @@ def test_first_merge_base_should_try_the_candidate_references_in_order(
1785
1792
  gate._first_merge_base(str(clone_path), "HEAD", ("no-such-branch", "parent"))
1786
1793
  == parent_commit
1787
1794
  )
1788
- assert gate._first_merge_base(str(clone_path), "HEAD") != parent_commit
1795
+ assert gate._first_merge_base(str(clone_path), "HEAD", ALL_DEFAULT_BRANCH_REFERENCES) != parent_commit
1796
+
1797
+
1798
+ def _stacked_repository(tmp_path: Path, parent_file_name: str) -> Path:
1799
+ clone_path = _repository_on_branch(tmp_path)
1800
+ _commit_file(clone_path, parent_file_name)
1801
+ _run_git(clone_path, "push", "-q", "origin", "parent")
1802
+ _run_git(clone_path, "checkout", "-q", "-b", "feature")
1803
+ _commit_file(clone_path, "tool.py")
1804
+ _run_git(clone_path, "push", "-q", "origin", "feature")
1805
+ return clone_path
1806
+
1807
+
1808
+ def test_should_judge_a_stack_level_only_on_its_own_files_against_its_base(tmp_path: Path) -> None:
1809
+ clone_path = _stacked_repository(tmp_path, "page.html")
1810
+ payload = _mcp_create_on_branch(PROVEN_BODY, clone_path, "parent")
1811
+
1812
+ assert gate.visible_changed_files(str(clone_path), "feature", "parent") == []
1813
+ assert gate.visible_changed_files(str(clone_path), "feature", None) == ["page.html"]
1814
+ assert gate.missing_look_reason(payload) is None
1815
+
1816
+
1817
+ def test_should_list_only_the_workflows_a_stack_level_adds_over_its_base(tmp_path: Path) -> None:
1818
+ clone_path = _stacked_repository(tmp_path, f"{WORKFLOW_DIRECTORY}/{NEW_WORKFLOW_NAME}")
1819
+ payload = _mcp_create_on_branch(_workflow_body(AFTER_MERGE_SECTION), clone_path, "parent")
1820
+
1821
+ assert gate.added_workflow_files(str(clone_path), "feature", "parent") == []
1822
+ assert gate.added_workflow_files(str(clone_path), "feature", None) == [f"{WORKFLOW_DIRECTORY}/{NEW_WORKFLOW_NAME}"]
1823
+ assert gate.missing_proof_reason(payload) == UNPROVEN_PROOF_REASON.format(admission=UNPROVEN_RUN_LINE)
1824
+
1825
+
1826
+ def test_should_leave_a_base_that_exists_only_locally_to_the_compare_api(
1827
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
1828
+ ) -> None:
1829
+ clone_path = _stacked_repository(tmp_path, "page.html")
1830
+ _run_git(clone_path, "branch", "local-only", "feature")
1831
+ all_endpoints: list[str] = []
1832
+ compare_endpoint = "repos/o/r/compare/local-only...feature"
1833
+ monkeypatch.setattr(
1834
+ gate, "_gh_api_lines", _fake_gh_api({compare_endpoint: [_compare_line("M", "", "page.html")]}, all_endpoints)
1835
+ )
1836
+
1837
+ assert gate.visible_changed_files(str(clone_path), "feature", "local-only") is None
1838
+ assert gate.added_workflow_files(str(clone_path), "feature", "local-only") is None
1839
+ assert gate._read_visible_files(str(clone_path), "o/r", "local-only", "feature") == ["page.html"]
1840
+ assert all_endpoints == [compare_endpoint]
1841
+ assert gate._read_visible_files(str(clone_path), None, "local-only", "feature") == ["page.html"]
1842
+
1843
+
1844
+ def test_should_measure_a_named_main_base_against_origin_main(tmp_path: Path) -> None:
1845
+ clone_path = _stacked_repository(tmp_path, "page.html")
1846
+ _run_git(clone_path, "symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/parent")
1847
+
1848
+ assert gate.visible_changed_files(str(clone_path), "feature", None) == []
1849
+ assert gate.visible_changed_files(str(clone_path), "feature", "main") == ["page.html"]
1850
+
1851
+ _run_git(clone_path, "update-ref", "-d", "refs/remotes/origin/main")
1852
+ assert gate.visible_changed_files(str(clone_path), "feature", "main") is None
1853
+ assert gate._read_visible_files(str(clone_path), None, "main", "feature") == []
1854
+
1855
+
1856
+ def test_should_ask_the_compare_api_when_the_create_names_another_repository(
1857
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
1858
+ ) -> None:
1859
+ clone_path = _stacked_repository(tmp_path / "checkout", "page.html")
1860
+ all_endpoints: list[str] = []
1861
+ compare_endpoint = "repos/o/r/compare/main...feature"
1862
+ monkeypatch.setattr(
1863
+ gate, "_gh_api_lines", _fake_gh_api({compare_endpoint: [_compare_line("M", "", "tool.py")]}, all_endpoints)
1864
+ )
1865
+ body_path = tmp_path / "body.md"
1866
+ body_path.write_text(PROVEN_BODY, encoding="utf-8")
1867
+ payload = _shell(f'gh pr create --title t --body-file "{body_path}" --repo o/r --base main --head feature', clone_path)
1868
+
1869
+ assert gate.missing_look_reason(payload) is None
1870
+ assert all_endpoints == [compare_endpoint]
1871
+
1872
+
1873
+ @pytest.mark.parametrize(
1874
+ ("repository_flag_value", "expected_repository"),
1875
+ [
1876
+ ("o/r", "o/r"),
1877
+ ("github.com/o/r", "o/r"),
1878
+ ("https://github.com/o/r", "o/r"),
1879
+ ("https://github.com/o/r.git/", "o/r"),
1880
+ ("HTTPS://GitHub.com/o/r", "o/r"),
1881
+ ],
1882
+ )
1883
+ def test_should_read_a_repository_flag_as_its_owner_and_name(
1884
+ tmp_path: Path, repository_flag_value: str, expected_repository: str
1885
+ ) -> None:
1886
+ payload = _shell(f"gh pr create --title t --repo {repository_flag_value} --head feature", tmp_path)
1887
+
1888
+ assert [each_call.repository for each_call in gate._create_calls(payload)] == [expected_repository]
1889
+
1890
+
1891
+ def test_should_leave_the_workflows_of_another_repository_out_of_the_workflow_check(
1892
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
1893
+ ) -> None:
1894
+ clone_path = _stacked_repository(tmp_path, f"{WORKFLOW_DIRECTORY}/{NEW_WORKFLOW_NAME}")
1895
+ monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api({}, []))
1896
+
1897
+ assert gate._read_added_workflow_files(str(clone_path), "o/r", "main", "feature") == []
1898
+ assert gate._read_added_workflow_files(str(clone_path), None, "main", "feature") == [
1899
+ f"{WORKFLOW_DIRECTORY}/{NEW_WORKFLOW_NAME}"
1900
+ ]
@@ -98,6 +98,7 @@ AFTER_MERGE_SENTENCE_SEPARATOR_PATTERN = r"[;\n]|\.(?=\s|$)"
98
98
  WORKFLOW_SUBJECT_PATTERN = r"\b(?:github actions|workflow)\b"
99
99
  RUN_WORD_PATTERN = r"\bruns?\b"
100
100
  GIT_URL_SUFFIX = ".git"
101
+ REPOSITORY_PATH_SEPARATOR = "/"
101
102
  REMOTE_LINE_FIELD_COUNT = 2
102
103
  WORKFLOW_NAME_MATCH_TEMPLATE = r"(?<![\w.-]){workflow_name}(?![\w-]|\.\w)"
103
104
  NEW_WORKFLOW_PATH_PATTERN = r"^\.github/workflows/[^/]+\.ya?ml$"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-dev-env",
3
- "version": "8.128.0",
3
+ "version": "8.128.2",
4
4
  "description": "Claude Code development standards — rules, hooks, agents, commands, and skills",
5
5
  "type": "module",
6
6
  "bin": {