This commit is contained in:
AI Christianson 2025-03-08 09:30:52 -05:00
parent b262305592
commit b9241780d0
1 changed files with 89 additions and 54 deletions

View File

@ -17,11 +17,9 @@ def test_show_thoughts_flag():
assert args.show_thoughts is True
@pytest.fixture(autouse=True)
@pytest.fixture
def mock_config_repository():
"""Mock the ConfigRepository to avoid database operations during tests"""
with patch('ra_aid.database.repositories.config_repository.config_repo_var') as mock_repo_var:
# Setup a mock repository
mock_repo = MagicMock()
# Create a dictionary to simulate config
@ -47,37 +45,74 @@ def mock_config_repository():
return config.copy()
mock_repo.get_all.side_effect = get_all_config
# Make the mock context var return our mock repo
mock_repo_var.get.return_value = mock_repo
yield mock_repo
return mock_repo
def test_show_thoughts_config(mock_config_repository):
"""Test that the show_thoughts flag is correctly stored in config."""
"""Test that the --show-thoughts flag is correctly stored in config."""
import sys
from unittest.mock import patch
from ra_aid.__main__ import main
# Create a mock parse_arguments function
def mock_parse_arguments(args=None):
# Create a mock arguments object with controlled values
mock_args = MagicMock()
mock_args.show_thoughts = "--show-thoughts" in sys.argv
# Explicitly set research_only and chat to False to avoid sys.exit(1)
mock_args.research_only = False
mock_args.chat = False
# Set message to a default value to avoid sys.exit(1) for missing message
mock_args.message = "test message"
mock_args.wipe_project_memory = False
mock_args.webui = False
return mock_args
# Reset mocks
mock_config_repository.set.reset_mock()
# For testing, we need to patch ConfigRepositoryManager.__enter__ to return our mock
with patch('ra_aid.database.repositories.config_repository.ConfigRepositoryManager.__enter__', return_value=mock_config_repository):
# Test with --show-thoughts flag
with patch.object(sys, "argv", ["ra-aid", "-m", "test message", "--show-thoughts"]):
with patch("ra_aid.__main__.run_research_agent", return_value=None):
with patch.object(sys, "argv", ["ra-aid", "--show-thoughts"]):
with patch("ra_aid.__main__.parse_arguments", side_effect=mock_parse_arguments):
# Mock ConfigRepositoryManager to return our mock
with patch('ra_aid.database.repositories.config_repository.ConfigRepositoryManager.__enter__',
return_value=mock_config_repository):
# Mock the required dependencies to prevent actual execution
with patch("ra_aid.__main__.setup_logging"), \
patch("ra_aid.__main__.DatabaseManager"), \
patch("ra_aid.__main__.ensure_migrations_applied"), \
patch("ra_aid.__main__.check_dependencies"), \
patch("ra_aid.__main__.validate_environment", return_value=(True, [], True, [])), \
patch("ra_aid.__main__.build_status"), \
patch("ra_aid.__main__.console.print"), \
patch("ra_aid.__main__.initialize_llm"), \
patch("ra_aid.__main__.run_research_agent"):
# Run the main function
from ra_aid.__main__ import main
main()
# Verify the show_thoughts flag is set to True in config
# Verify that show_thoughts was set to True in config
mock_config_repository.set.assert_any_call("show_thoughts", True)
# Reset mocks
# Reset mock for second test
mock_config_repository.set.reset_mock()
# Test without --show-thoughts flag (default: False)
with patch.object(sys, "argv", ["ra-aid", "-m", "test message"]):
with patch("ra_aid.__main__.run_research_agent", return_value=None):
# Test without --show-thoughts flag
with patch.object(sys, "argv", ["ra-aid"]):
with patch("ra_aid.__main__.parse_arguments", side_effect=mock_parse_arguments):
# Mock ConfigRepositoryManager to return our mock
with patch('ra_aid.database.repositories.config_repository.ConfigRepositoryManager.__enter__',
return_value=mock_config_repository):
# Mock the required dependencies to prevent actual execution
with patch("ra_aid.__main__.setup_logging"), \
patch("ra_aid.__main__.DatabaseManager"), \
patch("ra_aid.__main__.ensure_migrations_applied"), \
patch("ra_aid.__main__.check_dependencies"), \
patch("ra_aid.__main__.validate_environment", return_value=(True, [], True, [])), \
patch("ra_aid.__main__.build_status"), \
patch("ra_aid.__main__.console.print"), \
patch("ra_aid.__main__.initialize_llm"), \
patch("ra_aid.__main__.run_research_agent"):
# Run the main function
from ra_aid.__main__ import main
main()
# Verify the show_thoughts flag is set to False in config
# Verify that show_thoughts was set to False in config
mock_config_repository.set.assert_any_call("show_thoughts", False)