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

182 lines
9.0 KiB
Bash

#!/bin/bash
# Wird von tests/run.sh eingebunden: Effort-Normalisierung für Anthropic und
# unveränderter Body für OpenAI-kompatible Endpunkte (Ollama Cloud).
echo "== 41. Effort: Anthropic output_config, OpenAI-kompatible unverändert =="
EP=$((PORT+250))
OP=$((PORT+252))
EPS=$((PORT+251))
tests/stub $EPS "EFFORT" & PIDS+=($!)
wait_port "$EPS" 10 || bad "the effort stub did not come up"
# Anthropic: OpenAI-Effort wird output_config.effort; das Modell verliert "#variant".
# Ein eigener Schlüssel und die statische Versionszeile prüfen zugleich, dass der
# Client weder Authorization noch x-api-key doppelt und seine Version gewinnt.
cat > "$TMP/effort-anthropic.conf" <<CFG
listen 127.0.0.1:$EP
endpoint a {
base http://127.0.0.1:$EPS/v1
kind anthropic
context 200000
timeout 10
idle_timeout 5
api_key_env TEST_KEY
header "anthropic-version: 2023-06-01"
}
req for "claude-alias#*" check none pass a as "claude-alt"
req path "/v1/messages" check none pass a
req for "*" check none pass a
CFG
TEST_KEY=server-key ./junction --config "$TMP/effort-anthropic.conf" \
> "$TMP/effort-anthropic.log" 2>&1 &
PIDS+=($!)
wait_port $EP 10
apost() {
curl -s -m 10 -D- -o /dev/null -X POST -H 'Content-Type: application/json' \
-d "$1" "http://127.0.0.1:$EP/v1/messages"
}
R=$(apost '{"model":"claude-x#high","max_tokens":64,"reasoning_effort":"low","messages":[{"role":"user","content":"hi"}]}')
contains "$R" "X-Stub-Model: claude-x" "the #variant is removed from the Anthropic model"
contains "$R" "X-Stub-Effort: high" "model#variant becomes output_config.effort"
contains "$R" "X-Stub-Effort-Set: 1" "output_config carries an effort"
case "$R" in
*"X-Stub-Reasoning: low"*) bad "reasoning_effort was left in the Anthropic body";;
*) ok "reasoning_effort is removed from the Anthropic body";;
esac
R=$(apost '{"model":"claude-alias#high","max_tokens":64,"messages":[{"role":"user","content":"hi"}]}')
contains "$R" "X-Stub-Model: claude-alt" "an as-rewrite replaces the model after the variant is read"
contains "$R" "X-Stub-Effort: high" "the client variant survives the as-rewrite"
R=$(apost '{"model":"claude-x","max_tokens":64,"reasoning":{"effort":"medium"},"messages":[{"role":"user","content":"hi"}]}')
contains "$R" "X-Stub-Effort: medium" "reasoning.effort becomes output_config.effort"
contains "$R" "X-Stub-Has-Reasoning: 0" "the OpenAI reasoning object is removed"
R=$(apost '{"model":"claude-x","max_tokens":64,"reasoning_effort":"minimal","messages":[{"role":"user","content":"hi"}]}')
contains "$R" "X-Stub-Effort: low" "minimal is mapped to the Anthropic low level"
R=$(apost '{"model":"claude-x","max_tokens":64,"reasoning_effort":"none","messages":[{"role":"user","content":"hi"}]}')
contains "$R" "X-Stub-Thinking: disabled" "none disables thinking on Anthropic"
contains "$R" "X-Stub-Effort-Set: 0" "none does not invent an output_config effort"
R=$(apost '{"model":"claude-x","max_tokens":64,"output_config":{"effort":"xhigh"},"reasoning_effort":"low","messages":[{"role":"user","content":"hi"}]}')
contains "$R" "X-Stub-Effort: xhigh" "a native output_config.effort wins over OpenAI effort"
R=$(apost '{"model":"claude-x#max","max_tokens":64,"output_config":{"effort":"low"},"messages":[{"role":"user","content":"hi"}]}')
contains "$R" "X-Stub-Effort: max" "an explicit model#variant overrides a native output_config"
case "$R" in
*"X-Stub-Reasoning: low"*) bad "the losing reasoning_effort stayed in the body";;
*) ok "the losing reasoning_effort is removed";;
esac
R=$(apost '{"model":"claude-x","max_tokens":64,"reasoning_effort":"auto","messages":[{"role":"user","content":"hi"}]}')
contains "$R" "X-Stub-Effort-Set: 0" "auto means no explicit effort"
case "$R" in
*"X-Stub-Reasoning: auto"*) bad "auto was left as an OpenAI effort";;
*) ok "auto is removed instead of being passed as a level";;
esac
R=$(curl -s -m 10 -D- -o /dev/null -X POST -H 'Content-Type: application/json' \
-H 'Authorization: Bearer client-bearer' -H 'x-api-key: client-key' \
-H 'anthropic-version: 2026-10-21' \
-d '{"model":"claude-x","max_tokens":64,"messages":[{"role":"user","content":"hi"}]}' \
"http://127.0.0.1:$EP/v1/messages")
contains "$R" "X-Stub-Auth: Bearer server-key" "the endpoint key replaces the client Authorization"
case "$R" in
*"X-Stub-XApi-Key: client-key"*) bad "the client x-api-key was forwarded next to the endpoint key";;
*) ok "the client x-api-key is dropped when the endpoint injects a key";;
esac
contains "$R" "X-Stub-Anthropic-Version: 2026-10-21" "the client anthropic-version wins"
contains "$R" "X-Stub-Anthropic-Versions: 1" "the static anthropic-version is not duplicated"
# Ollama Cloud and every other OpenAI-compatible endpoint get the body as written.
cat > "$TMP/effort-openai.conf" <<CFG
listen 127.0.0.1:$OP
endpoint o {
base http://127.0.0.1:$EPS/v1
kind cloud
context 200000
timeout 10
}
req for "*" check none pass o
CFG
./junction --config "$TMP/effort-openai.conf" > "$TMP/effort-openai.log" 2>&1 &
PIDS+=($!)
wait_port $OP 10
opost() {
curl -s -m 10 -D- -o /dev/null -X POST -H 'Content-Type: application/json' \
-d "$1" "http://127.0.0.1:$OP/v1/chat/completions"
}
R=$(opost '{"model":"m","reasoning_effort":"high","messages":[{"role":"user","content":"hi"}],"max_tokens":8}')
contains "$R" "X-Stub-Reasoning: high" "reasoning_effort reaches an OpenAI-compatible endpoint unchanged"
R=$(opost '{"model":"m","reasoning":{"effort":"medium"},"messages":[{"role":"user","content":"hi"}],"max_tokens":8}')
contains "$R" "X-Stub-Effort: medium" "reasoning.effort reaches an OpenAI-compatible endpoint unchanged"
contains "$R" "X-Stub-Has-Reasoning: 1" "the OpenAI reasoning object is not stripped"
# The same selector on an OpenAI-compatible endpoint: #max strips from the model
# and becomes reasoning_effort.
R=$(opost '{"model":"m#max","messages":[{"role":"user","content":"hi"}],"max_tokens":8}')
contains "$R" "X-Stub-Model: m" "OpenAI #max is removed from the model id"
contains "$R" "X-Stub-Reasoning: max" "OpenAI #max becomes reasoning_effort"
R=$(opost '{"model":"m#minimal","messages":[{"role":"user","content":"hi"}],"max_tokens":8}')
contains "$R" "X-Stub-Reasoning: low" "OpenAI #minimal is mapped to low"
R=$(opost '{"model":"m#auto","messages":[{"role":"user","content":"hi"}],"max_tokens":8}')
case "$R" in
*"X-Stub-Reasoning: auto"*) bad "OpenAI #auto was sent as an effort";;
*) ok "OpenAI #auto means no explicit effort";;
esac
R=$(opost '{"model":"m#max","reasoning":{"effort":"low"},"messages":[{"role":"user","content":"hi"}],"max_tokens":8}')
contains "$R" "X-Stub-Effort: max" "an explicit model selector wins over reasoning.effort"
R=$(opost '{"model":"m","variant":"low","messages":[{"role":"user","content":"hi"}],"max_tokens":8}')
contains "$R" "X-Stub-Reasoning: low" "a top-level variant becomes reasoning_effort"
# A junction pool member can carry its own model and effort: endpoint/model#effort.
P2=$((PORT+253))
cat > "$TMP/effort-pool.conf" <<CFG
listen 127.0.0.1:$P2
endpoint a { base http://127.0.0.1:$EPS/v1; context 200000; timeout 10 }
endpoint b { base http://127.0.0.1:$EPS/v1; context 200000; timeout 10 }
pool membermodel a/deepseek-v4.1-flash#max, b/deepseek-v4.1-flash#high
req for "*" check none pass membermodel
CFG
./junction --config "$TMP/effort-pool.conf" > "$TMP/effort-pool.log" 2>&1 &
PIDS+=($!)
wait_port $P2 10
R=$(curl -s -m 10 -D- -o /dev/null -X POST -H 'Content-Type: application/json' \
-d '{"model":"whatever","messages":[{"role":"user","content":"hi"}],"max_tokens":8}' \
"http://127.0.0.1:$P2/v1/chat/completions")
contains "$R" "X-Stub-Model: deepseek-v4.1-flash" "a pool member model replaces the request model"
contains "$R" "X-Stub-Reasoning: max" "a pool member effort becomes reasoning_effort"
# A rule's "as" survives the pool expansion with bare members; endpoint#effort
# keeps the request's model and only adds the selector.
P3=$((PORT+254))
cat > "$TMP/effort-pool-as.conf" <<CFG
listen 127.0.0.1:$P3
endpoint a { base http://127.0.0.1:$EPS/v1; context 200000; timeout 10 }
endpoint b { base http://127.0.0.1:$EPS/v1; context 200000; timeout 10 }
pool bare a, b
pool membereff a#max, b#high
req for "withbare*" check none pass bare as "#low"
req for "*" check none pass membereff
CFG
./junction --config "$TMP/effort-pool-as.conf" > "$TMP/effort-pool-as.log" 2>&1 &
PIDS+=($!)
wait_port $P3 10
R=$(curl -s -m 10 -D- -o /dev/null -X POST -H 'Content-Type: application/json' \
-d '{"model":"withbare","messages":[{"role":"user","content":"hi"}],"max_tokens":8}' \
"http://127.0.0.1:$P3/v1/chat/completions")
contains "$R" "X-Stub-Model: withbare" "a rule's as effort keeps the request model"
contains "$R" "X-Stub-Reasoning: low" "a rule's as survives the bare pool expansion"
R=$(curl -s -m 10 -D- -o /dev/null -X POST -H 'Content-Type: application/json' \
-d '{"model":"witheff","messages":[{"role":"user","content":"hi"}],"max_tokens":8}' \
"http://127.0.0.1:$P3/v1/chat/completions")
contains "$R" "X-Stub-Model: witheff" "a pool endpoint#effort keeps the request model"
contains "$R" "X-Stub-Reasoning: max" "a pool endpoint#effort becomes reasoning_effort"