Files
Hermes c663be808c virtuelle Modelle: Ketten-Minimum, Metadaten und Next-Judge-Header
/v1/models für virtuelle Regeln (Pool, Alias, Judge, Review) verspricht
jetzt die kleinste ctx-Größe der ganzen Kette — Worker-Ziele plus alle
Judge-Schritte. output fällt nicht mehr auf die Endpoint-Kontextzahl
zurück; ohne veröffentlichte Ausgabegrenze gilt der effektive Kontext
als sichere Obergrenze. Jeder Eintrag trägt zusätzlich "name" und die
berechneten limit-Werte.

ctx-Überlauf gehört ab jetzt einer eigenen Regel: Ist die geschätzte
Prompt-Größe größer als das Ketten-Minimum, überspringt
first_matching_rule die virtuelle Regel und lässt die nächste passende
Regel (z. B. "req for ... ctx >N pass ...") den Request bedienen. Der
globale ctx_fallback greift für virtuelle Regeln nicht mehr — sonst
würde still der Judge oder die Cloud einspringen. Normale Regeln nutzen
ihn unverändert.

Jede Antwort einer Judge-Regel nennt den nächsten Judge:
X-Junction-Judge-Next (Zählerwert), -In (verbleibende Calls),
-Next-Step/-Every/-Target/-Model/-Cache. Das gilt auch auf Worker-Turns
und auf dem Judge-Turn selbst (für den nächsten danach); Regeln ohne
Judge senden keine solchen Header. j_judge_tick gibt dafür den Zähler
nach dem Request aus (0 nach dem letzten Schritt).

Tests:
- tests/virtual-models.sh: Worker 4000/1000, Judge 2000/500 ->
  vm-chain limit 2000/500 + name; kleiner Request geht zum Judge;
  großer Request über die explizite ctx-Regel zum Big-Endpoint;
  ohne ctx-Regel 503 no_matching_rule und kein ctx_fallback; eine
  normale Regel nutzt ctx_fallback weiterhin.
- tests/judge.sh: Next-Header auf Worker- und Judge-Turns, Ketten-
  5/10-Übergänge (3/5), Reset, Pool ("pool"), Fallback, negative
  Prüfung für Regeln ohne Judge.
- tests/stub.c: STUB_MODELS-Einträge können jetzt limit.context/output
  veröffentlichen.

Tests: 518 OK, 0 FAIL.
2026-11-18 13:28:34 +00:00

361 lines
21 KiB
Bash

