Files
stack/agents/researcher/work/i1-proxy-test/run-all.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

68 lines
3.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Row 96 (#1590): run the whole stand-in-key proxy test, then analyse and clean up.
#
# ./run-all.sh run everything (about 3 minutes)
#
# Everything the test starts runs in a private network namespace (unshare -rn): the
# stand-in proxy and stand-in upstream see only their own loopback, so they cannot reach
# the host's running proxy on 127.0.0.1:8317 nor anything off the machine. Before and after,
# this script records the host facts that must not change (running proxy process, its port,
# stat of its config; the content of that config is never read) and writes a verdict to
# out/host-guard.txt. Then cleanup.sh removes the runtime dir.
set -u
PKT=$(cd "$(dirname "$0")" && pwd)
OUT=$PKT/out
RUNNING_CONF=$HOME/.local/opt/EasyCLIProxyAPI/cpa-core/config.yaml
mkdir -p "$OUT"
rm -rf "$PKT/state"; mkdir -p "$PKT/state"
rm -f "$OUT"/*.stdout "$OUT"/*.stderr "$OUT"/*.rc "$OUT"/*.upstream.jsonl "$OUT"/*.log "$OUT"/upstream.all.jsonl "$OUT"/usage-*.json "$OUT"/queue-read-semantics.txt
rm -rf "$OUT/proxy-logs"
snapshot() {
echo "running proxy processes (pid, start, argv; never environ):"
for p in /proc/[0-9]*; do
cmd=$(tr '\0' ' ' < "$p/cmdline" 2>/dev/null) || continue
case "$cmd" in *cli-proxy-api*"$RUNNING_CONF"*)
pid=${p#/proc/}; echo " $pid $(ps -o lstart= -p "$pid") $cmd" ;;
esac
done
echo "listener on 127.0.0.1:8317 (host netns):"; ss -ltnH 'sport = :8317' | sed 's/^/ /'
echo "running proxy config, stat only:"; stat -c ' %n mtime=%y size=%s' "$RUNNING_CONF"
echo "pi config dir ~/.pi/agent changed since the marker (names only):"
[ ! -d "$HOME/.pi" ] || find "$HOME/.pi" -newer "$MARK" -type f 2>/dev/null | head -20 | sed 's/^/ /'
echo "stray names in /tmp: $(find /tmp -maxdepth 1 \( -name '*cli-proxy*' -o -name '*standin*' -o -name '*stand-in*' \) 2>/dev/null | wc -l)"
}
# Informational only, not part of the verdict: the live proxy is in use by other clients and
# writes its own logs and usage database while this test runs, so files under its data
# directory change whatever this test does. Names and connection count only; no contents.
activity() {
echo "established connections to 127.0.0.1:8317 from other host processes: $(ss -tnH 'dport = :8317' | wc -l)"
echo "files under the live proxy's data dir newer than the marker (names only):"
find "$HOME/.local/opt/EasyCLIProxyAPI" "$HOME/.cli-proxy-api" -newer "$MARK" -type f 2>/dev/null | head -20 | sed 's/^/ /'
}
MARK=$(mktemp "$PKT/.marker.XXXXXX")
snapshot > "$OUT/host-guard.before.txt"
echo "run started $(date -u +%Y-%m-%dT%H:%M:%SZ)" > "$OUT/host-guard.txt"
# Own session so a runaway client or proxy can be killed as a group.
setsid timeout -k 10 1500 unshare -rn bash "$PKT/inner.sh"
echo "inner exit: $?" | tee -a "$OUT/host-guard.txt"
node "$PKT/analyze.mjs" "$OUT" > "$OUT/analysis.txt" 2>&1 || echo "analysis failed, see out/analysis.txt"
bash "$PKT/cleanup.sh" | tee -a "$OUT/host-guard.txt"
snapshot > "$OUT/host-guard.after.txt"
activity > "$OUT/host-activity.txt"
rm -f "$MARK"
if diff <(grep -v 'stray names' "$OUT/host-guard.before.txt") <(grep -v 'stray names' "$OUT/host-guard.after.txt") > "$OUT/host-guard.diff"; then
echo "host guard: running proxy (pid, start time, argv), its 8317 listener and its config stat UNCHANGED; ~/.pi untouched" | tee -a "$OUT/host-guard.txt"
else
echo "host guard: DIFFERENCES, see out/host-guard.diff" | tee -a "$OUT/host-guard.txt"
fi
echo "live-proxy activity during the run (informational, other clients; see out/host-activity.txt):" | tee -a "$OUT/host-guard.txt"
sed 's/^/ /' "$OUT/host-activity.txt" | tee -a "$OUT/host-guard.txt"
left=$(find "$PKT" -path "$OUT" -prune -o \( -name state -o -name '.marker.*' \) -print | wc -l)
echo "left behind outside out/: $left" | tee -a "$OUT/host-guard.txt"