Files
junction/tests/ctx-fallback.sh
T
Hermes 883f111756 ctx: Fallback auf ds41flash, wenn kein Regel-Ziel den Kontext fasst
- global `ctx_fallback <pool> [as <model>]`
- passt ctx + max_tokens in kein Ziel der gewählten Regel, wird der Pool
  stattdessen versucht; das Modell kommt aus dem `as` des Pool-Members oder
  aus dem Modell der Direktive.
- der Fallback wird als ctx_fallback geloggt; ohne Konfiguration bleibt es
  beim bisherigen 503.
- Test mit kleinem und großem Stub deckt den Treffer und den Fallback ab.
2026-11-17 08:39:27 +00:00

60 lines
1.9 KiB
Bash

#!/bin/bash
# Wird von tests/run.sh eingebunden: ctx-Fallback, wenn keine Regel-Ziel den
# Kontext fassen kann.
echo "== 42. ctx-Fallback auf den ds41flash-Pool =="
CF=$((PORT+260))
CFS=$((PORT+261))
CFB=$((PORT+262))
STUB_CTX=4096 STUB_OUT=1000 tests/stub $CFS "SMALL" & PIDS+=($!)
STUB_CTX=200000 STUB_OUT=1000 tests/stub $CFB "BIG" & PIDS+=($!)
sleep 0.3
cat > "$TMP/ctx-fallback.conf" <<CFG
listen 127.0.0.1:$CF
ctx_chars_per_token 4
endpoint small {
base http://127.0.0.1:$CFS/v1
context 4096
timeout 10
}
endpoint big {
base http://127.0.0.1:$CFB/v1
context 200000
timeout 10
}
pool smallpool small
pool ds41flash big as "deepseek-v4.1-flash"
ctx_fallback ds41flash
req for "tiny" check none pass smallpool
req for "*" block
CFG
./junction --config "$TMP/ctx-fallback.conf" > "$TMP/ctx-fallback.log" 2>&1 &
PIDS+=($!)
wait_port $CF 10
# Small request: the small endpoint fits, no fallback.
R=$(curl -s -m 10 -D- -o /dev/null -X POST -H 'Content-Type: application/json' \
-d '{"model":"tiny","messages":[{"role":"user","content":"hi"}],"max_tokens":8}' \
"http://127.0.0.1:$CF/v1/chat/completions")
contains "$R" "X-Junction-Endpoint: small" "a fitting request stays on its rule target"
# Large request: ctx + max_tokens exceeds 4096; the fallback pool rewrites the model.
python3 - "$TMP/ctx-large.json" <<'PY'
import json, sys
body = {
"model": "tiny",
"messages": [{"role": "user", "content": "x" * 30000}],
"max_tokens": 1000,
}
open(sys.argv[1], "w").write(json.dumps(body))
PY
R=$(curl -s -m 20 -D- -o /dev/null -X POST -H 'Content-Type: application/json' \
--data-binary "@$TMP/ctx-large.json" \
"http://127.0.0.1:$CF/v1/chat/completions")
contains "$R" "X-Junction-Endpoint: big" "an oversized request falls back to the ctx pool"
contains "$R" "X-Stub-Model: deepseek-v4.1-flash" "the ctx fallback rewrites the model"
contains "$(cat "$TMP/ctx-fallback.log")" "ctx_fallback" "the fallback is logged"