Files
lai_automatisierung/tests/test_agent.py
Christian Meyer 886cdbf7ef
Some checks failed
CI / test (push) Has been cancelled
Plan complex repairs before editing
2026-08-28 14:14:43 +02:00

65 lines
2.3 KiB
Python

from pathlib import Path
from test_config import settings
from lai_automation.agent import AiderAgent
def test_aider_command_cannot_mutate_git_configuration_or_send_analytics() -> None:
command = AiderAgent(settings()).command(Path("/repo/.git/task.txt"))
assert "--no-gitignore" in command
assert "--no-analytics" in command
assert "--no-auto-commits" in command
assert command.count("/dev/null") == 2
assert command[-4:] == ["--edit-format", "udiff", "--timeout", "180"]
def test_aider_command_adds_existing_routed_files(tmp_path) -> None:
git_dir = tmp_path / ".git"
git_dir.mkdir()
controller = tmp_path / "app/Http/Controllers/ChatController.php"
controller.parent.mkdir(parents=True)
controller.write_text("<?php\n")
command = AiderAgent(settings()).command(
git_dir / "task.txt",
("app/Http/Controllers/ChatController.php", "missing.php"),
)
assert ["--file", "app/Http/Controllers/ChatController.php"] == command[
command.index("--file"):command.index("--file") + 2
]
assert "missing.php" not in command
assert "--architect" in command
assert command[command.index("--editor-model") + 1] == "mistral/test"
assert command[command.index("--editor-edit-format") + 1] == "udiff"
def test_unrouted_aider_command_stays_in_direct_edit_mode() -> None:
command = AiderAgent(settings()).command(Path("/repo/.git/task.txt"))
assert "--architect" not in command
def test_aider_environment_does_not_include_database_credentials(tmp_path, monkeypatch) -> None:
config = settings(workspace_root=tmp_path)
workspace = tmp_path / "repo"
(workspace / ".git").mkdir(parents=True)
monkeypatch.setenv("TEST_DB_PASSWORD", "must-not-reach-aider")
captured = {}
def run(command, **kwargs):
captured.update(kwargs["env"])
return type("Result", (), {"returncode": 0, "stdout": "ok", "stderr": ""})()
monkeypatch.setattr("lai_automation.agent.subprocess.run", run)
monkeypatch.setattr("lai_automation.agent.os.chown", lambda *args, **kwargs: None)
monkeypatch.setattr("lai_automation.agent.pwd.getpwnam", lambda _: type(
"Account", (), {"pw_dir": str(tmp_path), "pw_uid": 10001, "pw_gid": 10001}
)())
AiderAgent(config).run(workspace, "fix it")
assert "TEST_DB_PASSWORD" not in captured
assert "DB_PASSWORD" not in captured