Private
Public Access
0
0
Files
manual_slop/tests/test_external_mcp_hitl.py
T
ed 6a3c142bfa test: migrate src.models bare imports + PROVIDERS/Metadata sub-imports to direct subsystems
Removed 18 unused 'from src import models' imports. Migrated the
explicit sub-imports:
- 'from src.models import PROVIDERS' -> 'from src.ai_client import PROVIDERS'
  (test_minimax_provider x2, test_deepseek_infra)
- 'from src.models import Metadata' -> 'from src.type_aliases import Metadata'
  (test_project_manager_tracks, test_track_state_persistence, test_track_state_schema)

Kept the 2 'import src.models as models' in test_provider_curation +
test_providers_source_of_truth (they verify the backward-compat shim
still re-exports PROVIDERS) and the 2 self-tests
(test_models_no_top_level_pydantic + test_models_no_top_level_tomli_w)
that exercise the shim's no-leak invariants.
2026-07-05 20:12:17 -04:00

62 lines
2.1 KiB
Python

import asyncio
import json
import pytest
from unittest.mock import MagicMock, patch, AsyncMock
from src import ai_client
from src import mcp_client
@pytest.mark.asyncio
async def test_external_mcp_hitl_approval():
# 1. Setup mock manager and server
mock_manager = mcp_client.ExternalMCPManager()
mock_server = AsyncMock()
mock_server.name = "test-server"
mock_server.tools = {"ext_tool": {"name": "ext_tool", "description": "desc"}}
mock_server.call_tool.return_value = "Success"
mock_manager.servers["test-server"] = mock_server
with patch("src.mcp_client.get_external_mcp_manager", return_value=mock_manager):
# 2. Setup ai_client callbacks
mock_pre_tool = MagicMock(return_value="Approved")
ai_client.confirm_and_run_callback = mock_pre_tool
# 3. Call _execute_single_tool_call_async
name = "ext_tool"
args = {"arg1": "val1"}
call_id = "call_123"
base_dir = "."
# We need to pass the callback to the function
name, cid, out, orig_name = await ai_client._execute_single_tool_call_async(
name, args, call_id, base_dir, mock_pre_tool, None, 0
)
# 4. Assertions
assert out == "Success"
mock_pre_tool.assert_called_once()
# Check description contains EXTERNAL MCP
call_args = mock_pre_tool.call_args[0]
assert "EXTERNAL MCP TOOL: ext_tool" in call_args[0]
assert "arg1: 'val1'" in call_args[0]
@pytest.mark.asyncio
async def test_external_mcp_hitl_rejection():
mock_manager = mcp_client.ExternalMCPManager()
mock_server = AsyncMock()
mock_server.name = "test-server"
mock_server.tools = {"ext_tool": {"name": "ext_tool"}}
mock_manager.servers["test-server"] = mock_server
with patch("src.mcp_client.get_external_mcp_manager", return_value=mock_manager):
mock_pre_tool = MagicMock(return_value=None) # Rejection
name = "ext_tool"
args = {"arg1": "val1"}
name, cid, out, orig_name = await ai_client._execute_single_tool_call_async(
name, args, "id", ".", mock_pre_tool, None, 0
)
assert out == "USER REJECTED: tool execution cancelled"
mock_server.call_tool.assert_not_called()