96 lines
4.1 KiB
Python
96 lines
4.1 KiB
Python
"""
|
|
Tests for architecture_boundary_hardening_20260302 — Phase 2.
|
|
Tasks 2.1-2.4: MCP tool config exposure + MUTATING_TOOLS + HITL enforcement.
|
|
"""
|
|
import tomllib
|
|
import pytest
|
|
from project_manager import default_project
|
|
|
|
MUTATING_TOOLS = {"set_file_slice", "py_update_definition", "py_set_signature", "py_set_var_declaration"}
|
|
ALL_DISPATCH_TOOLS = {
|
|
"run_powershell", "read_file", "list_directory", "search_files", "get_file_summary",
|
|
"web_search", "fetch_url", "py_get_skeleton", "py_get_code_outline", "get_file_slice",
|
|
"py_get_definition", "py_update_definition", "py_get_signature", "py_set_signature",
|
|
"py_get_class_summary", "py_get_var_declaration", "py_set_var_declaration", "get_git_diff",
|
|
"py_find_usages", "py_get_imports", "py_check_syntax", "py_get_hierarchy",
|
|
"py_get_docstring", "get_tree", "get_ui_performance", "set_file_slice",
|
|
}
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Task 2.1: manual_slop.toml and default_project() expose all tools
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def test_toml_exposes_all_dispatch_tools():
|
|
"""manual_slop.toml [agent.tools] must list every tool in mcp_client.dispatch()."""
|
|
with open("manual_slop.toml", "rb") as f:
|
|
config = tomllib.load(f)
|
|
toml_tools = set(config["agent"]["tools"].keys())
|
|
missing = ALL_DISPATCH_TOOLS - toml_tools
|
|
assert not missing, f"Tools missing from manual_slop.toml: {missing}"
|
|
|
|
|
|
def test_toml_mutating_tools_disabled_by_default():
|
|
"""Mutating tools must default to false in manual_slop.toml."""
|
|
with open("manual_slop.toml", "rb") as f:
|
|
config = tomllib.load(f)
|
|
tools = config["agent"]["tools"]
|
|
for tool in MUTATING_TOOLS:
|
|
assert tool in tools, f"{tool} missing from toml"
|
|
assert tools[tool] is False, f"Mutating tool '{tool}' should default to false"
|
|
|
|
|
|
def test_default_project_exposes_all_dispatch_tools():
|
|
"""default_project() agent.tools must list every tool in mcp_client.dispatch()."""
|
|
proj = default_project()
|
|
project_tools = set(proj["agent"]["tools"].keys())
|
|
missing = ALL_DISPATCH_TOOLS - project_tools
|
|
assert not missing, f"Tools missing from default_project(): {missing}"
|
|
|
|
|
|
def test_default_project_mutating_tools_disabled():
|
|
"""Mutating tools must default to False in default_project()."""
|
|
proj = default_project()
|
|
tools = proj["agent"]["tools"]
|
|
for tool in MUTATING_TOOLS:
|
|
assert tool in tools, f"{tool} missing from default_project"
|
|
assert tools[tool] is False, f"Mutating tool '{tool}' should default to False"
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Task 2.2: AGENT_TOOL_NAMES in gui_2.py exposes all dispatch tools
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def test_gui_agent_tool_names_exposes_all_dispatch_tools():
|
|
"""AGENT_TOOL_NAMES in gui_2.py must include every tool in mcp_client.dispatch()."""
|
|
from gui_2 import AGENT_TOOL_NAMES
|
|
gui_tools = set(AGENT_TOOL_NAMES)
|
|
missing = ALL_DISPATCH_TOOLS - gui_tools
|
|
assert not missing, f"Tools missing from gui_2.AGENT_TOOL_NAMES: {missing}"
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Task 2.3: MUTATING_TOOLS constant in mcp_client.py
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def test_mcp_client_has_mutating_tools_constant():
|
|
"""mcp_client must expose a MUTATING_TOOLS frozenset."""
|
|
import mcp_client
|
|
assert hasattr(mcp_client, "MUTATING_TOOLS"), "MUTATING_TOOLS missing from mcp_client"
|
|
assert isinstance(mcp_client.MUTATING_TOOLS, frozenset)
|
|
|
|
|
|
def test_mutating_tools_contains_write_tools():
|
|
"""MUTATING_TOOLS must include all four write tools."""
|
|
import mcp_client
|
|
for tool in MUTATING_TOOLS:
|
|
assert tool in mcp_client.MUTATING_TOOLS, f"{tool} missing from mcp_client.MUTATING_TOOLS"
|
|
|
|
|
|
def test_mutating_tools_excludes_read_tools():
|
|
"""MUTATING_TOOLS must not include read-only tools."""
|
|
import mcp_client
|
|
read_only = {"read_file", "get_file_slice", "py_get_definition", "py_get_skeleton"}
|
|
for tool in read_only:
|
|
assert tool not in mcp_client.MUTATING_TOOLS, f"Read-only tool '{tool}' must not be in MUTATING_TOOLS"
|