Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/claude-code-plugin/hooks/session-start.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,9 @@ def main():

# Step 2.6: Ensure ~/.claude/mcp.json has codingbuddy entry (#1100)
try:
_ensure_mcp_json(home / ".claude" / "mcp.json")
import shutil as _shutil
if _shutil.which("codingbuddy"):
_ensure_mcp_json(home / ".claude" / "mcp.json")
except Exception:
pass # Never block session start

Expand Down
28 changes: 28 additions & 0 deletions packages/claude-code-plugin/hooks/test_session_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,34 @@ def test_handles_corrupted_mcp_json(self):
data = json.loads(mcp_path.read_text())
assert "codingbuddy" in data["mcpServers"]

def test_skips_mcp_json_when_binary_not_installed(self):
"""Test that mcp.json is NOT created when codingbuddy binary is not on PATH (#1237)."""
with tempfile.TemporaryDirectory() as tmpdir:
mcp_path = Path(tmpdir) / ".claude" / "mcp.json"

with patch("shutil.which", return_value=None):
# Simulate the guarded call from session-start main flow
import shutil as _shutil
if _shutil.which("codingbuddy"):
session_hook._ensure_mcp_json(mcp_path)

assert not mcp_path.exists()

def test_creates_mcp_json_when_binary_installed(self):
"""Test that mcp.json IS created when codingbuddy binary is on PATH (#1237)."""
with tempfile.TemporaryDirectory() as tmpdir:
mcp_path = Path(tmpdir) / ".claude" / "mcp.json"

with patch("shutil.which", return_value="/usr/local/bin/codingbuddy"):
import shutil as _shutil
if _shutil.which("codingbuddy"):
session_hook._ensure_mcp_json(mcp_path)

assert mcp_path.exists()
data = json.loads(mcp_path.read_text())
assert "codingbuddy" in data["mcpServers"]
assert data["mcpServers"]["codingbuddy"]["command"] == "codingbuddy"


class TestHookLibCopy:
"""Tests for lib/ directory copying alongside hook file (#1102)."""
Expand Down
Loading