Files
roboco/tests/unit/runtime/test_eval_mcp_config_isolation.py
T
488e9e2f11 [431e73b7] Wire the real-spawn path: OrchestratorStageSpawner + disposable MCP config (#701)
* [431e73b7] Wire the eval harness real-spawn path: OrchestratorStageSpawner + disposable MCP config

_generate_mcp_config now prefers settings.api_url when set (both
PROJECT_HOST_PATH branches), so spawned MCP servers resolve to the
harness's disposable orchestrator URL instead of the real production
hostname or 127.0.0.1:port. OrchestratorStageSpawner.__init__ replaces
the NotImplementedError with a real AgentOrchestrator() constructed the
same way the production dispatcher builds it. The runner module
docstring + __main__.py docstring/run-subparser help drop the
NOT-YET-FUNCTIONAL wording. A new unit test pins the no-production-reach
guarantee: with settings.api_url patched, the MCP config's
ROBOCO_API_URL/ROBOCO_ORCHESTRATOR_URL point at the disposable URL (not
production), and the agent UUID is the real fixed UUID from
foundation.identity.AGENTS.

* [431e73b7] docs(eval): reflect the wired real-spawn path in tests map, CLAUDE.md, and CHANGELOG

---------

Co-authored-by: Backend Developer 1 <be-dev-1@roboco.tech>
Co-authored-by: Backend Documenter <be-doc@roboco.tech>
2026-07-26 13:23:04 +00:00

61 lines
2.7 KiB
Python

"""The eval harness patches ``settings.api_url`` to its disposable stack URL
(see ``roboco/eval/runner.py``'s ``_bench_environment``). ``_generate_mcp_config``
must honor that patch so a spawned container's MCP servers resolve to the
throwaway orchestrator, never the real production hostname
(``http://roboco-orchestrator:8000``) or ``127.0.0.1:{port}`` — the
no-production-reach guarantee. The agent UUID in the config is the REAL fixed
UUID from ``foundation.identity.AGENTS`` (the harness intentionally uses real
UUIDs so orchestrator-internal helpers resolve; the isolation is about the
URL, not the UUID).
"""
from __future__ import annotations
import json
from pathlib import Path
from typing import TYPE_CHECKING
from roboco.config import settings
from roboco.foundation import identity as _foundation
from roboco.runtime.orchestrator import AgentOrchestrator
if TYPE_CHECKING:
import pytest
_AGENT_SLUG = "be-dev-1"
_DISPOSABLE_URL = "http://localhost:9999"
async def test_mcp_config_uses_disposable_api_url_when_set(
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""With ``settings.api_url`` patched to a disposable URL, the generated
MCP config's ROBOCO_API_URL / ROBOCO_ORCHESTRATOR_URL point at the
disposable URL — not the production hostname or 127.0.0.1:port."""
monkeypatch.setattr(settings, "api_url", _DISPOSABLE_URL)
orch = AgentOrchestrator.__new__(AgentOrchestrator)
config_path = await orch._generate_mcp_config(_AGENT_SLUG)
config = json.loads(Path(config_path).read_text())
# Every MCP server shares the same env dict; sample the first one.
first_env = next(iter(config["mcpServers"].values()))["env"]
assert first_env["ROBOCO_API_URL"] == _DISPOSABLE_URL
assert first_env["ROBOCO_ORCHESTRATOR_URL"] == _DISPOSABLE_URL
assert "roboco-orchestrator" not in first_env["ROBOCO_API_URL"]
assert "127.0.0.1" not in first_env["ROBOCO_API_URL"]
async def test_mcp_config_preserves_real_agent_uuid(
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""The agent UUID in the config is the REAL fixed UUID from
``foundation.identity.AGENTS`` — the harness intentionally uses real UUIDs
so orchestrator-internal helpers keyed by the static registry resolve
exactly as they would in a real deployment."""
monkeypatch.setattr(settings, "api_url", _DISPOSABLE_URL)
orch = AgentOrchestrator.__new__(AgentOrchestrator)
config_path = await orch._generate_mcp_config(_AGENT_SLUG)
config = json.loads(Path(config_path).read_text())
first_env = next(iter(config["mcpServers"].values()))["env"]
expected_uuid = str(_foundation.AGENTS[_AGENT_SLUG].uuid)
assert first_env["ROBOCO_AGENT_ID"] == expected_uuid