-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_install_flow.py
More file actions
275 lines (214 loc) · 10.2 KB
/
Copy pathtest_install_flow.py
File metadata and controls
275 lines (214 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
"""Integration tests for the install command."""
from pathlib import Path
from click.testing import CliRunner
from deepwork.cli.main import cli
from deepwork.utils.yaml_utils import load_yaml
class TestInstallCommand:
"""Integration tests for 'deepwork install' command."""
def test_install_with_claude(self, mock_claude_project: Path) -> None:
"""Test installing DeepWork in a Claude Code project."""
runner = CliRunner()
result = runner.invoke(
cli,
["install", "--platform", "claude", "--path", str(mock_claude_project)],
catch_exceptions=False,
)
assert result.exit_code == 0
assert "DeepWork Installation" in result.output
assert "Git repository found" in result.output
assert "Claude Code detected" in result.output
assert "DeepWork installed successfully" in result.output
# Verify directory structure
deepwork_dir = mock_claude_project / ".deepwork"
assert deepwork_dir.exists()
assert (deepwork_dir / "jobs").exists()
# Verify config.yml
config_file = deepwork_dir / "config.yml"
assert config_file.exists()
config = load_yaml(config_file)
assert config is not None
assert "claude" in config["platforms"]
# Verify core skills were created (directory/SKILL.md format)
claude_dir = mock_claude_project / ".claude" / "skills"
# Meta-skill
assert (claude_dir / "deepwork_jobs" / "SKILL.md").exists()
# Step skill (no prefix, but has user-invocable: false in frontmatter)
assert (claude_dir / "deepwork_jobs.define" / "SKILL.md").exists()
# Exposed step skill (user-invocable - learn has exposed: true)
assert (claude_dir / "deepwork_jobs.learn" / "SKILL.md").exists()
# Verify meta-skill content
meta_skill = (claude_dir / "deepwork_jobs" / "SKILL.md").read_text()
assert "# deepwork_jobs" in meta_skill
assert "Available Steps" in meta_skill
# Verify step skill content
define_skill = (claude_dir / "deepwork_jobs.define" / "SKILL.md").read_text()
assert "# deepwork_jobs.define" in define_skill
assert "Define Job Specification" in define_skill
def test_install_with_auto_detect(self, mock_claude_project: Path) -> None:
"""Test installing with auto-detection."""
runner = CliRunner()
result = runner.invoke(
cli, ["install", "--path", str(mock_claude_project)], catch_exceptions=False
)
assert result.exit_code == 0
assert "Auto-detecting AI platform" in result.output
assert "Claude Code detected" in result.output
def test_install_fails_without_git(self, temp_dir: Path) -> None:
"""Test that install fails in non-Git directory."""
runner = CliRunner()
result = runner.invoke(cli, ["install", "--platform", "claude", "--path", str(temp_dir)])
assert result.exit_code != 0
assert "Not a Git repository" in result.output
def test_install_defaults_to_claude_when_no_platform(self, mock_git_repo: Path) -> None:
"""Test that install defaults to Claude Code when no platform is detected."""
runner = CliRunner()
result = runner.invoke(
cli, ["install", "--path", str(mock_git_repo)], catch_exceptions=False
)
assert result.exit_code == 0
assert "No AI platform detected, defaulting to Claude Code" in result.output
assert "Created .claude/" in result.output
assert "DeepWork installed successfully for Claude Code" in result.output
# Verify .claude directory was created
claude_dir = mock_git_repo / ".claude"
assert claude_dir.exists()
# Verify config.yml has Claude
config_file = mock_git_repo / ".deepwork" / "config.yml"
config = load_yaml(config_file)
assert config is not None
assert "claude" in config["platforms"]
# Verify skills were created for Claude
skills_dir = claude_dir / "skills"
assert (skills_dir / "deepwork_jobs" / "SKILL.md").exists()
def test_install_with_multiple_platforms_auto_detect(
self, mock_multi_platform_project: Path
) -> None:
"""Test installing with auto-detection when multiple platforms are present."""
runner = CliRunner()
result = runner.invoke(
cli,
["install", "--path", str(mock_multi_platform_project)],
catch_exceptions=False,
)
assert result.exit_code == 0
assert "Auto-detecting AI platforms" in result.output
assert "Claude Code detected" in result.output
assert "Gemini CLI detected" in result.output
assert "DeepWork installed successfully for Claude Code, Gemini CLI" in result.output
# Verify config.yml has both platforms
config_file = mock_multi_platform_project / ".deepwork" / "config.yml"
config = load_yaml(config_file)
assert config is not None
assert "claude" in config["platforms"]
assert "gemini" in config["platforms"]
# Verify skills were created for both platforms
claude_dir = mock_multi_platform_project / ".claude" / "skills"
# Meta-skill and step skills (directory/SKILL.md format)
assert (claude_dir / "deepwork_jobs" / "SKILL.md").exists()
assert (claude_dir / "deepwork_jobs.define" / "SKILL.md").exists()
# Gemini uses job_name/step_id.toml structure
gemini_dir = mock_multi_platform_project / ".gemini" / "skills"
# Meta-skill (index.toml) and step skills
assert (gemini_dir / "deepwork_jobs" / "index.toml").exists()
assert (gemini_dir / "deepwork_jobs" / "define.toml").exists()
def test_install_with_specified_platform_when_missing(self, mock_git_repo: Path) -> None:
"""Test that install fails when specified platform is not present."""
runner = CliRunner()
result = runner.invoke(
cli, ["install", "--platform", "claude", "--path", str(mock_git_repo)]
)
assert result.exit_code != 0
assert "Claude Code not detected" in result.output
assert ".claude/" in result.output
def test_install_is_idempotent(self, mock_claude_project: Path) -> None:
"""Test that running install multiple times is safe."""
runner = CliRunner()
# First install
result1 = runner.invoke(
cli,
["install", "--platform", "claude", "--path", str(mock_claude_project)],
catch_exceptions=False,
)
assert result1.exit_code == 0
# Second install
result2 = runner.invoke(
cli,
["install", "--platform", "claude", "--path", str(mock_claude_project)],
catch_exceptions=False,
)
assert result2.exit_code == 0
# Verify files still exist and are valid
deepwork_dir = mock_claude_project / ".deepwork"
assert (deepwork_dir / "config.yml").exists()
claude_dir = mock_claude_project / ".claude" / "skills"
# Meta-skill and step skills (directory/SKILL.md format)
assert (claude_dir / "deepwork_jobs" / "SKILL.md").exists()
assert (claude_dir / "deepwork_jobs.define" / "SKILL.md").exists()
assert (claude_dir / "deepwork_jobs.learn" / "SKILL.md").exists()
def test_install_creates_rules_directory(self, mock_claude_project: Path) -> None:
"""Test that install creates the v2 rules directory with example templates."""
runner = CliRunner()
result = runner.invoke(
cli,
["install", "--platform", "claude", "--path", str(mock_claude_project)],
catch_exceptions=False,
)
assert result.exit_code == 0
assert ".deepwork/rules/ with example templates" in result.output
# Verify rules directory was created
rules_dir = mock_claude_project / ".deepwork" / "rules"
assert rules_dir.exists()
# Verify README was created
readme_file = rules_dir / "README.md"
assert readme_file.exists()
content = readme_file.read_text()
assert "DeepWork Rules" in content
assert "YAML frontmatter" in content
# Verify example templates were copied
example_files = list(rules_dir.glob("*.md.example"))
assert len(example_files) >= 1 # At least one example template
def test_install_preserves_existing_rules_directory(self, mock_claude_project: Path) -> None:
"""Test that install doesn't overwrite existing rules directory."""
runner = CliRunner()
# Create a custom rules directory before install
rules_dir = mock_claude_project / ".deepwork" / "rules"
rules_dir.mkdir(parents=True)
custom_rule = rules_dir / "my-custom-rule.md"
custom_content = """---
name: My Custom Rule
trigger: "src/**/*"
---
Custom instructions here.
"""
custom_rule.write_text(custom_content)
result = runner.invoke(
cli,
["install", "--platform", "claude", "--path", str(mock_claude_project)],
catch_exceptions=False,
)
assert result.exit_code == 0
assert ".deepwork/rules/ already exists" in result.output
# Verify original content is preserved
assert custom_rule.read_text() == custom_content
class TestCLIEntryPoint:
"""Tests for CLI entry point."""
def test_cli_version(self) -> None:
"""Test that --version works."""
runner = CliRunner()
result = runner.invoke(cli, ["--version"])
assert result.exit_code == 0
assert "version" in result.output.lower()
def test_cli_help(self) -> None:
"""Test that --help works."""
runner = CliRunner()
result = runner.invoke(cli, ["--help"])
assert result.exit_code == 0
assert "DeepWork" in result.output
assert "install" in result.output
def test_install_help(self) -> None:
"""Test that install --help works."""
runner = CliRunner()
result = runner.invoke(cli, ["install", "--help"])
assert result.exit_code == 0
assert "Install DeepWork" in result.output
assert "--platform" in result.output