#!/usr/bin/env bash
# A stand-in for `ps` in tests: answers `ps -o <field>= -p <pid>` from $FAKE_CLAUDE_STATE/ps/<pid>.<field>
# (written by fake-claude for each fake session); any other call goes to the real ps.
S=${FAKE_CLAUDE_STATE:-}
field=""; pid=""; prev=""
# the whole listing (ps -axo pid=,command=): $S/ps-list, empty when a test wrote none, so a test never
# reads the real Claude Code processes of the machine it runs on
if [ "$1" = -axo ] && [ -n "$S" ]; then cat "$S/ps-list" 2>/dev/null; exit 0; fi
for a in "$@"; do
  case "$prev" in -o) field=${a%=} ;; -p) pid=$a ;; esac
  prev=$a
done
if [ -n "$S" ] && [ -n "$field" ] && [ -n "$pid" ] && [ -f "$S/ps/$pid.$field" ]; then cat "$S/ps/$pid.$field"; exit 0; fi
PATH=/usr/bin:/bin exec ps "$@"
