You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@magpie.apache.org by po...@apache.org on 2026/09/24 11:12:49 UTC

(magpie) 13/13: test(agent-isolation): poll for the spawned session instead of sampling once

This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch feat/adversarial-review-tool
in repository https://gitbox.apache.org/repos/asf/magpie.git

commit cf1cfe9979942e0f1d689af55015402df5017dde
Author: Jarek Potiuk <po...@apache.org>
AuthorDate: Thu Sep 24 13:06:16 2026 +0200

    test(agent-isolation): poll for the spawned session instead of sampling once
    
    The spawn-session test read the backgrounded pid's group once, after a
    fixed 0.3 s. On a loaded CI runner the script had not reached its exec
    yet, so the pid still sat in the caller's group and the test failed
    (pid 1965, pgid 14). Poll up to 5 s for the group change instead.
    
    Generated-by: Claude Opus 5
---
 tools/agent-isolation/tests/test_gpg_touch_overlay.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/agent-isolation/tests/test_gpg_touch_overlay.py b/tools/agent-isolation/tests/test_gpg_touch_overlay.py
index 1bacecef..92495f0d 100644
--- a/tools/agent-isolation/tests/test_gpg_touch_overlay.py
+++ b/tools/agent-isolation/tests/test_gpg_touch_overlay.py
@@ -374,14 +374,21 @@ def test_spawn_session_makes_the_backgrounded_pid_the_group_leader() -> None:
     that same pid. Anything that leaves a shell in between — a wrapper
     function, say — records a pid that leads no group, and disarm then
     kills nothing and leaves the window on screen.
+
+    Until the script reaches its `exec`, the pid still sits in the caller's
+    group, so poll for the change rather than sampling once: a single
+    sample after a fixed delay loses that race on a loaded CI runner.
     """
     result = subprocess.run(
         [
             "bash",
             "-c",
             f'"{SCRIPT}" _spawn_session sleep 5 & '
-            'pid=$!; sleep 0.3; echo "$pid $(ps -o pgid= -p "$pid" 2>/dev/null)"; '
-            "kill -- -\"$pid\" 2>/dev/null; true",
+            "pid=$!; "
+            'for _ in $(seq 50); do pgid=$(ps -o pgid= -p "$pid" 2>/dev/null); '
+            '[[ ${pgid// /} == "$pid" ]] && break; sleep 0.1; done; '
+            'echo "$pid $pgid"; '
+            "kill -- -\"$pid\" 2>/dev/null; kill \"$pid\" 2>/dev/null; true",
         ],
         capture_output=True,
         text=True,