feat: replace Aider with secure mini-SWE-agent worker
Some checks failed
CI / test (push) Has been cancelled
CI / test (pull_request) Has been cancelled

This commit is contained in:
Christian Meyer
2026-08-31 02:46:58 +02:00
parent 582db3a654
commit 25ed6a8439
30 changed files with 4215 additions and 2148 deletions

View File

@@ -1,70 +1,20 @@
from pathlib import Path
from __future__ import annotations
from test_config import settings
from lai_automation.agent import AiderAgent
from lai_automation.agent import MiniSWEAgentRunner
from lai_automation.models import Issue
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 "--edit-format" not in command
assert command[-2:] == ["--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"),
def test_task_uses_issue_text_not_github_parser() -> None:
issue = Issue(
number=42,
title="Wrong result",
body="Original prompt and expected result",
html_url="https://gitea.example.test/owner/lai/issues/42",
labels=(),
)
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 "--editor-edit-format" not in command
task = MiniSWEAgentRunner._task(issue)
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")
monkeypatch.setenv("OPENROUTER_API_KEY", "qwen-provider-key")
monkeypatch.setenv("OLLAMA_API_BASE", "http://host.docker.internal:11434")
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
assert captured["OPENROUTER_API_KEY"] == "qwen-provider-key"
assert captured["OLLAMA_API_BASE"] == "http://host.docker.internal:11434"
assert "Issue #42: Wrong result" in task
assert issue.html_url in task
assert issue.body in task