#!/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+=($!) sleep 0.6 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" < "$TMP/oc.log" 2>&1 & PIDS+=($!) sleep 0.8 # 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":"glm-5.3-flash-free"' "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":"glm-5.3-flash-free","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":"beam-free","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. 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+=($!) sleep 0.8 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"