#!/usr/bin/env bash # Run one Codex CLI agent task against the stack that run-e2e.sh started (test tooling, runs inside a holder job via E2E_RUN_CMD). # # run-codex.sh ttt|crm # # Needs from the environment (run-e2e.sh sets them): E2E_BASE_URL, E2E_MODEL, E2E_OUT_DIR, E2E_API_KEY (a freshly generated test key). # Needs on disk (never in Git): CODEX_BIN (default ~/work/codex-e2e/bin/codex), for ttt a vendored three.module.min.js # (CODEX_VENDOR, default ~/work/codex-e2e/vendor) and optionally node + playwright (CODEX_NODE_DIR) for the browser checks. set -uo pipefail HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) TASK=${1:?ttt or crm} W=$HOME/work/codex-e2e CODEX_BIN=${CODEX_BIN:-$W/bin/codex} OUT=${E2E_OUT_DIR:?run through run-e2e.sh} TIMEOUT_S=${CODEX_TIMEOUT_S:-5400} [ -x "$CODEX_BIN" ] || { echo "codex binary not installed at $CODEX_BIN (see docs/e2e-run.md, Codex runs)"; exit 7; } [ -n "${E2E_API_KEY:-}" ] || { echo "E2E_API_KEY not set"; exit 7; } case "$TASK" in ttt) PROMPT=$HERE/prompt-threejs.txt ;; crm) PROMPT=$HERE/prompt-crm.txt ;; *) echo "unknown task $TASK"; exit 2 ;; esac WS=$OUT/workspace-$TASK export CODEX_HOME=$OUT/codex-home rm -rf "$WS" "$CODEX_HOME"; mkdir -p "$WS" "$CODEX_HOME"; chmod 700 "$CODEX_HOME" sed -e "s|@MODEL@|$E2E_MODEL|" -e "s|@BASE_URL@|$E2E_BASE_URL|" -e "s|@EFFORT@|${CODEX_EFFORT:-medium}|" "$HERE/config.toml.tmpl" >"$CODEX_HOME/config.toml" if [ "$TASK" = ttt ]; then VENDOR=${CODEX_VENDOR:-$W/vendor} [ -f "$VENDOR/three.module.min.js" ] || { echo "vendored three.module.min.js missing in $VENDOR"; exit 7; } cp "$VENDOR/three.module.min.js" "$WS/" fi "$CODEX_BIN" --version | tee "$OUT/codex-version.txt" sha256sum "$CODEX_BIN" "$PROMPT" | tee "$OUT/codex-inputs.sha256" echo "task=$TASK start=$(date -u +%FT%TZ)" | tee "$OUT/codex-task.txt" T0=$(date +%s) # The agent runs for a long time; the stack, the sampler and this timeout bound the job. # every JSONL event gets the wall-clock time it was read (t_unix_ms) so it can be joined with the engine-side log timeout "$TIMEOUT_S" "$CODEX_BIN" exec --json --skip-git-repo-check -C "$WS" "$(cat "$PROMPT")" "$OUT/codex.err" | python3 -u "$HERE/ts_lines.py" >"$OUT/codex-events.jsonl" RC=${PIPESTATUS[0]} echo "codex exit status $RC after $(( $(date +%s) - T0 )) s" | tee -a "$OUT/codex-task.txt" tail -n 5 "$OUT/codex.err" | cut -c1-300 VRC=0 if [ "$TASK" = crm ]; then python3 "$HERE/crm_acceptance.py" "$WS" 2>&1 | tee "$OUT/acceptance.log"; VRC=${PIPESTATUS[0]} else ls -l "$WS/index.html" 2>&1 | tee "$OUT/acceptance.log" sha256sum "$WS/index.html" 2>&1 | tee -a "$OUT/acceptance.log" if [ -n "${CODEX_NODE_DIR:-}" ] && [ -x "$CODEX_NODE_DIR/bin/node" ]; then (cd "$CODEX_NODE_DIR" && PATH="$CODEX_NODE_DIR/bin:$PATH" node "$HERE/check_ttt.mjs" "$WS/index.html") 2>&1 | tee -a "$OUT/acceptance.log"; VRC=${PIPESTATUS[0]} else echo "no node/playwright (CODEX_NODE_DIR): the 6 browser checks were not run on the server; run scripts/e2e/codex/check_ttt.mjs on the laptop" | tee -a "$OUT/acceptance.log"; VRC=0 fi fi echo "acceptance exit status $VRC" | tee -a "$OUT/codex-task.txt" python3 "$HERE/codex_report.py" "$OUT" 2>&1 | tee "$OUT/report.txt" [ "$RC" = 0 ] && exit "$VRC" exit "$RC"