Files
manual_slop/tests/test_arch_boundary_phase1.py

96 lines
3.6 KiB
Python

import os
import sys
import unittest
import unittest.mock as mock
import importlib
import inspect
import tempfile
import shutil
# Ensure scripts directory is in sys.path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'scripts')))
import mma_exec
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 tearDown(self):
os.chdir(self.old_cwd)
shutil.rmtree(self.test_dir)
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_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")
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_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()