claude-dev-env 8.117.3 → 8.117.5
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/_shared/pr-loop/scripts/pyproject.toml +1 -1
- package/_shared/process-tree/scripts/pyproject.toml +1 -1
- package/bin/cde.mjs +4 -3
- package/bin/cde.test.mjs +87 -1
- package/bin/codex-compat.mjs +4 -3
- package/bin/codex-compat.test.mjs +91 -1
- package/bin/install-plan.mjs +2 -1
- package/bin/install.mjs +24 -7
- package/bin/install.plan.test.mjs +15 -0
- package/bin/install.test.mjs +61 -0
- package/bin/python-probe.mjs +42 -0
- package/bin/python-probe.test.mjs +19 -2
- package/docs/references/advisor-tool.md +2 -0
- package/docs/rule-guides/features-start-with-an-eval.md +3 -3
- package/docs/rule-guides/proof-before-pull-request.md +2 -2
- package/hooks/blocking/bash_pre_tool_use_dispatcher.py +11 -4
- package/hooks/blocking/build_eval_before_eval_write_gate.py +10 -4
- package/hooks/blocking/followup_pr_dedupe.py +381 -64
- package/hooks/blocking/gate_child_process.py +187 -0
- package/hooks/blocking/gate_run_reads.py +116 -35
- package/hooks/blocking/merge_review_gate.py +93 -10
- package/hooks/blocking/merge_review_gate_parts/create_folders.py +346 -0
- package/hooks/blocking/merge_review_gate_parts/create_options.py +86 -0
- package/hooks/blocking/merge_review_gate_parts/folder_state.py +107 -0
- package/hooks/blocking/merge_review_gate_parts/open_request.py +199 -64
- package/hooks/blocking/merge_review_gate_parts/quoted_lines.py +283 -0
- package/hooks/blocking/merge_review_gate_parts/wrapped_creates.py +126 -0
- package/hooks/blocking/pr_lifecycle_skill_gate.py +61 -18
- package/hooks/blocking/pre_tool_use_dispatcher.py +25 -3
- package/hooks/blocking/pull_request_proof.py +5 -51
- package/hooks/blocking/pull_request_proof_edit_gate.py +19 -5
- package/hooks/blocking/test_bash_pre_tool_use_dispatcher.py +54 -0
- package/hooks/blocking/test_build_eval_before_eval_write_gate.py +64 -0
- package/hooks/blocking/test_followup_pr_dedupe.py +464 -1
- package/hooks/blocking/test_gate_child_process.py +64 -0
- package/hooks/blocking/test_gate_run_reads.py +364 -4
- package/hooks/blocking/test_merge_review_gate.py +832 -39
- package/hooks/blocking/test_pr_lifecycle_skill_gate.py +130 -4
- package/hooks/blocking/test_pre_tool_use_dispatcher.py +64 -0
- package/hooks/blocking/test_pull_request_proof.py +16 -0
- package/hooks/blocking/test_pull_request_proof_edit_gate.py +60 -0
- package/hooks/blocking/tests/test_create_folders.py +290 -0
- package/hooks/blocking/tests/test_create_options.py +34 -0
- package/hooks/blocking/tests/test_folder_state.py +40 -0
- package/hooks/blocking/tests/test_open_request.py +350 -44
- package/hooks/blocking/tests/test_quoted_lines.py +86 -0
- package/hooks/blocking/tests/test_wrapped_creates.py +42 -0
- package/hooks/features/bash-dispatchers.md +1 -1
- package/hooks/features/conduct-gates.md +7 -7
- package/hooks/features/session-context.md +3 -3
- package/hooks/features/write-edit-blocking.md +3 -3
- package/hooks/hooks_constants/advisor_rules_prompt_constants.py +14 -6
- package/hooks/hooks_constants/build_eval_before_eval_write_gate_constants.py +5 -0
- package/hooks/hooks_constants/followup_pr_dedupe_constants.py +34 -1
- package/hooks/hooks_constants/gate_fault.py +52 -0
- package/hooks/hooks_constants/gate_fault_constants.py +13 -0
- package/hooks/hooks_constants/gate_run_reads_constants.py +9 -1
- package/hooks/hooks_constants/merge_review_gate_constants.py +94 -1
- package/hooks/hooks_constants/piped_pytest_blocker_constants.py +2 -0
- package/hooks/hooks_constants/pr_lifecycle_skill_gate_constants.py +6 -1
- package/hooks/hooks_constants/pre_tool_use_stdin.py +23 -3
- package/hooks/hooks_constants/shell_command_pipeline.py +68 -8
- package/hooks/hooks_constants/shell_command_segments.py +2 -2
- package/hooks/hooks_constants/shell_command_wrappers.py +3 -2
- package/hooks/hooks_constants/test_followup_pr_dedupe_constants.py +7 -0
- package/hooks/hooks_constants/test_gate_fault.py +41 -0
- package/hooks/hooks_constants/test_piped_pytest_blocker_constants.py +5 -0
- package/hooks/hooks_constants/test_pr_lifecycle_skill_gate_constants.py +10 -0
- package/hooks/hooks_constants/test_pre_tool_use_stdin.py +97 -0
- package/hooks/hooks_constants/test_shell_command_pipeline.py +55 -0
- package/hooks/hooks_constants/test_shell_command_segments.py +15 -0
- package/hooks/hooks_constants/test_shell_command_wrappers.py +6 -0
- package/hooks/hooks_constants/transcript_skill_scan_constants.py +6 -0
- package/hooks/pyproject.toml +2 -3
- package/hooks/session/advisor_rules_prompt.py +53 -9
- package/hooks/session/test_advisor_rules_prompt.py +70 -4
- package/hooks/test_python_floor.py +197 -0
- package/hooks/test_transcript_skill_scan.py +324 -0
- package/hooks/transcript_skill_scan.py +233 -2
- package/package.json +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Behavioral tests for the folder state the create walk carries."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from blocking.merge_review_gate_parts.folder_state import FolderState, state_after_folder_change
|
|
8
|
+
|
|
9
|
+
START = FolderState("/w", True)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@pytest.mark.parametrize(
|
|
13
|
+
("all_tokens", "expected"),
|
|
14
|
+
[
|
|
15
|
+
(["cd", "sub"], FolderState("/w/sub", True)),
|
|
16
|
+
(["cd", "/abs"], FolderState("/abs", True)),
|
|
17
|
+
(["cd", "-"], FolderState(None, False)),
|
|
18
|
+
(["cd", "$X"], FolderState(None, False)),
|
|
19
|
+
(["pushd", "a"], FolderState("/w/a", True, (("/w", True),))),
|
|
20
|
+
(["popd"], FolderState(None, False)),
|
|
21
|
+
(["git", "status"], START),
|
|
22
|
+
],
|
|
23
|
+
)
|
|
24
|
+
def test_state_after_folder_change_should_follow_each_folder_change(
|
|
25
|
+
all_tokens: list[str], expected: FolderState
|
|
26
|
+
) -> None:
|
|
27
|
+
assert state_after_folder_change(all_tokens, START) == expected
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_state_after_folder_change_should_return_to_the_pushed_folder_on_popd() -> None:
|
|
31
|
+
pushed = state_after_folder_change(["pushd", "a"], START)
|
|
32
|
+
assert state_after_folder_change(["popd"], pushed) == START
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_state_after_folder_change_should_not_follow_a_relative_change_from_an_unfollowed_folder() -> (
|
|
36
|
+
None
|
|
37
|
+
):
|
|
38
|
+
assert state_after_folder_change(["cd", "sub"], FolderState(None, False)) == FolderState(
|
|
39
|
+
None, False
|
|
40
|
+
)
|
|
@@ -4,17 +4,30 @@ gh pr create --repo acme/tools --title "--head evil" -> acme/tools, quoted optio
|
|
|
4
4
|
mcp create_pull_request {owner, repo, head} -> acme/tools, head listed by GitHub
|
|
5
5
|
mcp create_pull_request {owner, repo, head: u:b} -> acme/tools, head listed for u
|
|
6
6
|
gh pr merge 12 -> no open
|
|
7
|
+
gh pr create --head a && cd x && gh pr create -> two opens, each with its own folder
|
|
7
8
|
"""
|
|
8
9
|
|
|
9
10
|
from __future__ import annotations
|
|
10
11
|
|
|
11
12
|
import subprocess
|
|
13
|
+
from collections.abc import Callable, Mapping, Sequence
|
|
12
14
|
from pathlib import Path
|
|
13
15
|
|
|
14
16
|
import pytest
|
|
15
17
|
|
|
18
|
+
from blocking.gate_run_reads import ReadSlice
|
|
16
19
|
from blocking.merge_review_gate_parts import open_request
|
|
17
|
-
from blocking.merge_review_gate_parts.open_request import
|
|
20
|
+
from blocking.merge_review_gate_parts.open_request import (
|
|
21
|
+
OpenRequest,
|
|
22
|
+
ShellOpenCall,
|
|
23
|
+
open_calls_from,
|
|
24
|
+
open_request_for,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _only_request(all_payload_fields: dict[str, object]) -> OpenRequest:
|
|
29
|
+
[only_call] = open_calls_from(all_payload_fields)
|
|
30
|
+
return open_request_for(only_call)
|
|
18
31
|
|
|
19
32
|
|
|
20
33
|
def _shell_payload(command: str, folder: Path) -> dict[str, object]:
|
|
@@ -74,7 +87,7 @@ def _redirect_github(monkeypatch: pytest.MonkeyPatch, github: Path) -> None:
|
|
|
74
87
|
|
|
75
88
|
def test_should_read_the_repository_and_ignore_options_quoted_in_the_title(tmp_path: Path) -> None:
|
|
76
89
|
payload = _shell_payload('gh pr create --repo acme/tools --title "--head evil"', tmp_path)
|
|
77
|
-
assert
|
|
90
|
+
assert _only_request(payload) == OpenRequest(owner="acme", repo="tools", head=None)
|
|
78
91
|
|
|
79
92
|
|
|
80
93
|
def test_should_read_the_create_tool_with_no_head_branch(tmp_path: Path) -> None:
|
|
@@ -83,7 +96,7 @@ def test_should_read_the_create_tool_with_no_head_branch(tmp_path: Path) -> None
|
|
|
83
96
|
"tool_input": {"owner": "acme", "repo": "tools"},
|
|
84
97
|
"cwd": str(tmp_path),
|
|
85
98
|
}
|
|
86
|
-
assert
|
|
99
|
+
assert _only_request(payload) == OpenRequest(owner="acme", repo="tools", head=None)
|
|
87
100
|
|
|
88
101
|
|
|
89
102
|
def test_should_read_a_pushed_branch_from_outside_any_checkout(
|
|
@@ -94,7 +107,7 @@ def test_should_read_a_pushed_branch_from_outside_any_checkout(
|
|
|
94
107
|
github = tmp_path / "github.com"
|
|
95
108
|
_git(checkout, "push", "--quiet", str(_bare_remote(github, "acme")), "feature")
|
|
96
109
|
_redirect_github(monkeypatch, github)
|
|
97
|
-
assert
|
|
110
|
+
assert _only_request(_create_payload("feature", tmp_path)) == OpenRequest(
|
|
98
111
|
owner="acme", repo="tools", head=head
|
|
99
112
|
)
|
|
100
113
|
|
|
@@ -110,7 +123,7 @@ def test_should_read_a_fork_branch_from_the_fork_owner(
|
|
|
110
123
|
_git(checkout, "push", "--quiet", str(_bare_remote(github, "someone")), "feature")
|
|
111
124
|
_redirect_github(monkeypatch, github)
|
|
112
125
|
assert base_head != fork_head
|
|
113
|
-
assert
|
|
126
|
+
assert _only_request(_create_payload("someone:feature", tmp_path)).head == fork_head
|
|
114
127
|
|
|
115
128
|
|
|
116
129
|
def test_should_read_no_head_for_a_branch_the_repository_does_not_list(
|
|
@@ -119,7 +132,7 @@ def test_should_read_no_head_for_a_branch_the_repository_does_not_list(
|
|
|
119
132
|
github = tmp_path / "github.com"
|
|
120
133
|
_bare_remote(github, "acme")
|
|
121
134
|
_redirect_github(monkeypatch, github)
|
|
122
|
-
assert
|
|
135
|
+
assert _only_request(_create_payload("feature", tmp_path)).head is None
|
|
123
136
|
|
|
124
137
|
|
|
125
138
|
def test_should_list_in_an_empty_folder_so_the_checkout_config_never_applies(
|
|
@@ -135,64 +148,80 @@ def test_should_list_in_an_empty_folder_so_the_checkout_config_never_applies(
|
|
|
135
148
|
_git(checkout, "push", "--quiet", str(_bare_remote(decoy, "acme")), "feature")
|
|
136
149
|
_git(checkout, "config", f"url.{decoy}/acme/.insteadOf", "https://github.com/acme/")
|
|
137
150
|
monkeypatch.chdir(checkout)
|
|
138
|
-
assert
|
|
151
|
+
assert _only_request(_create_payload("feature", tmp_path)).head == head
|
|
152
|
+
|
|
139
153
|
|
|
154
|
+
def _listing_answered_by(
|
|
155
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
156
|
+
answer: Callable[[list[str], Mapping[str, str] | None], str | None],
|
|
157
|
+
) -> None:
|
|
158
|
+
run_before_patch = open_request.child_stdout
|
|
140
159
|
|
|
141
|
-
def
|
|
142
|
-
|
|
143
|
-
|
|
160
|
+
def answer_the_listing(
|
|
161
|
+
all_command_words: Sequence[str],
|
|
162
|
+
own_timeout_seconds: float,
|
|
163
|
+
read_slice: ReadSlice,
|
|
164
|
+
working_directory: str | None = None,
|
|
165
|
+
all_environment_variables: Mapping[str, str] | None = None,
|
|
166
|
+
) -> str | None:
|
|
167
|
+
if "ls-remote" in all_command_words:
|
|
168
|
+
return answer(list(all_command_words), all_environment_variables)
|
|
169
|
+
return run_before_patch(
|
|
170
|
+
all_command_words, own_timeout_seconds, read_slice, working_directory, all_environment_variables
|
|
171
|
+
)
|
|
144
172
|
|
|
145
|
-
monkeypatch.setattr(open_request
|
|
146
|
-
assert open_request_from(_create_payload("feature", Path("."))).head is None
|
|
173
|
+
monkeypatch.setattr(open_request, "child_stdout", answer_the_listing)
|
|
147
174
|
|
|
148
175
|
|
|
149
|
-
def
|
|
176
|
+
def test_should_read_no_head_when_the_listing_gives_no_answer(
|
|
177
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
178
|
+
) -> None:
|
|
179
|
+
_listing_answered_by(monkeypatch, lambda _all_words, _environment: None)
|
|
180
|
+
assert _only_request(_create_payload("feature", tmp_path)).head is None
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def test_should_run_the_listing_without_a_terminal_prompt(
|
|
184
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
185
|
+
) -> None:
|
|
150
186
|
monkeypatch.delenv("GIT_TERMINAL_PROMPT", raising=False)
|
|
151
187
|
monkeypatch.delenv("GCM_INTERACTIVE", raising=False)
|
|
152
|
-
|
|
188
|
+
all_seen_environments: list[Mapping[str, str] | None] = []
|
|
153
189
|
|
|
154
190
|
def record_environment(
|
|
155
|
-
|
|
156
|
-
) ->
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
return subprocess.CompletedProcess(all_arguments, 1)
|
|
191
|
+
_all_words: list[str], all_environment_variables: Mapping[str, str] | None
|
|
192
|
+
) -> str | None:
|
|
193
|
+
all_seen_environments.append(all_environment_variables)
|
|
194
|
+
return None
|
|
160
195
|
|
|
161
|
-
monkeypatch
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
assert
|
|
196
|
+
_listing_answered_by(monkeypatch, record_environment)
|
|
197
|
+
_only_request(_create_payload("feature", tmp_path))
|
|
198
|
+
[all_environment_variables] = all_seen_environments
|
|
199
|
+
assert all_environment_variables is not None
|
|
200
|
+
assert all_environment_variables["GIT_TERMINAL_PROMPT"] == "0"
|
|
201
|
+
assert all_environment_variables["GCM_INTERACTIVE"] == "never"
|
|
165
202
|
|
|
166
203
|
|
|
167
204
|
def test_should_pick_the_listed_line_that_names_the_branch_exactly(
|
|
205
|
+
tmp_path: Path,
|
|
168
206
|
monkeypatch: pytest.MonkeyPatch,
|
|
169
207
|
) -> None:
|
|
170
208
|
listing = f"{'1' * 40}\trefs/heads/feature-two\n{'2' * 40}\trefs/heads/feature\n"
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
all_arguments: list[str], **all_keyword_arguments: object
|
|
174
|
-
) -> subprocess.CompletedProcess[bytes]:
|
|
175
|
-
all_keyword_arguments["stdout"].write(listing.encode())
|
|
176
|
-
return subprocess.CompletedProcess(all_arguments, 0)
|
|
177
|
-
|
|
178
|
-
monkeypatch.setattr(open_request.subprocess, "run", list_branches)
|
|
179
|
-
assert open_request_from(_create_payload("feature", Path("."))).head == "2" * 40
|
|
209
|
+
_listing_answered_by(monkeypatch, lambda _all_words, _environment: listing)
|
|
210
|
+
assert _only_request(_create_payload("feature", tmp_path)).head == "2" * 40
|
|
180
211
|
|
|
181
212
|
|
|
182
213
|
def test_should_run_no_listing_for_a_call_that_names_no_owner(
|
|
214
|
+
tmp_path: Path,
|
|
183
215
|
monkeypatch: pytest.MonkeyPatch,
|
|
184
216
|
) -> None:
|
|
185
217
|
all_commands: list[list[str]] = []
|
|
186
218
|
|
|
187
|
-
def record_command(
|
|
188
|
-
|
|
189
|
-
) -> subprocess.CompletedProcess[bytes]:
|
|
190
|
-
all_commands.append(all_arguments)
|
|
191
|
-
return subprocess.CompletedProcess(all_arguments, 1)
|
|
219
|
+
def record_command(all_words: list[str], _environment: Mapping[str, str] | None) -> None:
|
|
220
|
+
all_commands.append(all_words)
|
|
192
221
|
|
|
193
|
-
monkeypatch
|
|
194
|
-
assert
|
|
195
|
-
assert
|
|
222
|
+
_listing_answered_by(monkeypatch, record_command)
|
|
223
|
+
assert _only_request(_create_payload("feature", tmp_path, owner="")).head is None
|
|
224
|
+
assert all_commands == []
|
|
196
225
|
|
|
197
226
|
|
|
198
227
|
def test_should_read_the_checkout_branch_when_github_lists_none(
|
|
@@ -203,7 +232,7 @@ def test_should_read_the_checkout_branch_when_github_lists_none(
|
|
|
203
232
|
github = tmp_path / "github.com"
|
|
204
233
|
_bare_remote(github, "acme")
|
|
205
234
|
_redirect_github(monkeypatch, github)
|
|
206
|
-
assert
|
|
235
|
+
assert _only_request(_create_payload("feature", checkout)).head == head
|
|
207
236
|
|
|
208
237
|
|
|
209
238
|
def test_should_read_a_fork_branch_from_the_checkout_when_github_lists_none(
|
|
@@ -214,15 +243,292 @@ def test_should_read_a_fork_branch_from_the_checkout_when_github_lists_none(
|
|
|
214
243
|
github = tmp_path / "github.com"
|
|
215
244
|
_bare_remote(github, "someone")
|
|
216
245
|
_redirect_github(monkeypatch, github)
|
|
217
|
-
assert
|
|
246
|
+
assert _only_request(_create_payload("someone:feature", checkout)).head == head
|
|
218
247
|
|
|
219
248
|
|
|
220
249
|
def test_should_read_a_shell_open_branch_from_the_checkout(tmp_path: Path) -> None:
|
|
221
250
|
checkout = _checkout_on(tmp_path, "feature")
|
|
222
251
|
head = _commit(checkout, "first")
|
|
223
252
|
payload = _shell_payload("gh pr create --repo acme/tools --head feature", checkout)
|
|
224
|
-
assert
|
|
253
|
+
assert _only_request(payload) == OpenRequest(owner="acme", repo="tools", head=head)
|
|
225
254
|
|
|
226
255
|
|
|
227
256
|
def test_should_read_no_open_from_a_merge_command(tmp_path: Path) -> None:
|
|
228
|
-
assert
|
|
257
|
+
assert open_calls_from(_shell_payload("gh pr merge 12", tmp_path)) == []
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def test_should_read_every_chained_create_with_its_own_repository_head_and_folder(
|
|
261
|
+
tmp_path: Path,
|
|
262
|
+
) -> None:
|
|
263
|
+
other = tmp_path / "other"
|
|
264
|
+
command = (
|
|
265
|
+
"gh pr create --repo acme/tools --head one --fill && "
|
|
266
|
+
"cd other && python scripts/pull_request.py create --head two; "
|
|
267
|
+
"cd nested && gh pr create -R someone/fork --fill"
|
|
268
|
+
)
|
|
269
|
+
assert open_calls_from(_shell_payload(command, tmp_path)) == [
|
|
270
|
+
ShellOpenCall(repository=("acme", "tools"), branch="one", folder=str(tmp_path)),
|
|
271
|
+
ShellOpenCall(repository=None, branch="two", folder=str(other)),
|
|
272
|
+
ShellOpenCall(repository=("someone", "fork"), branch="HEAD", folder=str(other / "nested")),
|
|
273
|
+
]
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def test_should_read_creates_on_separate_lines_as_separate_opens(tmp_path: Path) -> None:
|
|
277
|
+
command = (
|
|
278
|
+
"python scripts/pull_request.py create --repo acme/tools\n"
|
|
279
|
+
"gh pr create --repo acme/tools --head two"
|
|
280
|
+
)
|
|
281
|
+
assert [
|
|
282
|
+
each_call.branch for each_call in open_calls_from(_shell_payload(command, tmp_path))
|
|
283
|
+
] == ["HEAD", "two"]
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def test_should_keep_a_head_on_a_continued_line_with_its_create(tmp_path: Path) -> None:
|
|
287
|
+
command = "gh pr create --repo acme/tools \\\n --head one --fill"
|
|
288
|
+
assert open_calls_from(_shell_payload(command, tmp_path)) == [
|
|
289
|
+
ShellOpenCall(repository=("acme", "tools"), branch="one", folder=str(tmp_path)),
|
|
290
|
+
]
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def test_should_read_the_head_of_each_chained_create(tmp_path: Path) -> None:
|
|
294
|
+
checkout = _checkout_on(tmp_path, "one")
|
|
295
|
+
first_head = _commit(checkout, "first")
|
|
296
|
+
_git(checkout, "checkout", "--quiet", "-b", "two")
|
|
297
|
+
second_head = _commit(checkout, "second")
|
|
298
|
+
command = (
|
|
299
|
+
"gh pr create --repo acme/tools --head one && gh pr create --repo acme/tools --head two"
|
|
300
|
+
)
|
|
301
|
+
all_requests = [
|
|
302
|
+
open_request_for(each_call)
|
|
303
|
+
for each_call in open_calls_from(_shell_payload(command, checkout))
|
|
304
|
+
]
|
|
305
|
+
assert [each_request.head for each_request in all_requests] == [first_head, second_head]
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
MAIN_FLOOR_START = "/work/main"
|
|
309
|
+
ALL_MAIN_FLOOR_READINGS = [
|
|
310
|
+
("cat <<'BODY' | bash\ngh pr create --head two\nBODY", None, "two", "/work/main"),
|
|
311
|
+
("cat > x.sh <<'BODY'\ngh pr create --head two\nBODY\nbash x.sh", None, "two", "/work/main"),
|
|
312
|
+
(". /dev/stdin <<'BODY'\ngh pr create --head two\nBODY", None, "two", "/work/main"),
|
|
313
|
+
("eval \"$(cat <<'BODY'\ngh pr create --head two\nBODY\n)\"", None, "two", "/work/main"),
|
|
314
|
+
("echo gh pr create --head two | bash; x=`gh pr create --head one`", None, "two", "/work/main"),
|
|
315
|
+
(
|
|
316
|
+
"echo gh pr create --head two | bash; bash -c 'gh pr create --head one'",
|
|
317
|
+
None,
|
|
318
|
+
"two",
|
|
319
|
+
"/work/main",
|
|
320
|
+
),
|
|
321
|
+
(
|
|
322
|
+
"echo gh pr create --head two | bash; eval 'gh pr create --head one'",
|
|
323
|
+
None,
|
|
324
|
+
"two",
|
|
325
|
+
"/work/main",
|
|
326
|
+
),
|
|
327
|
+
("{ cd ../rsub; } | true; gh pr create --fill", None, "HEAD", "/work/main"),
|
|
328
|
+
('gh pr create --head one --label "see gh pr create"', None, "one", "/work/main"),
|
|
329
|
+
('gh pr create --head one --label "a; gh pr create --head two"', None, "one", "/work/main"),
|
|
330
|
+
('gh pr create --head one --label "a && gh pr create --head two"', None, "one", "/work/main"),
|
|
331
|
+
('gh pr create --head one --label "a | gh pr create --head two"', None, "one", "/work/main"),
|
|
332
|
+
('gh pr create --head one --label "a\ngh pr create --head two"', None, "one", "/work/main"),
|
|
333
|
+
(
|
|
334
|
+
'gh pr create --fill --label "see gh pr create --repo acme/tools --head two"',
|
|
335
|
+
("acme", "tools"),
|
|
336
|
+
"two",
|
|
337
|
+
"/work/main",
|
|
338
|
+
),
|
|
339
|
+
(
|
|
340
|
+
'gh pr create --fill --label "a; gh pr create --repo acme/tools --head two"',
|
|
341
|
+
None,
|
|
342
|
+
"HEAD",
|
|
343
|
+
"/work/main",
|
|
344
|
+
),
|
|
345
|
+
(
|
|
346
|
+
'gh pr create --head one --label "see pull_request.py create --head two"',
|
|
347
|
+
None,
|
|
348
|
+
"one",
|
|
349
|
+
"/work/main",
|
|
350
|
+
),
|
|
351
|
+
("gh pr create --head one --label 'a; gh pr create --head two'", None, "one", "/work/main"),
|
|
352
|
+
("gh pr create --fill", None, "HEAD", "/work/main"),
|
|
353
|
+
("gh pr create --head two", None, "two", "/work/main"),
|
|
354
|
+
("gh pr create --head=two", None, "two", "/work/main"),
|
|
355
|
+
("gh pr create -H two", None, "two", "/work/main"),
|
|
356
|
+
("gh pr create -Htwo", None, "HEAD", "/work/main"),
|
|
357
|
+
("gh pr create --head one --head two", None, "one", "/work/main"),
|
|
358
|
+
("gh pr create --repo acme/tools --head two", ("acme", "tools"), "two", "/work/main"),
|
|
359
|
+
("gh pr create -R acme/tools --head two", ("acme", "tools"), "two", "/work/main"),
|
|
360
|
+
("gh pr create --repo=acme/tools --head two", ("acme", "tools"), "two", "/work/main"),
|
|
361
|
+
("cd ../rsub && gh pr create --fill", None, "HEAD", "/work/main/../rsub"),
|
|
362
|
+
("cd ../rsub; gh pr create --head two", None, "two", "/work/main/../rsub"),
|
|
363
|
+
("cd /abs/place && gh pr create --fill", None, "HEAD", "/abs/place"),
|
|
364
|
+
('cd "../with space" && gh pr create --fill', None, "HEAD", "/work/main/../with space"),
|
|
365
|
+
("pushd ../rsub && gh pr create --fill", None, "HEAD", "/work/main/../rsub"),
|
|
366
|
+
("Set-Location ../rsub; gh pr create --fill", None, "HEAD", "/work/main/../rsub"),
|
|
367
|
+
(
|
|
368
|
+
"(cd ../rsub && gh pr create --fill) ; gh pr create --fill",
|
|
369
|
+
None,
|
|
370
|
+
"HEAD",
|
|
371
|
+
"/work/main/../rsub",
|
|
372
|
+
),
|
|
373
|
+
("cd ../a && cd ../b && gh pr create --fill", None, "HEAD", "/work/main/../b"),
|
|
374
|
+
("gh pr create --head one && cd ../rsub && gh pr create --head two", None, "one", "/work/main"),
|
|
375
|
+
("gh pr create --head one ; gh pr create --head two", None, "one", "/work/main"),
|
|
376
|
+
("gh pr create --head one || gh pr create --head two", None, "one", "/work/main"),
|
|
377
|
+
("gh pr create --head one\ngh pr create --head two", None, "one", "/work/main"),
|
|
378
|
+
("python3 scripts/pull_request.py create --head two", None, "two", "/work/main"),
|
|
379
|
+
(
|
|
380
|
+
"python3 scripts/pull_request.py create --repo acme/tools --head two",
|
|
381
|
+
("acme", "tools"),
|
|
382
|
+
"two",
|
|
383
|
+
"/work/main",
|
|
384
|
+
),
|
|
385
|
+
("cd ../rsub && python3 scripts/pull_request.py create", None, "HEAD", "/work/main/../rsub"),
|
|
386
|
+
("gh pr create --title 'cd ../evil' --head two", None, "two", "/work/main"),
|
|
387
|
+
("gh pr create --body 'x' --head two", None, "two", "/work/main"),
|
|
388
|
+
(
|
|
389
|
+
'gh pr create --title "--head evil" --repo acme/tools',
|
|
390
|
+
("acme", "tools"),
|
|
391
|
+
"HEAD",
|
|
392
|
+
"/work/main",
|
|
393
|
+
),
|
|
394
|
+
("bash -c 'cd ../rsub && gh pr create --fill'", None, "HEAD", "/work/main"),
|
|
395
|
+
("echo gh pr create --head two | bash", None, "two", "/work/main"),
|
|
396
|
+
("bash <<'EOF'\ngh pr create --head two\nEOF", None, "two", "/work/main"),
|
|
397
|
+
("export GH_REPO=other/thing; gh pr create --head two", None, "two", "/work/main"),
|
|
398
|
+
("GH_REPO=other/thing gh pr create --head two", None, "two", "/work/main"),
|
|
399
|
+
("GH_REPO=other/thing env -u GH_REPO gh pr create --head two", None, "two", "/work/main"),
|
|
400
|
+
("GH_REPO=other/thing env -i gh pr create --head two", None, "two", "/work/main"),
|
|
401
|
+
("git commit -m 'x; gh pr create --head two'", None, "two", "/work/main"),
|
|
402
|
+
("gh.exe pr create --head two", None, "two", "/work/main"),
|
|
403
|
+
("cd $WORK && gh pr create --fill", None, "HEAD", "/work/main/$WORK"),
|
|
404
|
+
("cd - && gh pr create --fill", None, "HEAD", "/work/main/-"),
|
|
405
|
+
("x=$(gh pr create --head two)", None, "two)", "/work/main"),
|
|
406
|
+
("gh pr create --head 'two'", None, "two", "/work/main"),
|
|
407
|
+
('gh pr create --head "two"', None, "two", "/work/main"),
|
|
408
|
+
("gh pr create --head user:two", None, "user:two", "/work/main"),
|
|
409
|
+
]
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
@pytest.mark.parametrize(("command", "repository", "branch", "folder"), ALL_MAIN_FLOOR_READINGS)
|
|
413
|
+
def test_should_keep_the_first_create_reading_main_gave_as_one_of_its_calls(
|
|
414
|
+
command: str, repository: tuple[str, str] | None, branch: str, folder: str
|
|
415
|
+
) -> None:
|
|
416
|
+
payload = {"tool_name": "Bash", "tool_input": {"command": command}, "cwd": MAIN_FLOOR_START}
|
|
417
|
+
assert ShellOpenCall(repository=repository, branch=branch, folder=folder) in open_calls_from(
|
|
418
|
+
payload
|
|
419
|
+
)
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
def _branches(command: str) -> set[str]:
|
|
423
|
+
payload = {"tool_name": "Bash", "tool_input": {"command": command}, "cwd": MAIN_FLOOR_START}
|
|
424
|
+
return {each_call.branch for each_call in open_calls_from(payload)}
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
@pytest.mark.parametrize(
|
|
428
|
+
"command",
|
|
429
|
+
[
|
|
430
|
+
"gh pr create -Htwo",
|
|
431
|
+
"gh pr create -H=two",
|
|
432
|
+
"gh pr create --head one --head two",
|
|
433
|
+
"gh pr create -H one --head=two",
|
|
434
|
+
"gh pr create --head=one -Htwo",
|
|
435
|
+
"gh pr create --fill; gh pr create --head one -H two",
|
|
436
|
+
],
|
|
437
|
+
)
|
|
438
|
+
def test_should_check_every_head_a_create_names(command: str) -> None:
|
|
439
|
+
assert "two" in _branches(command)
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
@pytest.mark.parametrize(
|
|
443
|
+
"command",
|
|
444
|
+
[
|
|
445
|
+
"gh pr create -dHtwo",
|
|
446
|
+
"gh pr create -dH two",
|
|
447
|
+
"gh pr create -fH=two",
|
|
448
|
+
"gh pr create --head one -dHtwo",
|
|
449
|
+
"gh -R o/r pr create -wdHtwo --fill",
|
|
450
|
+
],
|
|
451
|
+
)
|
|
452
|
+
def test_should_check_the_head_a_short_flag_cluster_names(command: str) -> None:
|
|
453
|
+
assert "two" in _branches(command)
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
def test_should_read_the_rest_of_a_cluster_after_the_head_letter_as_the_head() -> None:
|
|
457
|
+
all_branches = _branches("gh pr create -Hdtwo")
|
|
458
|
+
assert "dtwo" in all_branches
|
|
459
|
+
assert "two" not in all_branches
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
def test_should_read_each_named_head_as_its_own_call() -> None:
|
|
463
|
+
assert _branches("python3 scripts/pull_request.py create --head one -Htwo --head=three") == {
|
|
464
|
+
"one",
|
|
465
|
+
"two",
|
|
466
|
+
"three",
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
@pytest.mark.parametrize(
|
|
471
|
+
"command",
|
|
472
|
+
[
|
|
473
|
+
"bash <<<'gh pr create --head two'",
|
|
474
|
+
"G=gh; $G pr create --head two",
|
|
475
|
+
"alias g=gh; g pr create --head two",
|
|
476
|
+
"bash make_pull_request.sh --head two",
|
|
477
|
+
],
|
|
478
|
+
)
|
|
479
|
+
def test_should_not_read_a_create_only_a_shell_input_variable_or_alias_holds(command: str) -> None:
|
|
480
|
+
assert "two" not in _branches(command)
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
def test_should_leave_unfollowed_a_create_with_no_repository_after_an_export_of_gh_repo() -> None:
|
|
484
|
+
payload = {
|
|
485
|
+
"tool_name": "Bash",
|
|
486
|
+
"tool_input": {"command": "export GH_REPO=other/thing; gh pr create --head two"},
|
|
487
|
+
"cwd": MAIN_FLOOR_START,
|
|
488
|
+
}
|
|
489
|
+
all_calls = open_calls_from(payload)
|
|
490
|
+
assert {each_call.repository for each_call in all_calls} == {None}
|
|
491
|
+
assert False in {getattr(each_call, "is_folder_followed", True) for each_call in all_calls}
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
def _repositories(command: str) -> set[tuple[str, str] | None]:
|
|
495
|
+
payload = {"tool_name": "Bash", "tool_input": {"command": command}, "cwd": MAIN_FLOOR_START}
|
|
496
|
+
return {each_call.repository for each_call in open_calls_from(payload)}
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
@pytest.mark.parametrize(
|
|
500
|
+
("command", "all_expected_repositories"),
|
|
501
|
+
[
|
|
502
|
+
("gh -R o/r pr create -R acme/tools --repo=a/b --repo=a/b", {("a", "b")}),
|
|
503
|
+
("gh -R a/b pr create --repo acme/tools", {("acme", "tools")}),
|
|
504
|
+
("gh -R a/b pr create --fill", {("a", "b")}),
|
|
505
|
+
("gh pr create --repo acme/tools -dRa/b", {("a", "b"), ("acme", "tools")}),
|
|
506
|
+
("gh pr create --repo acme/tools -R=a/b", {("a", "b"), ("acme", "tools")}),
|
|
507
|
+
("gh pr create --repo a/b --title --repo=acme/tools", {("a", "b")}),
|
|
508
|
+
("GH_REPO=acme/tools gh pr create -R a/b", {("a", "b")}),
|
|
509
|
+
("x & eval \"\"gh\" -R acme/tools pr create --repo=a/b ''\"\" ~\"", {("a", "b")}),
|
|
510
|
+
("python3 scripts/pull_request.py create --repo acme/tools --repo a/b", {("a", "b"), ("acme", "tools")}),
|
|
511
|
+
],
|
|
512
|
+
)
|
|
513
|
+
def test_should_read_the_repository_the_last_repository_flag_names(
|
|
514
|
+
command: str, all_expected_repositories: set[tuple[str, str] | None]
|
|
515
|
+
) -> None:
|
|
516
|
+
assert _repositories(command) == all_expected_repositories
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
@pytest.mark.parametrize("separator", [";", "&&", "||", "|", "\n"])
|
|
520
|
+
def test_should_read_create_words_after_a_separator_inside_a_quoted_value(separator: str) -> None:
|
|
521
|
+
assert "two" in _branches(f"git commit -m 'x{separator} gh pr create --head two'")
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
@pytest.mark.parametrize(
|
|
525
|
+
"command",
|
|
526
|
+
[
|
|
527
|
+
"gh pr create --head one; git commit -m 'x; gh pr create --head two'",
|
|
528
|
+
"gh pr create --head one --label 'a && gh pr create --head two'",
|
|
529
|
+
"gh pr create --head one; git commit -m 'x\ngh pr create --head two'",
|
|
530
|
+
'gh pr create --head one --body "a\ngh pr create --head two"',
|
|
531
|
+
],
|
|
532
|
+
)
|
|
533
|
+
def test_should_not_read_a_later_quoted_create(command: str) -> None:
|
|
534
|
+
assert "two" not in _branches(command)
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""Behavioral tests for cutting shell text into the logical lines bash reads.
|
|
2
|
+
|
|
3
|
+
a ; b<line break>c -> two lines
|
|
4
|
+
bash -c "a<line break>b" -> one line, the line break kept in the word
|
|
5
|
+
echo $'it\\'s' -> echo 'it'\\''s'
|
|
6
|
+
echo "open -> None
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import shlex
|
|
12
|
+
|
|
13
|
+
import pytest
|
|
14
|
+
|
|
15
|
+
from blocking.merge_review_gate_parts.quoted_lines import quote_aware_lines
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _words(text: str) -> list[list[str]]:
|
|
19
|
+
all_lines = quote_aware_lines(text)
|
|
20
|
+
assert all_lines is not None
|
|
21
|
+
return [shlex.split(each_line) for each_line in all_lines]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_should_cut_at_a_line_break_outside_quotes() -> None:
|
|
25
|
+
assert quote_aware_lines("a ; b\nc\r\nd") == ["a ; b", "c", "d"]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@pytest.mark.parametrize(
|
|
29
|
+
("text", "word"),
|
|
30
|
+
[
|
|
31
|
+
('bash -c "true\ngh pr create"', "true\ngh pr create"),
|
|
32
|
+
("bash -c 'true\ngh pr create'", "true\ngh pr create"),
|
|
33
|
+
("bash -c $'true\\ngh pr create'", "true\ngh pr create"),
|
|
34
|
+
("bash -c '\ngh pr create'", "\ngh pr create"),
|
|
35
|
+
('bash -c "\ngh pr create"', "\ngh pr create"),
|
|
36
|
+
],
|
|
37
|
+
)
|
|
38
|
+
def test_should_keep_a_quoted_line_break_inside_its_word(text: str, word: str) -> None:
|
|
39
|
+
assert _words(text) == [["bash", "-c", word]]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@pytest.mark.parametrize(
|
|
43
|
+
("text", "body"),
|
|
44
|
+
[
|
|
45
|
+
("x --body $'it\\'s' ; y", "it's"),
|
|
46
|
+
("x --body $'\\'' ; y", "'"),
|
|
47
|
+
("x --body $'a\\\\b\\\"c' ; y", 'a\\b"c'),
|
|
48
|
+
],
|
|
49
|
+
)
|
|
50
|
+
def test_should_read_an_ansi_c_word_as_bash_does(text: str, body: str) -> None:
|
|
51
|
+
assert _words(text) == [["x", "--body", body, ";", "y"]]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_should_keep_a_quote_inside_a_double_quoted_substitution_in_its_word() -> None:
|
|
55
|
+
assert _words('x --body "$(echo \'"\' \\\\)" ; y') == [
|
|
56
|
+
["x", "--body", "$(echo '\"' \\\\)", ";", "y"]
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_should_join_a_line_break_inside_a_group_or_substitution_with_a_separator() -> None:
|
|
61
|
+
assert quote_aware_lines("(cd a\ngh pr create)\nx=$(true\nls)") == [
|
|
62
|
+
"(cd a;gh pr create)",
|
|
63
|
+
"x=$(true;ls)",
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_should_drop_comments_and_heredoc_bodies() -> None:
|
|
68
|
+
text = "cat <<'EOF' # note\nit's \"open\nEOF\necho a#b # tail\nls"
|
|
69
|
+
assert quote_aware_lines(text) == ["cat <<'EOF' ", "echo a#b ", "ls"]
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_should_skip_no_lines_after_a_quoted_heredoc_word() -> None:
|
|
73
|
+
assert quote_aware_lines('x --body "a <<EOF"\nls\nEOF') == ['x --body "a <<EOF"', "ls", "EOF"]
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def test_should_keep_an_escaped_substitution_opener_in_one_word() -> None:
|
|
77
|
+
assert _words("echo \\$(ls) ; y") == [["echo", "$(ls)", ";", "y"]]
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def test_should_join_a_line_continuation() -> None:
|
|
81
|
+
assert quote_aware_lines('a \\\nb "c\\\nd"') == ['a b "cd"']
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@pytest.mark.parametrize("text", ['echo "open', "echo 'open", "echo $'open", "x=$(ls", "(ls"])
|
|
85
|
+
def test_should_return_none_for_text_left_open(text: str) -> None:
|
|
86
|
+
assert quote_aware_lines(text) is None
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Behavioral tests for finding wrapped creates the folder walk did not place.
|
|
2
|
+
|
|
3
|
+
bash -c "gh pr create --fill" -> ("--fill",) unless the walk placed it
|
|
4
|
+
--body "$(cat <<'B' ... B)" with a create -> nothing: the heredoc body runs no command
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from blocking.merge_review_gate_parts.wrapped_creates import unplaced_creates
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _unplaced_create_arguments(
|
|
13
|
+
command: str, all_placed_arguments: list[tuple[str, ...]]
|
|
14
|
+
) -> list[tuple[str, ...]]:
|
|
15
|
+
return [each_arguments for each_arguments, _each_words in unplaced_creates(command, all_placed_arguments)]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def test_should_give_each_unplaced_create_the_words_of_the_command_that_runs_it() -> None:
|
|
19
|
+
command = 'bash -c "cd sub && gh -R o/r pr create --repo a/b"'
|
|
20
|
+
assert unplaced_creates(command, []) == [
|
|
21
|
+
(("--repo", "a/b", "-R", "o/r"), ("gh", "-R", "o/r", "pr", "create", "--repo", "a/b"))
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_should_return_a_wrapped_create_the_walk_did_not_place() -> None:
|
|
26
|
+
assert _unplaced_create_arguments('bash -c "cd sub && gh pr create --fill"', []) == [("--fill",)]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_should_return_nothing_for_a_create_the_walk_placed_with_a_quoted_line_break() -> None:
|
|
30
|
+
command = "bash -c \"gh pr create --head one --body 'a\nb'\""
|
|
31
|
+
assert _unplaced_create_arguments(command, [("--head", "one", "--body", "a\nb")]) == []
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_should_not_join_the_next_line_of_a_wrapped_script_to_its_create() -> None:
|
|
35
|
+
assert _unplaced_create_arguments("bash -c 'gh pr create --fill\nls'", [("--fill",)]) == []
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_should_read_no_create_in_a_heredoc_body_inside_a_quoted_substitution() -> None:
|
|
39
|
+
command = (
|
|
40
|
+
'gh pr create --head one --body "$(cat <<\'B\'\nsee "q" ; gh pr create --head two\nB\n)"'
|
|
41
|
+
)
|
|
42
|
+
assert _unplaced_create_arguments(command, [("--head", "one", "--body", "x")]) == []
|