claude-dev-env 8.54.8 → 8.54.9
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.
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
title "docs: ..." -> pass, nothing to prove
|
|
6
6
|
title "fix: ..." changing only docs or .github -> pass, nothing to prove
|
|
7
7
|
title "fix: ..." with no changed Python test -> fail
|
|
8
|
-
title "fix: ..." with no changed Python or
|
|
8
|
+
title "fix: ..." with no changed Python, Node, or plugin test -> fail
|
|
9
9
|
changed test passes on head, fails on base -> pass
|
|
10
10
|
changed test passes on both -> fail
|
|
11
11
|
any changed test fails on head -> fail
|
|
@@ -14,8 +14,10 @@ Python tests reuse the regression gate's detached worktree: the changed test
|
|
|
14
14
|
files are copied onto the base checkout, which runs them with import isolation.
|
|
15
15
|
Node tests (``*.test.mjs``, ``*.test.js``, ``*.test.cjs``) run through
|
|
16
16
|
``node --test`` on the head, then on a detached base checkout that holds a copy
|
|
17
|
-
of the changed test files.
|
|
18
|
-
|
|
17
|
+
of the changed test files. Plugin tests (``*.test.ts``, ``*.test.tsx`` under a
|
|
18
|
+
directory that holds ``.claude-plugin/``) run through ``claude plugin test`` in
|
|
19
|
+
each plugin root on the head, then on the same kind of detached base checkout.
|
|
20
|
+
The fix is proven when at least one language's changed tests fail on the base.
|
|
19
21
|
"""
|
|
20
22
|
|
|
21
23
|
import argparse
|
|
@@ -23,7 +25,9 @@ import shutil
|
|
|
23
25
|
import subprocess
|
|
24
26
|
import sys
|
|
25
27
|
import tempfile
|
|
28
|
+
from collections.abc import Callable
|
|
26
29
|
from enum import Enum
|
|
30
|
+
from functools import partial
|
|
27
31
|
from pathlib import Path
|
|
28
32
|
|
|
29
33
|
from code_rules_gate_parts import staged_test_regression, staged_test_running
|
|
@@ -32,6 +36,8 @@ from code_rules_gate_parts.wrapper_plumb_check import is_test_path
|
|
|
32
36
|
from pr_loop_shared_constants.fix_pr_test_proof_constants import (
|
|
33
37
|
ALL_NODE_TEST_COMMAND,
|
|
34
38
|
ALL_NODE_TEST_SUFFIXES,
|
|
39
|
+
ALL_PLUGIN_TEST_COMMAND,
|
|
40
|
+
ALL_PLUGIN_TEST_SUFFIXES,
|
|
35
41
|
ALL_PRODUCTION_CODE_SUFFIXES,
|
|
36
42
|
CI_CONFIG_DIRECTORY_NAME,
|
|
37
43
|
FAILED_EXIT_CODE,
|
|
@@ -44,6 +50,7 @@ from pr_loop_shared_constants.fix_pr_test_proof_constants import (
|
|
|
44
50
|
NODE_BASE_WORKTREE_TEMP_DIRECTORY_PREFIX,
|
|
45
51
|
NOT_A_FIX_MESSAGE,
|
|
46
52
|
PASSED_EXIT_CODE,
|
|
53
|
+
PLUGIN_MANIFEST_DIRECTORY_NAME,
|
|
47
54
|
PROVEN_MESSAGE,
|
|
48
55
|
WORKTREE_FAILED_MESSAGE,
|
|
49
56
|
)
|
|
@@ -102,6 +109,25 @@ def _changed_node_tests(all_changed_paths: list[Path]) -> list[Path]:
|
|
|
102
109
|
]
|
|
103
110
|
|
|
104
111
|
|
|
112
|
+
def _plugin_root(test_path: Path, repository_root: Path) -> Path | None:
|
|
113
|
+
for each_directory in test_path.parents:
|
|
114
|
+
if (each_directory / PLUGIN_MANIFEST_DIRECTORY_NAME).is_dir():
|
|
115
|
+
return each_directory
|
|
116
|
+
if each_directory == repository_root:
|
|
117
|
+
return None
|
|
118
|
+
return None
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _changed_plugin_tests(all_changed_paths: list[Path], repository_root: Path) -> list[Path]:
|
|
122
|
+
return [
|
|
123
|
+
each_path
|
|
124
|
+
for each_path in all_changed_paths
|
|
125
|
+
if each_path.name.endswith(ALL_PLUGIN_TEST_SUFFIXES)
|
|
126
|
+
and each_path.is_file()
|
|
127
|
+
and _plugin_root(each_path, repository_root) is not None
|
|
128
|
+
]
|
|
129
|
+
|
|
130
|
+
|
|
105
131
|
def _python_proof_verdict(
|
|
106
132
|
all_changed_tests: list[Path], repository_root: Path, base_revision: str
|
|
107
133
|
) -> ProofVerdict:
|
|
@@ -130,7 +156,7 @@ def _python_proof_verdict(
|
|
|
130
156
|
return ProofVerdict.PROVEN
|
|
131
157
|
|
|
132
158
|
|
|
133
|
-
def _node_tests_pass(
|
|
159
|
+
def _node_tests_pass(all_relative_tests: list[Path], working_directory: Path) -> bool:
|
|
134
160
|
node_run = subprocess.run(
|
|
135
161
|
[*ALL_NODE_TEST_COMMAND, *(each_path.as_posix() for each_path in all_relative_tests)],
|
|
136
162
|
cwd=working_directory,
|
|
@@ -141,6 +167,20 @@ def _node_tests_pass(working_directory: Path, all_relative_tests: list[Path]) ->
|
|
|
141
167
|
return node_run.returncode == 0
|
|
142
168
|
|
|
143
169
|
|
|
170
|
+
def _plugin_tests_pass(all_relative_plugin_roots: list[Path], working_directory: Path) -> bool:
|
|
171
|
+
return all(
|
|
172
|
+
subprocess.run(
|
|
173
|
+
ALL_PLUGIN_TEST_COMMAND,
|
|
174
|
+
cwd=working_directory / each_relative_root,
|
|
175
|
+
capture_output=True,
|
|
176
|
+
text=True,
|
|
177
|
+
check=False,
|
|
178
|
+
).returncode
|
|
179
|
+
== 0
|
|
180
|
+
for each_relative_root in all_relative_plugin_roots
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
|
|
144
184
|
def _copy_tests_onto(
|
|
145
185
|
base_worktree: Path, repository_root: Path, all_relative_tests: list[Path]
|
|
146
186
|
) -> None:
|
|
@@ -150,11 +190,14 @@ def _copy_tests_onto(
|
|
|
150
190
|
shutil.copy2(repository_root / each_relative_test, base_test_path)
|
|
151
191
|
|
|
152
192
|
|
|
153
|
-
def
|
|
154
|
-
all_changed_tests: list[Path],
|
|
193
|
+
def _head_and_base_proof_verdict(
|
|
194
|
+
all_changed_tests: list[Path],
|
|
195
|
+
repository_root: Path,
|
|
196
|
+
base_revision: str,
|
|
197
|
+
tests_pass: Callable[[Path], bool],
|
|
155
198
|
) -> ProofVerdict:
|
|
156
199
|
all_relative_tests = [each_path.relative_to(repository_root) for each_path in all_changed_tests]
|
|
157
|
-
if not
|
|
200
|
+
if not tests_pass(repository_root):
|
|
158
201
|
sys.stderr.write(HEAD_FAILURE_MESSAGE.format(group_root=repository_root) + "\n")
|
|
159
202
|
return ProofVerdict.HEAD_FAILED
|
|
160
203
|
with tempfile.TemporaryDirectory(
|
|
@@ -168,7 +211,7 @@ def _node_proof_verdict(
|
|
|
168
211
|
return ProofVerdict.BASE_UNAVAILABLE
|
|
169
212
|
try:
|
|
170
213
|
_copy_tests_onto(base_worktree, repository_root, all_relative_tests)
|
|
171
|
-
passes_on_base =
|
|
214
|
+
passes_on_base = tests_pass(base_worktree)
|
|
172
215
|
finally:
|
|
173
216
|
staged_test_regression._remove_baseline_worktree(repository_root, base_worktree)
|
|
174
217
|
if passes_on_base:
|
|
@@ -177,6 +220,36 @@ def _node_proof_verdict(
|
|
|
177
220
|
return ProofVerdict.PROVEN
|
|
178
221
|
|
|
179
222
|
|
|
223
|
+
def _node_proof_verdict(
|
|
224
|
+
all_changed_tests: list[Path], repository_root: Path, base_revision: str
|
|
225
|
+
) -> ProofVerdict:
|
|
226
|
+
all_relative_tests = [each_path.relative_to(repository_root) for each_path in all_changed_tests]
|
|
227
|
+
return _head_and_base_proof_verdict(
|
|
228
|
+
all_changed_tests,
|
|
229
|
+
repository_root,
|
|
230
|
+
base_revision,
|
|
231
|
+
partial(_node_tests_pass, all_relative_tests),
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def _plugin_proof_verdict(
|
|
236
|
+
all_changed_tests: list[Path], repository_root: Path, base_revision: str
|
|
237
|
+
) -> ProofVerdict:
|
|
238
|
+
all_relative_plugin_roots = sorted(
|
|
239
|
+
{
|
|
240
|
+
each_root.relative_to(repository_root)
|
|
241
|
+
for each_path in all_changed_tests
|
|
242
|
+
if (each_root := _plugin_root(each_path, repository_root)) is not None
|
|
243
|
+
}
|
|
244
|
+
)
|
|
245
|
+
return _head_and_base_proof_verdict(
|
|
246
|
+
all_changed_tests,
|
|
247
|
+
repository_root,
|
|
248
|
+
base_revision,
|
|
249
|
+
partial(_plugin_tests_pass, all_relative_plugin_roots),
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
|
|
180
253
|
def _proof_exit_code(
|
|
181
254
|
all_verdicts: list[ProofVerdict], base_revision: str
|
|
182
255
|
) -> int:
|
|
@@ -213,7 +286,8 @@ def main(all_arguments: list[str]) -> int:
|
|
|
213
286
|
return PASSED_EXIT_CODE
|
|
214
287
|
all_changed_python_tests = _changed_python_tests(all_changed_paths)
|
|
215
288
|
all_changed_node_tests = _changed_node_tests(all_changed_paths)
|
|
216
|
-
|
|
289
|
+
all_changed_plugin_tests = _changed_plugin_tests(all_changed_paths, repository_root)
|
|
290
|
+
if not (all_changed_python_tests or all_changed_node_tests or all_changed_plugin_tests):
|
|
217
291
|
sys.stderr.write(NO_CHANGED_TEST_MESSAGE + "\n")
|
|
218
292
|
return FAILED_EXIT_CODE
|
|
219
293
|
base_revision = parsed_arguments.base_revision
|
|
@@ -226,6 +300,10 @@ def main(all_arguments: list[str]) -> int:
|
|
|
226
300
|
all_verdicts.append(
|
|
227
301
|
_node_proof_verdict(all_changed_node_tests, repository_root, base_revision)
|
|
228
302
|
)
|
|
303
|
+
if all_changed_plugin_tests:
|
|
304
|
+
all_verdicts.append(
|
|
305
|
+
_plugin_proof_verdict(all_changed_plugin_tests, repository_root, base_revision)
|
|
306
|
+
)
|
|
229
307
|
return _proof_exit_code(all_verdicts, base_revision)
|
|
230
308
|
|
|
231
309
|
|
|
@@ -17,6 +17,9 @@ ALL_PRODUCTION_CODE_SUFFIXES: tuple[str, ...] = (
|
|
|
17
17
|
)
|
|
18
18
|
ALL_NODE_TEST_SUFFIXES: tuple[str, ...] = (".test.mjs", ".test.js", ".test.cjs")
|
|
19
19
|
ALL_NODE_TEST_COMMAND: tuple[str, ...] = ("node", "--test")
|
|
20
|
+
ALL_PLUGIN_TEST_SUFFIXES: tuple[str, ...] = (".test.ts", ".test.tsx")
|
|
21
|
+
ALL_PLUGIN_TEST_COMMAND: tuple[str, ...] = ("claude", "plugin", "test", ".")
|
|
22
|
+
PLUGIN_MANIFEST_DIRECTORY_NAME: str = ".claude-plugin"
|
|
20
23
|
NODE_BASE_WORKTREE_TEMP_DIRECTORY_PREFIX: str = "fix_pr_test_proof_node_base_"
|
|
21
24
|
NODE_BASE_WORKTREE_DIRECTORY_NAME: str = "tree"
|
|
22
25
|
CI_CONFIG_DIRECTORY_NAME: str = ".github"
|
|
@@ -28,7 +31,7 @@ NO_PRODUCTION_CHANGE_MESSAGE: str = (
|
|
|
28
31
|
"fix_pr_test_proof: the fix changes no production code; nothing to prove."
|
|
29
32
|
)
|
|
30
33
|
NO_CHANGED_TEST_MESSAGE: str = (
|
|
31
|
-
"fix_pr_test_proof: this fix changes production code and no Python or
|
|
34
|
+
"fix_pr_test_proof: this fix changes production code and no Python, Node, or plugin test. "
|
|
32
35
|
"Add a test that fails on the base and passes on the head."
|
|
33
36
|
)
|
|
34
37
|
WORKTREE_FAILED_MESSAGE: str = (
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""Behavioral tests for the fix pull request test-proof check.
|
|
2
2
|
|
|
3
|
-
Every case drives a git repository under ``tmp_path`` and a pytest
|
|
4
|
-
``node --test`` subprocess, the same shape the CI job runs.
|
|
3
|
+
Every case drives a git repository under ``tmp_path`` and a pytest,
|
|
4
|
+
``node --test``, or ``claude plugin test`` subprocess, the same shape the CI job runs.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
7
|
from pathlib import Path
|
|
@@ -39,6 +39,25 @@ NODE_ALWAYS_PASSING_TEST_TEXT = (
|
|
|
39
39
|
"import { test } from 'node:test';\n\n"
|
|
40
40
|
"test('nothing in particular', () => {});\n"
|
|
41
41
|
)
|
|
42
|
+
PLUGIN_MANIFEST_TEXT = '{"name": "calc"}\n'
|
|
43
|
+
PLUGIN_HOOKS_TEXT = '{ "modules": ["./index.ts"] }\n'
|
|
44
|
+
BUGGY_PLUGIN_PRODUCTION_TEXT = (
|
|
45
|
+
"export function add(left: number, right: number): number {\n"
|
|
46
|
+
" return left - right\n}\n"
|
|
47
|
+
)
|
|
48
|
+
FIXED_PLUGIN_PRODUCTION_TEXT = (
|
|
49
|
+
"export function add(left: number, right: number): number {\n"
|
|
50
|
+
" return left + right\n}\n"
|
|
51
|
+
)
|
|
52
|
+
PLUGIN_PROOF_TEST_TEXT = (
|
|
53
|
+
"import { test, expect } from 'claude-code/testing'\n"
|
|
54
|
+
"import { add } from '../hooks/index'\n\n"
|
|
55
|
+
"test('add sums both operands', () => {\n expect(add(1, 2)).toBe(3)\n})\n"
|
|
56
|
+
)
|
|
57
|
+
PLUGIN_ALWAYS_PASSING_TEST_TEXT = (
|
|
58
|
+
"import { test, expect } from 'claude-code/testing'\n\n"
|
|
59
|
+
"test('nothing in particular', () => {\n expect(1).toBe(1)\n})\n"
|
|
60
|
+
)
|
|
42
61
|
|
|
43
62
|
|
|
44
63
|
def _commit_files(repository_root: Path, all_file_texts: dict[str, str]) -> None:
|
|
@@ -66,6 +85,19 @@ def _repository_at_buggy_node_base(tmp_path: Path) -> tuple[Path, str]:
|
|
|
66
85
|
return repository_root, _head_revision(repository_root)
|
|
67
86
|
|
|
68
87
|
|
|
88
|
+
def _repository_at_buggy_plugin_base(tmp_path: Path) -> tuple[Path, str]:
|
|
89
|
+
repository_root = repository_with_root_pytest_config(tmp_path)
|
|
90
|
+
_commit_files(
|
|
91
|
+
repository_root,
|
|
92
|
+
{
|
|
93
|
+
"plugins/calc/.claude-plugin/plugin.json": PLUGIN_MANIFEST_TEXT,
|
|
94
|
+
"plugins/calc/hooks/hooks.json": PLUGIN_HOOKS_TEXT,
|
|
95
|
+
"plugins/calc/hooks/index.ts": BUGGY_PLUGIN_PRODUCTION_TEXT,
|
|
96
|
+
},
|
|
97
|
+
)
|
|
98
|
+
return repository_root, _head_revision(repository_root)
|
|
99
|
+
|
|
100
|
+
|
|
69
101
|
def _run_check(repository_root: Path, title: str, base_revision: str) -> int:
|
|
70
102
|
return fix_pr_test_proof.main(
|
|
71
103
|
[
|
|
@@ -100,7 +132,7 @@ def test_a_fix_with_no_changed_test_fails(
|
|
|
100
132
|
_commit_files(repository_root, {"pkg/calc.py": FIXED_PRODUCTION_TEXT})
|
|
101
133
|
|
|
102
134
|
assert _run_check(repository_root, "fix: sum operands", base_revision) == 1
|
|
103
|
-
assert "no Python or
|
|
135
|
+
assert "no Python, Node, or plugin test" in capsys.readouterr().err
|
|
104
136
|
|
|
105
137
|
|
|
106
138
|
def test_a_fix_whose_test_fails_on_base_and_passes_on_head_passes(
|
|
@@ -186,6 +218,64 @@ def test_a_node_fix_whose_changed_test_fails_on_head_fails(
|
|
|
186
218
|
assert "fails on the head" in capsys.readouterr().err
|
|
187
219
|
|
|
188
220
|
|
|
221
|
+
def test_a_plugin_fix_with_no_changed_test_fails(
|
|
222
|
+
tmp_path: Path, capsys: pytest.CaptureFixture[str]
|
|
223
|
+
) -> None:
|
|
224
|
+
repository_root, base_revision = _repository_at_buggy_plugin_base(tmp_path)
|
|
225
|
+
_commit_files(repository_root, {"plugins/calc/hooks/index.ts": FIXED_PLUGIN_PRODUCTION_TEXT})
|
|
226
|
+
|
|
227
|
+
assert _run_check(repository_root, "fix(calc): sum operands", base_revision) == 1
|
|
228
|
+
assert "no Python, Node, or plugin test" in capsys.readouterr().err
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def test_a_plugin_fix_whose_test_fails_on_base_and_passes_on_head_passes(
|
|
232
|
+
tmp_path: Path, capsys: pytest.CaptureFixture[str]
|
|
233
|
+
) -> None:
|
|
234
|
+
repository_root, base_revision = _repository_at_buggy_plugin_base(tmp_path)
|
|
235
|
+
_commit_files(
|
|
236
|
+
repository_root,
|
|
237
|
+
{
|
|
238
|
+
"plugins/calc/hooks/index.ts": FIXED_PLUGIN_PRODUCTION_TEXT,
|
|
239
|
+
"plugins/calc/tests/calc.test.ts": PLUGIN_PROOF_TEST_TEXT,
|
|
240
|
+
},
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
assert _run_check(repository_root, "fix(calc): sum operands", base_revision) == 0
|
|
244
|
+
assert "fail on the base and pass on the head" in capsys.readouterr().out
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def test_a_plugin_fix_whose_changed_test_also_passes_on_base_fails(
|
|
248
|
+
tmp_path: Path, capsys: pytest.CaptureFixture[str]
|
|
249
|
+
) -> None:
|
|
250
|
+
repository_root, base_revision = _repository_at_buggy_plugin_base(tmp_path)
|
|
251
|
+
_commit_files(
|
|
252
|
+
repository_root,
|
|
253
|
+
{
|
|
254
|
+
"plugins/calc/hooks/index.ts": FIXED_PLUGIN_PRODUCTION_TEXT,
|
|
255
|
+
"plugins/calc/tests/calc.test.ts": PLUGIN_ALWAYS_PASSING_TEST_TEXT,
|
|
256
|
+
},
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
assert _run_check(repository_root, "fix(calc): sum operands", base_revision) == 1
|
|
260
|
+
assert "passes on the base" in capsys.readouterr().err
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def test_a_plugin_fix_whose_changed_test_fails_on_head_fails(
|
|
264
|
+
tmp_path: Path, capsys: pytest.CaptureFixture[str]
|
|
265
|
+
) -> None:
|
|
266
|
+
repository_root, base_revision = _repository_at_buggy_plugin_base(tmp_path)
|
|
267
|
+
_commit_files(
|
|
268
|
+
repository_root,
|
|
269
|
+
{
|
|
270
|
+
"plugins/calc/tests/calc.test.ts": PLUGIN_PROOF_TEST_TEXT,
|
|
271
|
+
"plugins/calc/hooks/extra.ts": "export const VALUE = 1\n",
|
|
272
|
+
},
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
assert _run_check(repository_root, "fix(calc): sum operands", base_revision) == 1
|
|
276
|
+
assert "fails on the head" in capsys.readouterr().err
|
|
277
|
+
|
|
278
|
+
|
|
189
279
|
BUGGY_GREETING_TEXT = 'def greet() -> str:\n return "helo"\n'
|
|
190
280
|
FIXED_GREETING_TEXT = 'def greet() -> str:\n return "hello"\n'
|
|
191
281
|
GREETING_TEST_TEXT = (
|
|
@@ -222,7 +312,7 @@ def test_a_fix_without_its_own_test_fails_when_the_base_branch_moved_with_a_test
|
|
|
222
312
|
)
|
|
223
313
|
|
|
224
314
|
assert _run_check(repository_root, "fix: sum operands", MERGE_REF_FIRST_PARENT) == 1
|
|
225
|
-
assert "no Python or
|
|
315
|
+
assert "no Python, Node, or plugin test" in capsys.readouterr().err
|
|
226
316
|
|
|
227
317
|
|
|
228
318
|
def test_a_fix_on_a_moved_base_branch_judges_only_its_own_test(
|