Files
traefik-llmgateway/passthrough_gemini_thoughts_test.go
lukaszraczyloandGitHub f1b198bce4 fix(security): audit run-4 fixes and run-3 leftovers (#26)
Corrects passthrough metering, the cost gate, credential redaction, reload drain, response headers and the discovery cap.
2026-11-29 10:50:36 +00:00

34 lines
1.3 KiB
Go

package traefikllmgateway
import (
"io"
"net/http"
"testing"
)
func geminiThoughtsBody() string {
return `{"candidates":[{"content":{"parts":[{"text":"hi"}]}}],"usageMetadata":{"promptTokenCount":700,"candidatesTokenCount":60,"thoughtsTokenCount":29940},"modelVersion":"gemini-x"}`
}
func TestPassthroughGemini_ThoughtsTokensBilledAsCompletion(t *testing.T) {
gw := newResidualGateway(t, providerTypeGemini, "gemini-x", jsonUpstream(geminiThoughtsBody))
residualPost(gw, "/up/v1beta/models/gemini-x:generateContent", `{"contents":[]}`)
in, out := residualCounters(gw)
if in != residualPrompt || out != residualCompletion {
t.Fatalf("tokens in/out = %d/%d, want %d/%d", in, out, residualPrompt, residualCompletion)
}
}
func TestPassthroughGeminiSSE_ThoughtsTokensBilledAsCompletion(t *testing.T) {
gw := newResidualGateway(t, providerTypeGemini, "gemini-x", func(w http.ResponseWriter, r *http.Request) {
_, _ = io.Copy(io.Discard, r.Body)
w.Header().Set("Content-Type", "text/event-stream")
_, _ = io.WriteString(w, "data: "+geminiThoughtsBody()+"\n\n")
})
residualPost(gw, "/up/v1beta/models/gemini-x:streamGenerateContent?alt=sse", `{"contents":[]}`)
in, out := residualCounters(gw)
if in != residualPrompt || out != residualCompletion {
t.Fatalf("tokens in/out = %d/%d, want %d/%d", in, out, residualPrompt, residualCompletion)
}
}