The background fetch now repeats (models_refresh, default 300 s) instead of
running once at startup. It reads the price fields the provider publishes next
to each model and merges them over prices.conf (budget/request windows from the
file survive). Known limits survive a refresh, so ollama is not asked
/api/show for every model on every pass.
A pool can be built from a provider's current model list:
pool free from opencode-go-free match "*-free"
Rules keep a marker and resolve the pool per request, so a model that appears
later is routable without a config reload. Pools used as judges or ctx_fallback
resolve the same way.
Virtual keys grow a deny glob: the olivia key hides the olivia model from that
key's /v1/models and refuses it on the request path, while other keys still see
it.
112 lines
4.2 KiB
Bash
112 lines
4.2 KiB
Bash
#!/bin/bash
|
|
# Wird von tests/run.sh eingebunden: benannte Ketten (pool) und einzeilige Blöcke.
|
|
|
|
echo "== 20. Pools und einzeilige Endpunkt-Blöcke =="
|
|
|
|
# 1. Einzeiliger Block: alles in einer Zeile, keine Klammerzeile nötig.
|
|
cat > "$TMP/inline.conf" <<CFG
|
|
listen 127.0.0.1:$((PORT+31))
|
|
probe_interval 0
|
|
endpoint kurz { base http://127.0.0.1:$P_GATED/v1; timeout 5; weight 2 }
|
|
req for "*" pass kurz
|
|
CFG
|
|
./junction --config "$TMP/inline.conf" > "$TMP/inline.log" 2>&1 &
|
|
PIDS+=($!)
|
|
wait_port $((PORT+31)) 30
|
|
R=$(curl -s -m 10 -X POST -H 'Content-Type: application/json' \
|
|
-d '{"model":"x","messages":[{"role":"user","content":"hi"}]}' \
|
|
"http://127.0.0.1:$((PORT+31))/v1/chat/completions")
|
|
contains "$R" "served by GATED" "a one-line endpoint block is enough to serve a request"
|
|
grep -q 'endpoint kurz: block not closed' "$TMP/inline.log" && \
|
|
bad "the one-line block was mistaken for an open block" || \
|
|
ok "the one-line block leaves no block open"
|
|
|
|
# 2. Pool: eine Kette bekommt einen Namen, die Regel benutzt ihn.
|
|
cat > "$TMP/pool.conf" <<CFG
|
|
listen 127.0.0.1:$((PORT+32))
|
|
probe_interval 0
|
|
endpoint eins { base http://127.0.0.1:$P_GATED/v1 }
|
|
endpoint zwei { base http://127.0.0.1:$((PORT+21))/v1 }
|
|
|
|
pool kette eins, zwei
|
|
req for "*" pass kette
|
|
CFG
|
|
./junction --config "$TMP/pool.conf" > "$TMP/pool.log" 2>&1 &
|
|
PIDS+=($!)
|
|
sleep 0.8
|
|
POOL=$(curl -s -m 5 "http://127.0.0.1:$((PORT+32))/status")
|
|
case "$POOL" in
|
|
*'"targets":"eins, zwei"'*|*'eins, zwei'*) ok "pool expands to its targets in the rule" ;;
|
|
*) bad "pool did not expand (status: $(printf '%s' "$POOL" | head -c 120))" ;;
|
|
esac
|
|
|
|
# 3. Verschachtelte Pools: alles → lokal → zwei Ziele
|
|
cat > "$TMP/pool2.conf" <<CFG
|
|
listen 127.0.0.1:$((PORT+33))
|
|
probe_interval 0
|
|
endpoint a { base http://127.0.0.1:$P_GATED/v1 }
|
|
endpoint b { base http://127.0.0.1:$((PORT+21))/v1 }
|
|
pool lokal a, b
|
|
pool alles lokal
|
|
req for "*" pass alles
|
|
CFG
|
|
./junction --config "$TMP/pool2.conf" > "$TMP/pool2.log" 2>&1 &
|
|
PIDS+=($!)
|
|
sleep 0.8
|
|
P2=$(curl -s -m 5 "http://127.0.0.1:$((PORT+33))/status")
|
|
case "$P2" in
|
|
*'a, b'*) ok "a pool may name another pool" ;;
|
|
*) bad "nested pools did not resolve" ;;
|
|
esac
|
|
|
|
# 4. Ein unbekannter Name bleibt ein Fehler — kein stiller Durchlauf.
|
|
cat > "$TMP/poolbad.conf" <<CFG
|
|
listen 127.0.0.1:$((PORT+34))
|
|
probe_interval 0
|
|
endpoint a { base http://127.0.0.1:$P_GATED/v1 }
|
|
req for "*" pass gibtesnicht
|
|
CFG
|
|
OUT=$(./junction --config "$TMP/poolbad.conf" --port $((PORT+34)) 2>&1 | head -1)
|
|
case "$OUT" in
|
|
*"unknown endpoint"*) ok "an unknown pool or endpoint name is refused" ;;
|
|
*) bad "unknown name was not refused: $OUT" ;;
|
|
esac
|
|
|
|
# 5. Dynamischer Pool: die Mitglieder sind die Modelle, die der Endpunkt
|
|
# gerade als *-free veroeffentlicht. Kein Name steht in der Konfiguration.
|
|
DYNP=$((PORT+305))
|
|
DYNS=$((PORT+306))
|
|
STUB_MODELS="alpha-free,beta-free,gamma" STUB_CTX=1000 STUB_OUT=100 \
|
|
tests/stub $DYNS MODELS > "$TMP/dyn_stub.log" 2>&1 & PIDS+=($!)
|
|
wait_port "$DYNS" 10 || bad "the dynamic-pool model stub did not come up"
|
|
cat > "$TMP/dynamic-pool.conf" <<CFG
|
|
listen 127.0.0.1:$DYNP
|
|
probe_interval 0
|
|
models_refresh 300
|
|
endpoint bag { base http://127.0.0.1:$DYNS/v1; context 1000; timeout 10 }
|
|
pool free from bag match "*-free"
|
|
req path "/v1/models" check none pass bag
|
|
req for "dynamic" check none pass free
|
|
req for "*" check none pass bag
|
|
CFG
|
|
./junction --config "$TMP/dynamic-pool.conf" > "$TMP/dynamic-pool.log" 2>&1 &
|
|
PIDS+=($!)
|
|
wait_port "$DYNP" 10 || bad "the dynamic-pool router did not come up"
|
|
for i in $(seq 1 100); do
|
|
grep -q 'models: bag 3 Modelle' "$TMP/dynamic-pool.log" 2>/dev/null && break
|
|
sleep 0.05
|
|
done
|
|
H=$(curl -s -m 10 -D- -o /dev/null -X POST -H 'Content-Type: application/json' \
|
|
-d '{"model":"dynamic","messages":[{"role":"user","content":"hi"}],"max_tokens":8}' \
|
|
"http://127.0.0.1:$DYNP/v1/chat/completions")
|
|
case "$H" in
|
|
*"X-Stub-Model: alpha-free"*|*"X-Stub-Model: beta-free"*)
|
|
ok "a dynamic pool sends one of the endpoint's *-free models" ;;
|
|
*) bad "the dynamic pool did not rewrite to a *-free model: $(printf '%s' "$H" | grep -i 'X-Stub-Model' || echo no header)" ;;
|
|
esac
|
|
case "$H" in
|
|
*"X-Stub-Model: gamma"*) bad "a model outside the glob leaked into the dynamic pool" ;;
|
|
*) ok "a model outside the glob stays out of the dynamic pool" ;;
|
|
esac
|
|
|