#!/bin/sh
# Test fixture: a fake `gh` for apps/review/tests/github/runGh.test.ts.
#
# Checked in and executable (not written at test time) so spawning it never
# races a fresh write-then-exec: on the Linux CI runner, exec'ing a just-written
# script returned exit 0 with the interpreter never running it (no log, empty
# stdout), regardless of whether the shebang was node or sh.
#
# Records the invocation (cwd via `pwd -P` to match realpath, args, stdin) to
# the JSON file named by $SMITHERS_FAKE_GH_LOG, then echoes deterministic output
# or fails like a real gh error.
log=$SMITHERS_FAKE_GH_LOG
input=$(cat)
{
  printf '{"cwd":"%s","args":[' "$(pwd -P)"
  first=1
  for a in "$@"; do
    [ "$first" -eq 1 ] || printf ','
    first=0
    printf '"%s"' "$a"
  done
  printf '],"input":"%s"}' "$input"
} > "$log"
for a in "$@"; do
  [ "$a" = fail ] && { printf 'fixture failure' >&2; exit 7; }
done
printf 'fixture stdout'
