Files
leleka/control-plane/tests/fixtures/mock_engine.sh
T
Pavlo RatushnyiandClaude Sonnet 5.5 81b907030f feat(vision): picture parts in the Chat, Messages and Responses dialects, the strata-vision encoder client and GENI embeddings
The three adapters reduce pictures to a Responses input_image, the prompt renderer writes the template's
picture items and returns their sources in prompt order, and the request path encodes them (in turn with the
engine), expands every image pad to its token count and sends GENI with the combined SVE1 file. The encoder
is configured by a top-level vision section, stops with the engine and starts before it. Goldens recorded from
the Python handlers cover fourteen Chat and Messages requests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-14 16:46:59 +02:00

190 lines
5.1 KiB
Bash
Executable File

#!/bin/sh
if [ "$1" != "--serve" ]; then
exit 2
fi
case "$2" in
ready)
printf 'INFO engine=mock\nREADY 262144 stop\n'
while IFS= read -r line; do
if [ "$line" = QUIT ]; then
exit 0
fi
done
;;
crash)
printf 'READY 262144 stop\n'
exit 7
;;
slow)
sleep 2
;;
exchange)
printf 'READY 262144 stop\n'
while IFS= read -r line; do
case "$line" in
'GEN 3 temperature=0.5 top_p=0.9 10,20')
printf 'RESUME 0\nPP 2 2 1 2.0\nREUSED 0\nT 31\nT 32\nDONE 2 2 1.0 2.0 stop 0 0 0 0 0 0 0 0.0\n'
;;
QUIT) exit 0 ;;
*) printf 'ERR unexpected request\n' ;;
esac
done
;;
blocked-input)
printf 'READY 262144 stop\n'
exec sleep 30
;;
flood)
printf 'READY 262144 stop\n'
IFS= read -r line || exit 3
while :; do printf 'T 31\n'; done
;;
cancel)
printf 'READY 262144 stop\n'
while IFS= read -r line; do
case "$line" in
'GEN 3 10,20')
: > "$3"
printf 'T 31\n'
IFS= read -r stop || exit 3
[ "$stop" = STOP ] || exit 4
printf 'DONE 1 2 1.0 2.0 cancel\n'
;;
'GEN 1 99')
printf 'T 42\nDONE 1 1 1.0 2.0 stop\n'
;;
QUIT) exit 0 ;;
*) printf 'ERR unexpected request\n' ;;
esac
done
;;
cancel-drain)
printf 'READY 262144 stop\n'
IFS= read -r line || exit 3
printf 'T 31\n'
IFS= read -r line || exit 3
[ "$line" = STOP ] || exit 4
: > "$3/stopped"
while [ ! -e "$3/release" ]; do sleep 0.01; done
printf 'DONE 1 2 1.0 2.0 cancel\n'
while IFS= read -r line; do
[ "$line" = QUIT ] && exit 0
done
;;
cancel-stall)
printf 'READY 262144 stop\n'
IFS= read -r line || exit 3
[ "$line" = 'GEN 3 10,20' ] || exit 4
printf 'T 31\n'
IFS= read -r stop || exit 3
[ "$stop" = STOP ] || exit 4
: > "$3"
printf 'T 32\nPP 2 2 1 2.0\n'
# Consume STOP but never report DONE. A following GEN would demonstrate
# unsafe reuse of this still-active generation.
while IFS= read -r line; do
case "$line" in
'GEN 1 99') printf 'T 42\nDONE 1 1 1.0 2.0 stop\n' ;;
QUIT) exit 0 ;;
esac
done
;;
restart-once)
printf 'boot\n' >> "$3/boots"
if [ ! -e "$3/crashed" ]; then
printf 'READY 262144 stop\n'
IFS= read -r line || exit 3
printf '%s\n' "$line" >> "$3/requests"
printf 'T 31\n'
: > "$3/active"
while [ ! -e "$3/release" ]; do sleep 0.01; done
: > "$3/crashed"
exit 7
fi
sleep 1
printf 'READY 262144 stop\n'
while IFS= read -r line; do
case "$line" in
'GEN 1 99')
printf '%s\n' "$line" >> "$3/requests"
printf 'T 42\nDONE 1 1 1.0 2.0 stop\n' ;;
QUIT) exit 0 ;;
*) printf 'ERR unexpected request\n' ;;
esac
done
;;
lifecycle)
printf 'boot\n' >> "$3/boots"
printf 'INFO engine=mock\nREADY %s stop\n' "${4:-4096}"
while IFS= read -r line; do
case "$line" in
'GEN 2 1,2') printf 'T 31\nT 32\nDONE 2 2 1.0 2.0 stop 0 0 0 0 0\n' ;;
QUIT) printf 'quit\n' >> "$3/quits"; exit 0 ;;
*) printf 'ERR unexpected request\n' ;;
esac
done
;;
budget)
printf 'READY 4096 stop\n'
while IFS= read -r line; do
case "$line" in
'GEN 40 temperature=0.7 10,20')
printf '%s\n' "$line" >> "$3/requests"
printf 'PP 2 2 1 2.0\nT 31\nT 32\nT 33\nT 34\nT 35\n'
IFS= read -r stop || exit 3
[ "$stop" = STOP ] || exit 4
printf 'DONE 5 2 1.0 2.0 cancel 0 0 0 4 8\n' ;;
'GEN 35 temperature=0.7 10,20,31,32,33,90,91')
printf '%s\n' "$line" >> "$3/requests"
printf 'PP 7 7 1 2.0\nT 40\nT 41\nDONE 2 7 3.0 4.0 stop 0 0 5 1 2\n' ;;
'GEN 5 temperature=0.7 10,20')
printf '%s\n' "$line" >> "$3/requests"
printf 'T 31\nT 32\nT 33\nT 34\n'
IFS= read -r stop || exit 3
[ "$stop" = STOP ] || exit 4
printf 'DONE 4 2 1.0 2.0 cancel\n' ;;
QUIT) exit 0 ;;
*) printf 'ERR unexpected request\n' ;;
esac
done
;;
images)
# GEN and GENI: log the line, answer "Hi". $3 is a scratch directory.
dir="$3"
printf 'boot\n' >> "$dir/boots"
printf 'READY 4096 stop\n'
while IFS= read -r line; do
case "$line" in
GEN*)
printf '%s\n' "$line" >> "$dir/requests"
case "$line" in
GENI*)
set -- $line
# the embeddings path is the field before the token ids
eval "emb=\${$(($# - 1))}"
[ -s "$emb" ] && printf 'embeddings-present\n' >> "$dir/requests"
;;
esac
printf 'T 72\nT 105\nDONE 2 7 1.0 2.0 stop 0 0 0 0 0\n' ;;
QUIT) exit 0 ;;
*) printf 'ERR unexpected request\n' ;;
esac
done
;;
stall)
printf 'READY 4096 stop\n'
IFS= read -r line || exit 3
sleep 30
;;
restart-loop)
printf 'boot\n' >> "$3/boots"
printf 'READY 262144 stop\n'
exit 7
;;
restart-bad)
printf 'boot\n' >> "$3/boots"
printf 'READY invalid\n'
;;
*) exit 2 ;;
esac