Merge pull request #131 from therality/master

Remove get_aider_executable and associated test
This commit is contained in:
Andrew I. Christianson 2025-03-14 15:40:39 -04:00 committed by GitHub
commit fe3adbd241
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 83 deletions

View File

@ -20,31 +20,6 @@ from ra_aid.database.repositories.related_files_repository import get_related_fi
console = Console() console = Console()
logger = get_logger(__name__) logger = get_logger(__name__)
def get_aider_executable() -> str:
"""Get the path to the aider executable in the same bin/Scripts directory as Python.
Returns:
str: Full path to aider executable
"""
# Get directory containing Python executable
bin_dir = Path(sys.executable).parent
# Check for platform-specific executable name
if sys.platform == "win32":
aider_exe = bin_dir / "aider.exe"
else:
aider_exe = bin_dir / "aider"
if not aider_exe.exists():
raise RuntimeError(f"Could not find aider executable at {aider_exe}")
if not os.access(aider_exe, os.X_OK):
raise RuntimeError(f"Aider executable at {aider_exe} is not executable")
return str(aider_exe)
def _truncate_for_log(text: str, max_length: int = 300) -> str: def _truncate_for_log(text: str, max_length: int = 300) -> str:
"""Truncate text for logging, adding [truncated] if necessary.""" """Truncate text for logging, adding [truncated] if necessary."""
if len(text) <= max_length: if len(text) <= max_length:
@ -79,9 +54,8 @@ def run_programming_task(
files: Optional; if not provided, uses related_files files: Optional; if not provided, uses related_files
""" """
# Build command # Build command
aider_exe = get_aider_executable()
command = [ command = [
aider_exe, "aider",
"--yes-always", "--yes-always",
"--no-git", "--no-git",
"--no-auto-commits", "--no-auto-commits",
@ -234,4 +208,4 @@ def parse_aider_flags(aider_flags: str) -> List[str]:
# Export the functions # Export the functions
__all__ = ["run_programming_task", "get_aider_executable"] __all__ = ["run_programming_task"]

View File

@ -3,7 +3,6 @@ import pytest
from unittest.mock import patch, MagicMock from unittest.mock import patch, MagicMock
from ra_aid.tools.programmer import ( from ra_aid.tools.programmer import (
get_aider_executable,
parse_aider_flags, parse_aider_flags,
run_programming_task, run_programming_task,
) )
@ -179,12 +178,6 @@ def test_path_normalization_and_deduplication(monkeypatch, tmp_path, mock_config
test_file.write_text("") test_file.write_text("")
new_file = tmp_path / "new.py" new_file = tmp_path / "new.py"
# Config is mocked by mock_config_repository fixture
monkeypatch.setattr(
"ra_aid.tools.programmer.get_aider_executable",
lambda: "/path/to/aider"
)
mock_run = MagicMock(return_value=(b"", 0)) mock_run = MagicMock(return_value=(b"", 0))
monkeypatch.setattr("ra_aid.tools.programmer.run_interactive_command", mock_run) monkeypatch.setattr("ra_aid.tools.programmer.run_interactive_command", mock_run)
@ -219,51 +212,3 @@ def test_path_normalization_and_deduplication(monkeypatch, tmp_path, mock_config
assert ( assert (
sum(1 for arg in cmd_args if arg == str(new_file)) == 1 sum(1 for arg in cmd_args if arg == str(new_file)) == 1
), "Expected one instance of new_file" ), "Expected one instance of new_file"
def test_get_aider_executable(monkeypatch):
"""Test the get_aider_executable function."""
# Create mock objects using standard unittest.mock.MagicMock
mock_path_instance = MagicMock()
mock_parent = MagicMock()
mock_aider = MagicMock()
# Setup sys mock
mock_sys_attrs = {
"executable": "/path/to/venv/bin/python",
"platform": "linux"
}
monkeypatch.setattr("ra_aid.tools.programmer.sys", MagicMock(**mock_sys_attrs))
# Setup Path mock
monkeypatch.setattr("ra_aid.tools.programmer.Path", lambda x: mock_path_instance)
mock_path_instance.parent = mock_parent
mock_parent.__truediv__.return_value = mock_aider
mock_aider.exists.return_value = True
# Setup os mock
mock_os = MagicMock()
mock_os.access.return_value = True
mock_os.X_OK = 1
monkeypatch.setattr("ra_aid.tools.programmer.os", mock_os)
# Test happy path on Linux
aider_path = get_aider_executable()
assert aider_path == str(mock_aider)
mock_parent.__truediv__.assert_called_with("aider")
# Test Windows path
monkeypatch.setattr("ra_aid.tools.programmer.sys.platform", "win32")
aider_path = get_aider_executable()
mock_parent.__truediv__.assert_called_with("aider.exe")
# Test executable not found
mock_aider.exists.return_value = False
with pytest.raises(RuntimeError, match="Could not find aider executable"):
get_aider_executable()
# Test not executable
mock_aider.exists.return_value = True
mock_os.access.return_value = False
with pytest.raises(RuntimeError, match="is not executable"):
get_aider_executable()