From 1a7aa97f83787b9be5f88d55c3e66f24416b1517 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 25 Feb 2026 22:43:33 +0000 Subject: [PATCH] test(mcp): add error handling test for install_mcp - Mock Path.read_text to raise OSError in install_mcp - Assert SystemExit(1) is raised when OSError occurs - Ensure pytest is imported in tests/test_codeclaw_cli_mcp.py Co-authored-by: YchampionOP <86096030+YchampionOP@users.noreply.github.com> --- tests/test_codeclaw_cli_mcp.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_codeclaw_cli_mcp.py b/tests/test_codeclaw_cli_mcp.py index b491746..c14ebfa 100644 --- a/tests/test_codeclaw_cli_mcp.py +++ b/tests/test_codeclaw_cli_mcp.py @@ -2,6 +2,7 @@ import subprocess import sys from pathlib import Path +import pytest from codeclaw import cli as codeclaw_cli from codeclaw import mcp_server @@ -215,3 +216,23 @@ def test_mcp_refresh_index_returns_meta(monkeypatch): assert payload["ok"] is True assert payload["meta"]["refresh_count"] == 1 assert payload["meta"]["session_count"] == 2 + +def test_install_mcp_handles_read_oserror(monkeypatch, tmp_path): + monkeypatch.setattr(Path, "home", lambda: tmp_path) + config_path = tmp_path / ".claude" / "mcp.json" + config_path.parent.mkdir(parents=True, exist_ok=True) + config_path.write_text("{}", encoding="utf-8") + + original_read_text = Path.read_text + + def mock_read_text(self, *args, **kwargs): + if str(self).endswith("mcp.json"): + raise OSError("Fake OS Error") + return original_read_text(self, *args, **kwargs) + + monkeypatch.setattr(Path, "read_text", mock_read_text) + + with pytest.raises(SystemExit) as excinfo: + mcp_server.install_mcp() + + assert excinfo.value.code == 1