Files
junction/tests/env-providers.sh
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

72 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
# Wird von tests/run.sh eingebunden: ein Schlüssel in der Umgebung ist ein Endpunkt.
#
# Der Fall: wer OLLAMA_KEY1 setzt, will ollama1 benutzen — ohne dafür einen Block in die
# Konfiguration zu schreiben. Die Datei bleibt die Wahrheit, wo sie spricht; die
# Umgebung füllt nur die Lücken.
echo
echo "== 39. Provider aus der Umgebung =="
E1=$((PORT+226))
E2=$((PORT+227))
tests/stub $E2 "ENVSTUB" > "$TMP/env_stub.log" 2>&1 &
PIDS+=($!)
wait_port "$E2" 10 || bad "the env stub did not come up"
# Keine Endpunkt-Blöcke, nur eine Regel — der Endpunkt soll aus der Umgebung kommen.
cat > "$TMP/env.conf" <<CFG
listen 127.0.0.1:$E1
log_prefix env
req for "*" check none pass ollama1
CFG
OLLAMA_KEY1=test-key OLLAMA_BASE="http://127.0.0.1:$E2/v1" \
./junction --config "$TMP/env.conf" > "$TMP/env.log" 2>&1 &
PIDS+=($!)
wait_port "$E1" 10 || bad "the env-config instance did not come up"
log_has "$TMP/env.log" "endpoint ollama1 added from OLLAMA_KEY1" \
"ollama1 comes from OLLAMA_KEY1 without an endpoint block"
r=$(curl -s -m 10 -X POST -H 'Content-Type: application/json' \
-d '{"model":"m","messages":[{"role":"user","content":"x"}],"max_tokens":3}' \
"http://127.0.0.1:$E1/v1/chat/completions")
contains "$r" "served by ENVSTUB" "and it actually routes there"
s=$(curl -s -m 5 "http://127.0.0.1:$E1/status")
contains "$s" '"name":"ollama1"' "/status lists the endpoint that was never written down"
contains "$s" '"keys":1' "the pool size comes from the single key variable"
# Die Basis lässt sich umbiegen (hier auf den Stub) — ohne sie wäre es der Anbieter.
contains "$s" "127.0.0.1:$E2" "the base was taken from OLLAMA_BASE"
# Ein zweiter Schlüssel ergibt einen zweiten Endpunkt, kein größeres Kontingent.
cat > "$TMP/env2.conf" <<CFG
listen 127.0.0.1:$((PORT+228))
log_prefix env2
req for "*" check none pass ollama1
CFG
OLLAMA_KEY1=a OLLAMA_KEY2=b OLLAMA_BASE="http://127.0.0.1:$E2/v1" \
./junction --config "$TMP/env2.conf" > "$TMP/env2.log" 2>&1 &
PIDS+=($!)
wait_port "$((PORT+228))" 10 || bad "the two-key instance did not come up"
log_has "$TMP/env2.log" "endpoint ollama2 added from OLLAMA_KEY2" \
"OLLAMA_KEY2 becomes ollama2, not a bigger pool on ollama1"
# Abschaltbar: ohne Automatik und ohne Block gibt es keinen Endpunkt — und die Regel
# nennt damit ein unbekanntes Ziel, was die Datei ungültig macht.
cat > "$TMP/env3.conf" <<CFG
listen 127.0.0.1:$((PORT+229))
log_prefix env3
auto_endpoints off
req for "*" check none pass ollama1
CFG
if OLLAMA_KEY1=a ./junction --config "$TMP/env3.conf" --check > "$TMP/env3.out" 2>&1; then
bad "auto_endpoints off still invented an endpoint"
else
contains "$(cat "$TMP/env3.out")" "auto_endpoints is off" \
"auto_endpoints off leaves the configuration without invented endpoints"
fi