claude-dev-env 8.109.4 → 8.109.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.
@@ -40,6 +40,6 @@ When you cannot prove it, leave the pull request unopened. Tell the owner in thr
40
40
 
41
41
  `hooks/blocking/pull_request_proof.py` reads the body of each new pull request before it opens. `pr_lifecycle_skill_gate.py` runs it on `gh pr create`, the `pull_request.py create` script, and each `mcp__*__create_pull_request` tool. The gate denies the call when the body has no "Proof in practice" heading, or when the text under that heading names no command in backticks. The gate also denies a section whose only commands run a test runner, such as `pytest`, `python -m unittest`, `uv run pytest`, `npm test`, `npx vitest`, `jest`, `go test` or `cargo test`. Quotes around a runner word, interpreter flags before `-m`, and `coverage run -m unittest` are still test runs. A command is an inline backticked span or a `$ ` line inside a fenced block. A span that starts with a path and line, such as `gate.py:12`, is not a command. A span that holds one path or file name, such as `src/x.py`, is not a command unless that span runs a test runner, such as `py.test` or `pytest.exe`. A test run piped into `tee`, `tail`, `head`, `grep` or `cat` is still a test run. The deny quotes the line "Unit tests are welcome as extra evidence. The live run is the proof." and asks for a run of the changed thing the way its user runs it, without the change and with it. The gate also denies a section whose prose says part of the change is not proven, not tested or not verified, with "yet", "been" or "fully" allowed after the "not", or says unproven, untested or unverified. The deny quotes that line, and asks for the run before the pull request opens, or for the line under a "Not covered" heading when the change does not target it. The same denial covers a proof line that opens with "not run", "not exercised" or "not executed" (a "yet" or "been" may follow the "not") or says "has not been run". A proof line with a merge word (merge, merged, merges or merging, so post-merge too) is denied with its own reason: run the check on the branch, and put a file or command name that contains merge in backticks. A step that needs the merged code to exist goes under a "Not covered" heading at the same level as the proof heading, as a line that opens with "not run". `UNPROVEN_ADMISSION_PATTERN` and `MERGE_WORD_PATTERN` list the shapes. Words inside backticks or a fenced block are quoted output and do not count. A section with one command that is not a test run, and no such line, passes. A `gh pr create` with no `--body` or `--body-file` is denied with a request for the body. A body edit through `update_pull_request`, `gh pr edit` or the `pull_request.py edit` script gets the same checks on its proof section that a new pull request gets, so an edit cannot swap in a proof that a new pull request would be denied. An edit with no proof section passes. A body the gate cannot read passes, such as an inline multi-line `--body`, a body from standard input, or a body written through `gh api`. Merges and pushes pass.
42
42
 
43
- When the checked-out branch changes a file people see (`.html`, `.htm`, `.css`, `.scss`, `.tsx`, `.jsx`, `.vue`, `.svelte`), the gate also denies a body whose proof section holds no picture: a markdown image, an image URL, or an Artifact page link that shows the screenshots. Render the change, read the screenshot, and put it in the section, so the reader sees what you looked at. When git in the session directory cannot list the branch's changed files, the gate asks for the picture as well.
43
+ When the checked-out branch changes a file people see (`.html`, `.htm`, `.css`, `.scss`, `.tsx`, `.jsx`, `.vue`, `.svelte`), the gate also denies a body whose proof section holds no picture: a markdown image, an image URL, or an Artifact page link that shows the screenshots. Render the change, read the screenshot, and put it in the section, so the reader sees what you looked at. A page the branch only moves to another folder or name that ends the same way, with every byte kept (`R100` in `git diff --name-status`), changes nothing people see, so the gate leaves it out; a moved page that also changed, or a file that becomes a page by a change of name ending, still needs the picture. When git in the session directory cannot list the branch's changed files, the gate asks for the picture as well.
44
44
 
45
45
  The gate checks that the section is there, names a command, and admits no unproven part. Whether the run proves the change stays a judgment for the author and the reviewer.
@@ -2,6 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import json
5
6
  import re
6
7
  import subprocess
