Files
Hermes 83a56eb11d tests: wait for a port instead of sleeping before it
Run 13 failed the whole cache section with six checks and no listener: the
router was started with "sleep 0.8" and curl asked too early. The same fixed
sleep sat in front of a dozen other routers and stubs. Every one now waits for
its port (wait_port), and the two checks that need a listener to be *absent*
(mesh without a secret, roll3 without SO_REUSEPORT) wait for their log line
(wait_log) instead of hoping the message is there after 0.6 s.

Same checks, no fixed windows left before a listener; the suite is also faster
because it no longer sleeps through them. Full run: 537 OK, 0 FAIL, PASS.
2026-11-19 06:59:55 +00:00

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