Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ def run(cmd: list[str], cwd: Path, timeout: int = 120) -> tuple[int, str]:
)
return proc.returncode, proc.stdout
except subprocess.TimeoutExpired as exc:
out = (exc.stdout or "") + "\n[command timed out]"
return 124, out
out = exc.stdout or ""
if isinstance(out, bytes):
out = out.decode(errors="replace")
return 124, f"{out}\n[command timed out]"


def safe_repo_name(url: str) -> str:
Expand Down
14 changes: 14 additions & 0 deletions backend/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import os
import subprocess
import tempfile
import unittest
from pathlib import Path
Expand All @@ -14,6 +15,7 @@
github_headers,
health,
parse_json_object,
run,
safe_branch_name,
safe_repo_name,
workspace_repo,
Expand Down Expand Up @@ -138,6 +140,18 @@ def test_run_request_rejects_invalid_iteration_count(self) -> None:
max_iterations=0,
)

def test_run_handles_bytes_output_from_timeout(self) -> None:
timeout = subprocess.TimeoutExpired(
cmd=["python", "-m", "pytest"],
timeout=1,
output=b"partial output",
)
with patch("app.main.subprocess.run", side_effect=timeout):
code, output = run(["python", "-m", "pytest"], Path("."), timeout=1)

self.assertEqual(code, 124)
self.assertEqual(output, "partial output\n[command timed out]")

def test_health_contract(self) -> None:
self.assertEqual(
asyncio.run(health()),
Expand Down
Loading