49 lines
1.5 KiB
Go
49 lines
1.5 KiB
Go
package ai
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestLLMWirePreservesOpaqueScalarParamsWithoutDefaults(t *testing.T) {
|
|
task, ps := currentFixture(t, "full_ai")
|
|
task = changeCurrentAgent(t, task, func(a map[string]any) {
|
|
a["llm"].(map[string]any)["params"] = map[string]any{"opaque": "vendor-value", "unknown_flag": false, "nullable": nil, "large_number": json.Number("9007199254740993"), "stream": false}
|
|
})
|
|
b, e := Bind(task, ps)
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
raw, e := io.ReadAll(r.Body)
|
|
if e != nil {
|
|
t.Error(e)
|
|
return
|
|
}
|
|
if !bytes.Contains(raw, []byte(`"large_number":9007199254740993`)) {
|
|
t.Error("large integer rewritten")
|
|
}
|
|
var body map[string]any
|
|
if json.Unmarshal(raw, &body) != nil {
|
|
t.Error("invalid request")
|
|
return
|
|
}
|
|
if len(body) != 7 || body["stream"] != false || body["model"] != "example-chat" || body["opaque"] != "vendor-value" || body["unknown_flag"] != false || body["nullable"] != nil {
|
|
t.Error("params dropped, rewritten or defaulted")
|
|
}
|
|
w.Header().Set("Content-Type", "application/json")
|
|
io.WriteString(w, `{"choices":[{"message":{"role":"assistant","content":"ok"}}]}`)
|
|
}))
|
|
defer server.Close()
|
|
b.LLM.Provider.Endpoint = server.URL + "/v1"
|
|
result, e := b.Complete(context.Background(), "Final user text")
|
|
if e != nil || result != "ok" {
|
|
t.Fatal("LLM passthrough failed", e)
|
|
}
|
|
}
|