36 lines
1.7 KiB
Python
36 lines
1.7 KiB
Python
import ast
|
|
import pathlib
|
|
import subprocess
|
|
import sys
|
|
import unittest
|
|
|
|
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
|
|
|
from repo_checks import ROOT
|
|
|
|
|
|
def denies_tools_without_strict_mcp(source: str) -> bool:
|
|
"""Whether the source passes "--tools" but never "--strict-mcp-config", so the MCP servers of the user's config would load beside the denied tools."""
|
|
strings = {node.value for node in ast.walk(ast.parse(source)) if isinstance(node, ast.Constant) and isinstance(node.value, str)}
|
|
return "--tools" in strings and "--strict-mcp-config" not in strings
|
|
|
|
|
|
class HeadlessMcp(unittest.TestCase):
|
|
def test_each_file_that_passes_tools_passes_strict_mcp_config_too(self):
|
|
# A file not yet staged counts too, so a new call is checked before its first commit.
|
|
listed = subprocess.run(["git", "ls-files", "--cached", "--others", "--exclude-standard", "*.py"], capture_output=True, check=True, cwd=ROOT, text=True).stdout.split()
|
|
self.assertIn("reviewer-merge-trials/analyze.py", listed)
|
|
self.assertIn("bin/agent_cycle/judge.py", listed)
|
|
files = [name for name in listed if not pathlib.PurePath(name).name.startswith("test_")]
|
|
lacking = {name for name in files if denies_tools_without_strict_mcp((ROOT / name).read_text(encoding="utf-8"))}
|
|
self.assertEqual(lacking, set(), "add --strict-mcp-config beside --tools, so no MCP server loads where the prompt holds text an outsider can write")
|
|
|
|
def test_a_file_with_tools_and_no_strict_mcp_config_is_found(self):
|
|
self.assertTrue(denies_tools_without_strict_mcp('args = ["--tools", ""]'))
|
|
self.assertFalse(denies_tools_without_strict_mcp('args = ["--tools", "", "--strict-mcp-config"]'))
|
|
self.assertFalse(denies_tools_without_strict_mcp('args = ["-p"]'))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|