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_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