claude-dev-env 8.127.0 → 8.128.1
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.
- package/.agents/skills/pr-lifecycle/reference/split-a-pull-request.md +4 -0
- package/hooks/blocking/oversized_change.py +10 -24
- package/hooks/blocking/pull_request_proof.py +42 -17
- package/hooks/blocking/test_oversized_change.py +9 -5
- package/hooks/blocking/test_pull_request_proof.py +84 -19
- package/package.json +1 -1
|
@@ -36,3 +36,7 @@ Sources: [Google small CLs](https://google.github.io/eng-practices/review/develo
|
|
|
36
36
|
5. Change no code during the split. The tree at the top of the stack equals the tree at the pinned head, so `git diff <pinned-sha> <tip> --stat` prints nothing.
|
|
37
37
|
6. Prove each level alone, as [each stack level stands on its own](../SKILL.md#each-stack-level-stands-on-its-own) describes. Where CI runs only on the stack tip, a lower level has no verdict until you run its checks.
|
|
38
38
|
7. Each new pull request links the original pull request and carries its own proof. Approvals do not carry over, so name the approvals each one still needs.
|
|
39
|
+
|
|
40
|
+
## After a level merges
|
|
41
|
+
|
|
42
|
+
The levels above a merged level restack themselves. A workflow rebases each one onto its new base and pushes it. A level with the `status: needs-rebase` label and a restack comment needs a hand restack, so run the commands in that comment.
|
|
@@ -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
36
|
checkout_is_for,
|
|
39
37
|
)
|
|
40
|
-
from hooks_constants.pull_request_proof_constants import
|
|
41
|
-
COMPARE_FILE_LIST_LIMIT,
|
|
42
|
-
REMOTE_BRANCH_PREFIX,
|
|
43
|
-
)
|
|
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,11 +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:
|
|
102
|
+
local_may_answer = bool(working_directory) and checkout_is_for(working_directory, repository)
|
|
106
103
|
measured_line_count = None
|
|
107
|
-
if
|
|
104
|
+
if local_may_answer:
|
|
108
105
|
measured_line_count = local_measured_line_count(working_directory, base_branch, head_branch)
|
|
109
106
|
if measured_line_count is None:
|
|
110
107
|
measured_line_count = remote_measured_line_count(repository, base_branch, head_branch)
|
|
108
|
+
if measured_line_count is None and base_branch and local_may_answer:
|
|
109
|
+
measured_line_count = local_measured_line_count(working_directory, None, head_branch)
|
|
111
110
|
return measured_line_count
|
|
112
111
|
|
|
113
112
|
|
|
@@ -124,15 +123,16 @@ def local_measured_line_count(
|
|
|
124
123
|
base names a branch the clone does not hold -> None
|
|
125
124
|
|
|
126
125
|
The head is the checked-out branch, or the named branch or its origin copy.
|
|
127
|
-
|
|
128
|
-
origin/main and main. A rename counts only its
|
|
126
|
+
A named base is read only as ``origin/<base>``. With no base named, it is
|
|
127
|
+
the first of origin/HEAD, origin/main and main. A rename counts only its
|
|
128
|
+
edited lines.
|
|
129
129
|
|
|
130
130
|
Args:
|
|
131
131
|
working_directory: The session directory the hook payload names.
|
|
132
132
|
base_branch: The base branch the create call names, or None.
|
|
133
133
|
head_branch: The head branch the create call names, or None.
|
|
134
134
|
"""
|
|
135
|
-
merge_base_and_head =
|
|
135
|
+
merge_base_and_head = _merge_base_and_head(working_directory, head_branch, base_branch)
|
|
136
136
|
if merge_base_and_head is None:
|
|
137
137
|
return None
|
|
138
138
|
merge_base, head_reference = merge_base_and_head
|
|
@@ -179,20 +179,6 @@ def _counts_without_lockfiles(numstat_output: str) -> dict[str, int] | None:
|
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
|
|
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
182
|
def _numstat_counts(numstat_output: str) -> dict[str, int] | None:
|
|
197
183
|
count_by_path: dict[str, int] = {}
|
|
198
184
|
all_fields = iter(numstat_output.split("\0"))
|
|
@@ -690,7 +690,7 @@ def _git_lines(working_directory: str, *all_git_arguments: str) -> list[str] | N
|
|
|
690
690
|
def _first_merge_base(
|
|
691
691
|
working_directory: str,
|
|
692
692
|
head_reference: str,
|
|
693
|
-
all_base_references: Sequence[str]
|
|
693
|
+
all_base_references: Sequence[str],
|
|
694
694
|
) -> str | None:
|
|
695
695
|
for each_base_reference in all_base_references:
|
|
696
696
|
all_merge_base_lines = _git_lines(working_directory, "merge-base", head_reference, each_base_reference)
|
|
@@ -718,18 +718,25 @@ def _head_reference(working_directory: str, head_branch: object) -> str | None:
|
|
|
718
718
|
return None
|
|
719
719
|
|
|
720
720
|
|
|
721
|
-
def visible_changed_files(
|
|
721
|
+
def visible_changed_files(
|
|
722
|
+
working_directory: str, head_branch: object, base_branch: str | None
|
|
723
|
+
) -> list[str] | None:
|
|
722
724
|
"""Return the changed files people see on the head branch, or None when git cannot tell.
|
|
723
725
|
|
|
724
726
|
The head is the checked-out branch, or the named branch or its origin copy
|
|
725
|
-
when the checkout holds another branch.
|
|
726
|
-
origin
|
|
727
|
+
when the checkout holds another branch. A named base is read only as
|
|
728
|
+
origin/<base>, the copy GitHub compares against, so a stack level counts
|
|
729
|
+
only its own files. A missing origin/<base> gives None, and the caller asks
|
|
730
|
+
the compare API. With no base named, the base is the first of origin/HEAD,
|
|
731
|
+
origin/main and main that git can reach::
|
|
727
732
|
|
|
728
733
|
checkout on feature, page.html changed -> ["page.html"]
|
|
729
734
|
page.html renamed with no edit -> []
|
|
730
735
|
page.html renamed and edited -> ["page.html"]
|
|
731
736
|
named head exists nowhere in the clone -> None
|
|
732
737
|
no base reference reachable -> None
|
|
738
|
+
--base parent, parent holds page.html -> []
|
|
739
|
+
--base parent, no origin/parent -> None
|
|
733
740
|
|
|
734
741
|
A rename whose old and new blob ids match and whose old and new names end the
|
|
735
742
|
same way, such as a.html to b/a.html, changes nothing people see. One that
|
|
@@ -739,11 +746,12 @@ def visible_changed_files(working_directory: str, head_branch: object) -> list[s
|
|
|
739
746
|
Args:
|
|
740
747
|
working_directory: The session directory the hook payload names.
|
|
741
748
|
head_branch: The head branch a create call names, or None.
|
|
749
|
+
base_branch: The base branch a create call names, or None.
|
|
742
750
|
"""
|
|
743
|
-
merge_base_and_head = _merge_base_and_head(working_directory, head_branch)
|
|
751
|
+
merge_base_and_head = _merge_base_and_head(working_directory, head_branch, base_branch)
|
|
744
752
|
if merge_base_and_head is None:
|
|
745
753
|
return None
|
|
746
|
-
raw_output =
|
|
754
|
+
raw_output = _raw_diff_output(working_directory, *merge_base_and_head)
|
|
747
755
|
if raw_output is None:
|
|
748
756
|
return None
|
|
749
757
|
all_changes = _git_changes(raw_output.split("\0"))
|
|
@@ -752,21 +760,30 @@ def visible_changed_files(working_directory: str, head_branch: object) -> list[s
|
|
|
752
760
|
return _visible_paths(all_changes)
|
|
753
761
|
|
|
754
762
|
|
|
755
|
-
def
|
|
763
|
+
def _raw_diff_output(working_directory: str, merge_base: str, head_reference: str) -> str | None:
|
|
764
|
+
return _git_output(working_directory, "diff", "--raw", "--no-abbrev", "-M", "-z", merge_base, head_reference)
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
def _merge_base_and_head(
|
|
768
|
+
working_directory: str, head_branch: object, base_branch: str | None
|
|
769
|
+
) -> tuple[str, str] | None:
|
|
756
770
|
named_head = head_branch if isinstance(head_branch, str) else None
|
|
757
771
|
return answer_once(
|
|
758
|
-
("merge base and head", working_directory, named_head),
|
|
759
|
-
lambda: _read_merge_base_and_head(working_directory, named_head),
|
|
772
|
+
("merge base and head", working_directory, named_head, base_branch),
|
|
773
|
+
lambda: _read_merge_base_and_head(working_directory, named_head, base_branch),
|
|
760
774
|
)
|
|
761
775
|
|
|
762
776
|
|
|
763
|
-
def _read_merge_base_and_head(
|
|
777
|
+
def _read_merge_base_and_head(
|
|
778
|
+
working_directory: str, head_branch: str | None, base_branch: str | None
|
|
779
|
+
) -> tuple[str, str] | None:
|
|
764
780
|
if not working_directory:
|
|
765
781
|
return None
|
|
766
782
|
head_reference = _cached_head_reference(working_directory, head_branch)
|
|
767
783
|
if head_reference is None:
|
|
768
784
|
return None
|
|
769
|
-
|
|
785
|
+
all_base_references = (REMOTE_BRANCH_PREFIX + base_branch,) if base_branch else ALL_DEFAULT_BRANCH_REFERENCES
|
|
786
|
+
merge_base = _first_merge_base(working_directory, head_reference, all_base_references)
|
|
770
787
|
return None if merge_base is None else (merge_base, head_reference)
|
|
771
788
|
|
|
772
789
|
|
|
@@ -825,7 +842,9 @@ def _workflow_paths(all_added_paths: list[str]) -> list[str]:
|
|
|
825
842
|
return [each_path for each_path in all_added_paths if re.match(NEW_WORKFLOW_PATH_PATTERN, each_path)]
|
|
826
843
|
|
|
827
844
|
|
|
828
|
-
def added_workflow_files(
|
|
845
|
+
def added_workflow_files(
|
|
846
|
+
working_directory: str, head_branch: object, base_branch: str | None
|
|
847
|
+
) -> list[str] | None:
|
|
829
848
|
"""Return the workflow files the head branch adds, or None when git cannot tell.
|
|
830
849
|
|
|
831
850
|
The head and base are chosen as in visible_changed_files. Only a file git
|
|
@@ -839,8 +858,9 @@ def added_workflow_files(working_directory: str, head_branch: object) -> list[st
|
|
|
839
858
|
Args:
|
|
840
859
|
working_directory: The session directory the hook payload names.
|
|
841
860
|
head_branch: The head branch a create call names, or None.
|
|
861
|
+
base_branch: The base branch a create call names, or None.
|
|
842
862
|
"""
|
|
843
|
-
merge_base_and_head = _merge_base_and_head(working_directory, head_branch)
|
|
863
|
+
merge_base_and_head = _merge_base_and_head(working_directory, head_branch, base_branch)
|
|
844
864
|
if merge_base_and_head is None:
|
|
845
865
|
return None
|
|
846
866
|
all_added_paths = _git_lines(
|
|
@@ -957,11 +977,14 @@ def _added_workflow_files_for_create(create_call: CreateCall, working_directory:
|
|
|
957
977
|
def _read_added_workflow_files(
|
|
958
978
|
working_directory: str, repository: str | None, base_branch: str | None, head_branch: str | None
|
|
959
979
|
) -> list[str]:
|
|
980
|
+
local_may_answer = _local_checkout_may_answer(working_directory, repository, head_branch)
|
|
960
981
|
all_workflow_paths = None
|
|
961
|
-
if
|
|
962
|
-
all_workflow_paths = added_workflow_files(working_directory, head_branch)
|
|
982
|
+
if local_may_answer:
|
|
983
|
+
all_workflow_paths = added_workflow_files(working_directory, head_branch, base_branch)
|
|
963
984
|
if all_workflow_paths is None:
|
|
964
985
|
all_workflow_paths = remote_added_workflow_files(repository, base_branch, head_branch)
|
|
986
|
+
if all_workflow_paths is None and base_branch and local_may_answer:
|
|
987
|
+
all_workflow_paths = added_workflow_files(working_directory, head_branch, None)
|
|
965
988
|
return all_workflow_paths or []
|
|
966
989
|
|
|
967
990
|
|
|
@@ -1116,7 +1139,9 @@ def _visible_files_for_create(create_call: CreateCall, working_directory: str) -
|
|
|
1116
1139
|
def _read_visible_files(
|
|
1117
1140
|
working_directory: str, repository: str | None, base_branch: str | None, head_branch: str | None
|
|
1118
1141
|
) -> list[str] | None:
|
|
1119
|
-
all_visible_files = visible_changed_files(working_directory, head_branch)
|
|
1142
|
+
all_visible_files = visible_changed_files(working_directory, head_branch, base_branch)
|
|
1120
1143
|
if all_visible_files is None:
|
|
1121
|
-
|
|
1144
|
+
all_visible_files = remote_visible_changed_files(repository, base_branch, head_branch)
|
|
1145
|
+
if all_visible_files is None and base_branch:
|
|
1146
|
+
all_visible_files = visible_changed_files(working_directory, head_branch, None)
|
|
1122
1147
|
return all_visible_files
|
|
@@ -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
|
|
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
|
|
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
|
|
|
@@ -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
|
|
|
@@ -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":
|
|
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(
|
|
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,62 @@ 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") == []
|