#!/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" < "$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" < "$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" < "$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" <&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" < "$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