Files
stack/agents/researcher/work/i1-proxy-test/cleanup.sh
T
jason.woltjeandClaude Sonnet 5.5 587e64a27f research: row 96 stand-in-key test of CLIProxyAPI for role sessions (#1590)
Packet under agents/researcher/work/i1-proxy-test: private-netns harness, stand-in
upstream, report, evidence. Stand-in keys only; running proxy untouched.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-13 16:07:07 -05:00

47 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Row 96 (#1590): stop whatever the stand-in test left running and remove its runtime
# directory. Touches only this packet: a process is signalled only if its cwd is under
# state/ or its command line names a file the test starts (state/, inner.sh,
# stand-in-upstream.mjs). This script and its ancestors are never signalled. Ports need no
# cleanup: the test runs in a private network namespace that disappears with its last
# process. Evidence in out/ stays.
set -u
PKT=$(cd "$(dirname "$0")" && pwd)
# this shell and every ancestor
skip=" "
pid=$$
while [ -n "$pid" ] && [ "$pid" != 0 ]; do
skip="$skip$pid "
pid=$(awk '/^PPid:/ {print $2}' "/proc/$pid/status" 2>/dev/null)
done
is_ours() { # pid
local cwd cmd
cwd=$(readlink "/proc/$1/cwd" 2>/dev/null) || return 1
case "$cwd" in "$PKT/state"|"$PKT/state"/*) return 0 ;; esac
cmd=$(tr '\0' ' ' < "/proc/$1/cmdline" 2>/dev/null) || return 1
case "$cmd" in *"$PKT/state/"*|*"$PKT/inner.sh"*|*"$PKT/stand-in-upstream.mjs"*) return 0 ;; esac
return 1
}
found=0
for p in /proc/[0-9]*; do
pid=${p#/proc/}
case "$skip" in *" $pid "*) continue ;; esac
if is_ours "$pid"; then
found=$((found + 1))
echo "stopping pid $pid: $(tr '\0' ' ' < "$p/cmdline" | cut -c1-120)"
kill "$pid" 2>/dev/null
fi
done
[ "$found" = 0 ] || sleep 1
for p in /proc/[0-9]*; do
pid=${p#/proc/}
case "$skip" in *" $pid "*) continue ;; esac
if is_ours "$pid"; then echo "force-killing pid $pid"; kill -9 "$pid" 2>/dev/null; fi
done
rm -rf "$PKT/state"
echo "cleanup done: $found process(es) signalled, state/ removed: $([ -e "$PKT/state" ] && echo NO || echo yes)"