From 230a2c273e0e11a5c431b4c73ccb02f10678e6d3 Mon Sep 17 00:00:00 2001 From: sunwz1115 <192549904+sunwz1115@users.noreply.github.com> Date: Wed, 29 Jul 2026 20:17:24 -0700 Subject: [PATCH] test: harden yolo and kanban signal tests on macOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Autouse fixture also resets approval_module._YOLO_MODE_FROZEN so a HERMES_YOLO_MODE=1 host env can't poison every case (the one startup-frozen test still patches it back explicitly). Adds the darwin 'ps -o stat=' zombie branch to _is_alive_like_dispatcher, mirroring production hermes_cli/kanban_db.py — a no-op on Linux. Salvaged from PR #34069 by @sunwz1115. Co-authored-by: sunwz1115 <192549904+sunwz1115@users.noreply.github.com> --- tests/cli/test_cli_yolo_toggle.py | 5 +++++ .../test_signal_handler_kanban_worker.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/tests/cli/test_cli_yolo_toggle.py b/tests/cli/test_cli_yolo_toggle.py index 36546fecb3c82..43dc6793c37b9 100644 --- a/tests/cli/test_cli_yolo_toggle.py +++ b/tests/cli/test_cli_yolo_toggle.py @@ -40,6 +40,11 @@ SESSION_KEY = "test-cli-yolo-session" def _clear_approval_state(monkeypatch): """Clear the YOLO bypass + env var around every test so cases are independent.""" monkeypatch.delenv("HERMES_YOLO_MODE", raising=False) + # The value is intentionally frozen at tools.approval import time. Local + # Hermes-driven test runs may inherit HERMES_YOLO_MODE=1 from the parent + # agent process, so make the default test state hermetic; the one test that + # covers startup-frozen YOLO explicitly patches it back to True. + monkeypatch.setattr(approval_module, "_YOLO_MODE_FROZEN", False) approval_module.clear_session(SESSION_KEY) approval_module.clear_session("default") yield diff --git a/tests/hermes_cli/test_signal_handler_kanban_worker.py b/tests/hermes_cli/test_signal_handler_kanban_worker.py index f59e3f678ec64..2b9ba4dd3d7d4 100644 --- a/tests/hermes_cli/test_signal_handler_kanban_worker.py +++ b/tests/hermes_cli/test_signal_handler_kanban_worker.py @@ -103,6 +103,22 @@ def _is_alive_like_dispatcher(pid: int) -> bool: break except (FileNotFoundError, PermissionError, OSError): pass + elif sys.platform == "darwin": + try: + proc = subprocess.run( + ["ps", "-o", "stat=", "-p", str(pid)], + stdout=subprocess.PIPE, + stderr=subprocess.DEVNULL, + text=True, + timeout=1, + check=False, + ) + if proc.returncode != 0: + return False + if "Z" in (proc.stdout or "").strip(): + return False + except (OSError, subprocess.SubprocessError, TimeoutError): + pass return True