Skip to content
Closed
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
17 changes: 16 additions & 1 deletion tests/gateway/test_shutdown_forensics.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,23 @@ def test_context_as_json_handles_unserialisable_values(self):

class TestSpawnAsyncDiagnostic:
@pytest.mark.skipif(sys.platform == "win32", reason="POSIX-only diagnostic")
def test_spawns_subprocess_and_writes_output(self, tmp_path):
def test_spawns_subprocess_and_writes_output(self, tmp_path, monkeypatch):
log_path = tmp_path / "diag.log"
real_popen = sf.subprocess.Popen

def popen_without_timeout(command, **kwargs):
assert command[:2] == ["timeout", "3"]
timeout_shim = (
"import subprocess, sys; "
"result = subprocess.run(sys.argv[2:], timeout=float(sys.argv[1])); "
"raise SystemExit(result.returncode)"
)
return real_popen(
[sys.executable, "-c", timeout_shim, command[1], *command[2:]],
**kwargs,
)

monkeypatch.setattr(sf.subprocess, "Popen", popen_without_timeout)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This replaces the Popen call being tested and strips the timeout executable from its command. Production still invokes ["timeout", ...] in gateway/shutdown_forensics.py:257-264, so the test passes without exercising the macOS failure. Please test the real launcher alongside a production portability fix instead.

pid = sf.spawn_async_diagnostic(log_path, "SIGTERM", timeout_seconds=3.0)
assert pid is not None and pid > 0

Expand Down