MCPcopy
hub / github.com/arc53/DocsGPT / test_tool_caching

Method test_tool_caching

tests/agents/test_tool_executor.py:984–1022  ·  view source on GitHub ↗
(self, mock_tool_manager, monkeypatch)

Source from the content-addressed store, hash-verified

982 assert truncated[0]["status"] == "completed"
983
984 def test_tool_caching(self, mock_tool_manager, monkeypatch):
985 executor = ToolExecutor(user="test_user")
986
987 monkeypatch.setattr(
988 "application.agents.tool_executor.ToolActionParser",
989 lambda _cls, **kw: Mock(parse_args=Mock(return_value=("t1", "test_action", {}))),
990 )
991
992 tools_dict = {
993 "t1": {
994 "id": "00000000-0000-0000-0000-000000000001",
995 "name": "test_tool",
996 "config": {"key": "val"},
997 "actions": [
998 {"name": "test_action", "description": "Test", "parameters": {"properties": {}}},
999 ],
1000 }
1001 }
1002
1003 call = self._make_call(name="test_action_t1")
1004
1005 # First execution — loads tool
1006 gen = executor.execute(tools_dict, call, "MockLLM")
1007 while True:
1008 try:
1009 next(gen)
1010 except StopIteration:
1011 break
1012
1013 # Second execution — should use cache
1014 gen = executor.execute(tools_dict, call, "MockLLM")
1015 while True:
1016 try:
1017 next(gen)
1018 except StopIteration:
1019 break
1020
1021 # load_tool called only once due to cache
1022 assert mock_tool_manager.load_tool.call_count == 1
1023
1024 def test_execute_api_tool(self, mock_tool_manager, monkeypatch):
1025 """Cover lines 199-202, 256-267: api_tool execution path."""

Callers

nothing calls this directly

Calls 3

_make_callMethod · 0.95
executeMethod · 0.95
ToolExecutorClass · 0.90

Tested by

no test coverage detected