#!/bin/bash
# Wird von tests/run.sh eingebunden: ein virtuelles Modell, bei dem jede N-te
# Anfrage einer Unterhaltung an einen Judge geht. Der Judge sieht den vollen
# Verlauf; fällt er aus, bedient der Worker den Turn.
#
# Die Zählung ist pro Unterhaltung. Der Test hält System-Prompt und erste
# User-Nachricht fest und variiert nur die letzte Nachricht — genau so wächst
# eine Chat-Anfrage.
echo
echo "== 41. Virtuelles Modell mit sampled Judge =="
JW=$((PORT+270))
JJ=$((PORT+271))
JP=$((PORT+272))
JF=$((PORT+273))
JP2=$((PORT+274))
JP3=$((PORT+275))
JJ2=$((PORT+276))
JP4=$((PORT+277))
JB=$((PORT+278))
JBJ=$((PORT+279))
tests/stub $JW "WORKER" > "$TMP/judge_worker.log" 2>&1 &
PIDS+=($!)
tests/stub $JJ "JUDGE" > "$TMP/judge_judge.log" 2>&1 &
PIDS+=($!)
tests/stub $JJ2 "JUDGE2" > "$TMP/judge_judge2.log" 2>&1 &
PIDS+=($!)
STUB_STATE="$TMP/judge_bad.state" tests/stub $JF "BADJUDGE" --fail-n 100 \
> "$TMP/judge_bad.log" 2>&1 &
PIDS+=($!)
STUB_FAIL_CACHE=1 tests/stub $JB "OVERLAP" > "$TMP/judge_overlap_stub.log" 2>&1 &
PIDS+=($!)
wait_port $JW 10 || bad "the judge worker stub did not come up"
wait_port $JJ 10 || bad "the judge stub did not come up"
wait_port $JJ2 10 || bad "the second judge stub did not come up"
wait_port $JF 10 || bad "the failing judge stub did not come up"
wait_port $JB 10 || bad "the overlap judge stub did not come up"
cat > "$TMP/judge.conf" <<CFG
listen 127.0.0.1:$JP
queue_timeout 10
models allow "qwen-judged" "WORKER" "JUDGE"
endpoint worker { base http://127.0.0.1:$JW/v1; context 8000; timeout 10; idle_timeout 5 }
endpoint judge { base http://127.0.0.1:$JJ/v1; context 12000; timeout 10; idle_timeout 5; header "anthropic-version: 2023-06-01" }
req path "/v1/models" pass worker, judge
req for "qwen-judged" judge every 3 judge as "judge-model" cache 1h pass worker as "worker-model"
CFG
./junction --config "$TMP/judge.conf" > "$TMP/judge.log" 2>&1 &
PIDS+=($!)
wait_port "$JP" 10 || bad "the judge instance did not come up"
SYS="You are a careful reviewer. Keep the answer short and check the previous step."
judge_body() { # judge_body <model> <first-user> <last-user>
python3 - "$SYS" "$2" "$3" "$1" <<'PY'
import json, sys
print(json.dumps({
"model": sys.argv[4],
"messages": [
{"role": "system", "content": sys.argv[1]},
{"role": "user", "content": sys.argv[2]},
{"role": "user", "content": sys.argv[3]},
],
"max_tokens": 4,
}))
PY
}
judge_ask() { # judge_ask <port> <model> <first-user> <last-user>
curl -s -D "$TMP/judge_h.txt" -o "$TMP/judge_b.txt" -m 20 \
-X POST -H 'Content-Type: application/json' \
-H 'anthropic-version: 2025-01-01' \
-d "$(judge_body "$2" "$3" "$4")" \
"http://127.0.0.1:$1/v1/chat/completions"
JNAME=$(tr -d '\r' < "$TMP/judge_h.txt" | sed -n 's/^X-Stub-Name: //p')
JCACHE=$(tr -d '\r' < "$TMP/judge_h.txt" | sed -n 's/^X-Stub-Cache-Control: //p')
JMODEL=$(tr -d '\r' < "$TMP/judge_h.txt" | sed -n 's/^X-Stub-Model: //p')
JAV=$(tr -d '\r' < "$TMP/judge_h.txt" | sed -n 's/^X-Stub-Anthropic-Version: //p')
JAVC=$(tr -d '\r' < "$TMP/judge_h.txt" | sed -n 's/^X-Stub-Anthropic-Versions: //p')
JJUDGE=$(tr -d '\r' < "$TMP/judge_h.txt" | sed -n 's/^X-Junction-Judge: //p')
JJSTEP=$(tr -d '\r' < "$TMP/judge_h.txt" | sed -n 's/^X-Junction-Judge-Step: //p')
JJEVERY=$(tr -d '\r' < "$TMP/judge_h.txt" | sed -n 's/^X-Junction-Judge-Every: //p')
JJMODEL=$(tr -d '\r' < "$TMP/judge_h.txt" | sed -n 's/^X-Junction-Judge-Model: //p')
JJSERVED=$(tr -d '\r' < "$TMP/judge_h.txt" | sed -n 's/^X-Junction-Judge-Served: //p')
JJNEXT=$(tr -d '\r' < "$TMP/judge_h.txt" | sed -n 's/^X-Junction-Judge-Next: //p')
JJIN=$(tr -d '\r' < "$TMP/judge_h.txt" | sed -n 's/^X-Junction-Judge-In: //p')
JJNSTEP=$(tr -d '\r' < "$TMP/judge_h.txt" | sed -n 's/^X-Junction-Judge-Next-Step: //p')
JJNEVERY=$(tr -d '\r' < "$TMP/judge_h.txt" | sed -n 's/^X-Junction-Judge-Next-Every: //p')
JJNTARGET=$(tr -d '\r' < "$TMP/judge_h.txt" | sed -n 's/^X-Junction-Judge-Next-Target: //p')
JJNMODEL=$(tr -d '\r' < "$TMP/judge_h.txt" | sed -n 's/^X-Junction-Judge-Next-Model: //p')
JJNCACHE=$(tr -d '\r' < "$TMP/judge_h.txt" | sed -n 's/^X-Junction-Judge-Next-Cache: //p')
JENDPOINT=$(tr -d '\r' < "$TMP/judge_h.txt" | sed -n 's/^X-Junction-Endpoint: //p')
}
# Unterhaltung A: 3., 6., 9. … Anfrage geht an den Judge.
A=("W" "W" "J" "W" "W" "J")
for i in 1 2 3 4 5 6; do
judge_ask "$JP" "qwen-judged" "$SYS" "conversation A, turn $i"
if [ "${A[$((i-1))]}" = "J" ]; then
[ "$JNAME" = "JUDGE" ] && ok "turn $i goes to the judge" \
|| bad "turn $i should go to the judge, got '$JNAME'"
[ "$JCACHE" = "1" ] && ok "turn $i carries the cache marker" \
|| bad "turn $i: judge request had no cache_control"
[ "$JMODEL" = "judge-model" ] && ok "turn $i sends the judge model" \
|| bad "turn $i: judge saw model '$JMODEL'"
[ "$JJUDGE" = "judge" ] && ok "turn $i names the judge in the headers" \
|| bad "turn $i: X-Junction-Judge='$JJUDGE'"
[ "$JJSTEP" = "0" ] && ok "turn $i names the judge step" \
|| bad "turn $i: judge step '$JJSTEP'"
[ "$JJEVERY" = "3" ] && ok "turn $i names the judge interval" \
|| bad "turn $i: judge every '$JJEVERY'"
[ "$JJMODEL" = "judge-model" ] && ok "turn $i names the judge model" \
|| bad "turn $i: judge model header '$JJMODEL'"
[ "$JJSERVED" = "1" ] && ok "turn $i says the judge served" \
|| bad "turn $i: judge served '$JJSERVED'"
[ "$JENDPOINT" = "judge" ] && ok "turn $i names the serving endpoint" \
|| bad "turn $i: endpoint '$JENDPOINT'"
if [ "$i" = "3" ]; then
[ "$JAV" = "2025-01-01" ] && ok "the client's anthropic-version wins" \
|| bad "the judge saw anthropic-version '$JAV'"
[ "$JAVC" = "1" ] && ok "the static anthropic-version is not duplicated" \
|| bad "the judge saw $JAVC anthropic-version headers"
fi
else
[ "$JNAME" = "WORKER" ] && ok "turn $i stays on the worker" \
|| bad "turn $i should stay on the worker, got '$JNAME'"
[ "$JCACHE" = "0" ] && ok "turn $i has no cache marker for the worker" \
|| bad "turn $i: worker request carried cache_control"
[ -z "$JJUDGE" ] && ok "turn $i has no judge header" \
|| bad "turn $i: worker turn carries judge '$JJUDGE'"
[ "$JENDPOINT" = "worker" ] && ok "turn $i names the worker endpoint" \
|| bad "turn $i: endpoint '$JENDPOINT'"
fi
NEXTIN=$(( i % 3 == 1 ? 2 : (i % 3 == 2 ? 1 : 3) ))
[ "$JJNEXT" = "3" ] && [ "$JJIN" = "$NEXTIN" ] && [ "$JJNSTEP" = "0" ] \
&& [ "$JJNEVERY" = "3" ] && [ "$JJNTARGET" = "judge" ] \
&& [ "$JJNMODEL" = "judge-model" ] && [ "$JJNCACHE" = "1h" ] \
&& ok "turn $i announces the next judge at 3 (in $NEXTIN)" \
|| bad "turn $i next judge: next=$JJNEXT in=$JJIN step=$JJNSTEP every=$JJNEVERY target=$JJNTARGET model=$JJNMODEL cache=$JJNCACHE"
done
# Unterhaltung B beginnt bei 1, obwohl A schon beim Judge war.
judge_ask "$JP" "qwen-judged" "A different system prompt for B." "conversation B, turn 1"
[ "$JNAME" = "WORKER" ] && ok "a second conversation starts with the worker" \
|| bad "conversation B inherited A's counter: $JNAME"
judge_ask "$JP" "qwen-judged" "A different system prompt for B." "conversation B, turn 2"
[ "$JNAME" = "WORKER" ] && ok "the second turn of B is still the worker" \
|| bad "conversation B's second turn hit the judge too early"
judge_ask "$JP" "qwen-judged" "A different system prompt for B." "conversation B, turn 3"
[ "$JNAME" = "JUDGE" ] && ok "the third turn of B goes to the judge" \
|| bad "conversation B's third turn did not reach the judge"
[ "$JJUDGE" = "judge" ] && [ "$JJSERVED" = "1" ] && ok "conversation B's judge is visible in the headers" \
|| bad "conversation B's judge headers are wrong: '$JJUDGE'/'$JJSERVED'"
# Eine Regel ohne judge darf keine Next-Judge-Header erfinden.
MJ=$(curl -s -D - -o /dev/null -m 10 "http://127.0.0.1:$JP/v1/models")
case "$(printf '%s' "$MJ" | tr -d '\r')" in
*"X-Junction-Judge-Next:"*) bad "a rule without a judge announces a next judge" ;;
*) ok "a rule without a judge has no next-judge headers" ;;
esac
contains "$(grep '\[junction\] judge ' "$TMP/judge.log" | head -1)" "cache=1h" \
"the judge log names the cache TTL"
contains "$(grep '\[junction\] judge ' "$TMP/judge.log" | head -1)" "conv=" \
"the judge log names the conversation"
# /v1/models kennt das virtuelle Modell und nimmt die engere Grenze (Worker 8000).
M=$(curl -s -m 10 "http://127.0.0.1:$JP/v1/models")
contains "$M" '"id":"qwen-judged"' "the virtual model is listed"
contains "$M" '"context":8000' "the virtual model keeps the worker's smaller context"
# Fällt der Judge aus, bedient der Worker den Turn. Der Cache-Marker darf dann
# nicht im Worker-Rumpf landen (der kennt ihn nicht).
cat > "$TMP/judge_fb.conf" <<CFG
listen 127.0.0.1:$JP2
queue_timeout 10
retry_num 0
models allow "qwen-judged" "WORKER"
endpoint worker { base http://127.0.0.1:$JW/v1; context 8000; timeout 10 }
endpoint badjudge { base http://127.0.0.1:$JF/v1; context 12000; timeout 10; cooldown 1 }
req for "qwen-judged" judge every 1 badjudge as "judge-model" cache 1h pass worker as "worker-model"
CFG
./junction --config "$TMP/judge_fb.conf" > "$TMP/judge_fb.log" 2>&1 &
PIDS+=($!)
wait_port "$JP2" 10 || bad "the judge-fallback instance did not come up"
judge_ask "$JP2" "qwen-judged" "$SYS" "fallback turn"
[ "$JNAME" = "WORKER" ] && ok "a failing judge falls back to the worker" \
|| bad "the failed judge did not fall back: '$JNAME'"
[ "$JCACHE" = "0" ] && ok "the worker fallback does not receive the judge's cache marker" \
|| bad "the worker fallback received cache_control"
[ "$JJUDGE" = "badjudge" ] && ok "the fallback header names the attempted judge" \
|| bad "the fallback judge header is '$JJUDGE'"
[ "$JJSERVED" = "0" ] && ok "the fallback header says the judge did not serve" \
|| bad "the fallback judge served header is '$JJSERVED'"
[ "$JENDPOINT" = "worker" ] && ok "the fallback header names the worker" \
|| bad "the fallback endpoint header is '$JENDPOINT'"
[ "$JJNEXT" = "1" ] && [ "$JJIN" = "1" ] && [ "$JJNSTEP" = "0" ] \
&& [ "$JJNEVERY" = "1" ] && [ "$JJNTARGET" = "badjudge" ] \
&& [ "$JJNMODEL" = "judge-model" ] && [ "$JJNCACHE" = "1h" ] \
&& ok "a failed judge still announces the next one at 1" \
|| bad "fallback next judge: next=$JJNEXT in=$JJIN target=$JJNTARGET model=$JJNMODEL"
contains "$(cat "$TMP/judge_fb.log")" "upstream_error endpoint=badjudge" \
"the judge's error body is logged"
contains "$(cat "$TMP/judge_fb.log")" "served_by endpoint=worker" \
"the fallback is visible in the log"
# Judge und Worker können denselben Endpoint nennen. Fällt der Judge aus und
# bedient der Worker, darf X-Junction-Judge-Served nicht 1 werden — die alte
# Namensprüfung hielt den Worker für den Judge. Der Stub scheitert nur, wenn der
# Judge-Rumpf den cache_control-Marker trägt.
cat > "$TMP/judge_overlap.conf" <<CFG
listen 127.0.0.1:$JBJ
queue_timeout 10
retry_num 0
models allow "vm-overlap" "OVERLAP"
endpoint both { base http://127.0.0.1:$JB/v1; context 8000; timeout 10; cooldown 0 }
req for "vm-overlap" judge every 1 both as "judge-model" cache 1h pass both as "worker-model"
CFG
./junction --config "$TMP/judge_overlap.conf" > "$TMP/judge_overlap.log" 2>&1 &
PIDS+=($!)
wait_port "$JBJ" 10 || bad "the overlap-judge instance did not come up"
judge_ask "$JBJ" "vm-overlap" "$SYS" "overlap turn"
[ "$JNAME" = "OVERLAP" ] && ok "the worker fallback on the judge's endpoint serves" \
|| bad "the overlap fallback got '$JNAME'"
[ "$JJUDGE" = "both" ] && ok "the overlap fallback still names the attempted judge" \
|| bad "overlap judge header is '$JJUDGE'"
[ "$JJSERVED" = "0" ] && ok "a worker on the judge's endpoint does not claim the judge served" \
|| bad "overlap judge served header is '$JJSERVED'"
[ "$JCACHE" = "0" ] && ok "the overlap worker fallback has no judge cache marker" \
|| bad "the overlap worker received cache_control"
contains "$(cat "$TMP/judge_overlap.log")" "served_by endpoint=both" \
"the overlap fallback is visible in the log"
# Ein Pool als Judge: das erste Mitglied fällt aus, das zweite bedient den Turn.
cat > "$TMP/judge_pool.conf" <<CFG
listen 127.0.0.1:$JP3
queue_timeout 10
retry_num 0
models allow "vm-pool" "WORKER" "JUDGE" "BADJUDGE"
endpoint worker { base http://127.0.0.1:$JW/v1; context 8000; timeout 10 }
endpoint judge { base http://127.0.0.1:$JJ/v1; context 12000; timeout 10 }
endpoint badjudge { base http://127.0.0.1:$JF/v1; context 12000; timeout 10; cooldown 1 }
pool judgepool badjudge as "bad-model", judge as "judge-model"
req for "vm-pool" judge every 1 judgepool cache off pass worker as "worker-model"
CFG
./junction --config "$TMP/judge_pool.conf" > "$TMP/judge_pool.log" 2>&1 &
PIDS+=($!)
wait_port "$JP3" 10 || bad "the judge-pool instance did not come up"
judge_ask "$JP3" "vm-pool" "$SYS" "pool judge turn"
[ "$JNAME" = "JUDGE" ] && ok "a judge pool falls through to its second member" \
|| bad "the judge pool did not reach the second member: '$JNAME'"
[ "$JMODEL" = "judge-model" ] && ok "the judge pool member keeps its own model" \
|| bad "the pool judge saw model '$JMODEL'"
[ "$JCACHE" = "0" ] && ok "cache off sends no marker to the pool judge" \
|| bad "the pool judge received cache_control"
[ "$JJUDGE" = "judgepool" ] && ok "the header names the judge pool" \
|| bad "the pool judge header is '$JJUDGE'"
[ "$JJMODEL" = "pool" ] && ok "the header says the judge model is the pool" \
|| bad "the pool judge model header is '$JJMODEL'"
[ "$JJSERVED" = "1" ] && ok "the pool judge header says it served" \
|| bad "the pool judge served header is '$JJSERVED'"
[ "$JJNEXT" = "1" ] && [ "$JJIN" = "1" ] && [ "$JJNSTEP" = "0" ] \
&& [ "$JJNEVERY" = "1" ] && [ "$JJNTARGET" = "judgepool" ] \
&& [ "$JJNMODEL" = "pool" ] && [ "$JJNCACHE" = "off" ] \
&& ok "a pool judge announces the next judge with the pool name" \
|| bad "pool next judge: next=$JJNEXT in=$JJIN target=$JJNTARGET model=$JJNMODEL"
contains "$(cat "$TMP/judge_pool.log")" "target=judgepool slots=2" \
"the judge log names the pool and its slot count"
contains "$(cat "$TMP/judge_pool.log")" "failed endpoint=badjudge" \
"the first judge pool member's failure is logged"
contains "$(cat "$TMP/judge_pool.log")" "served_by endpoint=judge" \
"the second judge pool member served the turn"
# Eine Kette: 3. Call -> DeepSeek-Judge, 5. Call -> Claude-Judge, dann wieder
# bei 0. Der 8. Call ist der 3. nach dem Reset, der 10. der 5.
cat > "$TMP/judge_chain.conf" <<CFG
listen 127.0.0.1:$JP4
queue_timeout 10
models allow "vm-chain" "WORKER" "JUDGE" "JUDGE2"
endpoint worker { base http://127.0.0.1:$JW/v1; context 8000; timeout 10 }
endpoint judge { base http://127.0.0.1:$JJ/v1; context 8000; timeout 10 }
endpoint judge2 { base http://127.0.0.1:$JJ2/v1; context 8000; timeout 10 }
pool judgea judge as "judge-a-model"
req for "vm-chain" judge every 3 judgea cache off judge every 5 judge2 as "judge-b-model" cache 1h pass worker as "worker-model"
CFG
./junction --config "$TMP/judge_chain.conf" > "$TMP/judge_chain.log" 2>&1 &
PIDS+=($!)
wait_port "$JP4" 10 || bad "the judge-chain instance did not come up"
CHAIN=("W" "W" "A" "W" "B" "W" "W" "A" "W" "B")
NEXTA=(3 3 5 5 3 3 3 5 5 3)
NEXTI=(2 1 2 1 3 2 1 2 1 3)
NEXTS=(0 0 1 1 0 0 0 1 1 0)
NEXTT=(judgea judgea judge2 judge2 judgea judgea judgea judge2 judge2 judgea)
NEXTM=(pool pool judge-b-model judge-b-model pool pool pool judge-b-model judge-b-model pool)
NEXTC=(off off 1h 1h off off off 1h 1h off)
for i in 1 2 3 4 5 6 7 8 9 10; do
judge_ask "$JP4" "vm-chain" "$SYS" "chain turn $i"
want=${CHAIN[$((i-1))]}
case "$want" in
W) [ "$JNAME" = "WORKER" ] && ok "chain call $i stays on the worker" \
|| bad "chain call $i should be the worker, got '$JNAME'"
[ -z "$JJUDGE" ] && ok "chain call $i has no judge header" \
|| bad "chain call $i: worker carries judge '$JJUDGE'" ;;
A) [ "$JNAME" = "JUDGE" ] && ok "chain call $i goes to the deepseek judge" \
|| bad "chain call $i should be the deepseek judge, got '$JNAME'"
[ "$JMODEL" = "judge-a-model" ] && ok "chain call $i uses judge-a model" \
|| bad "chain call $i model '$JMODEL'"
[ "$JCACHE" = "0" ] && ok "chain call $i sends no marker to deepseek" \
|| bad "chain call $i carried cache_control for deepseek"
[ "$JJUDGE" = "judgea" ] && [ "$JJSTEP" = "0" ] && [ "$JJEVERY" = "3" ] \
&& [ "$JJSERVED" = "1" ] && ok "chain call $i names the deepseek judge" \
|| bad "chain call $i judge headers are wrong" ;;
B) [ "$JNAME" = "JUDGE2" ] && ok "chain call $i goes to the claude judge" \
|| bad "chain call $i should be the claude judge, got '$JNAME'"
[ "$JMODEL" = "judge-b-model" ] && ok "chain call $i uses judge-b model" \
|| bad "chain call $i model '$JMODEL'"
[ "$JCACHE" = "1" ] && ok "chain call $i carries the claude cache marker" \
|| bad "chain call $i had no cache_control for claude"
[ "$JJUDGE" = "judge2" ] && [ "$JJSTEP" = "1" ] && [ "$JJEVERY" = "5" ] \
&& [ "$JJSERVED" = "1" ] && ok "chain call $i names the claude judge" \
|| bad "chain call $i judge headers are wrong" ;;
esac
[ "$JJNEXT" = "${NEXTA[$((i-1))]}" ] && [ "$JJIN" = "${NEXTI[$((i-1))]}" ] \
&& [ "$JJNSTEP" = "${NEXTS[$((i-1))]}" ] && [ "$JJNEVERY" = "${NEXTA[$((i-1))]}" ] \
&& [ "$JJNTARGET" = "${NEXTT[$((i-1))]}" ] && [ "$JJNMODEL" = "${NEXTM[$((i-1))]}" ] \
&& [ "$JJNCACHE" = "${NEXTC[$((i-1))]}" ] \
&& ok "chain call $i announces the next step ${NEXTS[$((i-1))]}" \
|| bad "chain call $i next judge: next=$JJNEXT in=$JJIN step=$JJNSTEP every=$JJNEVERY target=$JJNTARGET model=$JJNMODEL cache=$JJNCACHE"
done
contains "$(grep 'step=0 every=3 target=judgea' "$TMP/judge_chain.log" | head -1)" \
"step=0" "the chain log names the deepseek step"
contains "$(grep 'step=1 every=5 target=judge2' "$TMP/judge_chain.log" | head -1)" \
"step=1" "the chain log names the claude step"
CHAIN_A_CALLS=$(grep -c 'target=judgea' "$TMP/judge_chain.log")
[ "$CHAIN_A_CALLS" = "2" ] && ok "the chain reset after its last step and started again" \
|| bad "the chain did not reset: $CHAIN_A_CALLS deepseek judge calls"
ST=$(curl -s -m 10 "http://127.0.0.1:$JP4/status")
contains "$ST" '"judge":"3:judgea,5:judge2 as judge-b-model"' \
"the status names the judge chain"
# Konfigurationsfehler müssen laut sein.
printf 'endpoint e {\n base http://127.0.0.1:9995/v1\n}\nreq for "vm" judge every 2 missing as "m" pass e\n' \
> "$TMP/judge_bad_endpoint.conf"
OUT=$(./junction --config "$TMP/judge_bad_endpoint.conf" 2>&1)
contains "$OUT" "judge passes to unknown endpoint" "an unknown judge endpoint is rejected"
printf 'endpoint e {\n base http://127.0.0.1:9995/v1\n}\nreq for "vm" judge every 0 e as "m" pass e\n' \
> "$TMP/judge_bad_every.conf"
OUT=$(./junction --config "$TMP/judge_bad_every.conf" 2>&1)
contains "$OUT" "bad arguments" "judge every 0 is rejected"
printf 'endpoint e {\n base http://127.0.0.1:9995/v1\n}\nreq for "vm" judge every 2 e pass e\n' \
> "$TMP/judge_no_as.conf"
OUT=$(./junction --config "$TMP/judge_no_as.conf" 2>&1)
contains "$OUT" "judge needs" "a judge without a model is rejected"
printf 'endpoint e {\n base http://127.0.0.1:9995/v1\n}\nreq for "vm" judge every 10 e as "m" judge every 5 e as "m" pass e\n' \
> "$TMP/judge_order.conf"
OUT=$(./junction --config "$TMP/judge_order.conf" 2>&1)
contains "$OUT" "judge steps must be ascending" "a descending judge chain is rejected"