refactor(mma_exec): remove UNFETTERED_MODULES — all deps use generate_skeleton()
This commit is contained in:
71
tests/test_arch_boundary_phase1.py
Normal file
71
tests/test_arch_boundary_phase1.py
Normal file
@@ -0,0 +1,71 @@
|
||||
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)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user