claude-dev-env 8.109.4 → 8.109.6
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/review-loop-before-merge.md +2 -0
- package/docs/rule-guides/proof-before-pull-request.md +1 -1
- package/hooks/blocking/merge_review_gate.py +2 -1
- package/hooks/blocking/merge_review_gate_parts/open_request.py +52 -6
- package/hooks/blocking/merge_review_gate_parts/receipts.py +101 -15
- package/hooks/blocking/pull_request_proof.py +98 -14
- package/hooks/blocking/test_merge_review_gate.py +130 -3
- package/hooks/blocking/test_pull_request_proof.py +161 -10
- package/hooks/blocking/tests/test_open_request.py +195 -5
- package/hooks/blocking/tests/test_receipts.py +95 -2
- package/hooks/features/conduct-gates.md +3 -3
- package/hooks/hooks.json +1 -1
- package/hooks/hooks_constants/merge_review_gate_constants.py +24 -5
- package/hooks/hooks_constants/pull_request_proof_constants.py +11 -1
- package/package.json +1 -1
- package/scripts/merge_review_receipt.py +153 -21
- package/scripts/test_merge_review_receipt.py +168 -0
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"""Behavior tests for the clean-review merge gate."""
|
|
2
2
|
|
|
3
|
+
import io
|
|
4
|
+
import os
|
|
3
5
|
import subprocess
|
|
4
6
|
import sys
|
|
5
7
|
from pathlib import Path
|
|
@@ -25,9 +27,22 @@ def receipt_folder(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
|
|
|
25
27
|
monkeypatch.setenv("CLAUDE_MERGE_REVIEW_RECEIPT_DIR", str(tmp_path))
|
|
26
28
|
monkeypatch.delenv("CLAUDE_MERGE_REVIEW_EXEMPT_REPOSITORIES", raising=False)
|
|
27
29
|
monkeypatch.delenv("CLAUDE_MERGE_REVIEW_COMMAND", raising=False)
|
|
30
|
+
remotes = tmp_path / "github.com"
|
|
31
|
+
subprocess.run(
|
|
32
|
+
["git", "init", "--quiet", "--bare", str(remotes / "acme" / "tools.git")], check=True
|
|
33
|
+
)
|
|
34
|
+
index = int(os.environ.get("GIT_CONFIG_COUNT", "0"))
|
|
35
|
+
monkeypatch.setenv("GIT_CONFIG_COUNT", str(index + 1))
|
|
36
|
+
monkeypatch.setenv(f"GIT_CONFIG_KEY_{index}", f"url.{remotes}/.insteadOf")
|
|
37
|
+
monkeypatch.setenv(f"GIT_CONFIG_VALUE_{index}", "https://github.com/")
|
|
28
38
|
return tmp_path
|
|
29
39
|
|
|
30
40
|
|
|
41
|
+
@pytest.fixture
|
|
42
|
+
def github_repository(receipt_folder: Path) -> Path:
|
|
43
|
+
return receipt_folder / "github.com" / "acme" / "tools.git"
|
|
44
|
+
|
|
45
|
+
|
|
31
46
|
def _merge_tool(head: str | None = None) -> dict[str, object]:
|
|
32
47
|
tool_input: dict[str, object] = {"owner": "acme", "repo": "tools", "pullNumber": 12}
|
|
33
48
|
if head is not None:
|
|
@@ -210,7 +225,7 @@ def _git(folder: Path, *all_arguments: str) -> str:
|
|
|
210
225
|
|
|
211
226
|
|
|
212
227
|
@pytest.fixture
|
|
213
|
-
def branch_checkout(tmp_path: Path) -> tuple[Path, str]:
|
|
228
|
+
def branch_checkout(tmp_path: Path, github_repository: Path) -> tuple[Path, str]:
|
|
214
229
|
folder = tmp_path / "checkout"
|
|
215
230
|
folder.mkdir()
|
|
216
231
|
_git(folder, "init", "--quiet", "--initial-branch", "main")
|
|
@@ -228,9 +243,50 @@ def branch_checkout(tmp_path: Path) -> tuple[Path, str]:
|
|
|
228
243
|
"-m",
|
|
229
244
|
"first",
|
|
230
245
|
)
|
|
246
|
+
_git(folder, "push", "--quiet", str(github_repository), "feature")
|
|
231
247
|
return folder, _git(folder, "rev-parse", "HEAD")
|
|
232
248
|
|
|
233
249
|
|
|
250
|
+
@pytest.fixture
|
|
251
|
+
def ruled_checkout(
|
|
252
|
+
branch_checkout: tuple[Path, str], github_repository: Path, monkeypatch: pytest.MonkeyPatch
|
|
253
|
+
) -> tuple[Path, str]:
|
|
254
|
+
folder, _head = branch_checkout
|
|
255
|
+
(folder / "a.py").write_text("one\n", encoding="utf-8")
|
|
256
|
+
(folder / "b.py").write_text("one\ntwo\n", encoding="utf-8")
|
|
257
|
+
_git(folder, "add", "a.py", "b.py")
|
|
258
|
+
_git(
|
|
259
|
+
folder,
|
|
260
|
+
"-c",
|
|
261
|
+
"user.name=t",
|
|
262
|
+
"-c",
|
|
263
|
+
"user.email=t@example.com",
|
|
264
|
+
"commit",
|
|
265
|
+
"--quiet",
|
|
266
|
+
"-m",
|
|
267
|
+
"files",
|
|
268
|
+
)
|
|
269
|
+
_git(folder, "push", "--quiet", str(github_repository), "feature")
|
|
270
|
+
monkeypatch.chdir(folder)
|
|
271
|
+
return folder, _git(folder, "rev-parse", "HEAD")
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def _record_open_pass(head: str, findings: int, ruled_out: int, rulings: str) -> None:
|
|
275
|
+
merge_review_receipt.main(
|
|
276
|
+
[
|
|
277
|
+
"acme/tools",
|
|
278
|
+
"open",
|
|
279
|
+
head,
|
|
280
|
+
str(findings),
|
|
281
|
+
"--ruled-out",
|
|
282
|
+
str(ruled_out),
|
|
283
|
+
"--rulings",
|
|
284
|
+
rulings,
|
|
285
|
+
],
|
|
286
|
+
io.StringIO(),
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
|
|
234
290
|
def _create_tool(folder: Path, head: str = "feature") -> dict[str, object]:
|
|
235
291
|
return {
|
|
236
292
|
"tool_name": "mcp__github__create_pull_request",
|
|
@@ -248,6 +304,24 @@ def test_should_deny_a_pull_request_open_with_no_review(branch_checkout: tuple[P
|
|
|
248
304
|
reason = _reason(_create_tool(folder))
|
|
249
305
|
assert f"no clean review for head {head}" in reason
|
|
250
306
|
assert f"acme/tools open {head} 0" in reason
|
|
307
|
+
assert "--ruled-out" in reason
|
|
308
|
+
assert "--rulings" in reason
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def test_should_allow_a_pull_request_open_whose_findings_are_ruled_out_at_file_and_line(
|
|
312
|
+
ruled_checkout: tuple[Path, str],
|
|
313
|
+
) -> None:
|
|
314
|
+
folder, head = ruled_checkout
|
|
315
|
+
_record_open_pass(head, 2, 2, "a.py:1,b.py:2")
|
|
316
|
+
assert _reason(_create_tool(folder)) is None
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
def test_should_deny_a_pull_request_open_whose_rulings_leave_a_finding_unproven(
|
|
320
|
+
ruled_checkout: tuple[Path, str],
|
|
321
|
+
) -> None:
|
|
322
|
+
folder, head = ruled_checkout
|
|
323
|
+
_record_open_pass(head, 3, 2, "a.py:1,b.py:2")
|
|
324
|
+
assert "no clean review" in _reason(_create_tool(folder))
|
|
251
325
|
|
|
252
326
|
|
|
253
327
|
def test_should_allow_a_pull_request_open_reviewed_clean_at_its_head(
|
|
@@ -299,6 +373,27 @@ def test_should_deny_a_pull_request_open_whose_head_cannot_be_read(tmp_path: Pat
|
|
|
299
373
|
assert "names no repository or head commit" in reason
|
|
300
374
|
|
|
301
375
|
|
|
376
|
+
def test_should_read_the_pushed_head_of_a_branch_outside_any_checkout(
|
|
377
|
+
branch_checkout: tuple[Path, str], tmp_path: Path
|
|
378
|
+
) -> None:
|
|
379
|
+
_folder, head = branch_checkout
|
|
380
|
+
outside = tmp_path / "outside"
|
|
381
|
+
outside.mkdir()
|
|
382
|
+
assert f"no clean review for head {head}" in _reason(_create_tool(outside))
|
|
383
|
+
merge_review_receipt.record_open_review("acme/tools", head, 0)
|
|
384
|
+
assert _reason(_create_tool(outside)) is None
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def test_should_read_the_checkout_head_when_github_lists_no_such_repository(
|
|
388
|
+
branch_checkout: tuple[Path, str],
|
|
389
|
+
) -> None:
|
|
390
|
+
folder, head = branch_checkout
|
|
391
|
+
merge_review_receipt.record_open_review("acme/ghost", head, 0)
|
|
392
|
+
unlisted_create = _create_tool(folder)
|
|
393
|
+
unlisted_create["tool_input"]["repo"] = "ghost"
|
|
394
|
+
assert _reason(unlisted_create) is None
|
|
395
|
+
|
|
396
|
+
|
|
302
397
|
def test_should_allow_a_pull_request_open_in_an_exempt_repository(
|
|
303
398
|
branch_checkout: tuple[Path, str], monkeypatch: pytest.MonkeyPatch
|
|
304
399
|
) -> None:
|
|
@@ -314,6 +409,14 @@ def test_should_allow_a_merge_pinned_to_the_head_reviewed_clean_before_open() ->
|
|
|
314
409
|
assert _reason(_bash(command)) is None
|
|
315
410
|
|
|
316
411
|
|
|
412
|
+
def test_should_deny_a_merge_pinned_to_a_head_whose_open_pass_only_ruled_findings_out(
|
|
413
|
+
ruled_checkout: tuple[Path, str],
|
|
414
|
+
) -> None:
|
|
415
|
+
_folder, head = ruled_checkout
|
|
416
|
+
_record_open_pass(head, 2, 2, "a.py:1,b.py:2")
|
|
417
|
+
assert "no clean review" in _reason(_merge_tool(head))
|
|
418
|
+
|
|
419
|
+
|
|
317
420
|
def test_should_deny_a_merge_pinned_past_the_head_reviewed_before_open() -> None:
|
|
318
421
|
merge_review_receipt.record_open_review("acme/tools", CLEAN_HEAD, 0)
|
|
319
422
|
assert "no clean review" in _reason(_merge_tool(NEW_HEAD))
|
|
@@ -360,7 +463,7 @@ def test_should_check_a_merge_chained_after_a_reviewed_open(
|
|
|
360
463
|
|
|
361
464
|
|
|
362
465
|
def test_should_read_the_pushed_branch_before_the_local_one(
|
|
363
|
-
branch_checkout: tuple[Path, str],
|
|
466
|
+
branch_checkout: tuple[Path, str], github_repository: Path
|
|
364
467
|
) -> None:
|
|
365
468
|
folder, local_head = branch_checkout
|
|
366
469
|
_git(
|
|
@@ -376,12 +479,36 @@ def test_should_read_the_pushed_branch_before_the_local_one(
|
|
|
376
479
|
"pushed",
|
|
377
480
|
)
|
|
378
481
|
pushed_head = _git(folder, "rev-parse", "HEAD")
|
|
379
|
-
_git(folder, "
|
|
482
|
+
_git(folder, "push", "--quiet", str(github_repository), "HEAD:feature")
|
|
380
483
|
_git(folder, "reset", "--quiet", "--hard", local_head)
|
|
381
484
|
merge_review_receipt.record_open_review("acme/tools", local_head, 0)
|
|
382
485
|
assert f"head {pushed_head}" in _reason(_create_tool(folder))
|
|
383
486
|
|
|
384
487
|
|
|
488
|
+
def test_should_read_the_fetched_branch_before_the_local_one_for_a_shell_open(
|
|
489
|
+
branch_checkout: tuple[Path, str],
|
|
490
|
+
) -> None:
|
|
491
|
+
folder, local_head = branch_checkout
|
|
492
|
+
_git(
|
|
493
|
+
folder,
|
|
494
|
+
"-c",
|
|
495
|
+
"user.name=t",
|
|
496
|
+
"-c",
|
|
497
|
+
"user.email=t@example.com",
|
|
498
|
+
"commit",
|
|
499
|
+
"--quiet",
|
|
500
|
+
"--allow-empty",
|
|
501
|
+
"-m",
|
|
502
|
+
"fetched",
|
|
503
|
+
)
|
|
504
|
+
fetched_head = _git(folder, "rev-parse", "HEAD")
|
|
505
|
+
_git(folder, "update-ref", "refs/remotes/origin/feature", fetched_head)
|
|
506
|
+
_git(folder, "reset", "--quiet", "--hard", local_head)
|
|
507
|
+
merge_review_receipt.record_open_review("acme/tools", local_head, 0)
|
|
508
|
+
command = "gh pr create --repo acme/tools --head feature"
|
|
509
|
+
assert f"head {fetched_head}" in _reason(_bash_in(folder, command))
|
|
510
|
+
|
|
511
|
+
|
|
385
512
|
def test_should_not_match_an_open_receipt_on_a_short_pinned_head() -> None:
|
|
386
513
|
merge_review_receipt.record_open_review("acme/tools", CLEAN_HEAD, 0)
|
|
387
514
|
assert "no clean review" in _reason(_merge_tool(CLEAN_HEAD[:3]))
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Behavior tests for the proof-in-practice, existing-work and eval checks on a new pull request."""
|
|
2
2
|
|
|
3
|
+
import json
|
|
3
4
|
import subprocess
|
|
4
5
|
import sys
|
|
5
6
|
from pathlib import Path
|
|
@@ -13,6 +14,7 @@ if str(HOOKS_DIRECTORY) not in sys.path:
|
|
|
13
14
|
from blocking import pull_request_proof as gate
|
|
14
15
|
from hooks_constants.pull_request_proof_constants import (
|
|
15
16
|
COMPARE_FILE_LIST_LIMIT,
|
|
17
|
+
COMPARE_FILE_STATUS_QUERY,
|
|
16
18
|
DEFERRED_PROOF_REASON,
|
|
17
19
|
MISSING_BODY_REASON,
|
|
18
20
|
MISSING_EVAL_SECTION_REASON,
|
|
@@ -347,7 +349,7 @@ def test_other_pull_request_commands_should_pass_the_existing_work_check() -> No
|
|
|
347
349
|
def _repository_with_change(tmp_path: Path, changed_file_name: str) -> Path:
|
|
348
350
|
origin_path = tmp_path / "origin"
|
|
349
351
|
clone_path = tmp_path / "clone"
|
|
350
|
-
git_identity = ["-c", "user.name=t", "-c", "user.email=t@example.com"]
|
|
352
|
+
git_identity = ["-c", "user.name=t", "-c", "user.email=t@example.com", "-c", "commit.gpgsign=false"]
|
|
351
353
|
subprocess.run(["git", "init", "-q", "-b", "main", str(origin_path)], check=True)
|
|
352
354
|
(origin_path / "readme.md").write_text("base\n", encoding="utf-8")
|
|
353
355
|
subprocess.run(["git", "-C", str(origin_path), "add", "."], check=True)
|
|
@@ -397,6 +399,10 @@ def test_should_deny_when_git_cannot_read_the_branch_and_proof_shows_no_picture(
|
|
|
397
399
|
assert gate.missing_look_reason(payload) == UNREADABLE_CHANGES_REASON
|
|
398
400
|
|
|
399
401
|
|
|
402
|
+
def _compare_line(status: str, old_path: str, path: str) -> str:
|
|
403
|
+
return json.dumps([status, old_path, path], separators=(",", ":"), ensure_ascii=False)
|
|
404
|
+
|
|
405
|
+
|
|
400
406
|
def _fake_gh_api(all_responses: dict[str, list[str] | None], all_endpoints: list[str]):
|
|
401
407
|
def fake_gh_api_lines(endpoint: str, query: str) -> list[str] | None:
|
|
402
408
|
all_endpoints.append(endpoint)
|
|
@@ -416,7 +422,7 @@ def test_should_allow_a_python_only_change_the_compare_api_lists_when_git_cannot
|
|
|
416
422
|
) -> None:
|
|
417
423
|
all_endpoints: list[str] = []
|
|
418
424
|
compare_endpoint = "repos/o/r/compare/main...feature"
|
|
419
|
-
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api({compare_endpoint: ["tool.py"]}, all_endpoints))
|
|
425
|
+
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api({compare_endpoint: [_compare_line("M", "", "tool.py")]}, all_endpoints))
|
|
420
426
|
payload = _shell_create_elsewhere(tmp_path, "--repo o/r --base main --head feature")
|
|
421
427
|
assert gate.missing_look_reason(payload) is None
|
|
422
428
|
assert all_endpoints == [compare_endpoint]
|
|
@@ -425,7 +431,7 @@ def test_should_allow_a_python_only_change_the_compare_api_lists_when_git_cannot
|
|
|
425
431
|
def test_should_deny_a_page_change_the_compare_api_lists_without_a_picture(
|
|
426
432
|
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
427
433
|
) -> None:
|
|
428
|
-
all_responses = {"repos/o/r": ["trunk"], "repos/o/r/compare/trunk...feature": ["web/page.html", "tool.py"]}
|
|
434
|
+
all_responses = {"repos/o/r": ["trunk"], "repos/o/r/compare/trunk...feature": [_compare_line("M", "", "web/page.html"), _compare_line("M", "", "tool.py")]}
|
|
429
435
|
all_endpoints: list[str] = []
|
|
430
436
|
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api(all_responses, all_endpoints))
|
|
431
437
|
reason = gate.missing_look_reason(_shell_create_elsewhere(tmp_path, "-R o/r --head=feature"))
|
|
@@ -435,6 +441,151 @@ def test_should_deny_a_page_change_the_compare_api_lists_without_a_picture(
|
|
|
435
441
|
assert all_endpoints == ["repos/o/r", "repos/o/r/compare/trunk...feature"]
|
|
436
442
|
|
|
437
443
|
|
|
444
|
+
def _repository_with_rename(
|
|
445
|
+
tmp_path: Path,
|
|
446
|
+
edited_text: str | None,
|
|
447
|
+
old_name: str = "asset-specs.html",
|
|
448
|
+
new_name: str = "references/asset-specs.html",
|
|
449
|
+
reorder_lines: bool = False,
|
|
450
|
+
) -> Path:
|
|
451
|
+
origin_path = tmp_path / "origin"
|
|
452
|
+
clone_path = tmp_path / "clone"
|
|
453
|
+
git_identity = ["-c", "user.name=t", "-c", "user.email=t@example.com", "-c", "commit.gpgsign=false"]
|
|
454
|
+
all_page_lines = [f"page body line {each_index}\n" for each_index in range(20)]
|
|
455
|
+
page_text = "".join(all_page_lines)
|
|
456
|
+
subprocess.run(["git", "init", "-q", "-b", "main", str(origin_path)], check=True)
|
|
457
|
+
(origin_path / old_name).write_text(page_text, encoding="utf-8")
|
|
458
|
+
subprocess.run(["git", "-C", str(origin_path), "add", "."], check=True)
|
|
459
|
+
subprocess.run(["git", "-C", str(origin_path), *git_identity, "commit", "-q", "-m", "base"], check=True)
|
|
460
|
+
subprocess.run(["git", "clone", "-q", str(origin_path), str(clone_path)], check=True)
|
|
461
|
+
subprocess.run(["git", "-C", str(clone_path), "checkout", "-q", "-b", "feature"], check=True)
|
|
462
|
+
(clone_path / new_name).parent.mkdir(exist_ok=True)
|
|
463
|
+
subprocess.run(["git", "-C", str(clone_path), "mv", old_name, new_name], check=True)
|
|
464
|
+
moved_text = "".join(reversed(all_page_lines)) if reorder_lines else page_text
|
|
465
|
+
if edited_text is not None or reorder_lines:
|
|
466
|
+
(clone_path / new_name).write_text(moved_text + (edited_text or ""), encoding="utf-8")
|
|
467
|
+
subprocess.run(["git", "-C", str(clone_path), "add", "."], check=True)
|
|
468
|
+
subprocess.run(["git", "-C", str(clone_path), *git_identity, "commit", "-q", "-m", "move"], check=True)
|
|
469
|
+
return clone_path
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
def test_should_allow_a_pure_html_rename_without_a_picture(tmp_path: Path) -> None:
|
|
473
|
+
clone_path = _repository_with_rename(tmp_path, None)
|
|
474
|
+
assert gate.visible_changed_files(str(clone_path), "feature") == []
|
|
475
|
+
assert gate.missing_look_reason(_mcp_create_on_branch(PROVEN_BODY, clone_path)) is None
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
def test_should_deny_an_html_rename_that_also_edits_the_page(tmp_path: Path) -> None:
|
|
479
|
+
clone_path = _repository_with_rename(tmp_path, "<p>new line</p>\n")
|
|
480
|
+
assert gate.visible_changed_files(str(clone_path), "feature") == ["references/asset-specs.html"]
|
|
481
|
+
reason = gate.missing_look_reason(_mcp_create_on_branch(PROVEN_BODY, clone_path))
|
|
482
|
+
assert reason is not None
|
|
483
|
+
assert "references/asset-specs.html" in reason
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
def _stub_compare(monkeypatch: pytest.MonkeyPatch, all_lines: list[str]) -> None:
|
|
487
|
+
compare_endpoint = "repos/o/r/compare/main...feature"
|
|
488
|
+
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api({compare_endpoint: all_lines}, []))
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
def test_should_allow_a_compare_page_that_lists_a_pure_html_rename(
|
|
492
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
493
|
+
) -> None:
|
|
494
|
+
_stub_compare(monkeypatch, [_compare_line("R100", "asset-specs.html", "references/asset-specs.html"), _compare_line("added", "", "tool.py")])
|
|
495
|
+
assert gate.remote_visible_changed_files("o/r", "main", "feature") == []
|
|
496
|
+
assert gate.missing_look_reason(_shell_create_elsewhere(tmp_path, "--repo o/r --base main --head feature")) is None
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
def test_should_keep_a_compare_listed_pure_rename_from_a_hidden_suffix_to_a_page(
|
|
500
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
501
|
+
) -> None:
|
|
502
|
+
_stub_compare(monkeypatch, [_compare_line("R100", "notes.txt", "site/notes.html")])
|
|
503
|
+
assert gate.remote_visible_changed_files("o/r", "main", "feature") == ["site/notes.html"]
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
def test_should_deny_a_compare_page_that_lists_an_html_rename_with_an_edit(
|
|
507
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
508
|
+
) -> None:
|
|
509
|
+
_stub_compare(monkeypatch, [_compare_line("renamed", "asset-specs.html", "references/asset-specs.html")])
|
|
510
|
+
reason = gate.missing_look_reason(_shell_create_elsewhere(tmp_path, "--repo o/r --base main --head feature"))
|
|
511
|
+
assert reason is not None
|
|
512
|
+
assert "references/asset-specs.html" in reason
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
def test_should_deny_as_unreadable_when_a_full_compare_page_lists_only_pure_renames(
|
|
516
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
517
|
+
) -> None:
|
|
518
|
+
all_lines = [
|
|
519
|
+
_compare_line("R100", f"old/skill_{each_index}/page.html", f"skills/skill_{each_index}/page.html")
|
|
520
|
+
for each_index in range(COMPARE_FILE_LIST_LIMIT)
|
|
521
|
+
]
|
|
522
|
+
_stub_compare(monkeypatch, all_lines)
|
|
523
|
+
assert gate.remote_visible_changed_files("o/r", "main", "feature") is None
|
|
524
|
+
payload = _shell_create_elsewhere(tmp_path, "--repo o/r --base main --head feature")
|
|
525
|
+
assert gate.missing_look_reason(payload) == UNREADABLE_CHANGES_REASON
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
def test_compare_query_should_label_each_file_by_whether_a_rename_changed_it() -> None:
|
|
529
|
+
all_files = {
|
|
530
|
+
"files": [
|
|
531
|
+
{"status": "renamed", "changes": 0, "previous_filename": "a/x.html", "filename": "b/x.html"},
|
|
532
|
+
{"status": "renamed", "changes": 3, "previous_filename": "a/y.html", "filename": "b/y.html"},
|
|
533
|
+
{"status": "added", "changes": 5, "filename": "c.py"},
|
|
534
|
+
{"status": "modified", "changes": 2, "filename": "we\tird\nname.html"},
|
|
535
|
+
]
|
|
536
|
+
}
|
|
537
|
+
completed = subprocess.run(
|
|
538
|
+
["jq", "-r", COMPARE_FILE_STATUS_QUERY],
|
|
539
|
+
input=json.dumps(all_files),
|
|
540
|
+
capture_output=True,
|
|
541
|
+
text=True,
|
|
542
|
+
check=True,
|
|
543
|
+
)
|
|
544
|
+
assert completed.stdout.splitlines() == [
|
|
545
|
+
_compare_line("R100", "a/x.html", "b/x.html"),
|
|
546
|
+
_compare_line("renamed", "a/y.html", "b/y.html"),
|
|
547
|
+
_compare_line("added", "", "c.py"),
|
|
548
|
+
_compare_line("modified", "", "we\tird\nname.html"),
|
|
549
|
+
]
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
def test_should_report_an_unparseable_compare_line_as_unknown(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
553
|
+
_stub_compare(monkeypatch, ["not json"])
|
|
554
|
+
assert gate.remote_visible_changed_files("o/r", "main", "feature") is None
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
def test_should_deny_a_byte_identical_rename_from_a_hidden_suffix_to_a_page(tmp_path: Path) -> None:
|
|
558
|
+
clone_path = _repository_with_rename(tmp_path, None, "notes.txt", "site/notes.html")
|
|
559
|
+
assert gate.visible_changed_files(str(clone_path), "feature") == ["site/notes.html"]
|
|
560
|
+
assert gate.missing_look_reason(_mcp_create_on_branch(PROVEN_BODY, clone_path)) is not None
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
def test_should_deny_a_rename_whose_lines_were_reordered(tmp_path: Path) -> None:
|
|
564
|
+
clone_path = _repository_with_rename(tmp_path, None, reorder_lines=True)
|
|
565
|
+
assert gate.visible_changed_files(str(clone_path), "feature") == ["references/asset-specs.html"]
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
def test_should_deny_a_byte_identical_rename_from_one_page_type_to_another(tmp_path: Path) -> None:
|
|
569
|
+
clone_path = _repository_with_rename(tmp_path, None, "Widget.tsx", "site/widget.html")
|
|
570
|
+
assert gate.visible_changed_files(str(clone_path), "feature") == ["site/widget.html"]
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
def test_should_report_unreadable_git_output_as_unknown() -> None:
|
|
574
|
+
assert gate._git_changes([":100644 100644 abc R100", "a.html", "b.html"]) is None
|
|
575
|
+
assert gate._git_changes([":100644 100644 aaa bbb R100", "a.html"]) is None
|
|
576
|
+
assert gate._git_changes([":100644 100644 aaa bbb M", "a.html", "stray", ""]) is None
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
def test_should_keep_a_page_whose_name_holds_a_quote(tmp_path: Path) -> None:
|
|
580
|
+
clone_path = _repository_with_change(tmp_path, 'q"t.html')
|
|
581
|
+
assert gate.visible_changed_files(str(clone_path), "feature") == ['q"t.html']
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
def test_should_keep_a_page_whose_name_has_non_ascii_letters(tmp_path: Path) -> None:
|
|
585
|
+
clone_path = _repository_with_change(tmp_path, "página.html")
|
|
586
|
+
assert gate.visible_changed_files(str(clone_path), "feature") == ["página.html"]
|
|
587
|
+
|
|
588
|
+
|
|
438
589
|
def test_should_deny_as_unreadable_when_the_compare_api_fails(
|
|
439
590
|
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
440
591
|
) -> None:
|
|
@@ -451,8 +602,8 @@ def test_should_deny_as_unreadable_when_the_compare_api_fails(
|
|
|
451
602
|
assert "before any change to this gate" in reason
|
|
452
603
|
|
|
453
604
|
|
|
454
|
-
def
|
|
455
|
-
return [f"pkg/module_{each_index}.py" for each_index in range(count)]
|
|
605
|
+
def _python_status_lines(count: int) -> list[str]:
|
|
606
|
+
return [_compare_line("M", "", f"pkg/module_{each_index}.py") for each_index in range(count)]
|
|
456
607
|
|
|
457
608
|
|
|
458
609
|
def test_should_deny_as_unreadable_when_a_full_compare_page_lists_no_visible_file(
|
|
@@ -463,7 +614,7 @@ def test_should_deny_as_unreadable_when_a_full_compare_page_lists_no_visible_fil
|
|
|
463
614
|
monkeypatch.setattr(
|
|
464
615
|
gate,
|
|
465
616
|
"_gh_api_lines",
|
|
466
|
-
_fake_gh_api({compare_endpoint:
|
|
617
|
+
_fake_gh_api({compare_endpoint: _python_status_lines(COMPARE_FILE_LIST_LIMIT)}, all_endpoints),
|
|
467
618
|
)
|
|
468
619
|
assert COMPARE_FILE_LIST_LIMIT == 300
|
|
469
620
|
payload = _shell_create_elsewhere(tmp_path, "--repo o/r --base main --head feature")
|
|
@@ -480,7 +631,7 @@ def test_should_allow_a_short_compare_page_that_lists_only_python(
|
|
|
480
631
|
monkeypatch.setattr(
|
|
481
632
|
gate,
|
|
482
633
|
"_gh_api_lines",
|
|
483
|
-
_fake_gh_api({compare_endpoint:
|
|
634
|
+
_fake_gh_api({compare_endpoint: _python_status_lines(COMPARE_FILE_LIST_LIMIT - 1)}, all_endpoints),
|
|
484
635
|
)
|
|
485
636
|
payload = _shell_create_elsewhere(tmp_path, "--repo o/r --base main --head feature")
|
|
486
637
|
assert gate.remote_visible_changed_files("o/r", "main", "feature") == []
|
|
@@ -492,7 +643,7 @@ def test_should_deny_a_visible_file_on_a_full_compare_page(
|
|
|
492
643
|
) -> None:
|
|
493
644
|
all_endpoints: list[str] = []
|
|
494
645
|
compare_endpoint = "repos/o/r/compare/main...feature"
|
|
495
|
-
all_paths = [*
|
|
646
|
+
all_paths = [*_python_status_lines(COMPARE_FILE_LIST_LIMIT - 1), _compare_line("M", "", "web/page.html")]
|
|
496
647
|
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api({compare_endpoint: all_paths}, all_endpoints))
|
|
497
648
|
reason = gate.missing_look_reason(_shell_create_elsewhere(tmp_path, "--repo o/r --base main --head feature"))
|
|
498
649
|
assert reason is not None
|
|
@@ -505,7 +656,7 @@ def test_should_allow_a_page_the_compare_api_lists_when_the_proof_links_an_artif
|
|
|
505
656
|
) -> None:
|
|
506
657
|
all_endpoints: list[str] = []
|
|
507
658
|
compare_endpoint = "repos/o/r/compare/main...feature"
|
|
508
|
-
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api({compare_endpoint: ["page.html"]}, all_endpoints))
|
|
659
|
+
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api({compare_endpoint: [_compare_line("M", "", "page.html")]}, all_endpoints))
|
|
509
660
|
body_path = tmp_path / "body.md"
|
|
510
661
|
body_path.write_text(PROVEN_BODY + "https://claude.ai/code/artifact/abc-123\n", encoding="utf-8")
|
|
511
662
|
payload = _shell(
|
|
@@ -531,7 +682,7 @@ def test_should_read_owner_and_repo_of_an_mcp_create_for_the_compare_api(
|
|
|
531
682
|
) -> None:
|
|
532
683
|
all_endpoints: list[str] = []
|
|
533
684
|
compare_endpoint = "repos/o/r/compare/main...feature"
|
|
534
|
-
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api({compare_endpoint: ["tool.py"]}, all_endpoints))
|
|
685
|
+
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api({compare_endpoint: [_compare_line("M", "", "tool.py")]}, all_endpoints))
|
|
535
686
|
payload = _mcp_create_on_branch(PROVEN_BODY, tmp_path)
|
|
536
687
|
payload["tool_input"].update(owner="o", repo="r", base="main")
|
|
537
688
|
assert gate.missing_look_reason(payload) is None
|