122 lines
4.2 KiB
Bash
Executable File
122 lines
4.2 KiB
Bash
Executable File
#!/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" <<EOF
|
|
[defaults]
|
|
project_dir = "$REPO"
|
|
session_prefix = "$PREFIX"
|
|
log_dir = "$SANDBOX/state"
|
|
backend = "codex"
|
|
$model_line
|
|
watch = "none"
|
|
|
|
[backend.codex]
|
|
bin = "$CODEX_BIN"
|
|
preamble = "{bin} remote-control start --json >/dev/null"
|
|
remote_addr = "unix://"
|
|
flags = "--dangerously-bypass-approvals-and-sandbox --dangerously-bypass-hook-trust --no-alt-screen"
|
|
supports_resume = false
|
|
prompt_delivery = "arg"
|
|
process_name = "codex"
|
|
footer_ui = true
|
|
log_grace = 180
|
|
submit_key = "Enter"
|
|
startup_prompt_re = "Trusting the directory|Do you trust"
|
|
startup_prompt_response = "1"
|
|
startup_prompt_delay = 2
|
|
stall_idle = 300
|
|
active_re = "esc to interrupt|working|thinking|running|searching"
|
|
limit_re = "usage limit|limit reached"
|
|
|
|
[[agent]]
|
|
name = "probe"
|
|
kind = "persistent"
|
|
prompt = "You are a harness self-test. Reply exactly CODEX_BACKEND_READY and then wait silently. Do not use tools or modify files."
|
|
EOF
|
|
|
|
python3 "$REPO/agents.py" --config "$CFG" up probe \
|
|
|| { fail "agents.py up probe errored"; echo "=== CODEX BACKEND SMOKE: FAIL ==="; exit 1; }
|
|
|
|
sleep 12
|
|
if tmux has-session -t "=${PREFIX}probe" 2>/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 echo "$pane" | grep -Fq "$REPO"; then
|
|
pass "daemon-created Codex thread uses the requested project directory"
|
|
else
|
|
fail "Codex thread did not use requested directory $REPO"
|
|
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
|