|
3 | 3 | import sys |
4 | 4 | from pathlib import Path |
5 | 5 |
|
| 6 | +import pytest |
| 7 | + |
6 | 8 | from codeclaw import cli as codeclaw_cli |
7 | 9 | from codeclaw import mcp_server |
8 | 10 |
|
@@ -215,3 +217,24 @@ def test_mcp_refresh_index_returns_meta(monkeypatch): |
215 | 217 | assert payload["ok"] is True |
216 | 218 | assert payload["meta"]["refresh_count"] == 1 |
217 | 219 | 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