Repository navigation
Expand file tree
/
Copy pathtest_cli.py
More file actions
96 lines (71 loc) · 3.82 KB
/
Copy pathtest_cli.py
File metadata and controls
96 lines (71 loc) · 3.82 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
"""CLI contract: banner, progress completion marks, summary format."""
from __future__ import annotations
from pathlib import Path
from typer.testing import CliRunner
from sciogen.cli.main import app
from tests.conftest import write_sample_project
runner = CliRunner()
def test_index_banner_and_summary(tmp_path: Path):
write_sample_project(tmp_path)
result = runner.invoke(app, ["index", str(tmp_path)])
assert result.exit_code == 0, result.output
# banner, plain
assert "Codebase Intelligence Layer" in result.output
# completion summary: middle dots, comma thousands, one-decimal time
assert "✓ Done!" in result.output
assert " nodes · " in result.output and " edges · indexed in " in result.output
assert "Ready. Your codebase is now queryable." in result.output
# every pipeline step completed in place
assert "✓ Scanning project structure..." in result.output
assert "✓ Building knowledge graph..." in result.output
def test_search_command(tmp_path: Path):
write_sample_project(tmp_path)
assert runner.invoke(app, ["index", str(tmp_path)]).exit_code == 0
result = runner.invoke(app, ["search", "password hashing", "--path", str(tmp_path)])
assert result.exit_code == 0, result.output
assert "hash_password" in result.output
def test_impact_command(tmp_path: Path):
write_sample_project(tmp_path)
assert runner.invoke(app, ["index", str(tmp_path)]).exit_code == 0
result = runner.invoke(app, ["impact", "hash_password", "--path", str(tmp_path)])
assert result.exit_code == 0, result.output
assert "AuthService.check_password" in result.output
def test_unknown_symbol_is_single_warning_line(tmp_path: Path):
write_sample_project(tmp_path)
assert runner.invoke(app, ["index", str(tmp_path)]).exit_code == 0
result = runner.invoke(app, ["symbol", "nope_not_here", "--path", str(tmp_path)])
assert result.exit_code == 1
assert "⚠" in result.output
assert "Traceback" not in result.output
def test_version():
result = runner.invoke(app, ["--version"])
assert result.exit_code == 0
assert "sciogen" in result.output
def test_index_quiet_single_line(tmp_path: Path):
write_sample_project(tmp_path)
result = runner.invoke(app, ["index", str(tmp_path), "--quiet"])
assert result.exit_code == 0, result.output
assert "Codebase Intelligence Layer" not in result.output # no banner
assert "Scanning" not in result.output # no progress rows
assert "sciogen:" in result.output and "nodes" in result.output
def test_setup_agent_wires_repo(tmp_path: Path):
import json
write_sample_project(tmp_path)
(tmp_path / "CLAUDE.md").write_text("# my project\n", encoding="utf-8")
result = runner.invoke(app, ["setup-agent", str(tmp_path), "--hooks"])
assert result.exit_code == 0, result.output
mcp_config = json.loads((tmp_path / ".mcp.json").read_text(encoding="utf-8"))
assert mcp_config["mcpServers"]["sciogen"]["command"] == "sciogen"
claude_md = (tmp_path / "CLAUDE.md").read_text(encoding="utf-8")
assert claude_md.startswith("# my project") # existing content preserved
assert "<!-- sciogen:begin -->" in claude_md
assert "sciogen impact" in claude_md
settings = json.loads((tmp_path / ".claude" / "settings.json").read_text(encoding="utf-8"))
hooks = settings["hooks"]["PostToolUse"]
assert any("sciogen index . --quiet" in json.dumps(h) for h in hooks)
# idempotent: run again, nothing duplicated
assert runner.invoke(app, ["setup-agent", str(tmp_path), "--hooks"]).exit_code == 0
claude_md_2 = (tmp_path / "CLAUDE.md").read_text(encoding="utf-8")
assert claude_md_2.count("<!-- sciogen:begin -->") == 1
settings_2 = json.loads((tmp_path / ".claude" / "settings.json").read_text(encoding="utf-8"))
assert len(settings_2["hooks"]["PostToolUse"]) == len(hooks)