|
10 | 10 |
|
11 | 11 | from codeflash.cli_cmds.console import logger |
12 | 12 | from codeflash.code_utils.code_utils import custom_addopts |
13 | | -from codeflash.code_utils.shell_utils import get_cross_platform_subprocess_run_args |
14 | 13 | from codeflash.languages.registry import get_language_support |
15 | 14 |
|
16 | 15 | # Pattern to extract timing from stdout markers: !######...:<duration_ns>######! |
@@ -92,11 +91,35 @@ def _ensure_runtime_files(project_root: Path, language: str = "javascript") -> N |
92 | 91 |
|
93 | 92 | def execute_test_subprocess( |
94 | 93 | cmd_list: list[str], cwd: Path, env: dict[str, str] | None, timeout: int = 600 |
95 | | -) -> subprocess.CompletedProcess: |
| 94 | +) -> subprocess.CompletedProcess[str]: |
96 | 95 | """Execute a subprocess with the given command list, working directory, environment variables, and timeout.""" |
97 | 96 | logger.debug(f"executing test run with command: {' '.join(cmd_list)}") |
98 | 97 | with custom_addopts(): |
99 | | - run_args = get_cross_platform_subprocess_run_args( |
100 | | - cwd=cwd, env=env, timeout=timeout, check=False, text=True, capture_output=True |
101 | | - ) |
102 | | - return subprocess.run(cmd_list, **run_args) # noqa: PLW1510 |
| 98 | + return subprocess.run(cmd_list, cwd=cwd, env=env, timeout=timeout, check=False, text=True, capture_output=True) |
| 99 | + |
| 100 | + |
| 101 | +async def async_execute_test_subprocess( |
| 102 | + cmd_list: list[str], cwd: Path, env: dict[str, str] | None, timeout: int = 600 |
| 103 | +) -> subprocess.CompletedProcess[str]: |
| 104 | + """Execute a test subprocess asynchronously using anyio.""" |
| 105 | + import os as _os |
| 106 | + |
| 107 | + import anyio |
| 108 | + |
| 109 | + logger.debug(f"async executing test run with command: {' '.join(cmd_list)}") |
| 110 | + |
| 111 | + merged_env = _os.environ.copy() |
| 112 | + if env: |
| 113 | + merged_env.update(env) |
| 114 | + |
| 115 | + with custom_addopts(): |
| 116 | + try: |
| 117 | + with anyio.fail_after(timeout): |
| 118 | + result = await anyio.run_process(cmd_list, cwd=cwd, env=merged_env, check=False) |
| 119 | + except TimeoutError as e: |
| 120 | + raise subprocess.TimeoutExpired(cmd_list, timeout) from e |
| 121 | + |
| 122 | + stdout = result.stdout.decode("utf-8", errors="replace") if result.stdout else "" |
| 123 | + stderr = result.stderr.decode("utf-8", errors="replace") if result.stderr else "" |
| 124 | + |
| 125 | + return subprocess.CompletedProcess(args=cmd_list, returncode=result.returncode, stdout=stdout, stderr=stderr) |
0 commit comments