"""Hamilton review MINOR #7: standardize tool-failure error shapes. Pre-fix: tools that need state (`_axl`, `_cache`, `_docs`) had inconsistent error shapes. Most tools called `_client()` which raises `RuntimeError`. But `cache_stats` and `cache_clear` checked `if _cache is None` and returned `{"error": "..."}`. An LLM consuming responses had to handle two different patterns. After the fix, both shapes converge: all tools raise RuntimeError when their dependencies aren't initialized. """ import pytest from mcaxl import server def test_cache_stats_raises_when_uninitialized(monkeypatch): monkeypatch.setattr(server, "_cache", None) with pytest.raises(RuntimeError, match=r"[Cc]ache"): # @mcp.tool passes the function through unchanged; call directly. server.cache_stats() def test_cache_clear_raises_when_uninitialized(monkeypatch): monkeypatch.setattr(server, "_cache", None) with pytest.raises(RuntimeError, match=r"[Cc]ache"): server.cache_clear() def test_health_check_reports_each_subsystem(monkeypatch): """A health-check tool should report which globals are initialized, so an operator (or an LLM) can diagnose `RuntimeError: ... not initialized` issues without grepping source.""" # When all are None, health should report all three as down monkeypatch.setattr(server, "_cache", None) monkeypatch.setattr(server, "_axl", None) monkeypatch.setattr(server, "_docs", None) info = server.health() assert info["cache"] is False assert info["axl"] is False assert info["docs"] is False