Coverage for integrations / coding_agent / aider_core / run_cmd.py: 70.6%
17 statements
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-12 04:49 +0000
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-12 04:49 +0000
1"""
2Minimal run_cmd shim — replaces Aider's run_cmd.py (which needs pexpect/psutil).
4Provides subprocess execution using only stdlib.
5"""
6import os
7import subprocess
8import sys
11def run_cmd_subprocess(cmd, cwd=None, env=None, timeout=60):
12 """Run a command via subprocess, returning (exit_code, stdout).
14 Simplified version of Aider's run_cmd that doesn't require pexpect or psutil.
15 """
16 try:
17 # Hide the cmd console on Windows when aider runs flake8/black/etc
18 # — those binaries pop a brief console per invocation otherwise.
19 try:
20 from core.subprocess_safe import hidden_popen_kwargs
21 _hide = hidden_popen_kwargs()
22 except Exception:
23 _hide = {}
24 result = subprocess.run(
25 cmd,
26 shell=isinstance(cmd, str),
27 capture_output=True,
28 text=True,
29 cwd=cwd,
30 env=env or os.environ.copy(),
31 timeout=timeout,
32 **_hide,
33 )
34 combined = result.stdout
35 if result.stderr:
36 combined += '\n' + result.stderr
37 return result.returncode, combined
38 except subprocess.TimeoutExpired:
39 return 1, f"Command timed out after {timeout}s"
40 except (OSError, FileNotFoundError) as e:
41 return 1, str(e)