fix(gateway): make shutdown diagnostics and 2 tests work on macOS - #41958
Closed
3tty0n wants to merge 1 commit into
Closed
fix(gateway): make shutdown diagnostics and 2 tests work on macOS#419583tty0n wants to merge 1 commit into
3tty0n wants to merge 1 commit into
Conversation
Three macOS-portability fixes surfaced when running the suite on a darwin dev box (all pass on Linux/CI, so they were previously invisible): * spawn_async_diagnostic() hard-coded GNU `timeout`, which stock macOS doesn't ship (neither `timeout` nor `gtimeout` without Homebrew coreutils). Popen raised FileNotFoundError and the function returned None, so macOS gateways silently produced no shutdown snapshot. Now resolve `timeout`/`gtimeout` via shutil.which() and fall back to bare `bash` when neither exists — the script's commands are already bounded (head/tail) and detached via start_new_session, so a best-effort snapshot without the hard cap beats no diagnostics at all. * test_media_files_routed_by_type compared send_voice/video/etc. paths against an un-resolved mkdtemp() path, but the media-delivery validator (validate_media_delivery_path) resolves symlinks before its denylist check. On macOS the tempdir is /var/... → /private/var/..., so the assertions mismatched. realpath() the tempdir so expected == actual. * test_gateway_stop_systemd_service_restart_exits_cleanly asserted a clean exit code 0, but stop() deliberately keeps a non-zero (EX_TEMPFAIL) exit on darwin for launchd KeepAlive. The test simulated systemd via INVOCATION_ID but never pinned sys.platform, so it failed on a macOS host. Pin sys.platform="linux", mirroring the companion test_gateway_stop_launchd_service_restart_keeps_nonzero_exit. Verified via scripts/run_tests.sh: 3 files, 66 tests, all pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author
This was referenced Aug 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Makes the gateway's shutdown diagnostics work on macOS and fixes two tests that only passed on Linux. All three issues surface when running the suite on a darwin dev box; they're invisible on Linux/CI, so they had silently accumulated.
The one behavior change is real and user-facing:
spawn_async_diagnostic()(the detachedps-style snapshot written when the gateway receives SIGTERM/SIGINT) hard-coded the GNUtimeoutbinary. Stock macOS ships neithertimeoutnorgtimeout(the latter only arrives with Homebrew coreutils), sosubprocess.Popen(["timeout", ...])raisedFileNotFoundError, was swallowed, and the function returnedNone— meaning macOS gateway operators got no shutdown diagnostics at all. The fix resolvestimeout/gtimeoutviashutil.which()and falls back to runningbashdirectly when neither exists. The fallback loses the hard self-clean cap, but the snapshot script's commands are already individually bounded (head/tail) and the process is detached viastart_new_session, so a best-effort snapshot beats no diagnostics.The other two are test-robustness fixes (no production change):
test_media_files_routed_by_typecomparedsend_voice/send_video/etc. paths against an un-resolvedmkdtemp()path, but the media-delivery validator (validate_media_delivery_path) resolves symlinks before its denylist check. On macOS the tempdir lives under/var → /private/var, so the assertions mismatched.realpath()-ing the tempdir makes expected == actual on every platform.test_gateway_stop_systemd_service_restart_exits_cleanlyasserted exit code0, butstop()deliberately keeps a non-zero (EX_TEMPFAIL) exit on darwin for launchd'sKeepAlive. The test simulated systemd viaINVOCATION_IDbut never pinnedsys.platform, so it failed on a macOS host. Pinningsys.platform="linux"mirrors the existing companion testtest_gateway_stop_launchd_service_restart_keeps_nonzero_exit.Related Issue
Related: #32681
Type of Change
Changes Made
gateway/shutdown_forensics.py—spawn_async_diagnostic()now resolvestimeout/gtimeoutviashutil.which()and falls back to barebashwhen neither is on PATH (stock macOS). Addedimport shutil.tests/gateway/test_background_command.py—realpath()the media tempdir intest_media_files_routed_by_typeso expected paths match the validator's symlink-resolved output (/var → /private/varon macOS).tests/gateway/test_gateway_shutdown.py— pinsys.platform="linux"intest_gateway_stop_systemd_service_restart_exits_cleanlyso the systemd clean-exit path is exercised regardless of host OS.How to Test
timeouton PATH):scripts/run_tests.sh tests/gateway/test_shutdown_forensics.py \ tests/gateway/test_background_command.py \ tests/gateway/test_gateway_shutdown.pymain, three fail on macOS:test_shutdown_forensics.py::TestSpawnAsyncDiagnostic::test_spawns_subprocess_and_writes_output(pidNone)test_background_command.py::TestRunBackgroundTask::test_media_files_routed_by_type(/varvs/private/var)test_gateway_shutdown.py::test_gateway_stop_systemd_service_restart_exits_cleanly(exit75vs0)timeout/gtimeouton PATH,spawn_async_diagnostic(log, "SIGTERM")now returns a real pid and writes the=== shutdown diagnostic @ SIGTERM ===header to the log (previously returnedNoneand wrote nothing).Checklist
Code
fix(gateway): ...)scripts/run_tests.shover the 3 files: 66 tests, all green)test_spawns_subprocess_and_writes_output, which fails onmain/macOS and passes with this change)Documentation & Housekeeping
docs/, docstrings) — N/A (behavior fix; existing docstrings still accurate)cli-config.yaml.exampleif I added/changed config keys — N/A (no config keys)CONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/Aspawn_async_diagnosticis unchangedScreenshots / Logs