Skip to content

Commit 56fb2ac

Browse files
committed
Move Claude here-mode test to CLI suite
1 parent 3cec78d commit 56fb2ac

2 files changed

Lines changed: 27 additions & 33 deletions

File tree

tests/integrations/test_cli.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,33 @@ def test_ai_copilot_auto_promotes(self, tmp_path):
7676
assert "--integration copilot" in result.output
7777
assert (project / ".github" / "agents" / "speckit.plan.agent.md").exists()
7878

79+
def test_ai_claude_here_preserves_preexisting_commands(self, tmp_path):
80+
from typer.testing import CliRunner
81+
from specify_cli import app
82+
83+
project = tmp_path / "claude-here-existing"
84+
project.mkdir()
85+
commands_dir = project / ".claude" / "commands"
86+
commands_dir.mkdir(parents=True)
87+
command_file = commands_dir / "speckit.specify.md"
88+
command_file.write_text("# preexisting command\n", encoding="utf-8")
89+
90+
old_cwd = os.getcwd()
91+
try:
92+
os.chdir(project)
93+
runner = CliRunner()
94+
result = runner.invoke(app, [
95+
"init", "--here", "--force", "--ai", "claude", "--ai-skills", "--script", "sh", "--no-git", "--ignore-agent-tools",
96+
], catch_exceptions=False)
97+
finally:
98+
os.chdir(old_cwd)
99+
100+
assert result.exit_code == 0, result.output
101+
assert "--integration claude" in result.output
102+
assert command_file.exists()
103+
assert command_file.read_text(encoding="utf-8") == "# preexisting command\n"
104+
assert (project / ".claude" / "skills" / "speckit-plan" / "SKILL.md").exists()
105+
79106
def test_shared_infra_skips_existing_files(self, tmp_path):
80107
"""Pre-existing shared files are not overwritten by _install_shared_infra."""
81108
from typer.testing import CliRunner

tests/test_ai_skills.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -756,39 +756,6 @@ def test_download_and_extract_template_blocks_zip_path_traversal(self, tmp_path,
756756

757757
assert not (tmp_path / "evil.txt").exists()
758758

759-
def test_here_mode_commands_preserved(self, tmp_path, monkeypatch):
760-
"""For --here on existing repos, commands must NOT be removed."""
761-
from typer.testing import CliRunner
762-
763-
runner = CliRunner()
764-
# Create a mock existing project with commands already present
765-
target = tmp_path / "existing"
766-
target.mkdir()
767-
agent_folder = AGENT_CONFIG["claude"]["folder"]
768-
cmds_dir = target / agent_folder.rstrip("/") / "commands"
769-
cmds_dir.mkdir(parents=True)
770-
(cmds_dir / "speckit.specify.md").write_text("# spec")
771-
772-
# --here uses CWD, so chdir into the target
773-
monkeypatch.chdir(target)
774-
775-
def fake_download(project_path, *args, **kwargs):
776-
pass # commands already exist, no need to re-create
777-
778-
with patch("specify_cli.integrations.get_integration", return_value=None), \
779-
patch("specify_cli.download_and_extract_template", side_effect=fake_download), \
780-
patch("specify_cli.ensure_executable_scripts"), \
781-
patch("specify_cli.ensure_constitution_from_template"), \
782-
patch("specify_cli.install_ai_skills", return_value=True), \
783-
patch("specify_cli.is_git_repo", return_value=True), \
784-
patch("specify_cli.shutil.which", return_value="/usr/bin/git"):
785-
result = runner.invoke(app, ["init", "--here", "--ai", "claude", "--ai-skills", "--script", "sh", "--no-git"], input="y\n")
786-
787-
assert result.exit_code == 0
788-
# Commands must remain for --here
789-
assert cmds_dir.exists()
790-
assert (cmds_dir / "speckit.specify.md").exists()
791-
792759
# ===== Skip-If-Exists Tests =====
793760

794761
class TestSkipIfExists:

0 commit comments

Comments
 (0)