@leocm/flowcraft 2.2.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 +7 -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 -162
- package/setup/.claude/hooks/permission-request.py +132 -132
- 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 -186
- 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 -91
- package/setup/.claude/settings.json +233 -233
- 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 -199
- package/setup/tests/test_task_manager.py +148 -148
|
@@ -1,167 +1,167 @@
|
|
|
1
|
-
"""Bootstrap prompt tests for PRD R1-R4.
|
|
2
|
-
|
|
3
|
-
Detects non-SDLC projects (no state file) at SessionStart and emits a
|
|
4
|
-
one-time init prompt; opt-out marker silences it; enabled projects
|
|
5
|
-
keep the normal state-restore context.
|
|
6
|
-
"""
|
|
7
|
-
import json
|
|
8
|
-
import os
|
|
9
|
-
import shutil
|
|
10
|
-
import subprocess
|
|
11
|
-
import sys
|
|
12
|
-
from pathlib import Path
|
|
13
|
-
|
|
14
|
-
import pytest
|
|
15
|
-
|
|
16
|
-
HOOKS = Path(__file__).resolve().parents[1] / ".claude" / "hooks"
|
|
17
|
-
CODEX_HOOK = Path(__file__).resolve().parents[1] / ".codex" / "hooks" / "sdlc-codex-hook.cjs"
|
|
18
|
-
sys.path.insert(0, str(HOOKS))
|
|
19
|
-
|
|
20
|
-
OPT_OUT = ".flowcraft.optout"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def run_py_hook(name, payload, cwd, hook_dir):
|
|
24
|
-
"""Run a Python hook from a neutral copy (setup/.claude holds a template state)."""
|
|
25
|
-
env = os.environ.copy()
|
|
26
|
-
env["CLAUDE_PROJECT_DIR"] = str(cwd)
|
|
27
|
-
env.pop("FLOWCRAFT_TASK_ID", None)
|
|
28
|
-
env.pop("FLOWCRAFT_SESSION_ID", None)
|
|
29
|
-
return subprocess.run(
|
|
30
|
-
[sys.executable, str(hook_dir / name)],
|
|
31
|
-
input=payload,
|
|
32
|
-
capture_output=True,
|
|
33
|
-
encoding="utf-8",
|
|
34
|
-
errors="replace",
|
|
35
|
-
cwd=str(cwd),
|
|
36
|
-
env=env,
|
|
37
|
-
timeout=60,
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def run_codex_hook(payload, cwd, hook_copy_dir):
|
|
42
|
-
"""Run the codex hook from a neutral copy so __dirname never resolves to setup."""
|
|
43
|
-
return subprocess.run(
|
|
44
|
-
["node", str(hook_copy_dir / "sdlc-codex-hook.cjs"), "session-start"],
|
|
45
|
-
input=payload,
|
|
46
|
-
capture_output=True,
|
|
47
|
-
encoding="utf-8",
|
|
48
|
-
errors="replace",
|
|
49
|
-
cwd=str(cwd),
|
|
50
|
-
timeout=60,
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
@pytest.fixture
|
|
55
|
-
def py_hook_copy(tmp_path):
|
|
56
|
-
"""Copy session-start + its imports into a state-free dir."""
|
|
57
|
-
d = tmp_path / "pyhookcopy"
|
|
58
|
-
d.mkdir()
|
|
59
|
-
for name in ("session-start.py", "flowcraft_env.py", "task_manager.py"):
|
|
60
|
-
shutil.copy(str(HOOKS / name), str(d / name))
|
|
61
|
-
return d
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
@pytest.fixture
|
|
65
|
-
def codex_hook_copy(tmp_path):
|
|
66
|
-
"""Copy the codex hook into a state-free dir (setup/.codex has a template state)."""
|
|
67
|
-
d = tmp_path / "hookcopy"
|
|
68
|
-
d.mkdir()
|
|
69
|
-
shutil.copy(str(CODEX_HOOK), str(d / "sdlc-codex-hook.cjs"))
|
|
70
|
-
return d
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
def startup_payload(source="startup"):
|
|
74
|
-
return json.dumps({"source": source, "session_id": "s", "hook_event_name": "SessionStart"})
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
def make_claude_state(root, phase="P0"):
|
|
78
|
-
(root / ".claude").mkdir(parents=True, exist_ok=True)
|
|
79
|
-
(root / ".claude" / "project-state.md").write_text(
|
|
80
|
-
f"current_phase: {phase}\ntask_description: \"t\"\n", encoding="utf-8"
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
# ---------- R1/R2: Claude session-start prompt ----------
|
|
85
|
-
|
|
86
|
-
class TestSessionStartPrompt:
|
|
87
|
-
def test_no_state_startup_prompts(self, tmp_path, py_hook_copy):
|
|
88
|
-
p = run_py_hook("session-start.py", startup_payload("startup"), tmp_path, py_hook_copy)
|
|
89
|
-
assert p.returncode == 0
|
|
90
|
-
out = json.loads(p.stdout)
|
|
91
|
-
ctx = out["hookSpecificOutput"]["additionalContext"]
|
|
92
|
-
assert "未启用" in ctx
|
|
93
|
-
|
|
94
|
-
def test_optout_silences_prompt(self, tmp_path, py_hook_copy):
|
|
95
|
-
(tmp_path / OPT_OUT).write_text("", encoding="utf-8")
|
|
96
|
-
p = run_py_hook("session-start.py", startup_payload("startup"), tmp_path, py_hook_copy)
|
|
97
|
-
assert p.returncode == 0
|
|
98
|
-
assert p.stdout.strip() == ""
|
|
99
|
-
|
|
100
|
-
def test_resume_source_no_prompt(self, tmp_path, py_hook_copy):
|
|
101
|
-
p = run_py_hook("session-start.py", startup_payload("resume"), tmp_path, py_hook_copy)
|
|
102
|
-
assert p.returncode == 0
|
|
103
|
-
assert p.stdout.strip() == ""
|
|
104
|
-
|
|
105
|
-
def test_codex_state_silences_prompt(self, tmp_path, py_hook_copy):
|
|
106
|
-
"""R1: Codex 单侧管理的项目(已有 .codex 状态)不提示初始化。"""
|
|
107
|
-
(tmp_path / ".codex").mkdir()
|
|
108
|
-
(tmp_path / ".codex" / "project-state.md").write_text("current_phase: P0\n", encoding="utf-8")
|
|
109
|
-
p = run_py_hook("session-start.py", startup_payload("startup"), tmp_path, py_hook_copy)
|
|
110
|
-
assert p.returncode == 0
|
|
111
|
-
assert p.stdout.strip() == ""
|
|
112
|
-
|
|
113
|
-
def test_state_present_keeps_normal_context(self, tmp_path, py_hook_copy):
|
|
114
|
-
make_claude_state(tmp_path)
|
|
115
|
-
p = run_py_hook("session-start.py", startup_payload("startup"), tmp_path, py_hook_copy)
|
|
116
|
-
out = json.loads(p.stdout)
|
|
117
|
-
ctx = out["hookSpecificOutput"]["additionalContext"]
|
|
118
|
-
assert "未启用" not in ctx
|
|
119
|
-
assert "状态恢复" in ctx
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
# ---------- R1/R2: Codex session-start prompt ----------
|
|
123
|
-
|
|
124
|
-
def codex_payload(project_dir, source="startup"):
|
|
125
|
-
return json.dumps({"cwd": str(project_dir), "source": source})
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
def make_codex_state(root, phase="P0"):
|
|
129
|
-
(root / ".codex").mkdir(parents=True, exist_ok=True)
|
|
130
|
-
(root / ".codex" / "project-state.md").write_text(
|
|
131
|
-
f"current_phase: {phase}\ntask_description: \"t\"\n", encoding="utf-8"
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
class TestCodexSessionStartPrompt:
|
|
136
|
-
def test_no_state_prompts(self, tmp_path, codex_hook_copy):
|
|
137
|
-
proj = tmp_path / "proj"
|
|
138
|
-
proj.mkdir()
|
|
139
|
-
p = run_codex_hook(codex_payload(proj), proj, codex_hook_copy)
|
|
140
|
-
assert p.returncode == 0
|
|
141
|
-
assert "未启用" in p.stdout
|
|
142
|
-
|
|
143
|
-
def test_optout_silences_prompt(self, tmp_path, codex_hook_copy):
|
|
144
|
-
proj = tmp_path / "proj"
|
|
145
|
-
proj.mkdir()
|
|
146
|
-
(proj / OPT_OUT).write_text("", encoding="utf-8")
|
|
147
|
-
p = run_codex_hook(codex_payload(proj), proj, codex_hook_copy)
|
|
148
|
-
assert p.returncode == 0
|
|
149
|
-
assert p.stdout.strip() == ""
|
|
150
|
-
|
|
151
|
-
def test_claude_state_silences_prompt(self, tmp_path, codex_hook_copy):
|
|
152
|
-
"""R1: Claude 单侧管理的项目(已有 .claude 状态)不提示初始化。"""
|
|
153
|
-
proj = tmp_path / "proj"
|
|
154
|
-
proj.mkdir()
|
|
155
|
-
(proj / ".claude").mkdir()
|
|
156
|
-
(proj / ".claude" / "project-state.md").write_text("current_phase: P0\n", encoding="utf-8")
|
|
157
|
-
p = run_codex_hook(codex_payload(proj), proj, codex_hook_copy)
|
|
158
|
-
assert p.returncode == 0
|
|
159
|
-
assert p.stdout.strip() == ""
|
|
160
|
-
|
|
161
|
-
def test_state_present_keeps_normal_context(self, tmp_path, codex_hook_copy):
|
|
162
|
-
proj = tmp_path / "proj"
|
|
163
|
-
proj.mkdir()
|
|
164
|
-
make_codex_state(proj)
|
|
165
|
-
p = run_codex_hook(codex_payload(proj), proj, codex_hook_copy)
|
|
166
|
-
assert "未启用" not in p.stdout
|
|
167
|
-
assert "状态恢复" in p.stdout
|
|
1
|
+
"""Bootstrap prompt tests for PRD R1-R4.
|
|
2
|
+
|
|
3
|
+
Detects non-SDLC projects (no state file) at SessionStart and emits a
|
|
4
|
+
one-time init prompt; opt-out marker silences it; enabled projects
|
|
5
|
+
keep the normal state-restore context.
|
|
6
|
+
"""
|
|
7
|
+
import json
|
|
8
|
+
import os
|
|
9
|
+
import shutil
|
|
10
|
+
import subprocess
|
|
11
|
+
import sys
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
import pytest
|
|
15
|
+
|
|
16
|
+
HOOKS = Path(__file__).resolve().parents[1] / ".claude" / "hooks"
|
|
17
|
+
CODEX_HOOK = Path(__file__).resolve().parents[1] / ".codex" / "hooks" / "sdlc-codex-hook.cjs"
|
|
18
|
+
sys.path.insert(0, str(HOOKS))
|
|
19
|
+
|
|
20
|
+
OPT_OUT = ".flowcraft.optout"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def run_py_hook(name, payload, cwd, hook_dir):
|
|
24
|
+
"""Run a Python hook from a neutral copy (setup/.claude holds a template state)."""
|
|
25
|
+
env = os.environ.copy()
|
|
26
|
+
env["CLAUDE_PROJECT_DIR"] = str(cwd)
|
|
27
|
+
env.pop("FLOWCRAFT_TASK_ID", None)
|
|
28
|
+
env.pop("FLOWCRAFT_SESSION_ID", None)
|
|
29
|
+
return subprocess.run(
|
|
30
|
+
[sys.executable, str(hook_dir / name)],
|
|
31
|
+
input=payload,
|
|
32
|
+
capture_output=True,
|
|
33
|
+
encoding="utf-8",
|
|
34
|
+
errors="replace",
|
|
35
|
+
cwd=str(cwd),
|
|
36
|
+
env=env,
|
|
37
|
+
timeout=60,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def run_codex_hook(payload, cwd, hook_copy_dir):
|
|
42
|
+
"""Run the codex hook from a neutral copy so __dirname never resolves to setup."""
|
|
43
|
+
return subprocess.run(
|
|
44
|
+
["node", str(hook_copy_dir / "sdlc-codex-hook.cjs"), "session-start"],
|
|
45
|
+
input=payload,
|
|
46
|
+
capture_output=True,
|
|
47
|
+
encoding="utf-8",
|
|
48
|
+
errors="replace",
|
|
49
|
+
cwd=str(cwd),
|
|
50
|
+
timeout=60,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@pytest.fixture
|
|
55
|
+
def py_hook_copy(tmp_path):
|
|
56
|
+
"""Copy session-start + its imports into a state-free dir."""
|
|
57
|
+
d = tmp_path / "pyhookcopy"
|
|
58
|
+
d.mkdir()
|
|
59
|
+
for name in ("session-start.py", "flowcraft_env.py", "task_manager.py"):
|
|
60
|
+
shutil.copy(str(HOOKS / name), str(d / name))
|
|
61
|
+
return d
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@pytest.fixture
|
|
65
|
+
def codex_hook_copy(tmp_path):
|
|
66
|
+
"""Copy the codex hook into a state-free dir (setup/.codex has a template state)."""
|
|
67
|
+
d = tmp_path / "hookcopy"
|
|
68
|
+
d.mkdir()
|
|
69
|
+
shutil.copy(str(CODEX_HOOK), str(d / "sdlc-codex-hook.cjs"))
|
|
70
|
+
return d
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def startup_payload(source="startup"):
|
|
74
|
+
return json.dumps({"source": source, "session_id": "s", "hook_event_name": "SessionStart"})
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def make_claude_state(root, phase="P0"):
|
|
78
|
+
(root / ".claude").mkdir(parents=True, exist_ok=True)
|
|
79
|
+
(root / ".claude" / "project-state.md").write_text(
|
|
80
|
+
f"current_phase: {phase}\ntask_description: \"t\"\n", encoding="utf-8"
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
# ---------- R1/R2: Claude session-start prompt ----------
|
|
85
|
+
|
|
86
|
+
class TestSessionStartPrompt:
|
|
87
|
+
def test_no_state_startup_prompts(self, tmp_path, py_hook_copy):
|
|
88
|
+
p = run_py_hook("session-start.py", startup_payload("startup"), tmp_path, py_hook_copy)
|
|
89
|
+
assert p.returncode == 0
|
|
90
|
+
out = json.loads(p.stdout)
|
|
91
|
+
ctx = out["hookSpecificOutput"]["additionalContext"]
|
|
92
|
+
assert "未启用" in ctx
|
|
93
|
+
|
|
94
|
+
def test_optout_silences_prompt(self, tmp_path, py_hook_copy):
|
|
95
|
+
(tmp_path / OPT_OUT).write_text("", encoding="utf-8")
|
|
96
|
+
p = run_py_hook("session-start.py", startup_payload("startup"), tmp_path, py_hook_copy)
|
|
97
|
+
assert p.returncode == 0
|
|
98
|
+
assert p.stdout.strip() == ""
|
|
99
|
+
|
|
100
|
+
def test_resume_source_no_prompt(self, tmp_path, py_hook_copy):
|
|
101
|
+
p = run_py_hook("session-start.py", startup_payload("resume"), tmp_path, py_hook_copy)
|
|
102
|
+
assert p.returncode == 0
|
|
103
|
+
assert p.stdout.strip() == ""
|
|
104
|
+
|
|
105
|
+
def test_codex_state_silences_prompt(self, tmp_path, py_hook_copy):
|
|
106
|
+
"""R1: Codex 单侧管理的项目(已有 .codex 状态)不提示初始化。"""
|
|
107
|
+
(tmp_path / ".codex").mkdir()
|
|
108
|
+
(tmp_path / ".codex" / "project-state.md").write_text("current_phase: P0\n", encoding="utf-8")
|
|
109
|
+
p = run_py_hook("session-start.py", startup_payload("startup"), tmp_path, py_hook_copy)
|
|
110
|
+
assert p.returncode == 0
|
|
111
|
+
assert p.stdout.strip() == ""
|
|
112
|
+
|
|
113
|
+
def test_state_present_keeps_normal_context(self, tmp_path, py_hook_copy):
|
|
114
|
+
make_claude_state(tmp_path)
|
|
115
|
+
p = run_py_hook("session-start.py", startup_payload("startup"), tmp_path, py_hook_copy)
|
|
116
|
+
out = json.loads(p.stdout)
|
|
117
|
+
ctx = out["hookSpecificOutput"]["additionalContext"]
|
|
118
|
+
assert "未启用" not in ctx
|
|
119
|
+
assert "状态恢复" in ctx
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
# ---------- R1/R2: Codex session-start prompt ----------
|
|
123
|
+
|
|
124
|
+
def codex_payload(project_dir, source="startup"):
|
|
125
|
+
return json.dumps({"cwd": str(project_dir), "source": source})
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def make_codex_state(root, phase="P0"):
|
|
129
|
+
(root / ".codex").mkdir(parents=True, exist_ok=True)
|
|
130
|
+
(root / ".codex" / "project-state.md").write_text(
|
|
131
|
+
f"current_phase: {phase}\ntask_description: \"t\"\n", encoding="utf-8"
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class TestCodexSessionStartPrompt:
|
|
136
|
+
def test_no_state_prompts(self, tmp_path, codex_hook_copy):
|
|
137
|
+
proj = tmp_path / "proj"
|
|
138
|
+
proj.mkdir()
|
|
139
|
+
p = run_codex_hook(codex_payload(proj), proj, codex_hook_copy)
|
|
140
|
+
assert p.returncode == 0
|
|
141
|
+
assert "未启用" in p.stdout
|
|
142
|
+
|
|
143
|
+
def test_optout_silences_prompt(self, tmp_path, codex_hook_copy):
|
|
144
|
+
proj = tmp_path / "proj"
|
|
145
|
+
proj.mkdir()
|
|
146
|
+
(proj / OPT_OUT).write_text("", encoding="utf-8")
|
|
147
|
+
p = run_codex_hook(codex_payload(proj), proj, codex_hook_copy)
|
|
148
|
+
assert p.returncode == 0
|
|
149
|
+
assert p.stdout.strip() == ""
|
|
150
|
+
|
|
151
|
+
def test_claude_state_silences_prompt(self, tmp_path, codex_hook_copy):
|
|
152
|
+
"""R1: Claude 单侧管理的项目(已有 .claude 状态)不提示初始化。"""
|
|
153
|
+
proj = tmp_path / "proj"
|
|
154
|
+
proj.mkdir()
|
|
155
|
+
(proj / ".claude").mkdir()
|
|
156
|
+
(proj / ".claude" / "project-state.md").write_text("current_phase: P0\n", encoding="utf-8")
|
|
157
|
+
p = run_codex_hook(codex_payload(proj), proj, codex_hook_copy)
|
|
158
|
+
assert p.returncode == 0
|
|
159
|
+
assert p.stdout.strip() == ""
|
|
160
|
+
|
|
161
|
+
def test_state_present_keeps_normal_context(self, tmp_path, codex_hook_copy):
|
|
162
|
+
proj = tmp_path / "proj"
|
|
163
|
+
proj.mkdir()
|
|
164
|
+
make_codex_state(proj)
|
|
165
|
+
p = run_codex_hook(codex_payload(proj), proj, codex_hook_copy)
|
|
166
|
+
assert "未启用" not in p.stdout
|
|
167
|
+
assert "状态恢复" in p.stdout
|