claude-dev-env 8.128.1 → 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.
- package/hooks/blocking/oversized_change.py +9 -10
- package/hooks/blocking/pull_request_proof.py +73 -21
- package/hooks/blocking/test_oversized_change.py +10 -1
- package/hooks/blocking/test_pr_lifecycle_skill_gate.py +3 -1
- package/hooks/blocking/test_pull_request_proof.py +47 -0
- package/hooks/hooks_constants/pull_request_proof_constants.py +1 -0
- package/package.json +1 -1
|
@@ -33,7 +33,7 @@ from blocking.pull_request_proof import (
|
|
|
33
33
|
_git_lines,
|
|
34
34
|
_git_output,
|
|
35
35
|
_merge_base_and_head,
|
|
36
|
-
|
|
36
|
+
read_named_base_first,
|
|
37
37
|
)
|
|
38
38
|
from hooks_constants.pull_request_proof_constants import COMPARE_FILE_LIST_LIMIT
|
|
39
39
|
from hooks_constants.oversized_change_constants import (
|
|
@@ -99,15 +99,14 @@ def _measured_line_count_for_create(create_call: CreateCall, working_directory:
|
|
|
99
99
|
def _read_measured_line_count(
|
|
100
100
|
working_directory: str, repository: str | None, base_branch: str | None, head_branch: str | None
|
|
101
101
|
) -> int | None:
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
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
|
+
)
|
|
111
110
|
|
|
112
111
|
|
|
113
112
|
def local_measured_line_count(
|
|
@@ -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)
|
|
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):
|
|
@@ -977,26 +986,67 @@ def _added_workflow_files_for_create(create_call: CreateCall, working_directory:
|
|
|
977
986
|
def _read_added_workflow_files(
|
|
978
987
|
working_directory: str, repository: str | None, base_branch: str | None, head_branch: str | None
|
|
979
988
|
) -> list[str]:
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
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
|
+
)
|
|
988
997
|
return all_workflow_paths or []
|
|
989
998
|
|
|
990
999
|
|
|
991
|
-
def
|
|
992
|
-
working_directory: str,
|
|
993
|
-
|
|
994
|
-
|
|
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
|
|
995
1038
|
|
|
996
1039
|
|
|
997
1040
|
def checkout_is_for(working_directory: str, repository: str | None) -> bool:
|
|
998
1041
|
if repository is None:
|
|
999
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:
|
|
1000
1050
|
all_remote_lines = _git_lines(working_directory, "remote", "-v") if working_directory else None
|
|
1001
1051
|
all_repository_endings = ("/" + repository.lower(), ":" + repository.lower())
|
|
1002
1052
|
for each_line in all_remote_lines or []:
|
|
@@ -1139,9 +1189,11 @@ def _visible_files_for_create(create_call: CreateCall, working_directory: str) -
|
|
|
1139
1189
|
def _read_visible_files(
|
|
1140
1190
|
working_directory: str, repository: str | None, base_branch: str | None, head_branch: str | None
|
|
1141
1191
|
) -> list[str] | None:
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
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
|
+
)
|
|
@@ -254,7 +254,7 @@ def test_should_measure_remotely_when_the_create_names_another_repository(
|
|
|
254
254
|
large_branch: Path, monkeypatch: pytest.MonkeyPatch
|
|
255
255
|
) -> None:
|
|
256
256
|
monkeypatch.setattr(size, "remote_measured_line_count", lambda *all_arguments: None)
|
|
257
|
-
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")
|
|
258
258
|
assert size.oversized_pull_request_reason(payload) is None
|
|
259
259
|
|
|
260
260
|
|
|
@@ -309,3 +309,12 @@ def test_should_count_the_whole_branch_when_git_diffs_relative_to_the_session_fo
|
|
|
309
309
|
clone_path = _generated_schema_branch(tmp_path)
|
|
310
310
|
_git(clone_path, "config", "diff.relative", "true")
|
|
311
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":
|
|
649
|
+
"cwd": checkout_path,
|
|
648
650
|
}
|
|
649
651
|
|
|
650
652
|
|
|
@@ -1851,3 +1851,50 @@ def test_should_measure_a_named_main_base_against_origin_main(tmp_path: Path) ->
|
|
|
1851
1851
|
_run_git(clone_path, "update-ref", "-d", "refs/remotes/origin/main")
|
|
1852
1852
|
assert gate.visible_changed_files(str(clone_path), "feature", "main") is None
|
|
1853
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$"
|