MCPcopy Create free account
hub / github.com/IBM/mcp-cli / test_guard_blocks_tool

Method test_guard_blocks_tool

tests/planning/test_backends.py:254–275  ·  view source on GitHub ↗

When guards block, the tool is not executed.

(self)

Source from the content-addressed store, hash-verified

252
253 @pytest.mark.asyncio
254 async def test_guard_blocks_tool(self):
255 """When guards block, the tool is not executed."""
256 tm = FakeToolManager(result="should not see this")
257 backend = McpToolBackend(tm, enable_guards=True)
258
259 # Mock _check_guards to return a block
260 with patch(
261 "mcp_cli.planning.backends._check_guards",
262 return_value="Budget exhausted",
263 ):
264 request = ToolExecutionRequest(
265 tool_name="write_file",
266 args={"path": "/tmp/x", "content": "data"},
267 step_id="step-6",
268 )
269 result = await backend.execute_tool(request)
270
271 assert not result.success
272 assert "Guard blocked" in result.error
273 assert "Budget exhausted" in result.error
274 # Tool was never called
275 assert len(tm.calls) == 0
276
277 @pytest.mark.asyncio
278 async def test_guard_allows_tool(self):

Callers

nothing calls this directly

Calls 3

execute_toolMethod · 0.95
McpToolBackendClass · 0.90
FakeToolManagerClass · 0.70

Tested by

no test coverage detected