claude-dev-env 8.109.6 → 8.109.8

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.
@@ -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 + "![after](https://example.com/after.png)\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(tmp_path: Path, extra_flags: str) -> dict[str, object]:
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(PROVEN_BODY, encoding="utf-8")
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
  [
@@ -84,7 +84,25 @@ UNPROVEN_PROOF_REASON = (
84
84
  " Do not open the pull request, or ask for review of an open one, until that output"
85
85
  " is there. When it is a condition the change does not"
86
86
  " target, move the line under a 'Not covered' heading at the same level as the proof"
87
- " heading. Read " + PROOF_GUIDE_PATH + " for the full rule."
87
+ " heading. When the pull request adds a workflow file the default branch lacks, its first"
88
+ " run waits for the merge: add an 'After merge' heading that names the workflow file in"
89
+ " backticks and says who records the run link. Read " + PROOF_GUIDE_PATH + " for the full rule."
90
+ )
91
+ AFTER_MERGE_HEADING_PATTERN = r"^(#{1,6})[ \t]+after merge[ \t]*#*[ \t]*$"
92
+ AFTER_MERGE_RECORDER_PATTERN = r"\brecord(?:s|ed)?\b[^.;\n]{0,30}\b(?:run|link|url|result)s?\b"
93
+ AFTER_MERGE_NO_RECORDER_PATTERN = (
94
+ r"\b(?:nobody|no[ -]?one|not|never|cannot|can't|won't|doesn't)\b[^.;,\n]{0,60}\brecord(?:s|ed)?\b"
95
+ r"|\brecord(?:s|ed)?\s+(?:nothing|none|no)\b|\bno\s+records?\b"
96
+ )
97
+ AFTER_MERGE_SENTENCE_SEPARATOR_PATTERN = r"[;\n]|\.(?=\s|$)"
98
+ WORKFLOW_SUBJECT_PATTERN = r"\b(?:github actions|workflow)\b"
99
+ RUN_WORD_PATTERN = r"\bruns?\b"
100
+ GIT_URL_SUFFIX = ".git"
101
+ REMOTE_LINE_FIELD_COUNT = 2
102
+ WORKFLOW_NAME_MATCH_TEMPLATE = r"(?<![\w.-]){workflow_name}(?![\w-]|\.\w)"
103
+ NEW_WORKFLOW_PATH_PATTERN = r"^\.github/workflows/[^/]+\.ya?ml$"
104
+ ADDED_FILE_NAMES_QUERY = (
105
+ '(.files | length | tostring), (.files[] | select(.status == "added" or .status == "renamed" or .status == "copied") | .filename)'
88
106
  )
89
107
  DEFERRED_PROOF_REASON = (
90
108
  "This pull request's 'Proof in practice' section mentions a merge: \"{deferral}\". Run that"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-dev-env",
3
- "version": "8.109.6",
3
+ "version": "8.109.8",
4
4
  "description": "Claude Code development standards — rules, hooks, agents, commands, and skills",
5
5
  "type": "module",
6
6
  "bin": {
@@ -64,6 +64,7 @@ if _hooks_directory not in sys.path:
64
64
  sys.path.insert(0, _hooks_directory)
65
65
 
66
66
  from blocking.pull_request_proof import (
67
+ checkout_is_for,
67
68
  missing_eval_section_reason,
68
69
  missing_existing_work_reason,
69
70
  missing_proof_reason,
@@ -159,12 +160,32 @@ def _description_heading_findings(body_text: str) -> list[DurablePostFinding]:
159
160
  ]
160
161
 
161
162
 
163
+ def _checkout_directory(head_branch: str | None, repository: str | None) -> str:
164
+ current_directory = str(Path.cwd())
165
+ if head_branch and repository and checkout_is_for(current_directory, repository):
166
+ return current_directory
167
+ return ""
168
+
169
+
162
170
  def _pull_request_proof_findings(
163
- title: str | None, body_text: str
171
+ title: str | None,
172
+ body_text: str,
173
+ head_branch: str | None = None,
174
+ repository: str | None = None,
164
175
  ) -> list[DurablePostFinding]:
176
+ owner, _separator, repository_name = (repository or "").partition(
177
+ REPOSITORY_OWNER_SEPARATOR
178
+ )
165
179
  create_payload = {
166
180
  "tool_name": PROOF_GATE_CREATE_TOOL_NAME,
167
- "tool_input": {"title": title, "body": body_text},
181
+ "tool_input": {
182
+ "title": title,
183
+ "body": body_text,
184
+ "head": head_branch,
185
+ "owner": owner,
186
+ "repo": repository_name,
187
+ },
188
+ "cwd": _checkout_directory(head_branch, repository),
168
189
  }
169
190
  all_reasons = (
170
191
  missing_proof_reason(create_payload),
@@ -251,6 +272,7 @@ def _body_findings(
251
272
  body_text: str | None,
252
273
  head_branch: str | None = None,
253
274
  title: str | None = None,
275
+ repository: str | None = None,
254
276
  ) -> list[DurablePostFinding]:
255
277
  if body_text is None:
256
278
  return []
@@ -267,7 +289,9 @@ def _body_findings(
267
289
  else:
268
290
  if action == ACTION_PR_CREATE:
269
291
  all_findings.extend(_description_heading_findings(body_text))
270
- all_findings.extend(_pull_request_proof_findings(title, body_text))
292
+ all_findings.extend(
293
+ _pull_request_proof_findings(title, body_text, head_branch, repository)
294
+ )
271
295
  if action == ACTION_GITHUB_MCP_COMMENT:
272
296
  all_findings.extend(_comment_length_findings(body_text))
273
297
  all_findings.extend(_contrast_framing_findings(body_text))
@@ -307,7 +331,7 @@ def lint_durable_post(
307
331
  return (
308
332
  *_title_findings(title),
309
333
  *_private_term_findings(title, repository),
310
- *_body_findings(action, body_text, head_branch, title),
334
+ *_body_findings(action, body_text, head_branch, title, repository),
311
335
  *_private_term_findings(body_text, repository),
312
336
  )
313
337