Skip to content

Commit 59db497

Browse files
Copilotychampion
andcommitted
test(mcp): add OSError handling test for install_mcp (PR #3)
Co-authored-by: ychampion <68075205+ychampion@users.noreply.github.com>
1 parent eb65d3d commit 59db497

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

tests/test_codeclaw_cli_mcp.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import sys
44
from pathlib import Path
55

6+
import pytest
7+
68
from codeclaw import cli as codeclaw_cli
79
from codeclaw import mcp_server
810

@@ -215,3 +217,24 @@ def test_mcp_refresh_index_returns_meta(monkeypatch):
215217
assert payload["ok"] is True
216218
assert payload["meta"]["refresh_count"] == 1
217219
assert payload["meta"]["session_count"] == 2
220+
221+
222+
def test_install_mcp_handles_read_oserror(monkeypatch, tmp_path):
223+
monkeypatch.setattr(Path, "home", lambda: tmp_path)
224+
config_path = tmp_path / ".claude" / "mcp.json"
225+
config_path.parent.mkdir(parents=True, exist_ok=True)
226+
config_path.write_text("{}", encoding="utf-8")
227+
228+
original_read_text = Path.read_text
229+
230+
def mock_read_text(self, *args, **kwargs):
231+
if self == config_path:
232+
raise OSError("Fake OS Error")
233+
return original_read_text(self, *args, **kwargs)
234+
235+
monkeypatch.setattr(Path, "read_text", mock_read_text)
236+
237+
with pytest.raises(SystemExit) as excinfo:
238+
mcp_server.install_mcp()
239+
240+
assert excinfo.value.code == 1

0 commit comments

Comments
 (0)