#!/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+=($!) wait_port "$CFS" 10 && wait_port "$CFB" 10 \ || bad "the ctx-fallback stubs did not come up" cat > "$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"