72 lines
2.6 KiB
Python
72 lines
2.6 KiB
Python
import pytest
|
|
from unittest.mock import patch, MagicMock
|
|
from scripts.mma_exec import create_parser, get_role_documents, execute_agent
|
|
|
|
def test_parser_role_choices():
|
|
"""Test that the parser accepts valid roles and the prompt argument."""
|
|
parser = create_parser()
|
|
valid_roles = ['tier1', 'tier2', 'tier3', 'tier4']
|
|
test_prompt = "Analyze the codebase for bottlenecks."
|
|
|
|
for role in valid_roles:
|
|
args = parser.parse_args(['--role', role, test_prompt])
|
|
assert args.role == role
|
|
assert args.prompt == test_prompt
|
|
|
|
def test_parser_invalid_role():
|
|
"""Test that the parser rejects roles outside the specified choices."""
|
|
parser = create_parser()
|
|
with pytest.raises(SystemExit):
|
|
parser.parse_args(['--role', 'tier5', 'Some prompt'])
|
|
|
|
def test_parser_prompt_required():
|
|
"""Test that the prompt argument is mandatory."""
|
|
parser = create_parser()
|
|
with pytest.raises(SystemExit):
|
|
parser.parse_args(['--role', 'tier3'])
|
|
|
|
def test_parser_help():
|
|
"""Test that the help flag works without raising errors (exits with 0)."""
|
|
parser = create_parser()
|
|
with pytest.raises(SystemExit) as excinfo:
|
|
parser.parse_args(['--help'])
|
|
assert excinfo.value.code == 0
|
|
|
|
def test_get_role_documents():
|
|
"""Test that get_role_documents returns the correct documentation paths for each tier."""
|
|
assert get_role_documents('tier1') == ['conductor/product.md', 'conductor/product-guidelines.md']
|
|
assert get_role_documents('tier2') == ['conductor/tech-stack.md', 'conductor/workflow.md']
|
|
assert get_role_documents('tier3') == ['conductor/workflow.md']
|
|
assert get_role_documents('tier4') == []
|
|
|
|
def test_execute_agent():
|
|
"""
|
|
Test that execute_agent calls subprocess.run with the correct gemini CLI arguments
|
|
for context amnesia.
|
|
"""
|
|
role = "tier3"
|
|
prompt = "Write a unit test."
|
|
docs = ["file1.py", "docs/spec.md"]
|
|
|
|
expected_gemini_arg = "Activate the mma-tier3 skill. Write a unit test. @file1.py @docs/spec.md"
|
|
mock_stdout = "Mocked AI Response"
|
|
|
|
with patch("subprocess.run") as mock_run:
|
|
mock_process = MagicMock()
|
|
mock_process.stdout = mock_stdout
|
|
mock_process.returncode = 0
|
|
mock_run.return_value = mock_process
|
|
|
|
result = execute_agent(role, prompt, docs)
|
|
|
|
mock_run.assert_called_once()
|
|
args, kwargs = mock_run.call_args
|
|
cmd_list = args[0]
|
|
|
|
assert cmd_list[0] == "gemini"
|
|
assert cmd_list[1] == "-p"
|
|
assert cmd_list[2] == expected_gemini_arg
|
|
assert kwargs.get("capture_output") is True
|
|
assert kwargs.get("text") is True
|
|
|
|
assert result == mock_stdout |