Skip to content

The agent that grows with you

test(windows): realistic gateway-parent argv in the #87594 live probe (child code via file, one-line -c)

Teknium4c922a934881
diff --git a/tests/hermes_cli/test_venv_holder_windows_live.py b/tests/hermes_cli/test_venv_holder_windows_live.py
index 0c9de6f1523..b26ea7ebb4b 100644
--- a/tests/hermes_cli/test_venv_holder_windows_live.py
+++ b/tests/hermes_cli/test_venv_holder_windows_live.py
@@ -188,23 +188,28 @@ class TestAncestorExclusion:
ancestor-exclusion must not hide the gateway from the scan entirely:
the gateway must still be visible to the pause machinery."""
- def test_gateway_parent_visible_to_child_scan(self):
- # Simulate the /update topology: parent (fake gateway) spawns a
- # child python that runs the REAL detection and reports whether it
- # can see its gateway parent.
- child_code = (
- "import json, sys\n"
+ def test_gateway_parent_visible_to_child_scan(self, tmp_path):
+ # Simulate the /update topology: parent (gateway-argv process) spawns
+ # a child python that runs the REAL detection and reports whether it
+ # can see its gateway parent. The child's code lives in a FILE so the
+ # parent's cmdline stays realistic (a real gateway's argv is clean
+ # `... -m hermes_cli.main gateway run`, not a multi-line -c blob).
+ child_file = tmp_path / "child_scan.py"
+ child_file.write_text(
+ "import json, os, sys\n"
f"sys.path.insert(0, {str(PROJECT_ROOT)!r})\n"
"from hermes_cli.update_cmd import _detect_venv_python_processes\n"
- "import os\n"
"matches = _detect_venv_python_processes()\n"
- "print(json.dumps({'ppid': os.getppid(), 'pids': [p for p, _, _ in matches]}))\n"
+ "print(json.dumps({'ppid': os.getppid(),"
+ " 'pids': [p for p, _, _ in matches]}))\n",
+ encoding="utf-8",
)
- parent_code = (
- "import subprocess, sys\n"
- f"out = subprocess.run([sys.executable, '-c', {child_code!r}],"
- " capture_output=True, text=True, cwd=" + repr(str(PROJECT_ROOT)) + ")\n"
- "print(out.stdout.strip())\n"
+ parent_oneliner = (
+ "import subprocess, sys;"
+ f" r = subprocess.run([sys.executable, {str(child_file)!r}],"
+ f" capture_output=True, text=True, cwd={str(PROJECT_ROOT)!r});"
+ " print(r.stdout.strip());"
+ " sys.stderr.write(r.stderr[-500:])"
)
# The parent's argv carries `gateway run` so it IS a gateway to any
# cmdline classifier; it runs the child synchronously.
@@ -212,7 +217,7 @@ class TestAncestorExclusion:
[
sys.executable,
"-c",
- parent_code,
+ parent_oneliner,
"-m",
"hermes_cli.main",
"gateway",