claude-dev-env 8.109.5 → 8.109.7
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/SKILL.md +1 -1
- package/.agents/skills/pr-lifecycle/reference/review-loop-before-merge.md +2 -0
- package/docs/rule-guides/proof-before-pull-request.md +3 -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 +258 -50
- package/hooks/blocking/test_merge_review_gate.py +130 -3
- package/hooks/blocking/test_pull_request_proof.py +512 -2
- 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 +19 -1
- package/package.json +1 -1
- package/scripts/durable_post_lint.py +28 -4
- package/scripts/merge_review_receipt.py +153 -21
- package/scripts/test_durable_post_lint.py +135 -0
- package/scripts/test_merge_review_receipt.py +168 -0
|
@@ -377,6 +377,19 @@ def test_should_deny_a_page_change_whose_proof_shows_no_picture(tmp_path: Path)
|
|
|
377
377
|
assert "page.html" in reason
|
|
378
378
|
|
|
379
379
|
|
|
380
|
+
def test_should_read_the_checkout_when_the_call_names_a_repository_but_no_head(
|
|
381
|
+
tmp_path: Path,
|
|
382
|
+
) -> None:
|
|
383
|
+
clone_path = _repository_with_change(tmp_path, "tool.py")
|
|
384
|
+
body_path = tmp_path / "body.md"
|
|
385
|
+
body_path.write_text(PROVEN_BODY, encoding="utf-8")
|
|
386
|
+
payload = _shell(
|
|
387
|
+
f"gh pr create --title t --body-file {body_path} --repo o/r --base main",
|
|
388
|
+
clone_path,
|
|
389
|
+
)
|
|
390
|
+
assert gate.missing_look_reason(payload) is None
|
|
391
|
+
|
|
392
|
+
|
|
380
393
|
def test_should_allow_a_page_change_whose_proof_links_a_screenshot(tmp_path: Path) -> None:
|
|
381
394
|
clone_path = _repository_with_change(tmp_path, "page.html")
|
|
382
395
|
body = PROVEN_BODY + "\n"
|
|
@@ -411,9 +424,11 @@ def _fake_gh_api(all_responses: dict[str, list[str] | None], all_endpoints: list
|
|
|
411
424
|
return fake_gh_api_lines
|
|
412
425
|
|
|
413
426
|
|
|
414
|
-
def _shell_create_elsewhere(
|
|
427
|
+
def _shell_create_elsewhere(
|
|
428
|
+
tmp_path: Path, extra_flags: str, body: str = PROVEN_BODY
|
|
429
|
+
) -> dict[str, object]:
|
|
415
430
|
body_path = tmp_path / "body.md"
|
|
416
|
-
body_path.write_text(
|
|
431
|
+
body_path.write_text(body, encoding="utf-8")
|
|
417
432
|
return _shell(f"gh pr create --title t --body-file {body_path} {extra_flags}", tmp_path)
|
|
418
433
|
|
|
419
434
|
|
|
@@ -840,6 +855,501 @@ def test_is_create_call_should_name_shell_and_mcp_creates() -> None:
|
|
|
840
855
|
assert not gate.is_create_call({"tool_name": "Read", "tool_input": {"file_path": "a.py"}})
|
|
841
856
|
|
|
842
857
|
|
|
858
|
+
WORKFLOW_DIRECTORY = ".github/workflows"
|
|
859
|
+
NEW_WORKFLOW_NAME = "release-hold.yml"
|
|
860
|
+
UNPROVEN_RUN_LINE = "Not proven here: the live GitHub Actions run."
|
|
861
|
+
AFTER_MERGE_SECTION = (
|
|
862
|
+
"\n## After merge\n\n- The first owner approval runs `release-hold.yml`."
|
|
863
|
+
" The agent driving this change records that run link on this pull request.\n"
|
|
864
|
+
)
|
|
865
|
+
|
|
866
|
+
|
|
867
|
+
def _workflow_body(after_merge_section: str) -> str:
|
|
868
|
+
return (
|
|
869
|
+
"## Proof in practice\nRan `python run.py`.\n"
|
|
870
|
+
+ UNPROVEN_RUN_LINE
|
|
871
|
+
+ "\n"
|
|
872
|
+
+ after_merge_section
|
|
873
|
+
)
|
|
874
|
+
|
|
875
|
+
|
|
876
|
+
def _repository_with_workflow_change(
|
|
877
|
+
tmp_path: Path, changed_workflow_name: str
|
|
878
|
+
) -> Path:
|
|
879
|
+
origin_path = tmp_path / "origin"
|
|
880
|
+
clone_path = tmp_path / "clone"
|
|
881
|
+
git_identity = ["-c", "user.name=t", "-c", "user.email=t@example.com"]
|
|
882
|
+
subprocess.run(["git", "init", "-q", "-b", "main", str(origin_path)], check=True)
|
|
883
|
+
(origin_path / WORKFLOW_DIRECTORY).mkdir(parents=True)
|
|
884
|
+
(origin_path / WORKFLOW_DIRECTORY / "ci.yml").write_text(
|
|
885
|
+
"name: ci\n", encoding="utf-8"
|
|
886
|
+
)
|
|
887
|
+
subprocess.run(["git", "-C", str(origin_path), "add", "."], check=True)
|
|
888
|
+
subprocess.run(
|
|
889
|
+
["git", "-C", str(origin_path), *git_identity, "commit", "-q", "-m", "base"],
|
|
890
|
+
check=True,
|
|
891
|
+
)
|
|
892
|
+
subprocess.run(
|
|
893
|
+
["git", "clone", "-q", str(origin_path), str(clone_path)], check=True
|
|
894
|
+
)
|
|
895
|
+
subprocess.run(
|
|
896
|
+
["git", "-C", str(clone_path), "checkout", "-q", "-b", "feature"], check=True
|
|
897
|
+
)
|
|
898
|
+
(clone_path / WORKFLOW_DIRECTORY / changed_workflow_name).write_text(
|
|
899
|
+
"name: changed\n", encoding="utf-8"
|
|
900
|
+
)
|
|
901
|
+
subprocess.run(["git", "-C", str(clone_path), "add", "."], check=True)
|
|
902
|
+
subprocess.run(
|
|
903
|
+
["git", "-C", str(clone_path), *git_identity, "commit", "-q", "-m", "change"],
|
|
904
|
+
check=True,
|
|
905
|
+
)
|
|
906
|
+
return clone_path
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+
def test_unproven_line_should_pass_when_a_new_workflow_names_its_after_merge_run(
|
|
910
|
+
tmp_path: Path,
|
|
911
|
+
) -> None:
|
|
912
|
+
clone_path = _repository_with_workflow_change(tmp_path, NEW_WORKFLOW_NAME)
|
|
913
|
+
payload = _mcp_create_on_branch(_workflow_body(AFTER_MERGE_SECTION), clone_path)
|
|
914
|
+
assert gate.missing_proof_reason(payload) is None
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
def test_unproven_line_should_stay_denied_when_the_branch_only_edits_an_existing_workflow(
|
|
918
|
+
tmp_path: Path,
|
|
919
|
+
) -> None:
|
|
920
|
+
clone_path = _repository_with_workflow_change(tmp_path, "ci.yml")
|
|
921
|
+
after_merge_section = AFTER_MERGE_SECTION.replace(NEW_WORKFLOW_NAME, "ci.yml")
|
|
922
|
+
payload = _mcp_create_on_branch(_workflow_body(after_merge_section), clone_path)
|
|
923
|
+
assert gate.missing_proof_reason(payload) == UNPROVEN_PROOF_REASON.format(
|
|
924
|
+
admission=UNPROVEN_RUN_LINE
|
|
925
|
+
)
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
@pytest.mark.parametrize(
|
|
929
|
+
"after_merge_section",
|
|
930
|
+
[
|
|
931
|
+
"",
|
|
932
|
+
"\n## After merge\n\n- The first owner approval runs `other.yml`. The agent records the link.\n",
|
|
933
|
+
"\n## After merge\n\n- The first owner approval runs `release-hold.yml`.\n",
|
|
934
|
+
"\n## After merge\n\n- The first owner approval runs release-hold.yml. The agent records the link.\n",
|
|
935
|
+
],
|
|
936
|
+
ids=[
|
|
937
|
+
"no-section",
|
|
938
|
+
"other-workflow-named",
|
|
939
|
+
"no-recorder",
|
|
940
|
+
"workflow-not-in-backticks",
|
|
941
|
+
],
|
|
942
|
+
)
|
|
943
|
+
def test_unproven_line_should_stay_denied_when_the_after_merge_section_falls_short(
|
|
944
|
+
tmp_path: Path, after_merge_section: str
|
|
945
|
+
) -> None:
|
|
946
|
+
clone_path = _repository_with_workflow_change(tmp_path, NEW_WORKFLOW_NAME)
|
|
947
|
+
payload = _mcp_create_on_branch(_workflow_body(after_merge_section), clone_path)
|
|
948
|
+
assert gate.missing_proof_reason(payload) == UNPROVEN_PROOF_REASON.format(
|
|
949
|
+
admission=UNPROVEN_RUN_LINE
|
|
950
|
+
)
|
|
951
|
+
|
|
952
|
+
|
|
953
|
+
def test_unproven_line_should_stay_denied_when_git_cannot_read_the_branch(
|
|
954
|
+
tmp_path: Path,
|
|
955
|
+
) -> None:
|
|
956
|
+
payload = _mcp_create_on_branch(_workflow_body(AFTER_MERGE_SECTION), tmp_path)
|
|
957
|
+
assert gate.missing_proof_reason(payload) == UNPROVEN_PROOF_REASON.format(
|
|
958
|
+
admission=UNPROVEN_RUN_LINE
|
|
959
|
+
)
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
def test_added_workflow_files_should_list_only_files_the_branch_adds(
|
|
963
|
+
tmp_path: Path,
|
|
964
|
+
) -> None:
|
|
965
|
+
added_clone = _repository_with_workflow_change(
|
|
966
|
+
tmp_path / "added", NEW_WORKFLOW_NAME
|
|
967
|
+
)
|
|
968
|
+
edited_clone = _repository_with_workflow_change(tmp_path / "edited", "ci.yml")
|
|
969
|
+
assert gate.added_workflow_files(str(added_clone), "feature") == [
|
|
970
|
+
f"{WORKFLOW_DIRECTORY}/{NEW_WORKFLOW_NAME}"
|
|
971
|
+
]
|
|
972
|
+
assert gate.added_workflow_files(str(edited_clone), "feature") == []
|
|
973
|
+
assert gate.added_workflow_files(str(added_clone), "other-branch") is None
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
def _workflow_compare_lines(count: int, all_added_paths: list[str]) -> list[str]:
|
|
977
|
+
return [str(count), *all_added_paths]
|
|
978
|
+
|
|
979
|
+
|
|
980
|
+
def test_unproven_line_should_pass_on_the_compare_api_when_a_new_workflow_is_added(
|
|
981
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
982
|
+
) -> None:
|
|
983
|
+
all_endpoints: list[str] = []
|
|
984
|
+
compare_endpoint = "repos/o/r/compare/main...feature"
|
|
985
|
+
added_path = f"{WORKFLOW_DIRECTORY}/{NEW_WORKFLOW_NAME}"
|
|
986
|
+
all_responses = {compare_endpoint: _workflow_compare_lines(2, [added_path])}
|
|
987
|
+
monkeypatch.setattr(
|
|
988
|
+
gate, "_gh_api_lines", _fake_gh_api(all_responses, all_endpoints)
|
|
989
|
+
)
|
|
990
|
+
payload = _shell_create_elsewhere(
|
|
991
|
+
tmp_path,
|
|
992
|
+
"--repo o/r --base main --head feature",
|
|
993
|
+
_workflow_body(AFTER_MERGE_SECTION),
|
|
994
|
+
)
|
|
995
|
+
assert gate.remote_added_workflow_files("o/r", "main", "feature") == [added_path]
|
|
996
|
+
assert gate.missing_proof_reason(payload) is None
|
|
997
|
+
|
|
998
|
+
|
|
999
|
+
def test_remote_added_workflow_files_should_report_none_when_a_full_page_lists_no_workflow(
|
|
1000
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
1001
|
+
) -> None:
|
|
1002
|
+
compare_endpoint = "repos/o/r/compare/main...feature"
|
|
1003
|
+
all_responses = {
|
|
1004
|
+
compare_endpoint: _workflow_compare_lines(
|
|
1005
|
+
COMPARE_FILE_LIST_LIMIT, ["pkg/module_0.py"]
|
|
1006
|
+
),
|
|
1007
|
+
}
|
|
1008
|
+
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api(all_responses, []))
|
|
1009
|
+
assert gate.remote_added_workflow_files("o/r", "main", "feature") is None
|
|
1010
|
+
all_responses[compare_endpoint] = _workflow_compare_lines(
|
|
1011
|
+
COMPARE_FILE_LIST_LIMIT - 1, ["pkg/module_0.py"]
|
|
1012
|
+
)
|
|
1013
|
+
assert gate.remote_added_workflow_files("o/r", "main", "feature") == []
|
|
1014
|
+
assert gate.remote_added_workflow_files(None, "main", "feature") is None
|
|
1015
|
+
|
|
1016
|
+
|
|
1017
|
+
def test_unproven_line_should_stay_denied_when_it_is_about_something_other_than_a_run(tmp_path: Path) -> None:
|
|
1018
|
+
clone_path = _repository_with_workflow_change(tmp_path, NEW_WORKFLOW_NAME)
|
|
1019
|
+
unrelated_line = "Untested on Windows."
|
|
1020
|
+
body = _workflow_body(AFTER_MERGE_SECTION).replace(UNPROVEN_RUN_LINE, unrelated_line)
|
|
1021
|
+
payload = _mcp_create_on_branch(body, clone_path)
|
|
1022
|
+
assert gate.missing_proof_reason(payload) == UNPROVEN_PROOF_REASON.format(admission=unrelated_line)
|
|
1023
|
+
|
|
1024
|
+
|
|
1025
|
+
def test_unproven_line_should_stay_denied_and_quote_the_unrelated_line_when_one_of_two_lines_is_unrelated(tmp_path: Path) -> None:
|
|
1026
|
+
clone_path = _repository_with_workflow_change(tmp_path, NEW_WORKFLOW_NAME)
|
|
1027
|
+
unrelated_line = "Untested on Windows."
|
|
1028
|
+
body = _workflow_body(AFTER_MERGE_SECTION).replace(
|
|
1029
|
+
UNPROVEN_RUN_LINE, UNPROVEN_RUN_LINE + "\n" + unrelated_line
|
|
1030
|
+
)
|
|
1031
|
+
payload = _mcp_create_on_branch(body, clone_path)
|
|
1032
|
+
assert gate.missing_proof_reason(payload) == UNPROVEN_PROOF_REASON.format(admission=unrelated_line)
|
|
1033
|
+
|
|
1034
|
+
|
|
1035
|
+
@pytest.mark.parametrize(
|
|
1036
|
+
"recorder_sentence",
|
|
1037
|
+
["Nobody records that run link.", "No one will record the run link.", "The agent does not record the run link."],
|
|
1038
|
+
)
|
|
1039
|
+
def test_unproven_line_should_stay_denied_when_the_after_merge_section_denies_a_recorder(
|
|
1040
|
+
tmp_path: Path, recorder_sentence: str
|
|
1041
|
+
) -> None:
|
|
1042
|
+
clone_path = _repository_with_workflow_change(tmp_path, NEW_WORKFLOW_NAME)
|
|
1043
|
+
after_merge_section = f"\n## After merge\n\n- The first owner approval runs `release-hold.yml`. {recorder_sentence}\n"
|
|
1044
|
+
payload = _mcp_create_on_branch(_workflow_body(after_merge_section), clone_path)
|
|
1045
|
+
assert gate.missing_proof_reason(payload) == UNPROVEN_PROOF_REASON.format(admission=UNPROVEN_RUN_LINE)
|
|
1046
|
+
|
|
1047
|
+
|
|
1048
|
+
def test_unproven_admissions_should_list_every_prose_line_that_says_something_is_unproven() -> None:
|
|
1049
|
+
section = "Ran `python run.py`.\nNot proven here: the live run.\nUntested on Windows.\n"
|
|
1050
|
+
assert gate.unproven_admissions(section) == ["Not proven here: the live run.", "Untested on Windows."]
|
|
1051
|
+
assert gate.unproven_admissions(section)[0] == "Not proven here: the live run."
|
|
1052
|
+
assert gate.unproven_admissions("Ran `python run.py`.\n") == []
|
|
1053
|
+
|
|
1054
|
+
|
|
1055
|
+
def test_unproven_line_should_pass_when_the_after_merge_section_names_the_full_workflow_path(
|
|
1056
|
+
tmp_path: Path,
|
|
1057
|
+
) -> None:
|
|
1058
|
+
clone_path = _repository_with_workflow_change(tmp_path, NEW_WORKFLOW_NAME)
|
|
1059
|
+
after_merge_section = AFTER_MERGE_SECTION.replace(
|
|
1060
|
+
NEW_WORKFLOW_NAME, f"{WORKFLOW_DIRECTORY}/{NEW_WORKFLOW_NAME}"
|
|
1061
|
+
)
|
|
1062
|
+
payload = _mcp_create_on_branch(_workflow_body(after_merge_section), clone_path)
|
|
1063
|
+
assert gate.missing_proof_reason(payload) is None
|
|
1064
|
+
|
|
1065
|
+
|
|
1066
|
+
def test_added_workflow_files_should_count_a_renamed_workflow_as_added(
|
|
1067
|
+
tmp_path: Path,
|
|
1068
|
+
) -> None:
|
|
1069
|
+
clone_path = _repository_with_workflow_change(tmp_path, NEW_WORKFLOW_NAME)
|
|
1070
|
+
subprocess.run(
|
|
1071
|
+
[
|
|
1072
|
+
"git",
|
|
1073
|
+
"-C",
|
|
1074
|
+
str(clone_path),
|
|
1075
|
+
"mv",
|
|
1076
|
+
f"{WORKFLOW_DIRECTORY}/ci.yml",
|
|
1077
|
+
f"{WORKFLOW_DIRECTORY}/renamed.yml",
|
|
1078
|
+
],
|
|
1079
|
+
check=True,
|
|
1080
|
+
)
|
|
1081
|
+
git_identity = ["-c", "user.name=t", "-c", "user.email=t@example.com"]
|
|
1082
|
+
subprocess.run(
|
|
1083
|
+
["git", "-C", str(clone_path), *git_identity, "commit", "-q", "-m", "rename"],
|
|
1084
|
+
check=True,
|
|
1085
|
+
)
|
|
1086
|
+
assert f"{WORKFLOW_DIRECTORY}/renamed.yml" in gate.added_workflow_files(
|
|
1087
|
+
str(clone_path), "feature"
|
|
1088
|
+
)
|
|
1089
|
+
|
|
1090
|
+
|
|
1091
|
+
@pytest.mark.parametrize(
|
|
1092
|
+
"unrelated_line",
|
|
1093
|
+
[
|
|
1094
|
+
"Not proven here: the live run of the Convert change on Windows.",
|
|
1095
|
+
"Not proven here: release-hold.yml on macOS.",
|
|
1096
|
+
"Untested on Windows (`python run.py`) for the workflow helper.",
|
|
1097
|
+
],
|
|
1098
|
+
ids=["run-without-a-workflow", "workflow-without-a-run", "run-only-in-a-code-span"],
|
|
1099
|
+
)
|
|
1100
|
+
def test_unproven_line_should_stay_denied_when_it_is_not_about_a_workflow_run(
|
|
1101
|
+
tmp_path: Path, unrelated_line: str
|
|
1102
|
+
) -> None:
|
|
1103
|
+
clone_path = _repository_with_workflow_change(tmp_path, NEW_WORKFLOW_NAME)
|
|
1104
|
+
body = _workflow_body(AFTER_MERGE_SECTION).replace(UNPROVEN_RUN_LINE, unrelated_line)
|
|
1105
|
+
payload = _mcp_create_on_branch(body, clone_path)
|
|
1106
|
+
assert gate.missing_proof_reason(payload) == UNPROVEN_PROOF_REASON.format(
|
|
1107
|
+
admission=unrelated_line
|
|
1108
|
+
)
|
|
1109
|
+
|
|
1110
|
+
|
|
1111
|
+
def test_merge_word_line_should_pass_when_it_is_about_the_first_run_of_a_covered_workflow(
|
|
1112
|
+
tmp_path: Path,
|
|
1113
|
+
) -> None:
|
|
1114
|
+
clone_path = _repository_with_workflow_change(tmp_path, NEW_WORKFLOW_NAME)
|
|
1115
|
+
merge_line = "The live GitHub Actions run waits until this merges."
|
|
1116
|
+
body = _workflow_body(AFTER_MERGE_SECTION).replace(UNPROVEN_RUN_LINE, merge_line)
|
|
1117
|
+
assert gate.missing_proof_reason(_mcp_create_on_branch(body, clone_path)) is None
|
|
1118
|
+
assert gate.missing_proof_reason(_mcp_create(body)) == DEFERRED_PROOF_REASON.format(deferral=merge_line)
|
|
1119
|
+
|
|
1120
|
+
|
|
1121
|
+
def test_merge_word_line_should_stay_denied_when_it_is_not_about_a_workflow_run(
|
|
1122
|
+
tmp_path: Path,
|
|
1123
|
+
) -> None:
|
|
1124
|
+
clone_path = _repository_with_workflow_change(tmp_path, NEW_WORKFLOW_NAME)
|
|
1125
|
+
merge_line = "The Convert change is checked after the merge."
|
|
1126
|
+
body = _workflow_body(AFTER_MERGE_SECTION).replace(UNPROVEN_RUN_LINE, merge_line)
|
|
1127
|
+
assert gate.missing_proof_reason(_mcp_create_on_branch(body, clone_path)) == DEFERRED_PROOF_REASON.format(
|
|
1128
|
+
deferral=merge_line
|
|
1129
|
+
)
|
|
1130
|
+
|
|
1131
|
+
|
|
1132
|
+
def test_unproven_line_should_stay_denied_when_a_run_line_names_no_workflow(
|
|
1133
|
+
tmp_path: Path,
|
|
1134
|
+
) -> None:
|
|
1135
|
+
clone_path = _repository_with_workflow_change(tmp_path, NEW_WORKFLOW_NAME)
|
|
1136
|
+
unrelated_line = "Untested: the Convert run on Windows."
|
|
1137
|
+
body = _workflow_body(AFTER_MERGE_SECTION).replace(
|
|
1138
|
+
UNPROVEN_RUN_LINE, unrelated_line
|
|
1139
|
+
)
|
|
1140
|
+
payload = _mcp_create_on_branch(body, clone_path)
|
|
1141
|
+
assert gate.missing_proof_reason(payload) == UNPROVEN_PROOF_REASON.format(
|
|
1142
|
+
admission=unrelated_line
|
|
1143
|
+
)
|
|
1144
|
+
|
|
1145
|
+
|
|
1146
|
+
def test_unproven_line_should_pass_when_a_negation_sits_in_an_earlier_clause(
|
|
1147
|
+
tmp_path: Path,
|
|
1148
|
+
) -> None:
|
|
1149
|
+
clone_path = _repository_with_workflow_change(tmp_path, NEW_WORKFLOW_NAME)
|
|
1150
|
+
after_merge_section = "\n## After merge\n\n- `release-hold.yml` does not run on pull requests; the agent records the run link.\n"
|
|
1151
|
+
payload = _mcp_create_on_branch(_workflow_body(after_merge_section), clone_path)
|
|
1152
|
+
assert gate.missing_proof_reason(payload) is None
|
|
1153
|
+
|
|
1154
|
+
|
|
1155
|
+
@pytest.mark.parametrize(
|
|
1156
|
+
"after_merge_section",
|
|
1157
|
+
[
|
|
1158
|
+
"\n## After merge\n\n- Runs `release-hold.yml`. There are no records of it yet.\n",
|
|
1159
|
+
"\n## After merge\n\n- The first owner approval runs `pre-release-hold.yml`. The agent records the run link.\n",
|
|
1160
|
+
"\n## After merge\n\n- The first owner approval runs `release-hold.yml`.\n\n```\nagent records the run link\n```\n",
|
|
1161
|
+
"\n## After merge\n\n- The first owner approval runs `release-hold.yml`. The `agent records the run link`.\n",
|
|
1162
|
+
],
|
|
1163
|
+
ids=[
|
|
1164
|
+
"noun-records",
|
|
1165
|
+
"name-is-a-longer-file",
|
|
1166
|
+
"recorder-only-in-fence",
|
|
1167
|
+
"recorder-only-in-code-span",
|
|
1168
|
+
],
|
|
1169
|
+
)
|
|
1170
|
+
def test_unproven_line_should_stay_denied_when_the_after_merge_evidence_is_not_prose_about_this_workflow(
|
|
1171
|
+
tmp_path: Path, after_merge_section: str
|
|
1172
|
+
) -> None:
|
|
1173
|
+
clone_path = _repository_with_workflow_change(tmp_path, NEW_WORKFLOW_NAME)
|
|
1174
|
+
payload = _mcp_create_on_branch(_workflow_body(after_merge_section), clone_path)
|
|
1175
|
+
assert gate.missing_proof_reason(payload) == UNPROVEN_PROOF_REASON.format(
|
|
1176
|
+
admission=UNPROVEN_RUN_LINE
|
|
1177
|
+
)
|
|
1178
|
+
|
|
1179
|
+
|
|
1180
|
+
def test_unproven_line_should_use_the_compare_api_when_a_local_checkout_lists_no_added_workflow(
|
|
1181
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
1182
|
+
) -> None:
|
|
1183
|
+
compare_endpoint = "repos/o/r/compare/main...feature"
|
|
1184
|
+
added_path = f"{WORKFLOW_DIRECTORY}/{NEW_WORKFLOW_NAME}"
|
|
1185
|
+
all_responses = {compare_endpoint: _workflow_compare_lines(2, [added_path])}
|
|
1186
|
+
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api(all_responses, []))
|
|
1187
|
+
unrelated_checkout = _repository_with_change(tmp_path, "tool.py")
|
|
1188
|
+
payload = {
|
|
1189
|
+
"tool_name": "mcp__github__create_pull_request",
|
|
1190
|
+
"tool_input": {
|
|
1191
|
+
"owner": "o",
|
|
1192
|
+
"repo": "r",
|
|
1193
|
+
"base": "main",
|
|
1194
|
+
"head": "feature",
|
|
1195
|
+
"title": "t",
|
|
1196
|
+
"body": _workflow_body(AFTER_MERGE_SECTION),
|
|
1197
|
+
},
|
|
1198
|
+
"cwd": str(unrelated_checkout),
|
|
1199
|
+
}
|
|
1200
|
+
assert gate.missing_proof_reason(payload) is None
|
|
1201
|
+
|
|
1202
|
+
|
|
1203
|
+
@pytest.mark.parametrize(
|
|
1204
|
+
"after_merge_section",
|
|
1205
|
+
[
|
|
1206
|
+
"\n## After merge\n\n- The first owner approval runs `other/release-hold.yml`. The agent records the run link.\n",
|
|
1207
|
+
"\n## After merge\n\n- The first owner approval runs `release-hold.yml`. Nobody has recorded the run link.\n",
|
|
1208
|
+
],
|
|
1209
|
+
ids=["same-name-in-another-directory", "past-tense-negated-recorder"],
|
|
1210
|
+
)
|
|
1211
|
+
def test_unproven_line_should_stay_denied_for_a_wrong_path_or_a_negated_past_tense_recorder(
|
|
1212
|
+
tmp_path: Path, after_merge_section: str
|
|
1213
|
+
) -> None:
|
|
1214
|
+
clone_path = _repository_with_workflow_change(tmp_path, NEW_WORKFLOW_NAME)
|
|
1215
|
+
payload = _mcp_create_on_branch(_workflow_body(after_merge_section), clone_path)
|
|
1216
|
+
assert gate.missing_proof_reason(payload) == UNPROVEN_PROOF_REASON.format(admission=UNPROVEN_RUN_LINE)
|
|
1217
|
+
|
|
1218
|
+
|
|
1219
|
+
def test_unproven_line_should_stay_denied_when_it_is_about_another_workflow_the_branch_changes(
|
|
1220
|
+
tmp_path: Path,
|
|
1221
|
+
) -> None:
|
|
1222
|
+
clone_path = _repository_with_workflow_change(tmp_path, NEW_WORKFLOW_NAME)
|
|
1223
|
+
unrelated_line = "The ci.yml workflow change is untested on Windows runners."
|
|
1224
|
+
body = _workflow_body(AFTER_MERGE_SECTION).replace(UNPROVEN_RUN_LINE, unrelated_line)
|
|
1225
|
+
payload = _mcp_create_on_branch(body, clone_path)
|
|
1226
|
+
assert gate.missing_proof_reason(payload) == UNPROVEN_PROOF_REASON.format(admission=unrelated_line)
|
|
1227
|
+
|
|
1228
|
+
|
|
1229
|
+
def test_unproven_line_should_ignore_a_checkout_that_belongs_to_another_repository(
|
|
1230
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
1231
|
+
) -> None:
|
|
1232
|
+
other_checkout = _repository_with_workflow_change(tmp_path, NEW_WORKFLOW_NAME)
|
|
1233
|
+
subprocess.run(
|
|
1234
|
+
["git", "-C", str(other_checkout), "remote", "set-url", "origin", "https://github.com/x/other.git"],
|
|
1235
|
+
check=True,
|
|
1236
|
+
)
|
|
1237
|
+
compare_endpoint = "repos/o/r/compare/main...feature"
|
|
1238
|
+
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api({compare_endpoint: ["1", "tool.py"]}, []))
|
|
1239
|
+
payload = {
|
|
1240
|
+
"tool_name": "mcp__github__create_pull_request",
|
|
1241
|
+
"tool_input": {
|
|
1242
|
+
"owner": "o",
|
|
1243
|
+
"repo": "r",
|
|
1244
|
+
"base": "main",
|
|
1245
|
+
"head": "feature",
|
|
1246
|
+
"title": "t",
|
|
1247
|
+
"body": _workflow_body(AFTER_MERGE_SECTION),
|
|
1248
|
+
},
|
|
1249
|
+
"cwd": str(other_checkout),
|
|
1250
|
+
}
|
|
1251
|
+
assert gate.missing_proof_reason(payload) == UNPROVEN_PROOF_REASON.format(admission=UNPROVEN_RUN_LINE)
|
|
1252
|
+
|
|
1253
|
+
|
|
1254
|
+
def test_unproven_line_should_pass_when_a_negation_sits_in_an_earlier_comma_clause(tmp_path: Path) -> None:
|
|
1255
|
+
clone_path = _repository_with_workflow_change(tmp_path, NEW_WORKFLOW_NAME)
|
|
1256
|
+
after_merge_section = (
|
|
1257
|
+
"\n## After merge\n\n- `release-hold.yml` cannot run on pull requests, so the agent records the run link.\n"
|
|
1258
|
+
)
|
|
1259
|
+
payload = _mcp_create_on_branch(_workflow_body(after_merge_section), clone_path)
|
|
1260
|
+
assert gate.missing_proof_reason(payload) is None
|
|
1261
|
+
|
|
1262
|
+
|
|
1263
|
+
def test_unproven_line_should_pass_when_one_sentence_names_a_recorder_beside_a_negated_one(
|
|
1264
|
+
tmp_path: Path,
|
|
1265
|
+
) -> None:
|
|
1266
|
+
clone_path = _repository_with_workflow_change(tmp_path, NEW_WORKFLOW_NAME)
|
|
1267
|
+
after_merge_section = (
|
|
1268
|
+
"\n## After merge\n\n- Nobody records the run link for ci.yml. The agent records the run link of `release-hold.yml`.\n"
|
|
1269
|
+
)
|
|
1270
|
+
payload = _mcp_create_on_branch(_workflow_body(after_merge_section), clone_path)
|
|
1271
|
+
assert gate.missing_proof_reason(payload) is None
|
|
1272
|
+
|
|
1273
|
+
|
|
1274
|
+
def test_unproven_line_should_stay_denied_when_the_recorder_records_nothing(tmp_path: Path) -> None:
|
|
1275
|
+
clone_path = _repository_with_workflow_change(tmp_path, NEW_WORKFLOW_NAME)
|
|
1276
|
+
after_merge_section = "\n## After merge\n\n- Runs `release-hold.yml`. The agent records nothing; the run link is lost.\n"
|
|
1277
|
+
payload = _mcp_create_on_branch(_workflow_body(after_merge_section), clone_path)
|
|
1278
|
+
assert gate.missing_proof_reason(payload) == UNPROVEN_PROOF_REASON.format(admission=UNPROVEN_RUN_LINE)
|
|
1279
|
+
|
|
1280
|
+
|
|
1281
|
+
def test_unproven_line_should_stay_denied_when_the_line_is_about_another_live_run(tmp_path: Path) -> None:
|
|
1282
|
+
clone_path = _repository_with_workflow_change(tmp_path, NEW_WORKFLOW_NAME)
|
|
1283
|
+
unrelated_line = "Not proven here: the live Convert run on Windows."
|
|
1284
|
+
body = _workflow_body(AFTER_MERGE_SECTION).replace(UNPROVEN_RUN_LINE, unrelated_line)
|
|
1285
|
+
payload = _mcp_create_on_branch(body, clone_path)
|
|
1286
|
+
assert gate.missing_proof_reason(payload) == UNPROVEN_PROOF_REASON.format(admission=unrelated_line)
|
|
1287
|
+
|
|
1288
|
+
|
|
1289
|
+
@pytest.mark.parametrize(
|
|
1290
|
+
("origin_url", "repository", "expected"),
|
|
1291
|
+
[
|
|
1292
|
+
("https://github.com/o/r.git", "o/r", True),
|
|
1293
|
+
("git@github.com:o/r.git", "o/r", True),
|
|
1294
|
+
("https://github.com/o/r/", "o/r", True),
|
|
1295
|
+
("https://github.com/foo/r", "o/r", False),
|
|
1296
|
+
("https://github.com/o/r", None, True),
|
|
1297
|
+
],
|
|
1298
|
+
)
|
|
1299
|
+
def test_checkout_should_belong_to_the_target_repository_only_on_a_full_name_match(
|
|
1300
|
+
tmp_path: Path, origin_url: str, repository: str | None, expected: bool
|
|
1301
|
+
) -> None:
|
|
1302
|
+
subprocess.run(["git", "init", "-q", "-b", "main", str(tmp_path)], check=True)
|
|
1303
|
+
subprocess.run(["git", "-C", str(tmp_path), "remote", "add", "origin", origin_url], check=True)
|
|
1304
|
+
assert gate.checkout_is_for(str(tmp_path), repository) is expected
|
|
1305
|
+
|
|
1306
|
+
|
|
1307
|
+
def test_checkout_should_belong_to_the_target_repository_when_a_fork_checkout_names_it_as_upstream(
|
|
1308
|
+
tmp_path: Path,
|
|
1309
|
+
) -> None:
|
|
1310
|
+
subprocess.run(["git", "init", "-q", "-b", "main", str(tmp_path)], check=True)
|
|
1311
|
+
for each_name, each_url in (("origin", "https://github.com/me/r.git"), ("upstream", "https://github.com/o/r.git")):
|
|
1312
|
+
subprocess.run(["git", "-C", str(tmp_path), "remote", "add", each_name, each_url], check=True)
|
|
1313
|
+
assert gate.checkout_is_for(str(tmp_path), "o/r") is True
|
|
1314
|
+
assert gate.checkout_is_for(str(tmp_path), "x/r") is False
|
|
1315
|
+
|
|
1316
|
+
|
|
1317
|
+
def test_unproven_line_should_stay_denied_when_a_matching_checkout_lists_no_added_workflow(
|
|
1318
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
1319
|
+
) -> None:
|
|
1320
|
+
stale_checkout = _repository_with_change(tmp_path, "tool.py")
|
|
1321
|
+
subprocess.run(
|
|
1322
|
+
["git", "-C", str(stale_checkout), "remote", "set-url", "origin", "https://github.com/o/r.git"], check=True
|
|
1323
|
+
)
|
|
1324
|
+
added_path = f"{WORKFLOW_DIRECTORY}/{NEW_WORKFLOW_NAME}"
|
|
1325
|
+
compare_endpoint = "repos/o/r/compare/main...feature"
|
|
1326
|
+
monkeypatch.setattr(
|
|
1327
|
+
gate, "_gh_api_lines", _fake_gh_api({compare_endpoint: _workflow_compare_lines(2, [added_path])}, [])
|
|
1328
|
+
)
|
|
1329
|
+
payload = {
|
|
1330
|
+
"tool_name": "mcp__github__create_pull_request",
|
|
1331
|
+
"tool_input": {
|
|
1332
|
+
"owner": "o",
|
|
1333
|
+
"repo": "r",
|
|
1334
|
+
"base": "main",
|
|
1335
|
+
"head": "feature",
|
|
1336
|
+
"title": "t",
|
|
1337
|
+
"body": _workflow_body(AFTER_MERGE_SECTION),
|
|
1338
|
+
},
|
|
1339
|
+
"cwd": str(stale_checkout),
|
|
1340
|
+
}
|
|
1341
|
+
assert gate.missing_proof_reason(payload) == UNPROVEN_PROOF_REASON.format(admission=UNPROVEN_RUN_LINE)
|
|
1342
|
+
|
|
1343
|
+
|
|
1344
|
+
def test_unproven_line_should_stay_denied_when_a_longer_file_name_contains_the_workflow_name(tmp_path: Path) -> None:
|
|
1345
|
+
clone_path = _repository_with_workflow_change(tmp_path, "ci2.yml")
|
|
1346
|
+
unrelated_line = "Untested: the ci2.yml.bak migration path."
|
|
1347
|
+
after_merge_section = AFTER_MERGE_SECTION.replace(NEW_WORKFLOW_NAME, "ci2.yml")
|
|
1348
|
+
body = _workflow_body(after_merge_section).replace(UNPROVEN_RUN_LINE, unrelated_line)
|
|
1349
|
+
payload = _mcp_create_on_branch(body, clone_path)
|
|
1350
|
+
assert gate.missing_proof_reason(payload) == UNPROVEN_PROOF_REASON.format(admission=unrelated_line)
|
|
1351
|
+
|
|
1352
|
+
|
|
843
1353
|
@pytest.mark.parametrize(
|
|
844
1354
|
"admission",
|
|
845
1355
|
[
|