Private
Public Access
0
0
Files
manual_slop/tests/test_external_mcp_e2e.py
T
ed 94cfb1b5ff test(fix): Update tests to route config through AppController/env var
Four test files had patches/monkeypatches that referenced the
removed src.models.load_config or src.models.CONFIG_PATH module
constant. These all stem from the config I/O refactor (commit
7bcb5a8c) that renamed load_config/save_config to private I/O
primitives.

- tests/test_external_editor_gui.py: 2 sites changed from
  monkeypatch.setattr(models_module, 'load_config', ...) to
  monkeypatch.setattr('src.app_controller.AppController.load_config', ...)
- tests/test_external_mcp_e2e.py: CONFIG_PATH monkeypatch changed
  to SLOP_CONFIG env var (the only supported override path)
- tests/test_log_management_ui.py: same CONFIG_PATH -> SLOP_CONFIG fix
- tests/test_gen_send_empty_context.py: _StubController now receives
  ui_selected_context_files and _pending_generation_action from the
  app_instance BEFORE being assigned as controller (App.__getattr__
  delegates to controller, so attrs must be on the stub first)

Also: deleted tests/artifacts/manualslop_layout.ini (gitignored
stale file from March 4 referencing pre-refactor window names like
"Projects"/"Files"/"Screenshots" that no longer exist in the code).
Repo-root manualslop_layout.ini still references the same old
window names; user should run the existing "Reset Layout" command
(or delete it manually) to regenerate with the current window
catalog (Context Hub / AI Settings Hub / Discussion Hub / etc.).

Verified: 13 targeted tests pass:
- test_external_editor_gui.py (5/5)
- test_external_mcp_e2e.py (1/1)
- test_log_management_ui.py (2/2)
- test_gen_send_empty_context.py (5/5)
2026-06-07 21:21:38 -04:00

68 lines
1.7 KiB
Python

import asyncio
import json
import os
from pathlib import Path
import pytest
from src.app_controller import AppController
from src import mcp_client
from src import ai_client
from src import models
@pytest.mark.asyncio
async def test_external_mcp_e2e_refresh_and_call(tmp_path, monkeypatch):
# 1. Setup mock config and mock server script
config_file = tmp_path / "config.toml"
monkeypatch.setenv("SLOP_CONFIG", str(config_file))
mock_script = Path("scripts/mock_mcp_server.py").absolute()
mcp_config_file = tmp_path / "mcp_config.json"
mcp_data = {
"mcpServers": {
"e2e-server": {
"command": "python",
"args": [str(mock_script)],
"auto_start": True
}
}
}
mcp_config_file.write_text(json.dumps(mcp_data))
config_content = f"""
[ai]
mcp_config_path = "{mcp_config_file.as_posix()}"
[projects]
paths = []
active = ""
"""
config_file.write_text(config_content)
# 2. Initialize AppController
ctrl = AppController()
monkeypatch.setattr(ctrl, "_load_active_project", lambda: None)
ctrl.project = {}
# We need to mock start_services or just manually call what we need
ctrl.init_state()
# Trigger refresh event manually (since we don't have the background thread running in unit test)
await ctrl.refresh_external_mcps()
# 3. Verify tools are discovered
manager = mcp_client.get_external_mcp_manager()
tools = manager.get_all_tools()
assert "echo" in tools
# 4. Mock pre_tool_callback to auto-approve
mock_pre_tool = lambda desc, base, qa: "Approved"
# 5. Call execute_single_tool_call_async (via ai_client)
name, cid, out, orig = await ai_client._execute_single_tool_call_async(
"echo", {"message": "hello"}, "id1", ".", mock_pre_tool, None, 0
)
assert "ECHO: {'message': 'hello'}" in out
# Cleanup
await manager.stop_all()