-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Fix Claude Code CLI detection for npm-local installs #1978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+104
−5
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| """Tests for check_tool() — Claude Code CLI detection across install methods. | ||
|
|
||
| Covers issue https://github.com/github/spec-kit/issues/550: | ||
| `specify check` reports "Claude Code CLI (not found)" even when claude is | ||
| installed via npm-local (the default `claude` installer path). | ||
| """ | ||
|
|
||
| from unittest.mock import patch, MagicMock | ||
|
|
||
| from specify_cli import check_tool | ||
|
|
||
|
|
||
| class TestCheckToolClaude: | ||
| """Claude CLI detection must work for all install methods.""" | ||
|
|
||
| def test_detected_via_migrate_installer_path(self, tmp_path): | ||
| """claude migrate-installer puts binary at ~/.claude/local/claude.""" | ||
| fake_claude = tmp_path / "claude" | ||
| fake_claude.touch() | ||
|
|
||
| # Ensure npm-local path is missing so we only exercise migrate-installer path | ||
| fake_missing = tmp_path / "nonexistent" / "claude" | ||
|
|
||
| with patch("specify_cli.CLAUDE_LOCAL_PATH", fake_claude), \ | ||
| patch("specify_cli.CLAUDE_NPM_LOCAL_PATH", fake_missing), \ | ||
| patch("shutil.which", return_value=None): | ||
| assert check_tool("claude") is True | ||
|
|
||
| def test_detected_via_npm_local_path(self, tmp_path): | ||
| """npm-local install puts binary at ~/.claude/local/node_modules/.bin/claude.""" | ||
| fake_npm_claude = tmp_path / "node_modules" / ".bin" / "claude" | ||
| fake_npm_claude.parent.mkdir(parents=True) | ||
| fake_npm_claude.touch() | ||
|
|
||
| # Neither the migrate-installer path nor PATH has claude | ||
| fake_migrate = tmp_path / "nonexistent" / "claude" | ||
|
|
||
| with patch("specify_cli.CLAUDE_LOCAL_PATH", fake_migrate), \ | ||
| patch("specify_cli.CLAUDE_NPM_LOCAL_PATH", fake_npm_claude), \ | ||
| patch("shutil.which", return_value=None): | ||
| assert check_tool("claude") is True | ||
|
|
||
| def test_detected_via_path(self, tmp_path): | ||
| """claude on PATH (global npm install) should still work.""" | ||
| fake_missing = tmp_path / "nonexistent" / "claude" | ||
|
|
||
| with patch("specify_cli.CLAUDE_LOCAL_PATH", fake_missing), \ | ||
| patch("specify_cli.CLAUDE_NPM_LOCAL_PATH", fake_missing), \ | ||
| patch("shutil.which", return_value="/usr/local/bin/claude"): | ||
| assert check_tool("claude") is True | ||
|
|
||
| def test_not_found_when_nowhere(self, tmp_path): | ||
| """Should return False when claude is genuinely not installed.""" | ||
| fake_missing = tmp_path / "nonexistent" / "claude" | ||
|
|
||
| with patch("specify_cli.CLAUDE_LOCAL_PATH", fake_missing), \ | ||
| patch("specify_cli.CLAUDE_NPM_LOCAL_PATH", fake_missing), \ | ||
| patch("shutil.which", return_value=None): | ||
| assert check_tool("claude") is False | ||
|
|
||
| def test_tracker_updated_on_npm_local_detection(self, tmp_path): | ||
| """StepTracker should be marked 'available' for npm-local installs.""" | ||
| fake_npm_claude = tmp_path / "node_modules" / ".bin" / "claude" | ||
| fake_npm_claude.parent.mkdir(parents=True) | ||
| fake_npm_claude.touch() | ||
|
|
||
| fake_missing = tmp_path / "nonexistent" / "claude" | ||
| tracker = MagicMock() | ||
|
|
||
| with patch("specify_cli.CLAUDE_LOCAL_PATH", fake_missing), \ | ||
| patch("specify_cli.CLAUDE_NPM_LOCAL_PATH", fake_npm_claude), \ | ||
| patch("shutil.which", return_value=None): | ||
| result = check_tool("claude", tracker=tracker) | ||
|
|
||
| assert result is True | ||
| tracker.complete.assert_called_once_with("claude", "available") | ||
|
|
||
|
|
||
| class TestCheckToolOther: | ||
| """Non-Claude tools should be unaffected by the fix.""" | ||
|
|
||
| def test_git_detected_via_path(self): | ||
| with patch("shutil.which", return_value="/usr/bin/git"): | ||
| assert check_tool("git") is True | ||
|
|
||
| def test_missing_tool(self): | ||
| with patch("shutil.which", return_value=None): | ||
| assert check_tool("nonexistent-tool") is False | ||
|
|
||
| def test_kiro_fallback(self): | ||
| """kiro-cli detection should try both kiro-cli and kiro.""" | ||
| def fake_which(name): | ||
| return "/usr/bin/kiro" if name == "kiro" else None | ||
|
|
||
| with patch("shutil.which", side_effect=fake_which): | ||
| assert check_tool("kiro-cli") is True | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.