claude-dev-env 2.12.0 → 2.13.0

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.
Files changed (193) hide show
  1. package/_shared/pr-loop/scripts/code_rules_gate.py +2 -3
  2. package/_shared/pr-loop/scripts/test_code_rules_gate.py +0 -26
  3. package/agents/CLAUDE.md +1 -2
  4. package/agents/pr-description-writer.md +11 -81
  5. package/bin/install.mjs +48 -9
  6. package/bin/install.prune.test.mjs +26 -0
  7. package/bin/install.settings-defaults.test.mjs +60 -33
  8. package/bin/install.test.mjs +2 -4
  9. package/commands/sr-loop.md +9 -5
  10. package/docs/CLAUDE.md +0 -1
  11. package/docs/references/CLAUDE.md +0 -1
  12. package/hooks/CLAUDE.md +1 -1
  13. package/hooks/blocking/CLAUDE.md +2 -27
  14. package/hooks/blocking/config/CLAUDE.md +1 -13
  15. package/hooks/blocking/conventional_pr_title_gate.py +1 -2
  16. package/hooks/blocking/send_user_file_open_locally_blocker.py +1 -1
  17. package/hooks/blocking/stop_dispatcher.py +4 -4
  18. package/hooks/blocking/test_bash_pre_tool_use_dispatcher.py +0 -3
  19. package/hooks/blocking/test_pre_tool_use_dispatcher.py +6 -7
  20. package/hooks/blocking/test_send_user_file_open_locally_blocker.py +4 -3
  21. package/hooks/blocking/test_shared_stdin_adoption.py +0 -2
  22. package/hooks/diagnostic/CLAUDE.md +3 -3
  23. package/hooks/diagnostic/hook_log_extractor.py +2 -36
  24. package/hooks/diagnostic/hook_log_stop_wrapper.py +6 -155
  25. package/hooks/diagnostic/test_hook_log_extractor.py +8 -21
  26. package/hooks/diagnostic/test_hook_log_stop_wrapper.py +3 -331
  27. package/hooks/git-hooks/git_hooks_constants/__init__.py +0 -6
  28. package/hooks/git-hooks/pre_push.py +3 -85
  29. package/hooks/git-hooks/test_pre_push.py +0 -130
  30. package/hooks/hooks.json +0 -35
  31. package/hooks/hooks_constants/CLAUDE.md +0 -9
  32. package/hooks/hooks_constants/bash_pre_tool_use_dispatcher_constants.py +0 -11
  33. package/hooks/hooks_constants/convergence_branch_constants.py +0 -1
  34. package/hooks/hooks_constants/fable_spawn_gate_constants.py +3 -4
  35. package/hooks/hooks_constants/pre_tool_use_dispatcher_constants.py +0 -8
  36. package/hooks/hooks_constants/send_user_file_open_locally_blocker_constants.py +1 -6
  37. package/hooks/hooks_constants/stop_dispatcher_constants.py +0 -1
  38. package/hooks/hooks_constants/test_bash_pre_tool_use_dispatcher_constants.py +1 -26
  39. package/hooks/hooks_constants/test_pre_tool_use_dispatcher_constants.py +0 -5
  40. package/hooks/hooks_constants/test_stop_dispatcher_constants.py +0 -1
  41. package/hooks/lifecycle/CLAUDE.md +1 -3
  42. package/package.json +1 -1
  43. package/rules/CLAUDE.md +0 -2
  44. package/rules/gh-cli-conventions.md +0 -1
  45. package/rules/git-workflow.md +1 -3
  46. package/scripts/CLAUDE.md +0 -1
  47. package/scripts/_code_review_test_support.py +0 -95
  48. package/scripts/dev_env_scripts_constants/code_review_constants.py +9 -98
  49. package/scripts/dev_env_scripts_constants/test_code_review_constants.py +1 -44
  50. package/scripts/invoke_code_review.py +8 -451
  51. package/scripts/test_invoke_code_review.py +5 -61
  52. package/scripts/test_invoke_code_review_cli.py +1 -45
  53. package/scripts/test_invoke_code_review_contract.py +1 -118
  54. package/settings.json +1 -10
  55. package/skills/CLAUDE.md +8 -0
  56. package/skills/autoconverge/reference/CLAUDE.md +1 -1
  57. package/skills/autoconverge/reference/convergence.md +7 -7
  58. package/skills/autoconverge/reference/gotchas.md +3 -10
  59. package/skills/autoconverge/workflow/converge.contract.test.mjs +53 -1388
  60. package/skills/autoconverge/workflow/converge.copilot-gate.test.mjs +4 -3
  61. package/skills/autoconverge/workflow/converge.fix-recovery.test.mjs +33 -493
  62. package/skills/autoconverge/workflow/converge.merge-conflict.test.mjs +15 -97
  63. package/skills/autoconverge/workflow/converge.mjs +201 -238
  64. package/skills/autoconverge/workflow/converge.precatch.test.mjs +1 -1
  65. package/skills/bugteam/CONSTRAINTS.md +1 -1
  66. package/skills/bugteam/SKILL.md +9 -0
  67. package/skills/bugteam/reference/audit-and-teammates.md +10 -6
  68. package/skills/bugteam/test_skill_additions.py +9 -0
  69. package/skills/comments/SKILL.md +65 -0
  70. package/skills/descriptions/SKILL.md +51 -0
  71. package/skills/emergencies/SKILL.md +42 -0
  72. package/skills/imagegen/SKILL.md +21 -0
  73. package/skills/imagegen/scripts/config/__init__.py +1 -0
  74. package/skills/imagegen/scripts/config/constants.py +28 -0
  75. package/skills/imagegen/scripts/imagegen.py +45 -0
  76. package/skills/imagegen/scripts/imagegen_core.py +528 -0
  77. package/skills/imagegen/scripts/test_imagegen.py +204 -0
  78. package/skills/orchestrator/SKILL.md +2 -4
  79. package/skills/plan-to-pr/SKILL.md +6 -7
  80. package/skills/plan-to-pr/reference/final-validation-tasks.md +1 -1
  81. package/skills/plan-to-pr/reference/process-inventory.md +2 -2
  82. package/skills/plan-to-pr/reference/review-loop.md +2 -2
  83. package/skills/plan-to-pr/reference/run-record.schema.json +1 -1
  84. package/skills/plan-to-pr/reference/task-seeds.md +1 -1
  85. package/skills/plan-to-pr/reference/task-ticket.md +3 -4
  86. package/skills/plan-to-pr/scripts/config/constants.py +1 -2
  87. package/skills/plan-to-pr/scripts/test_validate_protocol.py +1 -1
  88. package/skills/plan-to-pr/test_skill_contract.py +2 -2
  89. package/skills/pr-converge/SKILL.md +13 -16
  90. package/skills/pr-converge/reference/progress-checklist.md +6 -5
  91. package/skills/pr-converge/reference/state-schema.md +1 -27
  92. package/skills/pr-loop-cloud-transport/SKILL.md +1 -1
  93. package/skills/pr-loop-cloud-transport/reference/identity-and-hooks.md +3 -3
  94. package/skills/pr-loop-lifecycle/SKILL.md +1 -1
  95. package/skills/pr-loop-lifecycle/reference/teardown-publish-permissions.md +1 -1
  96. package/skills/prototype/SKILL.md +4 -4
  97. package/skills/prototype/reference/honest-limitations.md +4 -4
  98. package/skills/prototype/reference/promotion-tasks.md +2 -2
  99. package/skills/prototype/workflows/promotion.md +4 -6
  100. package/skills/reviews/SKILL.md +85 -0
  101. package/skills/small-cl/SKILL.md +52 -0
  102. package/agents/code-verifier.md +0 -74
  103. package/docs/PR_DESCRIPTION_GUIDE.md +0 -157
  104. package/docs/references/code-review-enforcement.md +0 -132
  105. package/hooks/blocking/code_review_enforcement_config_bootstrap.py +0 -53
  106. package/hooks/blocking/code_review_gate_deny.py +0 -74
  107. package/hooks/blocking/code_review_pr_create_gate.py +0 -198
  108. package/hooks/blocking/code_review_push_gate.py +0 -145
  109. package/hooks/blocking/code_review_stamp_directory_write_blocker.py +0 -348
  110. package/hooks/blocking/code_review_stamp_store.py +0 -233
  111. package/hooks/blocking/code_review_stamp_write_blocker_parts/__init__.py +0 -7
  112. package/hooks/blocking/code_review_stamp_write_blocker_parts/conftest.py +0 -15
  113. package/hooks/blocking/code_review_stamp_write_blocker_parts/obfuscated_stamp_path_reference.py +0 -212
  114. package/hooks/blocking/code_review_stamp_write_blocker_parts/split_directory_change_into_stamp.py +0 -138
  115. package/hooks/blocking/code_review_stamp_write_blocker_parts/test_obfuscated_stamp_path_reference.py +0 -49
  116. package/hooks/blocking/code_review_stamp_write_blocker_parts/test_split_directory_change_into_stamp.py +0 -38
  117. package/hooks/blocking/code_verifier_spawn_preflight_gate.py +0 -483
  118. package/hooks/blocking/config/code_review_enforcement_constants.py +0 -143
  119. package/hooks/blocking/config/test_code_review_enforcement_constants.py +0 -166
  120. package/hooks/blocking/config/verified_commit_constants.py +0 -160
  121. package/hooks/blocking/config/verified_commit_context_constants.py +0 -21
  122. package/hooks/blocking/config/verified_commit_gate_output_constants.py +0 -14
  123. package/hooks/blocking/conftest.py +0 -123
  124. package/hooks/blocking/convergence_gate_blocker.py +0 -310
  125. package/hooks/blocking/pr_converge_bugteam_enforcer.py +0 -170
  126. package/hooks/blocking/pr_description_body_audit.py +0 -148
  127. package/hooks/blocking/pr_description_command_parser.py +0 -237
  128. package/hooks/blocking/pr_description_enforcer.py +0 -227
  129. package/hooks/blocking/pr_description_pr_number.py +0 -155
  130. package/hooks/blocking/pr_description_proof_of_work.py +0 -385
  131. package/hooks/blocking/pr_description_readability.py +0 -364
  132. package/hooks/blocking/reviewer_spawn_gate.py +0 -182
  133. package/hooks/blocking/test_code_review_enforcement_config_bootstrap.py +0 -62
  134. package/hooks/blocking/test_code_review_gate_deny.py +0 -54
  135. package/hooks/blocking/test_code_review_pr_create_gate.py +0 -199
  136. package/hooks/blocking/test_code_review_push_gate.py +0 -205
  137. package/hooks/blocking/test_code_review_stamp_directory_write_blocker.py +0 -199
  138. package/hooks/blocking/test_code_review_stamp_store.py +0 -205
  139. package/hooks/blocking/test_code_verifier_spawn_preflight_gate.py +0 -710
  140. package/hooks/blocking/test_code_verifier_tools_contract.py +0 -28
  141. package/hooks/blocking/test_convergence_gate_blocker.py +0 -428
  142. package/hooks/blocking/test_pr_converge_bugteam_enforcer.py +0 -311
  143. package/hooks/blocking/test_pr_converge_bugteam_enforcer_state_tolerance.py +0 -184
  144. package/hooks/blocking/test_pr_description_enforcer.py +0 -221
  145. package/hooks/blocking/test_pr_description_enforcer_body_audit.py +0 -247
  146. package/hooks/blocking/test_pr_description_enforcer_body_rules.py +0 -493
  147. package/hooks/blocking/test_pr_description_enforcer_command_parser.py +0 -366
  148. package/hooks/blocking/test_pr_description_enforcer_pr_number.py +0 -159
  149. package/hooks/blocking/test_pr_description_enforcer_proof_gate.py +0 -175
  150. package/hooks/blocking/test_pr_description_enforcer_readability.py +0 -443
  151. package/hooks/blocking/test_pr_description_proof_of_work.py +0 -313
  152. package/hooks/blocking/test_reviewer_spawn_gate.py +0 -230
  153. package/hooks/blocking/test_verdict_directory_write_blocker.py +0 -804
  154. package/hooks/blocking/test_verification_verdict_store.py +0 -974
  155. package/hooks/blocking/test_verified_commit_config_bootstrap.py +0 -67
  156. package/hooks/blocking/test_verified_commit_docs_delta.py +0 -176
  157. package/hooks/blocking/test_verified_commit_gate.py +0 -581
  158. package/hooks/blocking/test_verified_commit_gate_additional_context.py +0 -134
  159. package/hooks/blocking/test_verified_commit_message_accuracy_blocker.py +0 -131
  160. package/hooks/blocking/test_verifier_verdict_minter.py +0 -299
  161. package/hooks/blocking/tests/test_verified_commit_gate.py +0 -41
  162. package/hooks/blocking/verdict_directory_write_blocker.py +0 -687
  163. package/hooks/blocking/verification_verdict_store.py +0 -1039
  164. package/hooks/blocking/verified_commit_config_bootstrap.py +0 -63
  165. package/hooks/blocking/verified_commit_gate.py +0 -113
  166. package/hooks/blocking/verified_commit_gate_parts/CLAUDE.md +0 -28
  167. package/hooks/blocking/verified_commit_gate_parts/__init__.py +0 -1
  168. package/hooks/blocking/verified_commit_gate_parts/command_tokenization.py +0 -174
  169. package/hooks/blocking/verified_commit_gate_parts/deny_payload.py +0 -53
  170. package/hooks/blocking/verified_commit_gate_parts/deny_reason.py +0 -80
  171. package/hooks/blocking/verified_commit_gate_parts/directory_resolution.py +0 -170
  172. package/hooks/blocking/verified_commit_gate_parts/gated_invocations.py +0 -217
  173. package/hooks/blocking/verified_commit_gate_parts/tests/conftest.py +0 -10
  174. package/hooks/blocking/verified_commit_gate_parts/tests/test_command_tokenization.py +0 -94
  175. package/hooks/blocking/verified_commit_gate_parts/tests/test_deny_payload.py +0 -17
  176. package/hooks/blocking/verified_commit_gate_parts/tests/test_deny_reason.py +0 -38
  177. package/hooks/blocking/verified_commit_gate_parts/tests/test_directory_resolution.py +0 -71
  178. package/hooks/blocking/verified_commit_gate_parts/tests/test_gated_invocations.py +0 -96
  179. package/hooks/blocking/verified_commit_message_accuracy_blocker.py +0 -167
  180. package/hooks/blocking/verifier_verdict_minter.py +0 -280
  181. package/hooks/hooks_constants/code_verifier_spawn_preflight_gate_constants.py +0 -64
  182. package/hooks/hooks_constants/convergence_gate_blocker_constants.py +0 -53
  183. package/hooks/hooks_constants/pr_converge_bugteam_enforcer_constants.py +0 -55
  184. package/hooks/hooks_constants/pr_converge_bugteam_enforcer_state.py +0 -67
  185. package/hooks/hooks_constants/pr_description_enforcer_constants.py +0 -167
  186. package/hooks/hooks_constants/pr_description_proof_of_work_constants.py +0 -107
  187. package/hooks/hooks_constants/reviewer_spawn_gate_constants.py +0 -41
  188. package/hooks/hooks_constants/test_pr_description_enforcer_constants.py +0 -292
  189. package/hooks/lifecycle/pr_converge_bugteam_skill_tracker.py +0 -198
  190. package/hooks/lifecycle/test_pr_converge_bugteam_skill_tracker.py +0 -283
  191. package/rules/proof-of-work-pr-comments.md +0 -22
  192. package/rules/verified-commit-gate-skip.md +0 -4
  193. package/scripts/Show-Asset.ps1 +0 -106
