b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
68 lines
2.3 KiB
Python
68 lines
2.3 KiB
Python
"""Coverage for _run_with_idle_timeout — the streaming subprocess helper.
|
|
|
|
Kept in a dedicated test file because the tests spawn real ``subprocess.Popen``
|
|
instances; pytest-isolate runs each test file in its own worker process, so
|
|
isolating these here prevents real-Popen state from racing with the
|
|
``subprocess.run`` / ``_run_with_idle_timeout`` patches used by
|
|
``test_web_ui_build.py``.
|
|
|
|
Added for issue #33788: ``hermes update`` got stuck at "webui-build" because
|
|
``npm run build`` ran with ``capture_output=True`` and no timeout. The helper
|
|
fixes both halves — streams output AND idle-kills the process.
|
|
"""
|
|
|
|
import sys as _sys
|
|
import time
|
|
|
|
from hermes_cli.main import _run_with_idle_timeout
|
|
|
|
|
|
def test_streams_output_and_returns_zero_on_success(tmp_path):
|
|
script = tmp_path / "ok.py"
|
|
script.write_text("print('line one'); print('line two')\n")
|
|
result = _run_with_idle_timeout(
|
|
[_sys.executable, str(script)], cwd=tmp_path, idle_timeout_seconds=10
|
|
)
|
|
assert result.returncode == 0
|
|
assert "line one" in result.stdout
|
|
assert "line two" in result.stdout
|
|
|
|
|
|
def test_propagates_nonzero_exit(tmp_path):
|
|
script = tmp_path / "fail.py"
|
|
script.write_text("import sys; print('boom', file=sys.stderr); sys.exit(7)\n")
|
|
result = _run_with_idle_timeout(
|
|
[_sys.executable, str(script)], cwd=tmp_path, idle_timeout_seconds=10
|
|
)
|
|
assert result.returncode == 7
|
|
# stderr is merged into stdout in the helper.
|
|
assert "boom" in result.stdout
|
|
|
|
|
|
def test_kills_process_on_idle_timeout(tmp_path):
|
|
# Sleeps without printing — exactly the failure mode users see when
|
|
# `npm run build` stalls. Idle timeout must terminate it.
|
|
script = tmp_path / "stall.py"
|
|
script.write_text("import time; time.sleep(30)\n")
|
|
|
|
start = time.monotonic()
|
|
result = _run_with_idle_timeout(
|
|
[_sys.executable, str(script)],
|
|
cwd=tmp_path,
|
|
idle_timeout_seconds=1,
|
|
)
|
|
elapsed = time.monotonic() - start
|
|
# Should have died well before the 30s sleep completes.
|
|
assert elapsed < 15
|
|
assert result.returncode != 0
|
|
assert "produced no output" in result.stdout
|
|
|
|
|
|
def test_returns_127_when_binary_missing(tmp_path):
|
|
result = _run_with_idle_timeout(
|
|
["/nonexistent/binary/does/not/exist"],
|
|
cwd=tmp_path,
|
|
idle_timeout_seconds=5,
|
|
)
|
|
assert result.returncode == 127
|