7
8
  import sys
@@ -31,7 +32,7 @@ from hooks_constants.pull_request_proof_constants import (
31
32
  BASE_FLAG_ASSIGNMENT_PREFIX,
32
33
  COMPARE_ENDPOINT_TEMPLATE,
33
34
  COMPARE_FILE_LIST_LIMIT,
34
- COMPARE_FILE_NAMES_QUERY,
35
+ COMPARE_FILE_STATUS_QUERY,
35
36
  DEFAULT_BRANCH_QUERY,
36
37
  GH_TIMEOUT_SECONDS,
37
38
  HEAD_FLAG_ASSIGNMENT_PREFIX,
@@ -51,6 +52,12 @@ from hooks_constants.pull_request_proof_constants import (
51
52
  MISSING_PROOF_REASON,
52
53
  NEXT_HEADING_PATTERN,
53
54
  PROOF_HEADING_PATTERN,
55
+ PURE_RENAME_STATUS,
56
+ RAW_HEADER_FIELD_COUNT,
57
+ RAW_RECORD_PREFIX,
58
+ RAW_RENAME_PATH_COUNT,
59
+ RAW_RENAME_STATUS_LETTER,
60
+ ALL_RAW_TWO_PATH_STATUS_LETTERS,
54
61
  PROOF_IMAGE_PATTERN,
55
62
  PULL_REQUEST_SCRIPT_CREATE_WORD,
56
63
  PULL_REQUEST_SCRIPT_EDIT_WORD,
@@ -626,18 +633,31 @@ def missing_existing_work_reason(all_payload_fields: Mapping[str, object]) -> st
626
633
  return None
627
634
 
628
635
 
629
- def _git_lines(working_directory: str, *all_git_arguments: str) -> list[str] | None:
636
+ class ChangedFile(NamedTuple):
637
+ path: str
638
+ old_path: str
639
+ is_pure_rename: bool
640
+
641
+
642
+ def _git_output(working_directory: str, *all_git_arguments: str) -> str | None:
630
643
  try:
631
644
  completed = subprocess.run(
632
645
  ["git", "-C", working_directory, *all_git_arguments],
633
646
  capture_output=True,
634
647
  text=True,
648
+ encoding="utf-8",
649
+ errors="replace",
635
650
  timeout=GIT_TIMEOUT_SECONDS,
636
651
  check=False,
637
652
  )
638
653
  except (OSError, subprocess.SubprocessError):
639
654
  return None
640
- return completed.stdout.splitlines() if completed.returncode == 0 else None
655
+ return completed.stdout if completed.returncode == 0 else None
656
+
657
+
658
+ def _git_lines(working_directory: str, *all_git_arguments: str) -> list[str] | None:
659
+ output = _git_output(working_directory, *all_git_arguments)
660
+ return output.splitlines() if output is not None else None
641
661
 
642
662
 
643
663
  def _first_merge_base(working_directory: str, head_reference: str) -> str | None:
@@ -667,9 +687,16 @@ def visible_changed_files(working_directory: str, head_branch: object) -> list[s
667
687
  origin/HEAD, origin/main and main that git can reach::
668
688
 
669
689
  checkout on feature, page.html changed -> ["page.html"]
690
+ page.html renamed with no edit -> []
691
+ page.html renamed and edited -> ["page.html"]
670
692
  named head exists nowhere in the clone -> None
671
693
  no base reference reachable -> None
672
694
 
695
+ A rename whose old and new blob ids match and whose old and new names end the
696
+ same way, such as a.html to b/a.html, changes nothing people see. One that
697
+ changes the ending, such as notes.txt or Widget.tsx to page.html, still makes a
698
+ page. A copy or a rename with an edit keeps its path.
699
+
673
700
  Args:
674
701
  working_directory: The session directory the hook payload names.
675
702
  head_branch: The head branch a create call names, or None.
@@ -682,14 +709,64 @@ def visible_changed_files(working_directory: str, head_branch: object) -> list[s
682
709
  merge_base = _first_merge_base(working_directory, head_reference)
683
710
  if merge_base is None:
684
711
  return None
685
- all_changed_paths = _git_lines(working_directory, "diff", "--name-only", merge_base, head_reference)
686
- if all_changed_paths is None:
712
+ raw_output = _git_output(working_directory, "diff", "--raw", "--no-abbrev", "-M", "-z", merge_base, head_reference)
713
+ if raw_output is None:
714
+ return None
715
+ all_changes = _git_changes(raw_output.split("\0"))
716
+ if all_changes is None:
717
+ return None
718
+ return _visible_paths(all_changes)
719
+
720
+
721
+ def _git_changes(all_raw_fields: list[str]) -> list[ChangedFile] | None:
722
+ all_changes = []
723
+ field_index = 0
724
+ while field_index < len(all_raw_fields) and all_raw_fields[field_index].startswith(RAW_RECORD_PREFIX):
725
+ all_header_fields = all_raw_fields[field_index][1:].split(" ")
726
+ if len(all_header_fields) != RAW_HEADER_FIELD_COUNT:
727
+ return None
728
+ old_mode, new_mode, old_blob, new_blob, status = all_header_fields
729
+ path_count = RAW_RENAME_PATH_COUNT if status[:1] in ALL_RAW_TWO_PATH_STATUS_LETTERS else 1
730
+ all_paths = all_raw_fields[field_index + 1 : field_index + 1 + path_count]
731
+ if len(all_paths) != path_count:
732
+ return None
733
+ is_pure_rename = status.startswith(RAW_RENAME_STATUS_LETTER) and old_mode == new_mode and old_blob == new_blob
734
+ all_changes.append(ChangedFile(path=all_paths[-1], old_path=all_paths[0], is_pure_rename=is_pure_rename))
735
+ field_index += 1 + path_count
736
+ if any(all_raw_fields[field_index:]):
687
737
  return None
688
- return _visible_paths(all_changed_paths)
738
+ return all_changes
689
739
 
690
740
 
691
- def _visible_paths(all_changed_paths: list[str]) -> list[str]:
692
- return [each_path for each_path in all_changed_paths if each_path.lower().endswith(ALL_VISIBLE_FILE_SUFFIXES)]
741
+ def _compare_changes(all_json_lines: list[str]) -> list[ChangedFile] | None:
742
+ all_changes = []
743
+ for each_line in all_json_lines:
744
+ try:
745
+ status, old_path, path = json.loads(each_line)
746
+ except (ValueError, TypeError):
747
+ return None
748
+ all_changes.append(ChangedFile(path=path, old_path=old_path, is_pure_rename=status == PURE_RENAME_STATUS))
749
+ return all_changes
750
+
751
+
752
+ def _visible_suffix(path: str) -> str | None:
753
+ lowered_path = path.lower()
754
+ for each_suffix in ALL_VISIBLE_FILE_SUFFIXES:
755
+ if lowered_path.endswith(each_suffix):
756
+ return each_suffix
757
+ return None
758
+
759
+
760
+ def _is_unchanged_move(change: ChangedFile) -> bool:
761
+ return change.is_pure_rename and _visible_suffix(change.old_path) == _visible_suffix(change.path)
762
+
763
+
764
+ def _visible_paths(all_changes: list[ChangedFile]) -> list[str]:
765
+ return [
766
+ each_change.path
767
+ for each_change in all_changes
768
+ if _visible_suffix(each_change.path) is not None and not _is_unchanged_move(each_change)
769
+ ]
693
770
 
694
771
 
695
772
  def _gh_api_lines(endpoint: str, query: str) -> list[str] | None:
@@ -698,6 +775,8 @@ def _gh_api_lines(endpoint: str, query: str) -> list[str] | None:
698
775
  ["gh", "api", endpoint, "--jq", query],
699
776
  capture_output=True,
700
777
  text=True,
778
+ encoding="utf-8",
779
+ errors="replace",
701
780
  timeout=GH_TIMEOUT_SECONDS,
702
781
  check=False,
703
782
  )
@@ -718,16 +797,19 @@ def _compare_base_branch(repository: str, base_branch: str | None) -> str | None
718
797
 
719
798
 
720
799
  def _visible_compare_paths(repository: str, base_branch: str, head_branch: str) -> list[str] | None:
721
- all_changed_paths = _gh_api_lines(
800
+ all_status_lines = _gh_api_lines(
722
801
  COMPARE_ENDPOINT_TEMPLATE.format(
723
802
  repository=repository, base_branch=base_branch, head_branch=head_branch
724
803
  ),
725
- COMPARE_FILE_NAMES_QUERY,
804
+ COMPARE_FILE_STATUS_QUERY,
726
805
  )
727
- if all_changed_paths is None:
806
+ if all_status_lines is None:
807
+ return None
808
+ all_changes = _compare_changes(all_status_lines)
809
+ if all_changes is None:
728
810
  return None
729
- all_visible_paths = _visible_paths(all_changed_paths)
730
- if all_visible_paths or len(all_changed_paths) < COMPARE_FILE_LIST_LIMIT:
811
+ all_visible_paths = _visible_paths(all_changes)
812
+ if all_visible_paths or len(all_status_lines) < COMPARE_FILE_LIST_LIMIT:
731
813
  return all_visible_paths
732
814
  return None
733
815
 
@@ -741,13 +823,15 @@ def remote_visible_changed_files(
741
823
 
742
824
  compare lists tool.py -> []
743
825
  compare lists web/page.html -> ["web/page.html"]
826
+ compare lists web/page.html renamed, no edit -> []
744
827
  compare returns 300 paths and none are visible -> None
745
828
  repository or head missing -> None
746
829
 
747
830
  The base is the named base branch, else the repository's default branch.
748
831
  A page of 300 paths is the compare API's file cap. A visible file on that
749
832
  page is returned. A full page with none is None, because a later file can
750
- still be one people see.
833
+ still be one people see. A pure rename counts toward the 300. It is not
834
+ visible when the file it moved from ended the same way.
751
835
 
752
836
  Args:
753
837
  repository: The owner/name the create call names, or None.
@@ -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 _python_paths(count: int) -> list[str]:
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: _python_paths(COMPARE_FILE_LIST_LIMIT)}, all_endpoints),
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: _python_paths(COMPARE_FILE_LIST_LIMIT - 1)}, all_endpoints),
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 = [*_python_paths(COMPARE_FILE_LIST_LIMIT - 1), "web/page.html"]
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
@@ -123,7 +123,17 @@ REPOSITORY_FLAG_ASSIGNMENT_PREFIX = "--repo="
123
123
  GIT_TIMEOUT_SECONDS = 5
124
124
  GH_TIMEOUT_SECONDS = 15
125
125
  COMPARE_ENDPOINT_TEMPLATE = "repos/{repository}/compare/{base_branch}...{head_branch}"
126
- COMPARE_FILE_NAMES_QUERY = ".files[].filename"
126
+ PURE_RENAME_STATUS = "R100"
127
+ RAW_RECORD_PREFIX = ":"
128
+ RAW_RENAME_PATH_COUNT = 2
129
+ RAW_HEADER_FIELD_COUNT = 5
130
+ RAW_RENAME_STATUS_LETTER = "R"
131
+ ALL_RAW_TWO_PATH_STATUS_LETTERS = (RAW_RENAME_STATUS_LETTER, "C")
132
+ COMPARE_FILE_STATUS_QUERY = (
133
+ '.files[] | [(if .status == "renamed" and .changes == 0 then "'
134
+ + PURE_RENAME_STATUS
135
+ + '" else .status end), (.previous_filename // ""), .filename] | @json'
136
+ )
127
137
  COMPARE_FILE_LIST_LIMIT = 300
128
138
  REPOSITORY_ENDPOINT_TEMPLATE = "repos/{repository}"
129
139
  DEFAULT_BRANCH_QUERY = ".default_branch"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-dev-env",
3
- "version": "8.109.4",
3
+ "version": "8.109.5",
4
4
  "description": "Claude Code development standards — rules, hooks, agents, commands, and skills",
5
5
  "type": "module",
6
6
  "bin": {