#!/usr/bin/env bash # Isolated live smoke of the Codex backend, driven entirely through agents.py. # It starts one uniquely-named tmux session, verifies Remote Control and a daemon-connected Codex # TUI, then removes only that session. The shared Remote Control daemon intentionally remains # available. set -uo pipefail HERE="$(cd "$(dirname "$0")" && pwd)" REPO="$(cd "$HERE/.." && pwd)" CODEX_BIN="${CODEX_BIN:-$(command -v codex 2>/dev/null || echo "$HOME/.local/bin/codex")}" MODEL="${AOTEST_CODEX_MODEL:-}" PREFIX="aotest-x-$$-" SANDBOX="$(mktemp -d)" CFG="$SANDBOX/agents.toml" FAILED=0 pass(){ echo " PASS: $*"; } fail(){ echo " FAIL: $*"; FAILED=1; } cleanup(){ local rc=$? python3 "$REPO/agents.py" --config "$CFG" down probe >/dev/null 2>&1 || true if command -v tmux >/dev/null 2>&1; then tmux ls 2>/dev/null | sed 's/:.*//' | grep "^${PREFIX}" | while read -r s; do tmux kill-session -t "=$s" 2>/dev/null || true done || true fi rm -rf "$SANDBOX" exit "$rc" } trap cleanup EXIT INT TERM echo "=== codex backend smoke (isolated: prefix=${PREFIX}) ===" command -v tmux >/dev/null 2>&1 || { echo "SKIP: tmux not on PATH"; exit 0; } [ -x "$CODEX_BIN" ] || command -v "$CODEX_BIN" >/dev/null 2>&1 \ || { echo "SKIP: codex binary not found ($CODEX_BIN)"; exit 0; } "$CODEX_BIN" login status >/dev/null 2>&1 \ || { echo "SKIP: Codex is not logged in"; exit 0; } remote_status="$("$CODEX_BIN" remote-control start --json 2>&1)" echo "$remote_status" | grep -q '"status":"connected"' \ || { echo "SKIP: Codex Remote Control is not connected: $remote_status"; exit 0; } pass "Codex Remote Control reports connected" model_line="" [ -n "$MODEL" ] && model_line="model = \"$MODEL\"" cat > "$CFG" </dev/null; then cmd="$(tmux display-message -p -t "=${PREFIX}probe:" '#{pane_current_command}')" pass "session ${PREFIX}probe created via agents.py (pane command: ${cmd})" else fail "${PREFIX}probe session was not created" echo "=== CODEX BACKEND SMOKE: FAIL ===" exit 1 fi pane="$(tmux capture-pane -p -t "=${PREFIX}probe:" -S -200 2>/dev/null)" if [ "$cmd" = "codex" ] && echo "$pane" | grep -q "CODEX_BACKEND_READY"; then pass "Codex TUI attached and completed the probe" else fail "Codex probe did not complete (cmd=${cmd}); tail: $(echo "$pane" | grep -vE '^\s*$' | tail -5)" fi if python3 "$REPO/agents.py" --config "$CFG" status \ | grep -E '^\s*probe\b' | grep -q RUNNING; then pass "agents.py status reports probe RUNNING" else fail "agents.py status did not report probe RUNNING" fi python3 "$REPO/agents.py" --config "$CFG" down probe >/dev/null 2>&1 sleep 2 if tmux has-session -t "=${PREFIX}probe" 2>/dev/null; then fail "${PREFIX}probe still alive after agents.py down" else pass "agents.py down cleanly removed the session" fi if [ "$FAILED" = 0 ]; then echo "=== CODEX BACKEND SMOKE: PASS ==="; exit 0 else echo "=== CODEX BACKEND SMOKE: FAIL ==="; exit 1; fi