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.
181 lines
8.9 KiB
Bash
181 lines
8.9 KiB
Bash
#!/bin/bash
|
|
# Wird von tests/run.sh eingebunden: die opencode-Brücke gegen einen Nachbau.
|
|
# Erwartet: $TMP, $PORT, ok/bad/contains, ./junction
|
|
|
|
echo "== 18. opencode serve als Endpunkt (Brücke zu /v1/) =="
|
|
|
|
OC_PORT=$((PORT+18))
|
|
OC_JUNC=$((PORT+19))
|
|
|
|
python3 tests/opencode_stub.py $OC_PORT > "$TMP/oc-stub.log" 2>&1 &
|
|
PIDS+=($!)
|
|
wait_port "$OC_PORT" 10 || bad "the opencode stub did not come up"
|
|
|
|
printf 'opencode:testpasswort\n' > "$TMP/oc.pass"
|
|
chmod +x "$TMP/oc.pass"
|
|
cat > "$TMP/oc.pass.sh" <<'SH'
|
|
#!/bin/sh
|
|
cat "$1" 2>/dev/null
|
|
SH
|
|
# Ein Skript, das das Passwort ausgibt — so wie im Betrieb opencode_password.sh.
|
|
printf '#!/bin/sh\necho opencode:testpasswort | cut -d: -f2\n' > "$TMP/oc.pass.sh"
|
|
chmod +x "$TMP/oc.pass.sh"
|
|
|
|
cat > "$TMP/oc.conf" <<CFG
|
|
listen 127.0.0.1:$OC_JUNC
|
|
|
|
endpoint oc {
|
|
base http://127.0.0.1:$OC_PORT
|
|
kind opencode
|
|
context 200000
|
|
timeout 30
|
|
idle_timeout 10
|
|
auth_basic opencode
|
|
pass_cmd "$TMP/oc.pass.sh"
|
|
}
|
|
|
|
# A model selector with "#effort" is either passed through as written (first rule) or
|
|
# rewritten by an "as" — the variant must survive both paths.
|
|
req for "deepseek-v4.1-flash#*" pass oc
|
|
req for "*#*" pass oc as "deepseek-v4.1-flash-alt"
|
|
req for "*" pass oc
|
|
CFG
|
|
|
|
./junction --config "$TMP/oc.conf" > "$TMP/oc.log" 2>&1 &
|
|
PIDS+=($!)
|
|
wait_port "$OC_JUNC" 30 || bad "the opencode bridge did not come up"
|
|
|
|
# 1. Modellliste kommt als OpenAI-Liste, ohne die Varianten der Modelle
|
|
R=$(curl -s -m 20 "http://127.0.0.1:$OC_JUNC/v1/models")
|
|
contains "$R" '"id":"deepseek-v4.1-flash"' "the bridge lists opencode models as an OpenAI list"
|
|
case "$R" in
|
|
*'"id":"low"'*) bad "model variants leak into the list as models";;
|
|
*) ok "model variants do not leak into the list";;
|
|
esac
|
|
|
|
# 2. Chat: OpenAI rein, Antwort raus
|
|
R=$(curl -s -m 40 -X POST -H 'Content-Type: application/json' \
|
|
-d '{"model":"deepseek-v4.1-flash","messages":[{"role":"user","content":"hallo welt"}],"max_tokens":10}' \
|
|
"http://127.0.0.1:$OC_JUNC/v1/chat/completions")
|
|
contains "$R" '"object":"chat.completion"' "a chat request becomes an OpenAI completion"
|
|
contains "$R" 'ANTWORT auf: hallo welt' "the prompt reached the session and the answer came back"
|
|
contains "$R" '"reasoning_content":"kurz nachgedacht"' "reasoning is carried separately from the answer"
|
|
contains "$R" '"finish_reason":"stop"' "the finish reason is translated"
|
|
contains "$R" '"prompt_tokens":11' "the token counts are read from the session"
|
|
|
|
# 3. Das Modell kam als provider/id an
|
|
R=$(curl -s -m 20 "http://127.0.0.1:$OC_JUNC/v1/models")
|
|
case "$R" in
|
|
*'"object":"list"'*) ok "the models call goes through the bridge, not the plain proxy";;
|
|
*) bad "the models call did not go through the bridge";;
|
|
esac
|
|
|
|
# 4. Ein Systemprompt wird mitgeschickt, nicht verschluckt
|
|
R=$(curl -s -m 40 -X POST -H 'Content-Type: application/json' \
|
|
-d '{"model":"deepseek-v4.1-flash-alt","messages":[{"role":"system","content":"sei knapp"},{"role":"user","content":"frage"}]}' \
|
|
"http://127.0.0.1:$OC_JUNC/v1/chat/completions")
|
|
contains "$R" 'System: sei knapp' "a system prompt survives into the session"
|
|
|
|
# 5. Reasoning effort des Clients kommt als opencode-Modellvariante an. opencode
|
|
# trägt "reasoningEffort" nicht im Prompt, sondern in der Variante des Modells.
|
|
OC_LAST="http://127.0.0.1:$OC_PORT/test/last"
|
|
|
|
R=$(curl -s -m 40 -u opencode:testpasswort -X POST -H 'Content-Type: application/json' \
|
|
-d '{"model":"deepseek-v4.1-flash","messages":[{"role":"user","content":"denk nach"}],"reasoning_effort":"high"}' \
|
|
"http://127.0.0.1:$OC_JUNC/v1/chat/completions")
|
|
contains "$R" '"object":"chat.completion"' "reasoning_effort request is served"
|
|
R=$(curl -s -m 10 -u opencode:testpasswort "$OC_LAST")
|
|
contains "$R" '"variant": "high"' "reasoning_effort becomes the opencode model variant"
|
|
contains "$R" '"model": "opencode/deepseek-v4.1-flash"' "the variant does not become part of the model id"
|
|
|
|
R=$(curl -s -m 40 -u opencode:testpasswort -X POST -H 'Content-Type: application/json' \
|
|
-d '{"model":"deepseek-v4.1-flash-alt","messages":[{"role":"user","content":"auch nachdenken"}],"reasoning":{"effort":"low"}}' \
|
|
"http://127.0.0.1:$OC_JUNC/v1/chat/completions")
|
|
contains "$R" '"object":"chat.completion"' "reasoning.effort request is served"
|
|
R=$(curl -s -m 10 -u opencode:testpasswort "$OC_LAST")
|
|
contains "$R" '"variant": "low"' "reasoning.effort is passed through as a variant"
|
|
|
|
R=$(curl -s -m 40 -u opencode:testpasswort -X POST -H 'Content-Type: application/json' \
|
|
-d '{"model":"deepseek-v4.1-flash-alt","messages":[{"role":"user","content":"nicht nachdenken"}],"thinking":{"type":"disabled"}}' \
|
|
"http://127.0.0.1:$OC_JUNC/v1/chat/completions")
|
|
contains "$R" '"object":"chat.completion"' "a thinking:disabled request is served"
|
|
R=$(curl -s -m 10 -u opencode:testpasswort "$OC_LAST")
|
|
contains "$R" '"variant": "none"' "thinking:disabled becomes the none variant"
|
|
|
|
R=$(curl -s -m 40 -u opencode:testpasswort -X POST -H 'Content-Type: application/json' \
|
|
-d '{"model":"deepseek-v4.1-flash#max","messages":[{"role":"user","content":"maximum"}],"reasoning_effort":"low"}' \
|
|
"http://127.0.0.1:$OC_JUNC/v1/chat/completions")
|
|
contains "$R" '"object":"chat.completion"' "a model with #variant is served"
|
|
R=$(curl -s -m 10 -u opencode:testpasswort "$OC_LAST")
|
|
contains "$R" '"variant": "max"' "the explicit #variant wins over reasoning_effort"
|
|
contains "$R" '"model": "opencode/deepseek-v4.1-flash"' "the #variant is not sent as part of the model id"
|
|
|
|
# A rule's "as" replaces the model before the bridge starts; the variant from the
|
|
# client's selector must not disappear with the old name.
|
|
R=$(curl -s -m 40 -u opencode:testpasswort -X POST -H 'Content-Type: application/json' \
|
|
-d '{"model":"anything#high","messages":[{"role":"user","content":"durch as"}],"reasoning_effort":"low"}' \
|
|
"http://127.0.0.1:$OC_JUNC/v1/chat/completions")
|
|
contains "$R" '"object":"chat.completion"' "a rewritten model with #variant is served"
|
|
R=$(curl -s -m 10 -u opencode:testpasswort "$OC_LAST")
|
|
contains "$R" '"variant": "high"' "the client's #variant survives a rule's as rewrite"
|
|
contains "$R" '"model": "opencode/deepseek-v4.1-flash-alt"' "the as target is the model that reaches opencode"
|
|
|
|
R=$(curl -s -m 40 -u opencode:testpasswort -X POST -H 'Content-Type: application/json' \
|
|
-d '{"model":"deepseek-v4.1-flash-alt","messages":[{"role":"user","content":"variant direkt"}],"variant":"medium"}' \
|
|
"http://127.0.0.1:$OC_JUNC/v1/chat/completions")
|
|
contains "$R" '"object":"chat.completion"' "an explicit variant request is served"
|
|
R=$(curl -s -m 10 -u opencode:testpasswort "$OC_LAST")
|
|
contains "$R" '"variant": "medium"' "an explicit variant is passed through unchanged"
|
|
|
|
R=$(curl -s -m 40 -u opencode:testpasswort -X POST -H 'Content-Type: application/json' \
|
|
-d '{"model":"deepseek-v4.1-flash-alt","messages":[{"role":"user","content":"ohne effort"}]}' \
|
|
"http://127.0.0.1:$OC_JUNC/v1/chat/completions")
|
|
contains "$R" '"object":"chat.completion"' "a request without effort is served"
|
|
R=$(curl -s -m 10 -u opencode:testpasswort "$OC_LAST")
|
|
contains "$R" '"variant": null' "no effort means no variant is invented"
|
|
|
|
# 6. Dieselbe Modell-Politik gilt auch für die opencode-Brücke.
|
|
OC_POLICY=$((PORT+50))
|
|
cat > "$TMP/oc.policy.conf" <<CFG
|
|
listen 127.0.0.1:$OC_POLICY
|
|
endpoint oc {
|
|
base http://127.0.0.1:$OC_PORT
|
|
kind opencode
|
|
context 200000
|
|
timeout 30
|
|
idle_timeout 10
|
|
auth_basic opencode
|
|
pass_cmd "$TMP/oc.pass.sh"
|
|
}
|
|
models allow "deepseek-v4.1-flash"
|
|
req path "/v1/models" check none pass oc
|
|
req for "*" check none pass oc
|
|
CFG
|
|
./junction --config "$TMP/oc.policy.conf" > "$TMP/oc.policy.log" 2>&1 &
|
|
PIDS+=($!)
|
|
wait_port $OC_POLICY 10
|
|
|
|
R=$(curl -s -m 20 "http://127.0.0.1:$OC_POLICY/v1/models")
|
|
contains "$R" '"id":"deepseek-v4.1-flash"' "the opencode list keeps the whitelisted model"
|
|
case "$R" in
|
|
*'"id":"deepseek-v4.1-flash-alt"'*) bad "the opencode list leaked a non-whitelisted model";;
|
|
*) ok "the opencode list hides a non-whitelisted model";;
|
|
esac
|
|
CODE=$(curl -s -m 20 -o /dev/null -w '%{http_code}' -X POST -H 'Content-Type: application/json' \
|
|
-d '{"model":"deepseek-v4.1-flash-alt","messages":[{"role":"user","content":"nein"}]}' \
|
|
"http://127.0.0.1:$OC_POLICY/v1/chat/completions")
|
|
[ "$CODE" = "403" ] && ok "the opencode path refuses a non-whitelisted model" \
|
|
|| bad "the opencode path refused with HTTP $CODE"
|
|
|
|
# 7. Falsches Passwort ist ein sauberer Fehler, kein Absturz
|
|
printf '#!/bin/sh\necho falsch\n' > "$TMP/oc.bad.sh"
|
|
chmod +x "$TMP/oc.bad.sh"
|
|
sed "s|pass_cmd .*|pass_cmd \"$TMP/oc.bad.sh\"|; s|$OC_JUNC|$((PORT+20))|" "$TMP/oc.conf" > "$TMP/oc2.conf"
|
|
./junction --config "$TMP/oc2.conf" > "$TMP/oc2.log" 2>&1 &
|
|
PIDS+=($!)
|
|
wait_port $((PORT + 20)) 30 || bad "the pass_cmd instance did not come up"
|
|
R=$(curl -s -m 20 -X POST -H 'Content-Type: application/json' \
|
|
-d '{"model":"x","messages":[{"role":"user","content":"hi"}]}' \
|
|
"http://127.0.0.1:$((PORT+20))/v1/chat/completions")
|
|
contains "$R" 'no_endpoint_available' "a rejected password fails as a routing error, not a crash"
|