#!/bin/sh
# Deterministic worker fixture for admission/deadline tests.  It consumes the
# JSON request as data and never evaluates or interpolates it.

set -eu

[ "$#" -eq 0 ] || exit 63

IFS= read -r request || exit 64

case "$request" in
  *'"engine_name":"limit-engine-'*)
    trap '' TERM
    while :; do
      sleep 10
    done
    ;;
  *'"engine_name":"quick-after-cancel"'*)
    printf '%s\n' '{"ok":true,"results":[]}'
    ;;
  *'"engine_name":"orphaning-engine"'*)
    # The leader exits successfully while a descendant retains both capture
    # pipes. The parent must kill the residual process group instead of
    # blocking on pipe EOF.
    sleep 10 &
    printf '%s\n' '{"ok":true,"results":[]}'
    exit 0
    ;;
  *)
    printf '%s\n' '{"ok":false,"error":"unexpected test engine"}'
    exit 65
    ;;
esac