@@ -1,581 +0,0 @@
1
- """Tests for the gated-invocation parser in verified_commit_gate.
2
-
3
- Each test asserts which directories a command string's git commit/push verbs
4
- target, exercising the same token-walk the verified_commit_gate hook runs to
5
- decide what to gate.
6
- """
7
-
8
- import importlib.util
9
- import io
10
- import json
11
- import os
12
- import pathlib
13
- import subprocess
14
- import sys
15
- from collections.abc import Callable
16
-
17
- import pytest
18
-
19
- _HOOK_DIR = pathlib.Path(__file__).parent
20
- if str(_HOOK_DIR) not in sys.path:
21
- sys.path.insert(0, str(_HOOK_DIR))
22
-
23
- gate_spec = importlib.util.spec_from_file_location(
24
- "verified_commit_gate",
25
- _HOOK_DIR / "verified_commit_gate.py",
26
- )
27
- assert gate_spec is not None
28
- assert gate_spec.loader is not None
29
- gate_module = importlib.util.module_from_spec(gate_spec)
30
- gate_spec.loader.exec_module(gate_module)
31
- gated_repo_directories = gate_module.gated_repo_directories
32
- deny_reason_for_directory = gate_module.deny_reason_for_directory
33
- gate_main = gate_module.main
34
-
35
- store_spec = importlib.util.spec_from_file_location(
36
- "verification_verdict_store",
37
- _HOOK_DIR / "verification_verdict_store.py",
38
- )
39
- assert store_spec is not None
40
- assert store_spec.loader is not None
41
- store_module = importlib.util.module_from_spec(store_spec)
42
- store_spec.loader.exec_module(store_module)
43
- resolve_merge_base = store_module.resolve_merge_base
44
- branch_surface_manifest = store_module.branch_surface_manifest
45
- manifest_sha256 = store_module.manifest_sha256
46
-
47
- PRODUCTION_SOURCE = "def add(left: int, right: int) -> int:\n return left + right\n"
48
-
49
-
50
- def test_plain_git_commit_is_gated() -> None:
51
- assert gated_repo_directories("git commit -m x", "FALLBACK") == ["FALLBACK"]
52
-
53
-
54
- def test_git_exe_commit_is_gated() -> None:
55
- assert gated_repo_directories("git.exe commit -m x", "FALLBACK") == ["FALLBACK"]
56
-
57
-
58
- def test_git_exe_push_is_gated() -> None:
59
- assert gated_repo_directories("git.exe push origin main", "FALLBACK") == [
60
- "FALLBACK"
61
- ]
62
-
63
-
64
- def test_git_exe_commit_records_repo_directory_option() -> None:
65
- assert gated_repo_directories('git.exe -C "/repo" commit -m x', "FALLBACK") == [
66
- "/repo"
67
- ]
68
-
69
-
70
- def test_git_log_grep_commit_is_not_gated() -> None:
71
- assert gated_repo_directories("git log --grep commit", "FALLBACK") == []
72
-
73
-
74
- def test_git_stash_push_is_not_gated() -> None:
75
- assert gated_repo_directories("git stash push", "FALLBACK") == []
76
-
77
-
78
- def test_git_dir_option_value_yields_single_entry() -> None:
79
- assert gated_repo_directories(
80
- "git --git-dir=/x/.git commit", "FALLBACK"
81
- ) == ["FALLBACK"]
82
-
83
-
84
- def test_substring_git_in_branch_name_is_not_a_git_word() -> None:
85
- assert gated_repo_directories("git push origin legit-branch", "FALLBACK") == [
86
- "FALLBACK"
87
- ]
88
-
89
-
90
- def test_two_real_git_commits_yield_two_entries() -> None:
91
- assert gated_repo_directories(
92
- "git commit -m x && git push origin main", "FALLBACK"
93
- ) == ["FALLBACK", "FALLBACK"]
94
-
95
-
96
- def test_unix_path_prefixed_git_commit_is_gated() -> None:
97
- assert gated_repo_directories("/usr/bin/git commit -m x", "FALLBACK") == [
98
- "FALLBACK"
99
- ]
100
-
101
-
102
- def test_windows_path_prefixed_git_exe_commit_is_gated() -> None:
103
- assert gated_repo_directories(
104
- "C:/Program Files/Git/bin/git.exe commit -m x", "FALLBACK"
105
- ) == ["FALLBACK"]
106
-
107
-
108
- def test_backslash_path_prefixed_git_exe_commit_is_gated() -> None:
109
- assert gated_repo_directories(
110
- "C:\\Program Files\\Git\\cmd\\git.exe commit", "FALLBACK"
111
- ) == ["FALLBACK"]
112
-
113
-
114
- def test_quoted_git_word_commit_is_gated() -> None:
115
- assert gated_repo_directories('"git" commit -m x', "FALLBACK") == ["FALLBACK"]
116
-
117
-
118
- def test_call_operator_path_git_exe_commit_is_gated() -> None:
119
- assert gated_repo_directories("& 'C:/x/git.exe' commit", "FALLBACK") == [
120
- "FALLBACK"
121
- ]
122
-
123
-
124
- def test_call_operator_program_files_git_exe_commit_is_gated() -> None:
125
- assert gated_repo_directories(
126
- '& "C:\\Program Files\\Git\\cmd\\git.exe" commit -m x', "C:/repo"
127
- ) == ["C:/repo"]
128
-
129
-
130
- def test_quoted_program_files_git_exe_commit_is_gated() -> None:
131
- assert gated_repo_directories(
132
- '"C:/Program Files/Git/cmd/git.exe" commit', "C:/repo"
133
- ) == ["C:/repo"]
134
-
135
-
136
- def test_quoted_program_files_path_without_git_segment_is_not_gated() -> None:
137
- assert gated_repo_directories(
138
- '"C:/Program Files/Other/tool.exe" commit', "C:/repo"
139
- ) == []
140
-
141
-
142
- def test_path_prefixed_git_log_grep_commit_is_not_gated() -> None:
143
- assert gated_repo_directories("/usr/bin/git log --grep commit", "FALLBACK") == []
144
-
145
-
146
- def test_mygit_commit_is_not_a_git_word() -> None:
147
- assert gated_repo_directories("mygit commit", "FALLBACK") == []
148
-
149
-
150
- def test_legit_commit_is_not_a_git_word() -> None:
151
- assert gated_repo_directories("legit commit", "FALLBACK") == []
152
-
153
-
154
- def test_cd_then_git_commit_gates_the_cd_directory() -> None:
155
- assert gated_repo_directories(
156
- "cd /other/repo && git commit -m x", "FALLBACK"
157
- ) == ["/other/repo"]
158
-
159
-
160
- def test_pushd_then_git_commit_gates_the_pushd_directory() -> None:
161
- assert gated_repo_directories(
162
- "pushd /other/repo; git commit -m x", "FALLBACK"
163
- ) == ["/other/repo"]
164
-
165
-
166
- def test_cd_with_quoted_directory_gates_the_quoted_directory() -> None:
167
- assert gated_repo_directories(
168
- 'cd "/path with spaces" && git commit -m x', "FALLBACK"
169
- ) == ["/path with spaces"]
170
-
171
-
172
- def test_explicit_repo_option_overrides_cd_directory() -> None:
173
- assert gated_repo_directories(
174
- 'cd /other/repo && git -C "/repo" commit -m x', "FALLBACK"
175
- ) == ["/repo"]
176
-
177
-
178
- def test_later_cd_applies_to_later_git_commit() -> None:
179
- assert gated_repo_directories(
180
- "git commit -m a && cd /second && git commit -m b", "FALLBACK"
181
- ) == ["FALLBACK", "/second"]
182
-
183
-
184
- def test_cd_without_argument_keeps_the_fallback_directory() -> None:
185
- assert gated_repo_directories("cd && git commit -m x", "FALLBACK") == [
186
- "FALLBACK"
187
- ]
188
-
189
-
190
- def test_set_location_then_git_commit_gates_the_set_location_directory() -> None:
191
- assert gated_repo_directories(
192
- "Set-Location /other/repo; git commit -m x", "FALLBACK"
193
- ) == ["/other/repo"]
194
-
195
-
196
- def test_sl_alias_then_git_commit_gates_the_sl_directory() -> None:
197
- assert gated_repo_directories(
198
- "sl /other/repo; git commit -m x", "FALLBACK"
199
- ) == ["/other/repo"]
200
-
201
-
202
- def test_set_location_is_matched_case_insensitively() -> None:
203
- assert gated_repo_directories(
204
- "set-location /other/repo; git commit -m x", "FALLBACK"
205
- ) == ["/other/repo"]
206
-
207
-
208
- def test_relative_cd_target_resolves_against_the_fallback_directory() -> None:
209
- expected_directory = os.path.join("/session/dir", "subdir")
210
- assert gated_repo_directories(
211
- "cd subdir && git commit -m x", "/session/dir"
212
- ) == [expected_directory]
213
-
214
-
215
- def test_relative_set_location_target_resolves_against_the_fallback_directory() -> None:
216
- expected_directory = os.path.join("/session/dir", "subdir")
217
- assert gated_repo_directories(
218
- "Set-Location subdir; git commit -m x", "/session/dir"
219
- ) == [expected_directory]
220
-
221
-
222
- def test_absolute_cd_target_is_not_joined_to_the_fallback_directory() -> None:
223
- assert gated_repo_directories(
224
- "cd /other/repo && git commit -m x", "/session/dir"
225
- ) == ["/other/repo"]
226
-
227
-
228
- def test_work_tree_option_gates_the_work_tree_directory() -> None:
229
- assert gated_repo_directories(
230
- "git --git-dir=/other/.git --work-tree=/other commit", "/session"
231
- ) == ["/other"]
232
-
233
-
234
- def test_work_tree_space_separated_option_gates_the_work_tree_directory() -> None:
235
- assert gated_repo_directories(
236
- "git --work-tree /other commit -m x", "/session"
237
- ) == ["/other"]
238
-
239
-
240
- def test_repo_option_overrides_work_tree_option() -> None:
241
- assert gated_repo_directories(
242
- 'git -C "/repo" --work-tree=/other commit', "/session"
243
- ) == ["/repo"]
244
-
245
-
246
- def test_relative_repo_option_resolves_against_the_active_directory() -> None:
247
- expected_directory = os.path.join("/repo", "subdir")
248
- assert gated_repo_directories(
249
- "cd /repo && git -C subdir commit -m x", "FALLBACK"
250
- ) == [expected_directory]
251
-
252
-
253
- def test_relative_work_tree_option_resolves_against_the_active_directory() -> None:
254
- expected_directory = os.path.join("/repo", "subtree")
255
- assert gated_repo_directories(
256
- "cd /repo && git --work-tree subtree commit -m x", "FALLBACK"
257
- ) == [expected_directory]
258
-
259
-
260
- def test_relative_repo_option_resolves_against_the_fallback_directory() -> None:
261
- expected_directory = os.path.join("/session/dir", "subdir")
262
- assert gated_repo_directories(
263
- "git -C subdir commit -m x", "/session/dir"
264
- ) == [expected_directory]
265
-
266
-
267
- def _set_fake_home(monkeypatch: pytest.MonkeyPatch, fake_home: pathlib.Path) -> str:
268
- home_text = str(fake_home)
269
- monkeypatch.setenv("HOME", home_text)
270
- monkeypatch.setenv("USERPROFILE", home_text)
271
- monkeypatch.delenv("HOMEDRIVE", raising=False)
272
- monkeypatch.delenv("HOMEPATH", raising=False)
273
- return home_text
274
-
275
-
276
- def test_cd_into_tilde_repo_gates_the_expanded_home_path(
277
- monkeypatch: pytest.MonkeyPatch, tmp_path: pathlib.Path
278
- ) -> None:
279
- home_text = _set_fake_home(monkeypatch, tmp_path)
280
- expected_directory = os.path.expanduser("~/myrepo")
281
- assert home_text in expected_directory
282
- assert gated_repo_directories(
283
- "cd ~/myrepo && git commit -m x", "FALLBACK"
284
- ) == [expected_directory]
285
-
286
-
287
- def test_git_dash_c_tilde_repo_gates_the_expanded_home_path(
288
- monkeypatch: pytest.MonkeyPatch, tmp_path: pathlib.Path
289
- ) -> None:
290
- home_text = _set_fake_home(monkeypatch, tmp_path)
291
- expected_directory = os.path.expanduser("~/myrepo")
292
- assert home_text in expected_directory
293
- assert gated_repo_directories(
294
- "git -C ~/myrepo commit -m x", "FALLBACK"
295
- ) == [expected_directory]
296
-
297
-
298
- def test_git_work_tree_tilde_repo_gates_the_expanded_home_path(
299
- monkeypatch: pytest.MonkeyPatch, tmp_path: pathlib.Path
300
- ) -> None:
301
- home_text = _set_fake_home(monkeypatch, tmp_path)
302
- expected_directory = os.path.expanduser("~/myrepo")
303
- assert home_text in expected_directory
304
- assert gated_repo_directories(
305
- "git --work-tree ~/myrepo commit -m x", "FALLBACK"
306
- ) == [expected_directory]
307
-
308
-
309
- def test_set_location_path_option_gates_the_path_value() -> None:
310
- assert gated_repo_directories(
311
- "Set-Location -Path /repo; git commit -m x", "FALLBACK"
312
- ) == ["/repo"]
313
-
314
-
315
- def test_pushd_literal_path_option_gates_the_path_value() -> None:
316
- assert gated_repo_directories(
317
- "pushd -LiteralPath /repo; git commit", "FALLBACK"
318
- ) == ["/repo"]
319
-
320
-
321
- def test_cd_double_dash_terminator_gates_the_path_value() -> None:
322
- assert gated_repo_directories(
323
- "cd -- /repo && git commit", "FALLBACK"
324
- ) == ["/repo"]
325
-
326
-
327
- def test_cd_inside_double_quoted_commit_message_does_not_divert_later_push() -> None:
328
- assert gated_repo_directories(
329
- 'git commit -m "context: cd /var/empty/nonrepo first" && git push',
330
- "/real/repo/worktree",
331
- ) == ["/real/repo/worktree", "/real/repo/worktree"]
332
-
333
-
334
- def test_cd_inside_single_quoted_commit_message_does_not_divert_later_push() -> None:
335
- assert gated_repo_directories(
336
- "git commit -m 'context: cd /var/empty/nonrepo first' && git push",
337
- "/real/repo/worktree",
338
- ) == ["/real/repo/worktree", "/real/repo/worktree"]
339
-
340
-
341
- def test_pushd_inside_quoted_commit_message_does_not_divert_later_push() -> None:
342
- assert gated_repo_directories(
343
- 'git commit -m "context: pushd /var/empty/nonrepo first" && git push',
344
- "/real/repo/worktree",
345
- ) == ["/real/repo/worktree", "/real/repo/worktree"]
346
-
347
-
348
- def test_real_cd_outside_quotes_still_diverts_after_a_quoted_message() -> None:
349
- assert gated_repo_directories(
350
- 'git commit -m "msg" && cd /other/repo && git push',
351
- "/real/repo/worktree",
352
- ) == ["/real/repo/worktree", "/other/repo"]
353
-
354
-
355
- def test_git_word_inside_quoted_commit_message_yields_one_entry() -> None:
356
- assert gated_repo_directories(
357
- 'git commit -m "remember to git commit later"', "FB"
358
- ) == ["FB"]
359
-
360
-
361
- def test_git_word_inside_single_quoted_message_value_yields_one_entry() -> None:
362
- assert gated_repo_directories(
363
- "git commit -m 'remember to git commit later'", "FB"
364
- ) == ["FB"]
365
-
366
-
367
- def test_backslash_newline_after_git_word_is_gated() -> None:
368
- assert gated_repo_directories("git \\\n commit -m x", "FB") == ["FB"]
369
-
370
-
371
- def test_backslash_newline_abutting_subcommand_is_gated() -> None:
372
- assert gated_repo_directories("git commit\\\n -m x", "FB") == ["FB"]
373
-
374
-
375
- def test_backslash_newline_splitting_git_word_is_gated() -> None:
376
- assert gated_repo_directories("g\\\nit commit -m x", "FB") == ["FB"]
377
-
378
-
379
- def test_git_verb_inside_echo_prose_is_not_gated() -> None:
380
- assert gated_repo_directories(
381
- 'echo "Next: git commit and git push"', "/d"
382
- ) == []
383
-
384
-
385
- def test_git_verb_inside_gh_comment_body_is_not_gated() -> None:
386
- assert gated_repo_directories(
387
- 'gh pr comment -b "please git commit your work"', "/d"
388
- ) == []
389
-
390
-
391
- def _run_git(repo_dir: pathlib.Path, *git_arguments: str) -> None:
392
- subprocess.run(
393
- ["git", "-C", str(repo_dir), *git_arguments],
394
- check=True,
395
- capture_output=True,
396
- text=True,
397
- )
398
-
399
-
400
- def _make_gated_repo(tmp_path: pathlib.Path) -> pathlib.Path:
401
- origin_dir = tmp_path / "origin.git"
402
- work_dir = tmp_path / "work"
403
- work_dir.mkdir()
404
- subprocess.run(
405
- ["git", "init", "--bare", "--initial-branch=main", str(origin_dir)],
406
- check=True,
407
- capture_output=True,
408
- text=True,
409
- )
410
- _run_git(work_dir, "init", "--initial-branch=main")
411
- _run_git(work_dir, "config", "user.email", "tests@example.com")
412
- _run_git(work_dir, "config", "user.name", "Gate Tests")
413
- (work_dir / "app.py").write_text(PRODUCTION_SOURCE, encoding="utf-8")
414
- _run_git(work_dir, "add", "-A")
415
- _run_git(work_dir, "commit", "-m", "base")
416
- _run_git(work_dir, "remote", "add", "origin", str(origin_dir))
417
- _run_git(work_dir, "push", "-u", "origin", "main")
418
- (work_dir / "app.py").write_text(
419
- "def add(left: int, right: int) -> int:\n return left - right\n",
420
- encoding="utf-8",
421
- )
422
- return work_dir
423
-
424
-
425
- def _live_surface_hash(work_dir: pathlib.Path) -> str:
426
- merge_base_sha = resolve_merge_base(str(work_dir))
427
- assert merge_base_sha is not None
428
- surface_manifest_text = branch_surface_manifest(str(work_dir), merge_base_sha)
429
- assert surface_manifest_text is not None
430
- return manifest_sha256(surface_manifest_text)
431
-
432
-
433
- def _write_workflow_verdict(
434
- transcript_path: pathlib.Path, bound_manifest_sha256: str
435
- ) -> None:
436
- subagents_dir = transcript_path.with_suffix("") / "subagents"
437
- workflow_dir = subagents_dir / "workflows" / "wf_x"
438
- workflow_dir.mkdir(parents=True)
439
- verdict_record = {
440
- "all_pass": True,
441
- "findings": [],
442
- "manifest_sha256": bound_manifest_sha256,
443
- }
444
- assistant_text = (
445
- "Verification complete.\n\n```verdict\n"
446
- + json.dumps(verdict_record)
447
- + "\n```\n"
448
- )
449
- assistant_entry = {
450
- "type": "assistant",
451
- "message": {"content": [{"type": "text", "text": assistant_text}]},
452
- }
453
- (workflow_dir / "agent-01.jsonl").write_text(
454
- json.dumps(assistant_entry) + "\n", encoding="utf-8"
455
- )
456
- (workflow_dir / "agent-01.meta.json").write_text(
457
- json.dumps({"agentType": "code-verifier"}), encoding="utf-8"
458
- )
459
-
460
-
461
- def _isolate_home(monkeypatch: pytest.MonkeyPatch, fake_home: pathlib.Path) -> None:
462
- home_text = str(fake_home)
463
- monkeypatch.setenv("HOME", home_text)
464
- monkeypatch.setenv("USERPROFILE", home_text)
465
- monkeypatch.delenv("HOMEDRIVE", raising=False)
466
- monkeypatch.delenv("HOMEPATH", raising=False)
467
-
468
-
469
- def test_workflow_verdict_allows_commit_without_a_minted_verdict_file(
470
- monkeypatch: pytest.MonkeyPatch, tmp_path: pathlib.Path
471
- ) -> None:
472
- fake_home = tmp_path / "home"
473
- fake_home.mkdir()
474
- _isolate_home(monkeypatch, fake_home)
475
- work_dir = _make_gated_repo(tmp_path)
476
- live_surface_hash = _live_surface_hash(work_dir)
477
- transcript_path = tmp_path / "projects" / "demo" / "sess1.jsonl"
478
- transcript_path.parent.mkdir(parents=True)
479
- transcript_path.write_text("", encoding="utf-8")
480
- _write_workflow_verdict(transcript_path, live_surface_hash)
481
- assert (
482
- deny_reason_for_directory(str(work_dir), str(transcript_path)) is None
483
- )
484
-
485
-
486
- def test_no_verdict_of_either_kind_denies_the_commit(
487
- monkeypatch: pytest.MonkeyPatch, tmp_path: pathlib.Path
488
- ) -> None:
489
- fake_home = tmp_path / "home"
490
- fake_home.mkdir()
491
- _isolate_home(monkeypatch, fake_home)
492
- work_dir = _make_gated_repo(tmp_path)
493
- transcript_path = tmp_path / "projects" / "demo" / "sess1.jsonl"
494
- transcript_path.parent.mkdir(parents=True)
495
- transcript_path.write_text("", encoding="utf-8")
496
- deny_reason = deny_reason_for_directory(str(work_dir), str(transcript_path))
497
- assert deny_reason is not None
498
- assert "VERIFIED_COMMIT_GATE" in deny_reason
499
-
500
-
501
- def _run_gate_main(
502
- monkeypatch: pytest.MonkeyPatch, command_text: str, work_dir: pathlib.Path
503
- ) -> None:
504
- payload_text = json.dumps(
505
- {
506
- "tool_name": "Bash",
507
- "tool_input": {"command": command_text},
508
- "cwd": str(work_dir),
509
- "transcript_path": "",
510
- }
511
- )
512
- monkeypatch.setattr(sys, "stdin", io.StringIO(payload_text))
513
- gate_main()
514
-
515
-
516
- def test_verification_bypass_marker_allows_an_otherwise_gated_commit(
517
- monkeypatch: pytest.MonkeyPatch,
518
- capsys: pytest.CaptureFixture[str],
519
- tmp_path: pathlib.Path,
520
- ) -> None:
521
- fake_home = tmp_path / "home"
522
- fake_home.mkdir()
523
- _isolate_home(monkeypatch, fake_home)
524
- work_dir = _make_gated_repo(tmp_path)
525
- _run_gate_main(monkeypatch, "git commit -m x", work_dir)
526
- assert "VERIFIED_COMMIT_GATE" in capsys.readouterr().out
527
- _run_gate_main(monkeypatch, "git commit -m x # verify-skip", work_dir)
528
- assert capsys.readouterr().out == ""
529
-
530
-
531
- def test_minted_verdict_from_other_worktree_allows_commit_by_hash(
532
- monkeypatch: pytest.MonkeyPatch, tmp_path: pathlib.Path
533
- ) -> None:
534
- fake_home = tmp_path / "home"
535
- fake_home.mkdir()
536
- _isolate_home(monkeypatch, fake_home)
537
- work_dir = _make_gated_repo(tmp_path)
538
- live_surface_hash = _live_surface_hash(work_dir)
539
- store_module.write_verdict(
540
- str(tmp_path / "sibling" / "worktree"),
541
- live_surface_hash,
542
- True,
543
- [],
544
- "agent-x",
545
- )
546
- transcript_path = tmp_path / "projects" / "demo" / "sess1.jsonl"
547
- transcript_path.parent.mkdir(parents=True)
548
- transcript_path.write_text("", encoding="utf-8")
549
- assert deny_reason_for_directory(str(work_dir), str(transcript_path)) is None
550
-
551
-
552
- def test_minted_verdict_from_other_worktree_with_wrong_hash_denies(
553
- monkeypatch: pytest.MonkeyPatch, tmp_path: pathlib.Path
554
- ) -> None:
555
- fake_home = tmp_path / "home"
556
- fake_home.mkdir()
557
- _isolate_home(monkeypatch, fake_home)
558
- work_dir = _make_gated_repo(tmp_path)
559
- store_module.write_verdict(
560
- str(tmp_path / "sibling" / "worktree"),
561
- "d" * 64,
562
- True,
563
- [],
564
- "agent-x",
565
- )
566
- transcript_path = tmp_path / "projects" / "demo" / "sess1.jsonl"
567
- transcript_path.parent.mkdir(parents=True)
568
- transcript_path.write_text("", encoding="utf-8")
569
- deny_reason = deny_reason_for_directory(str(work_dir), str(transcript_path))
570
- assert deny_reason is not None
571
- assert "VERIFIED_COMMIT_GATE" in deny_reason
572
-
573
-
574
- def test_gate_imports_under_foreign_config_shadow(
575
- run_under_config_shadow: Callable[[str], subprocess.CompletedProcess[str]],
576
- ) -> None:
577
- completed_probe = run_under_config_shadow(
578
- "import verified_commit_gate\nprint('IMPORT_OK')\n"
579
- )
580
- assert completed_probe.returncode == 0, completed_probe.stderr
581
- assert "IMPORT_OK" in completed_probe.stdout