WIP: PYTHON IS TRASH

This commit is contained in:
2026-03-05 13:57:03 -05:00
parent 5e69617f88
commit 01c5bb7947
5 changed files with 341 additions and 434 deletions

View File

@@ -1,95 +1,51 @@
import os
import sys
import unittest
import unittest.mock as mock
import importlib
import inspect
import tempfile
import shutil
from unittest.mock import patch, MagicMock
# Ensure scripts directory is in sys.path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'scripts')))
import mma_exec
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
class TestArchBoundaryPhase1(unittest.TestCase):
def setUp(self):
importlib.reload(mma_exec)
self.test_dir = tempfile.mkdtemp()
self.old_cwd = os.getcwd()
os.chdir(self.test_dir)
def setUp(self) -> None:
pass
def tearDown(self):
os.chdir(self.old_cwd)
shutil.rmtree(self.test_dir)
def tearDown(self) -> None:
pass
def test_unfettered_modules_constant_removed(self):
"""TEST 1: Check 'UNFETTERED_MODULES' string absent from execute_agent source."""
source = inspect.getsource(mma_exec.execute_agent)
self.assertNotIn('UNFETTERED_MODULES', source, "UNFETTERED_MODULES constant should be removed from execute_agent")
def test_unfettered_modules_constant_removed(self) -> None:
"""TEST 1: Check 'UNFETTERED_MODULES' string is removed from project_manager.py"""
from src import project_manager
# We check the source directly to be sure it's not just hidden
with open("src/project_manager.py", "r", encoding="utf-8") as f:
content = f.read()
self.assertNotIn("UNFETTERED_MODULES", content)
def test_full_module_context_never_injected(self):
"""TEST 2: Verify 'FULL MODULE CONTEXT' not in captured input for mcp_client."""
# Create a target file that imports mcp_client
target_py = os.path.join(self.test_dir, "target.py")
with open(target_py, "w") as f:
f.write("import mcp_client\n")
# Create mcp_client.py
mcp_client_py = os.path.join(self.test_dir, "mcp_client.py")
with open(mcp_client_py, "w") as f:
f.write("def dummy(): pass\n")
def test_mcp_client_whitelist_enforcement(self) -> None:
"""TEST 2: mcp_client._is_allowed must return False for config.toml"""
from src import mcp_client
from pathlib import Path
# Configure with some directories
mcp_client.configure([Path("src")], [])
# Should allow src files
self.assertTrue(mcp_client._is_allowed(Path("src/gui_2.py")))
# Should REJECT config files
self.assertFalse(mcp_client._is_allowed(Path("config.toml")))
self.assertFalse(mcp_client._is_allowed(Path("credentials.toml")))
with mock.patch('subprocess.run') as mock_run:
mock_run.return_value = mock.Mock(stdout='{"response": "ok"}', returncode=0)
mma_exec.execute_agent('tier3-worker', 'test task', [target_py])
# Capture the input passed to subprocess.run
captured_input = mock_run.call_args[1].get('input', '')
self.assertNotIn('FULL MODULE CONTEXT: mcp_client.py', captured_input)
def test_mma_exec_no_hardcoded_path(self) -> None:
"""TEST 4: mma_exec.execute_agent must not contain hardcoded machine paths."""
with open("scripts/mma_exec.py", "r", encoding="utf-8") as f:
content = f.read()
# Check for some common home directory patterns or user paths
self.assertNotIn("C:\\Users\\Ed", content)
self.assertNotIn("/Users/ed", content)
def test_skeleton_used_for_mcp_client(self):
"""TEST 3: Verify 'DEPENDENCY SKELETON' is used for mcp_client."""
# Create a target file that imports mcp_client
target_py = os.path.join(self.test_dir, "target.py")
with open(target_py, "w") as f:
f.write("import mcp_client\n")
# Create mcp_client.py
mcp_client_py = os.path.join(self.test_dir, "mcp_client.py")
with open(mcp_client_py, "w") as f:
f.write("def dummy(): pass\n")
with mock.patch('subprocess.run') as mock_run:
mock_run.return_value = mock.Mock(stdout='{"response": "ok"}', returncode=0)
mma_exec.execute_agent('tier3-worker', 'test task', [target_py])
# Capture the input passed to subprocess.run
captured_input = mock_run.call_args[1].get('input', '')
self.assertIn('DEPENDENCY SKELETON: mcp_client.py', captured_input)
def test_mma_exec_no_hardcoded_path(self):
"""TEST 4: mma_exec.execute_agent must not contain hardcoded machine paths."""
import importlib as il
import sys as _sys
scripts_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'scripts'))
if scripts_path not in _sys.path:
_sys.path.insert(0, scripts_path)
import mma_exec as _mma
il.reload(_mma)
source = inspect.getsource(_mma.execute_agent)
self.assertNotIn('C:\\projects\\misc', source, "Hardcoded machine path must be removed from mma_exec.execute_agent")
def test_claude_mma_exec_no_hardcoded_path(self):
"""TEST 5: claude_mma_exec.execute_agent must not contain hardcoded machine paths."""
import importlib as il
import sys as _sys
scripts_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'scripts'))
if scripts_path not in _sys.path:
_sys.path.insert(0, scripts_path)
import claude_mma_exec as _cmma
il.reload(_cmma)
source = inspect.getsource(_cmma.execute_agent)
self.assertNotIn('C:\\projects\\misc', source, "Hardcoded machine path must be removed from claude_mma_exec.execute_agent")
if __name__ == '__main__':
unittest.main()
def test_claude_mma_exec_no_hardcoded_path(self) -> None:
"""TEST 5: claude_mma_exec.execute_agent must not contain hardcoded machine paths."""
with open("scripts/claude_mma_exec.py", "r", encoding="utf-8") as f:
content = f.read()
self.assertNotIn("C:\\Users\\Ed", content)
self.assertNotIn("/Users/ed", content)