@leocm/flowcraft 2.1.0 → 2.3.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.
- package/README.md +19 -2
- package/bin/cli.js +108 -108
- package/flowcraft.yaml +30 -30
- package/install.sh +24 -24
- package/lib/args.js +38 -38
- package/lib/config.js +20 -20
- package/lib/copy.js +131 -131
- package/lib/fix.js +110 -110
- package/lib/fsutil.js +104 -104
- package/lib/global.js +229 -229
- package/lib/init.js +43 -43
- package/lib/runtime.js +84 -84
- package/lib/version.js +55 -55
- package/lib/wizard.js +125 -125
- package/package.json +33 -33
- package/presets/backend.yaml +20 -20
- package/presets/default.yaml +15 -15
- package/presets/frontend.yaml +20 -20
- package/presets/quick-fix.yaml +15 -15
- package/setup/.claude/hooks/check-phase-test.py +152 -152
- package/setup/.claude/hooks/check-phase-write.py +235 -235
- package/setup/.claude/hooks/dispatch.py +67 -67
- package/setup/.claude/hooks/file-suggestion.py +45 -45
- package/setup/.claude/hooks/flowcraft_env.py +162 -137
- package/setup/.claude/hooks/permission-request.py +132 -125
- package/setup/.claude/hooks/post-tool-failure.py +36 -36
- package/setup/.claude/hooks/pre-compact.py +66 -66
- package/setup/.claude/hooks/review-runner.py +846 -846
- package/setup/.claude/hooks/setup-keys.py +282 -282
- package/setup/.claude/hooks/statusline.py +63 -63
- package/setup/.claude/hooks/stop-check.py +186 -171
- package/setup/.claude/hooks/subagent-start.py +50 -50
- package/setup/.claude/hooks/subagent-stop.py +63 -63
- package/setup/.claude/hooks/task-completed.py +57 -57
- package/setup/.claude/hooks/task_manager.py +592 -592
- package/setup/.claude/hooks/user-prompt-submit.py +91 -85
- package/setup/.claude/settings.json +233 -237
- package/setup/.claude/skills/Pstatus/SKILL.md +68 -68
- package/setup/.claude/skills/archive/SKILL.md +195 -195
- package/setup/.claude/skills/brainstorming/SKILL.md +5 -5
- package/setup/.claude/skills/brainstorming/scripts/server.cjs +723 -723
- package/setup/.claude/skills/brainstorming/scripts/start-server.py +245 -245
- package/setup/.claude/skills/brainstorming/scripts/stop-server.py +178 -178
- package/setup/.claude/skills/brainstorming/visual-companion.md +298 -298
- package/setup/.claude/skills/chrome-integration/SKILL.md +66 -66
- package/setup/.claude/skills/code-review/SKILL.md +264 -264
- package/setup/.claude/skills/executing-plans/SKILL.md +1 -1
- package/setup/.claude/skills/gitnexus/gitnexus-cli/SKILL.md +67 -67
- package/setup/.claude/skills/gitnexus/gitnexus-debugging/SKILL.md +1 -1
- package/setup/.claude/skills/gitnexus/gitnexus-exploring/SKILL.md +1 -1
- package/setup/.claude/skills/gitnexus/gitnexus-guide/SKILL.md +1 -1
- package/setup/.claude/skills/gitnexus/gitnexus-impact-analysis/SKILL.md +1 -1
- package/setup/.claude/skills/gitnexus/gitnexus-refactoring/SKILL.md +1 -1
- package/setup/.claude/skills/methodology/SKILL.md +124 -0
- package/setup/.claude/skills/phase/SKILL.md +62 -62
- package/setup/.claude/skills/playwright/SKILL.md +85 -85
- package/setup/.claude/skills/review/SKILL.md +97 -97
- package/setup/.claude/skills/task/SKILL.md +26 -26
- package/setup/.claude/skills/test-driven-development/SKILL.md +1 -1
- package/setup/.claude/skills/ui-ux-pro-max/SKILL.md +1 -1
- package/setup/.claude/skills/verification-before-completion/SKILL.md +1 -1
- package/setup/.claude/skills/writing-plans/SKILL.md +1 -1
- package/setup/.codex/.agents/skills/archive/SKILL.md +195 -195
- package/setup/.codex/.agents/skills/brainstorming/SKILL.md +5 -5
- package/setup/.codex/.agents/skills/brainstorming/scripts/server.cjs +723 -723
- package/setup/.codex/.agents/skills/brainstorming/scripts/start-server.py +245 -245
- package/setup/.codex/.agents/skills/brainstorming/scripts/stop-server.py +178 -178
- package/setup/.codex/.agents/skills/brainstorming/visual-companion.md +298 -298
- package/setup/.codex/.agents/skills/chrome-integration/SKILL.md +66 -66
- package/setup/.codex/.agents/skills/code-review/SKILL.md +264 -264
- package/setup/.codex/.agents/skills/executing-plans/SKILL.md +1 -1
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-cli/SKILL.md +67 -67
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-debugging/SKILL.md +1 -1
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-exploring/SKILL.md +1 -1
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-guide/SKILL.md +1 -1
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-impact-analysis/SKILL.md +1 -1
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-refactoring/SKILL.md +1 -1
- package/setup/.codex/.agents/skills/methodology/SKILL.md +124 -0
- package/setup/.codex/.agents/skills/phase/SKILL.md +62 -62
- package/setup/.codex/.agents/skills/playwright/SKILL.md +85 -85
- package/setup/.codex/.agents/skills/review/SKILL.md +97 -97
- package/setup/.codex/.agents/skills/task/SKILL.md +27 -27
- package/setup/.codex/.agents/skills/test-driven-development/SKILL.md +1 -1
- package/setup/.codex/.agents/skills/ui-ux-pro-max/SKILL.md +1 -1
- package/setup/.codex/.agents/skills/verification-before-completion/SKILL.md +1 -1
- package/setup/.codex/.agents/skills/writing-plans/SKILL.md +1 -1
- package/setup/.codex/hooks/review-runner.py +851 -851
- package/setup/.codex/hooks/setup-keys.py +287 -287
- package/setup/AGENTS.md +11 -1
- package/setup/CLAUDE.md +11 -1
- package/setup/install.sh +24 -24
- package/setup/tests/test_decision_timeout.py +241 -241
- package/setup/tests/test_hook_guards.py +357 -357
- package/setup/tests/test_sdlc_bootstrap.py +167 -167
- package/setup/tests/test_sessionlog_switch.py +199 -0
- package/setup/tests/test_task_manager.py +148 -148
|
@@ -1,357 +1,357 @@
|
|
|
1
|
-
"""Hook guard tests for PRD R1-R6: payload extraction, phase write guards.
|
|
2
|
-
|
|
3
|
-
Runs the real hook scripts via subprocess with stdin payloads (same shape
|
|
4
|
-
Claude Code sends), asserting exit codes, stderr and state mutations.
|
|
5
|
-
"""
|
|
6
|
-
import json
|
|
7
|
-
import os
|
|
8
|
-
import subprocess
|
|
9
|
-
import sys
|
|
10
|
-
from pathlib import Path
|
|
11
|
-
|
|
12
|
-
import pytest
|
|
13
|
-
|
|
14
|
-
HOOKS = Path(__file__).resolve().parents[1] / ".claude" / "hooks"
|
|
15
|
-
sys.path.insert(0, str(HOOKS))
|
|
16
|
-
|
|
17
|
-
import flowcraft_env as fe
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def run_hook(name, payload, cwd, extra_env=None):
|
|
21
|
-
"""Run a hook script with the given stdin payload from cwd.
|
|
22
|
-
|
|
23
|
-
CLAUDE_PROJECT_DIR pins root resolution to the tmp project so the walk-up
|
|
24
|
-
never escapes into the real user home or the repo's setup template state.
|
|
25
|
-
"""
|
|
26
|
-
env = os.environ.copy()
|
|
27
|
-
env["CLAUDE_PROJECT_DIR"] = str(cwd)
|
|
28
|
-
env.pop("FLOWCRAFT_TASK_ID", None)
|
|
29
|
-
env.pop("FLOWCRAFT_SESSION_ID", None)
|
|
30
|
-
if extra_env:
|
|
31
|
-
env.update(extra_env)
|
|
32
|
-
return subprocess.run(
|
|
33
|
-
[sys.executable, str(HOOKS / name)],
|
|
34
|
-
input=payload,
|
|
35
|
-
capture_output=True,
|
|
36
|
-
encoding="utf-8",
|
|
37
|
-
errors="replace",
|
|
38
|
-
cwd=str(cwd),
|
|
39
|
-
env=env,
|
|
40
|
-
timeout=60,
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
def make_state(root, phase, complexity='"medium"'):
|
|
45
|
-
"""Create a minimal project-state.md in tmp root."""
|
|
46
|
-
(root / ".claude").mkdir(parents=True, exist_ok=True)
|
|
47
|
-
(root / ".claude" / "project-state.md").write_text(
|
|
48
|
-
f"current_phase: {phase}\ncomplexity_level: {complexity}\nphase_history: []\n",
|
|
49
|
-
encoding="utf-8",
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def edit_payload(file_path, new_string="b"):
|
|
54
|
-
"""Realistic PreToolUse payload: file_path nested under tool_input."""
|
|
55
|
-
return json.dumps({
|
|
56
|
-
"tool_name": "Edit",
|
|
57
|
-
"tool_input": {"file_path": file_path, "old_string": "a", "new_string": new_string},
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def read_phase(root):
|
|
62
|
-
content = (root / ".claude" / "project-state.md").read_text(encoding="utf-8")
|
|
63
|
-
for line in content.splitlines():
|
|
64
|
-
if line.startswith("current_phase:"):
|
|
65
|
-
return line.split(":", 1)[1].strip()
|
|
66
|
-
return ""
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
# ---------- R5: extract_nested unit tests ----------
|
|
70
|
-
|
|
71
|
-
class TestExtractNested:
|
|
72
|
-
def test_nested_tool_input(self):
|
|
73
|
-
raw = '{"tool_name":"Edit","tool_input":{"file_path":"C:/a.py"}}'
|
|
74
|
-
assert fe.extract_nested(raw, "file_path") == "C:/a.py"
|
|
75
|
-
|
|
76
|
-
def test_flat_top_level(self):
|
|
77
|
-
raw = '{"file_path":"C:/b.py"}'
|
|
78
|
-
assert fe.extract_nested(raw, "file_path") == "C:/b.py"
|
|
79
|
-
|
|
80
|
-
def test_missing_key_returns_empty(self):
|
|
81
|
-
raw = '{"tool_name":"Edit","tool_input":{"other":1}}'
|
|
82
|
-
assert fe.extract_nested(raw, "file_path") == ""
|
|
83
|
-
|
|
84
|
-
def test_empty_payload(self):
|
|
85
|
-
assert fe.extract_nested("", "file_path") == ""
|
|
86
|
-
|
|
87
|
-
def test_malformed_json_regex_fallback(self):
|
|
88
|
-
raw = 'not json {"tool_input":{"command":"pytest -q"}} tail'
|
|
89
|
-
assert fe.extract_nested(raw, "command") == "pytest -q"
|
|
90
|
-
|
|
91
|
-
def test_bytes_input(self):
|
|
92
|
-
raw = b'{"file_path":"C:/c.py"}'
|
|
93
|
-
assert fe.extract_nested(raw, "file_path") == "C:/c.py"
|
|
94
|
-
|
|
95
|
-
def test_nested_empty_value_falls_to_flat(self):
|
|
96
|
-
raw = '{"tool_input":{"command":""},"command":"pytest"}'
|
|
97
|
-
assert fe.extract_nested(raw, "command") == "pytest"
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
# ---------- R1: check-phase-write extraction + phase blocks ----------
|
|
101
|
-
|
|
102
|
-
class TestCheckPhaseWrite:
|
|
103
|
-
def test_p1_nested_payload_blocks(self, tmp_path):
|
|
104
|
-
make_state(tmp_path, "P1")
|
|
105
|
-
p = run_hook("check-phase-write.py", edit_payload("C:/x/demo.py"), tmp_path)
|
|
106
|
-
assert p.returncode == 2
|
|
107
|
-
assert "P1阶段禁止" in p.stderr
|
|
108
|
-
|
|
109
|
-
def test_p1_flat_payload_blocks(self, tmp_path):
|
|
110
|
-
make_state(tmp_path, "P1")
|
|
111
|
-
p = run_hook("check-phase-write.py", '{"file_path":"C:/x/demo.py"}', tmp_path)
|
|
112
|
-
assert p.returncode == 2
|
|
113
|
-
|
|
114
|
-
def test_p05_nested_payload_blocks(self, tmp_path):
|
|
115
|
-
make_state(tmp_path, "P0.5")
|
|
116
|
-
p = run_hook("check-phase-write.py", edit_payload("C:/x/demo.py"), tmp_path)
|
|
117
|
-
assert p.returncode == 2
|
|
118
|
-
assert "P0.5" in p.stderr
|
|
119
|
-
|
|
120
|
-
def test_p5_nested_payload_blocks(self, tmp_path):
|
|
121
|
-
make_state(tmp_path, "P5")
|
|
122
|
-
p = run_hook("check-phase-write.py", edit_payload("C:/x/demo.py"), tmp_path)
|
|
123
|
-
assert p.returncode == 2
|
|
124
|
-
|
|
125
|
-
def test_p1_plan_file_allowed(self, tmp_path):
|
|
126
|
-
make_state(tmp_path, "P1")
|
|
127
|
-
p = run_hook("check-phase-write.py", edit_payload("C:/x/plan/t.md"), tmp_path)
|
|
128
|
-
assert p.returncode == 0
|
|
129
|
-
|
|
130
|
-
def test_framework_file_blocked(self, tmp_path):
|
|
131
|
-
"""R1: 项目内 .claude 框架文件仍拦(守卫只守本项目,项目内不放开)。"""
|
|
132
|
-
make_state(tmp_path, "P2")
|
|
133
|
-
target = tmp_path / ".claude" / "settings.json"
|
|
134
|
-
p = run_hook("check-phase-write.py", edit_payload(str(target)), tmp_path)
|
|
135
|
-
assert p.returncode == 2
|
|
136
|
-
|
|
137
|
-
def test_user_level_claude_allowed(self, tmp_path):
|
|
138
|
-
"""R1: 非项目内的 .claude(如 ~/.claude/plans/ 计划草稿)不归守卫管,放行。"""
|
|
139
|
-
make_state(tmp_path, "P2")
|
|
140
|
-
outside = tmp_path.parent / "fake-home" / ".claude" / "plans" / "draft.md"
|
|
141
|
-
p = run_hook("check-phase-write.py", edit_payload(str(outside)), tmp_path)
|
|
142
|
-
assert p.returncode == 0
|
|
143
|
-
|
|
144
|
-
def test_project_claude_plans_allowed(self, tmp_path):
|
|
145
|
-
"""R2: 白名单补 plans/,项目内计划草稿目录放行。"""
|
|
146
|
-
make_state(tmp_path, "P2")
|
|
147
|
-
target = tmp_path / ".claude" / "plans" / "x.md"
|
|
148
|
-
p = run_hook("check-phase-write.py", edit_payload(str(target)), tmp_path)
|
|
149
|
-
assert p.returncode == 0
|
|
150
|
-
|
|
151
|
-
def test_task_state_file_allowed(self, tmp_path):
|
|
152
|
-
"""R6: .claude/tasks/*.md editable (multi-task state files)."""
|
|
153
|
-
make_state(tmp_path, "P2")
|
|
154
|
-
p = run_hook("check-phase-write.py", edit_payload("C:/x/.claude/tasks/t1.md"), tmp_path)
|
|
155
|
-
assert p.returncode == 0
|
|
156
|
-
|
|
157
|
-
def test_code_review_report_allowed(self, tmp_path):
|
|
158
|
-
"""AI 审查报告是框架规定产物,任意阶段可写(与 prd.md 同类)。"""
|
|
159
|
-
make_state(tmp_path, "P2")
|
|
160
|
-
p = run_hook("check-phase-write.py", edit_payload("C:/x/.claude/code-review-report.md"), tmp_path)
|
|
161
|
-
assert p.returncode == 0
|
|
162
|
-
|
|
163
|
-
def test_missing_state_allows(self, tmp_path):
|
|
164
|
-
"""R3 AC1: no state file -> non-SDLC project, allow."""
|
|
165
|
-
(tmp_path / ".claude").mkdir()
|
|
166
|
-
p = run_hook("check-phase-write.py", edit_payload("C:/x/demo.py"), tmp_path)
|
|
167
|
-
assert p.returncode == 0
|
|
168
|
-
|
|
169
|
-
def test_no_file_path_allows(self, tmp_path):
|
|
170
|
-
make_state(tmp_path, "P1")
|
|
171
|
-
p = run_hook("check-phase-write.py", '{"tool_name":"Edit","tool_input":{"other":1}}', tmp_path)
|
|
172
|
-
assert p.returncode == 0
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
# ---------- R2: P0 write blocked + auto-transition to P1 ----------
|
|
176
|
-
|
|
177
|
-
class TestP0Behavior:
|
|
178
|
-
def test_p0_code_write_blocks_and_transitions(self, tmp_path):
|
|
179
|
-
make_state(tmp_path, "P0")
|
|
180
|
-
p = run_hook("check-phase-write.py", edit_payload("C:/x/demo.py"), tmp_path)
|
|
181
|
-
assert p.returncode == 2
|
|
182
|
-
assert read_phase(tmp_path) == "P1"
|
|
183
|
-
|
|
184
|
-
def test_p0_bash_write_blocks_and_transitions(self, tmp_path):
|
|
185
|
-
make_state(tmp_path, "P0")
|
|
186
|
-
payload = json.dumps({"tool_name": "Bash", "tool_input": {"command": "echo x > C:/x/demo.py"}})
|
|
187
|
-
p = run_hook("check-phase-test.py", payload, tmp_path)
|
|
188
|
-
assert p.returncode == 2
|
|
189
|
-
assert read_phase(tmp_path) == "P1"
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
# ---------- R3: get_project_root strict walk-up ----------
|
|
193
|
-
|
|
194
|
-
class TestGetProjectRoot:
|
|
195
|
-
def test_finds_project_by_state_file(self, tmp_path):
|
|
196
|
-
make_state(tmp_path, "P0")
|
|
197
|
-
sub = tmp_path / "sub"
|
|
198
|
-
sub.mkdir()
|
|
199
|
-
# cwd changed via subprocess-free direct call with monkeypatched cwd
|
|
200
|
-
import flowcraft_env
|
|
201
|
-
saved = os.getcwd()
|
|
202
|
-
try:
|
|
203
|
-
os.chdir(str(sub))
|
|
204
|
-
assert flowcraft_env.get_project_root() == tmp_path.resolve()
|
|
205
|
-
finally:
|
|
206
|
-
os.chdir(saved)
|
|
207
|
-
|
|
208
|
-
def test_skips_non_empty_claude_without_state(self, tmp_path):
|
|
209
|
-
"""A non-empty .claude dir without state (e.g. user-level) is skipped;
|
|
210
|
-
the walk continues to the real state-bearing ancestor."""
|
|
211
|
-
make_state(tmp_path, "P0")
|
|
212
|
-
fake_home = tmp_path / "home"
|
|
213
|
-
(fake_home / ".claude").mkdir(parents=True)
|
|
214
|
-
(fake_home / ".claude" / "settings.json").write_text("{}", encoding="utf-8")
|
|
215
|
-
sub = fake_home / "sub"
|
|
216
|
-
sub.mkdir()
|
|
217
|
-
import flowcraft_env
|
|
218
|
-
saved = os.getcwd()
|
|
219
|
-
try:
|
|
220
|
-
os.chdir(str(sub))
|
|
221
|
-
# walk: sub -> fake_home (non-empty .claude, no state -> skip) -> tmp (state)
|
|
222
|
-
assert flowcraft_env.get_project_root() == tmp_path.resolve()
|
|
223
|
-
finally:
|
|
224
|
-
os.chdir(saved)
|
|
225
|
-
|
|
226
|
-
def test_home_state_never_project_root(self, tmp_path, monkeypatch):
|
|
227
|
-
"""R3 AC2: a state-bearing user home must not become the project root."""
|
|
228
|
-
fake_home = tmp_path / "home"
|
|
229
|
-
make_state(fake_home, "P1")
|
|
230
|
-
sub = fake_home / "sub"
|
|
231
|
-
sub.mkdir()
|
|
232
|
-
import flowcraft_env
|
|
233
|
-
monkeypatch.setattr(flowcraft_env.Path, "home", classmethod(lambda cls: fake_home))
|
|
234
|
-
saved = os.getcwd()
|
|
235
|
-
try:
|
|
236
|
-
os.chdir(str(sub))
|
|
237
|
-
# walk: sub -> home (state-bearing ancestor that IS the user home -> skipped)
|
|
238
|
-
root = flowcraft_env.get_project_root()
|
|
239
|
-
assert root != fake_home
|
|
240
|
-
finally:
|
|
241
|
-
os.chdir(saved)
|
|
242
|
-
|
|
243
|
-
def test_home_as_cwd_allowed(self, tmp_path, monkeypatch):
|
|
244
|
-
"""R3 AC2 exception: when cwd IS the home dir, its state may match."""
|
|
245
|
-
fake_home = tmp_path / "home"
|
|
246
|
-
make_state(fake_home, "P1")
|
|
247
|
-
import flowcraft_env
|
|
248
|
-
monkeypatch.setattr(flowcraft_env.Path, "home", classmethod(lambda cls: fake_home))
|
|
249
|
-
saved = os.getcwd()
|
|
250
|
-
try:
|
|
251
|
-
os.chdir(str(fake_home))
|
|
252
|
-
assert flowcraft_env.get_project_root() == fake_home.resolve()
|
|
253
|
-
finally:
|
|
254
|
-
os.chdir(saved)
|
|
255
|
-
|
|
256
|
-
def test_env_var_priority(self, tmp_path):
|
|
257
|
-
make_state(tmp_path, "P0")
|
|
258
|
-
import flowcraft_env
|
|
259
|
-
saved = os.environ.get("CLAUDE_PROJECT_DIR")
|
|
260
|
-
os.environ["CLAUDE_PROJECT_DIR"] = str(tmp_path)
|
|
261
|
-
try:
|
|
262
|
-
assert flowcraft_env.get_project_root() == tmp_path.resolve()
|
|
263
|
-
finally:
|
|
264
|
-
if saved is None:
|
|
265
|
-
os.environ.pop("CLAUDE_PROJECT_DIR", None)
|
|
266
|
-
else:
|
|
267
|
-
os.environ["CLAUDE_PROJECT_DIR"] = saved
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
# ---------- R4: advancement supports P0.5 ----------
|
|
271
|
-
|
|
272
|
-
def adv_payload(state_path, old_phase, new_phase):
|
|
273
|
-
return json.dumps({
|
|
274
|
-
"tool_name": "Edit",
|
|
275
|
-
"tool_input": {
|
|
276
|
-
"file_path": str(state_path).replace("\\", "/"),
|
|
277
|
-
"old_string": f"current_phase: {old_phase}",
|
|
278
|
-
"new_string": f"current_phase: {new_phase}",
|
|
279
|
-
},
|
|
280
|
-
})
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
class TestAdvancementP05:
|
|
284
|
-
def _state(self, tmp_path, phase):
|
|
285
|
-
make_state(tmp_path, phase)
|
|
286
|
-
return tmp_path / ".claude" / "project-state.md"
|
|
287
|
-
|
|
288
|
-
def test_p2_to_p05_allowed(self, tmp_path):
|
|
289
|
-
state = self._state(tmp_path, "P2")
|
|
290
|
-
p = run_hook(
|
|
291
|
-
"check-phase-advancement.py",
|
|
292
|
-
adv_payload(state, "P2", "P0.5"),
|
|
293
|
-
tmp_path,
|
|
294
|
-
extra_env={"CLAUDE_PROJECT_DIR": str(tmp_path)},
|
|
295
|
-
)
|
|
296
|
-
assert p.returncode == 0, p.stdout
|
|
297
|
-
|
|
298
|
-
def test_p2_to_p3_still_allowed(self, tmp_path):
|
|
299
|
-
state = self._state(tmp_path, "P2")
|
|
300
|
-
p = run_hook(
|
|
301
|
-
"check-phase-advancement.py",
|
|
302
|
-
adv_payload(state, "P2", "P3"),
|
|
303
|
-
tmp_path,
|
|
304
|
-
extra_env={"CLAUDE_PROJECT_DIR": str(tmp_path)},
|
|
305
|
-
)
|
|
306
|
-
assert p.returncode == 0, p.stdout
|
|
307
|
-
|
|
308
|
-
def test_p2_to_p4_still_denied(self, tmp_path):
|
|
309
|
-
state = self._state(tmp_path, "P2")
|
|
310
|
-
p = run_hook(
|
|
311
|
-
"check-phase-advancement.py",
|
|
312
|
-
adv_payload(state, "P2", "P4"),
|
|
313
|
-
tmp_path,
|
|
314
|
-
extra_env={"CLAUDE_PROJECT_DIR": str(tmp_path)},
|
|
315
|
-
)
|
|
316
|
-
assert p.returncode == 1
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
# ---------- R5: permission-request migration keeps behavior ----------
|
|
320
|
-
|
|
321
|
-
class TestPermissionRequest:
|
|
322
|
-
def test_write_py_in_p1_denies(self, tmp_path):
|
|
323
|
-
make_state(tmp_path, "P1")
|
|
324
|
-
p = run_hook(
|
|
325
|
-
"permission-request.py",
|
|
326
|
-
edit_payload("C:/x/demo.py"),
|
|
327
|
-
tmp_path,
|
|
328
|
-
extra_env={"CLAUDE_PROJECT_DIR": str(tmp_path)},
|
|
329
|
-
)
|
|
330
|
-
assert p.returncode == 0
|
|
331
|
-
out = json.loads(p.stdout)
|
|
332
|
-
assert out["hookSpecificOutput"]["decision"]["behavior"] == "deny"
|
|
333
|
-
|
|
334
|
-
def test_write_md_in_p1_allows(self, tmp_path):
|
|
335
|
-
make_state(tmp_path, "P1")
|
|
336
|
-
p = run_hook(
|
|
337
|
-
"permission-request.py",
|
|
338
|
-
edit_payload("C:/x/readme.md"),
|
|
339
|
-
tmp_path,
|
|
340
|
-
extra_env={"CLAUDE_PROJECT_DIR": str(tmp_path)},
|
|
341
|
-
)
|
|
342
|
-
assert p.returncode == 0
|
|
343
|
-
out = json.loads(p.stdout)
|
|
344
|
-
assert out["hookSpecificOutput"]["decision"]["behavior"] == "allow"
|
|
345
|
-
|
|
346
|
-
def test_bash_git_commit_in_p2_denies(self, tmp_path):
|
|
347
|
-
make_state(tmp_path, "P2")
|
|
348
|
-
payload = json.dumps({"tool_name": "Bash", "tool_input": {"command": "git commit -m x"}})
|
|
349
|
-
p = run_hook(
|
|
350
|
-
"permission-request.py",
|
|
351
|
-
payload,
|
|
352
|
-
tmp_path,
|
|
353
|
-
extra_env={"CLAUDE_PROJECT_DIR": str(tmp_path)},
|
|
354
|
-
)
|
|
355
|
-
assert p.returncode == 0
|
|
356
|
-
out = json.loads(p.stdout)
|
|
357
|
-
assert out["hookSpecificOutput"]["decision"]["behavior"] == "deny"
|
|
1
|
+
"""Hook guard tests for PRD R1-R6: payload extraction, phase write guards.
|
|
2
|
+
|
|
3
|
+
Runs the real hook scripts via subprocess with stdin payloads (same shape
|
|
4
|
+
Claude Code sends), asserting exit codes, stderr and state mutations.
|
|
5
|
+
"""
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import subprocess
|
|
9
|
+
import sys
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
import pytest
|
|
13
|
+
|
|
14
|
+
HOOKS = Path(__file__).resolve().parents[1] / ".claude" / "hooks"
|
|
15
|
+
sys.path.insert(0, str(HOOKS))
|
|
16
|
+
|
|
17
|
+
import flowcraft_env as fe
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def run_hook(name, payload, cwd, extra_env=None):
|
|
21
|
+
"""Run a hook script with the given stdin payload from cwd.
|
|
22
|
+
|
|
23
|
+
CLAUDE_PROJECT_DIR pins root resolution to the tmp project so the walk-up
|
|
24
|
+
never escapes into the real user home or the repo's setup template state.
|
|
25
|
+
"""
|
|
26
|
+
env = os.environ.copy()
|
|
27
|
+
env["CLAUDE_PROJECT_DIR"] = str(cwd)
|
|
28
|
+
env.pop("FLOWCRAFT_TASK_ID", None)
|
|
29
|
+
env.pop("FLOWCRAFT_SESSION_ID", None)
|
|
30
|
+
if extra_env:
|
|
31
|
+
env.update(extra_env)
|
|
32
|
+
return subprocess.run(
|
|
33
|
+
[sys.executable, str(HOOKS / name)],
|
|
34
|
+
input=payload,
|
|
35
|
+
capture_output=True,
|
|
36
|
+
encoding="utf-8",
|
|
37
|
+
errors="replace",
|
|
38
|
+
cwd=str(cwd),
|
|
39
|
+
env=env,
|
|
40
|
+
timeout=60,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def make_state(root, phase, complexity='"medium"'):
|
|
45
|
+
"""Create a minimal project-state.md in tmp root."""
|
|
46
|
+
(root / ".claude").mkdir(parents=True, exist_ok=True)
|
|
47
|
+
(root / ".claude" / "project-state.md").write_text(
|
|
48
|
+
f"current_phase: {phase}\ncomplexity_level: {complexity}\nphase_history: []\n",
|
|
49
|
+
encoding="utf-8",
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def edit_payload(file_path, new_string="b"):
|
|
54
|
+
"""Realistic PreToolUse payload: file_path nested under tool_input."""
|
|
55
|
+
return json.dumps({
|
|
56
|
+
"tool_name": "Edit",
|
|
57
|
+
"tool_input": {"file_path": file_path, "old_string": "a", "new_string": new_string},
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def read_phase(root):
|
|
62
|
+
content = (root / ".claude" / "project-state.md").read_text(encoding="utf-8")
|
|
63
|
+
for line in content.splitlines():
|
|
64
|
+
if line.startswith("current_phase:"):
|
|
65
|
+
return line.split(":", 1)[1].strip()
|
|
66
|
+
return ""
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# ---------- R5: extract_nested unit tests ----------
|
|
70
|
+
|
|
71
|
+
class TestExtractNested:
|
|
72
|
+
def test_nested_tool_input(self):
|
|
73
|
+
raw = '{"tool_name":"Edit","tool_input":{"file_path":"C:/a.py"}}'
|
|
74
|
+
assert fe.extract_nested(raw, "file_path") == "C:/a.py"
|
|
75
|
+
|
|
76
|
+
def test_flat_top_level(self):
|
|
77
|
+
raw = '{"file_path":"C:/b.py"}'
|
|
78
|
+
assert fe.extract_nested(raw, "file_path") == "C:/b.py"
|
|
79
|
+
|
|
80
|
+
def test_missing_key_returns_empty(self):
|
|
81
|
+
raw = '{"tool_name":"Edit","tool_input":{"other":1}}'
|
|
82
|
+
assert fe.extract_nested(raw, "file_path") == ""
|
|
83
|
+
|
|
84
|
+
def test_empty_payload(self):
|
|
85
|
+
assert fe.extract_nested("", "file_path") == ""
|
|
86
|
+
|
|
87
|
+
def test_malformed_json_regex_fallback(self):
|
|
88
|
+
raw = 'not json {"tool_input":{"command":"pytest -q"}} tail'
|
|
89
|
+
assert fe.extract_nested(raw, "command") == "pytest -q"
|
|
90
|
+
|
|
91
|
+
def test_bytes_input(self):
|
|
92
|
+
raw = b'{"file_path":"C:/c.py"}'
|
|
93
|
+
assert fe.extract_nested(raw, "file_path") == "C:/c.py"
|
|
94
|
+
|
|
95
|
+
def test_nested_empty_value_falls_to_flat(self):
|
|
96
|
+
raw = '{"tool_input":{"command":""},"command":"pytest"}'
|
|
97
|
+
assert fe.extract_nested(raw, "command") == "pytest"
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
# ---------- R1: check-phase-write extraction + phase blocks ----------
|
|
101
|
+
|
|
102
|
+
class TestCheckPhaseWrite:
|
|
103
|
+
def test_p1_nested_payload_blocks(self, tmp_path):
|
|
104
|
+
make_state(tmp_path, "P1")
|
|
105
|
+
p = run_hook("check-phase-write.py", edit_payload("C:/x/demo.py"), tmp_path)
|
|
106
|
+
assert p.returncode == 2
|
|
107
|
+
assert "P1阶段禁止" in p.stderr
|
|
108
|
+
|
|
109
|
+
def test_p1_flat_payload_blocks(self, tmp_path):
|
|
110
|
+
make_state(tmp_path, "P1")
|
|
111
|
+
p = run_hook("check-phase-write.py", '{"file_path":"C:/x/demo.py"}', tmp_path)
|
|
112
|
+
assert p.returncode == 2
|
|
113
|
+
|
|
114
|
+
def test_p05_nested_payload_blocks(self, tmp_path):
|
|
115
|
+
make_state(tmp_path, "P0.5")
|
|
116
|
+
p = run_hook("check-phase-write.py", edit_payload("C:/x/demo.py"), tmp_path)
|
|
117
|
+
assert p.returncode == 2
|
|
118
|
+
assert "P0.5" in p.stderr
|
|
119
|
+
|
|
120
|
+
def test_p5_nested_payload_blocks(self, tmp_path):
|
|
121
|
+
make_state(tmp_path, "P5")
|
|
122
|
+
p = run_hook("check-phase-write.py", edit_payload("C:/x/demo.py"), tmp_path)
|
|
123
|
+
assert p.returncode == 2
|
|
124
|
+
|
|
125
|
+
def test_p1_plan_file_allowed(self, tmp_path):
|
|
126
|
+
make_state(tmp_path, "P1")
|
|
127
|
+
p = run_hook("check-phase-write.py", edit_payload("C:/x/plan/t.md"), tmp_path)
|
|
128
|
+
assert p.returncode == 0
|
|
129
|
+
|
|
130
|
+
def test_framework_file_blocked(self, tmp_path):
|
|
131
|
+
"""R1: 项目内 .claude 框架文件仍拦(守卫只守本项目,项目内不放开)。"""
|
|
132
|
+
make_state(tmp_path, "P2")
|
|
133
|
+
target = tmp_path / ".claude" / "settings.json"
|
|
134
|
+
p = run_hook("check-phase-write.py", edit_payload(str(target)), tmp_path)
|
|
135
|
+
assert p.returncode == 2
|
|
136
|
+
|
|
137
|
+
def test_user_level_claude_allowed(self, tmp_path):
|
|
138
|
+
"""R1: 非项目内的 .claude(如 ~/.claude/plans/ 计划草稿)不归守卫管,放行。"""
|
|
139
|
+
make_state(tmp_path, "P2")
|
|
140
|
+
outside = tmp_path.parent / "fake-home" / ".claude" / "plans" / "draft.md"
|
|
141
|
+
p = run_hook("check-phase-write.py", edit_payload(str(outside)), tmp_path)
|
|
142
|
+
assert p.returncode == 0
|
|
143
|
+
|
|
144
|
+
def test_project_claude_plans_allowed(self, tmp_path):
|
|
145
|
+
"""R2: 白名单补 plans/,项目内计划草稿目录放行。"""
|
|
146
|
+
make_state(tmp_path, "P2")
|
|
147
|
+
target = tmp_path / ".claude" / "plans" / "x.md"
|
|
148
|
+
p = run_hook("check-phase-write.py", edit_payload(str(target)), tmp_path)
|
|
149
|
+
assert p.returncode == 0
|
|
150
|
+
|
|
151
|
+
def test_task_state_file_allowed(self, tmp_path):
|
|
152
|
+
"""R6: .claude/tasks/*.md editable (multi-task state files)."""
|
|
153
|
+
make_state(tmp_path, "P2")
|
|
154
|
+
p = run_hook("check-phase-write.py", edit_payload("C:/x/.claude/tasks/t1.md"), tmp_path)
|
|
155
|
+
assert p.returncode == 0
|
|
156
|
+
|
|
157
|
+
def test_code_review_report_allowed(self, tmp_path):
|
|
158
|
+
"""AI 审查报告是框架规定产物,任意阶段可写(与 prd.md 同类)。"""
|
|
159
|
+
make_state(tmp_path, "P2")
|
|
160
|
+
p = run_hook("check-phase-write.py", edit_payload("C:/x/.claude/code-review-report.md"), tmp_path)
|
|
161
|
+
assert p.returncode == 0
|
|
162
|
+
|
|
163
|
+
def test_missing_state_allows(self, tmp_path):
|
|
164
|
+
"""R3 AC1: no state file -> non-SDLC project, allow."""
|
|
165
|
+
(tmp_path / ".claude").mkdir()
|
|
166
|
+
p = run_hook("check-phase-write.py", edit_payload("C:/x/demo.py"), tmp_path)
|
|
167
|
+
assert p.returncode == 0
|
|
168
|
+
|
|
169
|
+
def test_no_file_path_allows(self, tmp_path):
|
|
170
|
+
make_state(tmp_path, "P1")
|
|
171
|
+
p = run_hook("check-phase-write.py", '{"tool_name":"Edit","tool_input":{"other":1}}', tmp_path)
|
|
172
|
+
assert p.returncode == 0
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
# ---------- R2: P0 write blocked + auto-transition to P1 ----------
|
|
176
|
+
|
|
177
|
+
class TestP0Behavior:
|
|
178
|
+
def test_p0_code_write_blocks_and_transitions(self, tmp_path):
|
|
179
|
+
make_state(tmp_path, "P0")
|
|
180
|
+
p = run_hook("check-phase-write.py", edit_payload("C:/x/demo.py"), tmp_path)
|
|
181
|
+
assert p.returncode == 2
|
|
182
|
+
assert read_phase(tmp_path) == "P1"
|
|
183
|
+
|
|
184
|
+
def test_p0_bash_write_blocks_and_transitions(self, tmp_path):
|
|
185
|
+
make_state(tmp_path, "P0")
|
|
186
|
+
payload = json.dumps({"tool_name": "Bash", "tool_input": {"command": "echo x > C:/x/demo.py"}})
|
|
187
|
+
p = run_hook("check-phase-test.py", payload, tmp_path)
|
|
188
|
+
assert p.returncode == 2
|
|
189
|
+
assert read_phase(tmp_path) == "P1"
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
# ---------- R3: get_project_root strict walk-up ----------
|
|
193
|
+
|
|
194
|
+
class TestGetProjectRoot:
|
|
195
|
+
def test_finds_project_by_state_file(self, tmp_path):
|
|
196
|
+
make_state(tmp_path, "P0")
|
|
197
|
+
sub = tmp_path / "sub"
|
|
198
|
+
sub.mkdir()
|
|
199
|
+
# cwd changed via subprocess-free direct call with monkeypatched cwd
|
|
200
|
+
import flowcraft_env
|
|
201
|
+
saved = os.getcwd()
|
|
202
|
+
try:
|
|
203
|
+
os.chdir(str(sub))
|
|
204
|
+
assert flowcraft_env.get_project_root() == tmp_path.resolve()
|
|
205
|
+
finally:
|
|
206
|
+
os.chdir(saved)
|
|
207
|
+
|
|
208
|
+
def test_skips_non_empty_claude_without_state(self, tmp_path):
|
|
209
|
+
"""A non-empty .claude dir without state (e.g. user-level) is skipped;
|
|
210
|
+
the walk continues to the real state-bearing ancestor."""
|
|
211
|
+
make_state(tmp_path, "P0")
|
|
212
|
+
fake_home = tmp_path / "home"
|
|
213
|
+
(fake_home / ".claude").mkdir(parents=True)
|
|
214
|
+
(fake_home / ".claude" / "settings.json").write_text("{}", encoding="utf-8")
|
|
215
|
+
sub = fake_home / "sub"
|
|
216
|
+
sub.mkdir()
|
|
217
|
+
import flowcraft_env
|
|
218
|
+
saved = os.getcwd()
|
|
219
|
+
try:
|
|
220
|
+
os.chdir(str(sub))
|
|
221
|
+
# walk: sub -> fake_home (non-empty .claude, no state -> skip) -> tmp (state)
|
|
222
|
+
assert flowcraft_env.get_project_root() == tmp_path.resolve()
|
|
223
|
+
finally:
|
|
224
|
+
os.chdir(saved)
|
|
225
|
+
|
|
226
|
+
def test_home_state_never_project_root(self, tmp_path, monkeypatch):
|
|
227
|
+
"""R3 AC2: a state-bearing user home must not become the project root."""
|
|
228
|
+
fake_home = tmp_path / "home"
|
|
229
|
+
make_state(fake_home, "P1")
|
|
230
|
+
sub = fake_home / "sub"
|
|
231
|
+
sub.mkdir()
|
|
232
|
+
import flowcraft_env
|
|
233
|
+
monkeypatch.setattr(flowcraft_env.Path, "home", classmethod(lambda cls: fake_home))
|
|
234
|
+
saved = os.getcwd()
|
|
235
|
+
try:
|
|
236
|
+
os.chdir(str(sub))
|
|
237
|
+
# walk: sub -> home (state-bearing ancestor that IS the user home -> skipped)
|
|
238
|
+
root = flowcraft_env.get_project_root()
|
|
239
|
+
assert root != fake_home
|
|
240
|
+
finally:
|
|
241
|
+
os.chdir(saved)
|
|
242
|
+
|
|
243
|
+
def test_home_as_cwd_allowed(self, tmp_path, monkeypatch):
|
|
244
|
+
"""R3 AC2 exception: when cwd IS the home dir, its state may match."""
|
|
245
|
+
fake_home = tmp_path / "home"
|
|
246
|
+
make_state(fake_home, "P1")
|
|
247
|
+
import flowcraft_env
|
|
248
|
+
monkeypatch.setattr(flowcraft_env.Path, "home", classmethod(lambda cls: fake_home))
|
|
249
|
+
saved = os.getcwd()
|
|
250
|
+
try:
|
|
251
|
+
os.chdir(str(fake_home))
|
|
252
|
+
assert flowcraft_env.get_project_root() == fake_home.resolve()
|
|
253
|
+
finally:
|
|
254
|
+
os.chdir(saved)
|
|
255
|
+
|
|
256
|
+
def test_env_var_priority(self, tmp_path):
|
|
257
|
+
make_state(tmp_path, "P0")
|
|
258
|
+
import flowcraft_env
|
|
259
|
+
saved = os.environ.get("CLAUDE_PROJECT_DIR")
|
|
260
|
+
os.environ["CLAUDE_PROJECT_DIR"] = str(tmp_path)
|
|
261
|
+
try:
|
|
262
|
+
assert flowcraft_env.get_project_root() == tmp_path.resolve()
|
|
263
|
+
finally:
|
|
264
|
+
if saved is None:
|
|
265
|
+
os.environ.pop("CLAUDE_PROJECT_DIR", None)
|
|
266
|
+
else:
|
|
267
|
+
os.environ["CLAUDE_PROJECT_DIR"] = saved
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
# ---------- R4: advancement supports P0.5 ----------
|
|
271
|
+
|
|
272
|
+
def adv_payload(state_path, old_phase, new_phase):
|
|
273
|
+
return json.dumps({
|
|
274
|
+
"tool_name": "Edit",
|
|
275
|
+
"tool_input": {
|
|
276
|
+
"file_path": str(state_path).replace("\\", "/"),
|
|
277
|
+
"old_string": f"current_phase: {old_phase}",
|
|
278
|
+
"new_string": f"current_phase: {new_phase}",
|
|
279
|
+
},
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
class TestAdvancementP05:
|
|
284
|
+
def _state(self, tmp_path, phase):
|
|
285
|
+
make_state(tmp_path, phase)
|
|
286
|
+
return tmp_path / ".claude" / "project-state.md"
|
|
287
|
+
|
|
288
|
+
def test_p2_to_p05_allowed(self, tmp_path):
|
|
289
|
+
state = self._state(tmp_path, "P2")
|
|
290
|
+
p = run_hook(
|
|
291
|
+
"check-phase-advancement.py",
|
|
292
|
+
adv_payload(state, "P2", "P0.5"),
|
|
293
|
+
tmp_path,
|
|
294
|
+
extra_env={"CLAUDE_PROJECT_DIR": str(tmp_path)},
|
|
295
|
+
)
|
|
296
|
+
assert p.returncode == 0, p.stdout
|
|
297
|
+
|
|
298
|
+
def test_p2_to_p3_still_allowed(self, tmp_path):
|
|
299
|
+
state = self._state(tmp_path, "P2")
|
|
300
|
+
p = run_hook(
|
|
301
|
+
"check-phase-advancement.py",
|
|
302
|
+
adv_payload(state, "P2", "P3"),
|
|
303
|
+
tmp_path,
|
|
304
|
+
extra_env={"CLAUDE_PROJECT_DIR": str(tmp_path)},
|
|
305
|
+
)
|
|
306
|
+
assert p.returncode == 0, p.stdout
|
|
307
|
+
|
|
308
|
+
def test_p2_to_p4_still_denied(self, tmp_path):
|
|
309
|
+
state = self._state(tmp_path, "P2")
|
|
310
|
+
p = run_hook(
|
|
311
|
+
"check-phase-advancement.py",
|
|
312
|
+
adv_payload(state, "P2", "P4"),
|
|
313
|
+
tmp_path,
|
|
314
|
+
extra_env={"CLAUDE_PROJECT_DIR": str(tmp_path)},
|
|
315
|
+
)
|
|
316
|
+
assert p.returncode == 1
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
# ---------- R5: permission-request migration keeps behavior ----------
|
|
320
|
+
|
|
321
|
+
class TestPermissionRequest:
|
|
322
|
+
def test_write_py_in_p1_denies(self, tmp_path):
|
|
323
|
+
make_state(tmp_path, "P1")
|
|
324
|
+
p = run_hook(
|
|
325
|
+
"permission-request.py",
|
|
326
|
+
edit_payload("C:/x/demo.py"),
|
|
327
|
+
tmp_path,
|
|
328
|
+
extra_env={"CLAUDE_PROJECT_DIR": str(tmp_path)},
|
|
329
|
+
)
|
|
330
|
+
assert p.returncode == 0
|
|
331
|
+
out = json.loads(p.stdout)
|
|
332
|
+
assert out["hookSpecificOutput"]["decision"]["behavior"] == "deny"
|
|
333
|
+
|
|
334
|
+
def test_write_md_in_p1_allows(self, tmp_path):
|
|
335
|
+
make_state(tmp_path, "P1")
|
|
336
|
+
p = run_hook(
|
|
337
|
+
"permission-request.py",
|
|
338
|
+
edit_payload("C:/x/readme.md"),
|
|
339
|
+
tmp_path,
|
|
340
|
+
extra_env={"CLAUDE_PROJECT_DIR": str(tmp_path)},
|
|
341
|
+
)
|
|
342
|
+
assert p.returncode == 0
|
|
343
|
+
out = json.loads(p.stdout)
|
|
344
|
+
assert out["hookSpecificOutput"]["decision"]["behavior"] == "allow"
|
|
345
|
+
|
|
346
|
+
def test_bash_git_commit_in_p2_denies(self, tmp_path):
|
|
347
|
+
make_state(tmp_path, "P2")
|
|
348
|
+
payload = json.dumps({"tool_name": "Bash", "tool_input": {"command": "git commit -m x"}})
|
|
349
|
+
p = run_hook(
|
|
350
|
+
"permission-request.py",
|
|
351
|
+
payload,
|
|
352
|
+
tmp_path,
|
|
353
|
+
extra_env={"CLAUDE_PROJECT_DIR": str(tmp_path)},
|
|
354
|
+
)
|
|
355
|
+
assert p.returncode == 0
|
|
356
|
+
out = json.loads(p.stdout)
|
|
357
|
+
assert out["hookSpecificOutput"]["decision"]["behavior"] == "deny"
|