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{"model": "ignored-params-model", "messages": "ignored-params-messages", "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") } messages, ok := body["messages"].([]any) if !ok || len(messages) != 2 || messages[1].(map[string]any)["content"] != "Final user text" { t.Error("params overrode the task/session messages") } 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) } }