package llm import ( "context" "encoding/json" "io" "net/http" "net/http/httptest" "testing" "time" ) // capturedTemperature runs one Complete against a fake gateway and returns the // "temperature" field the request carried, and whether it was present at all. func capturedTemperature(t *testing.T, opts ...Option) (float64, bool) { t.Helper() var body map[string]any srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { raw, _ := io.ReadAll(r.Body) _ = json.Unmarshal(raw, &body) w.Header().Set("Content-Type", "application/json") _ = json.NewEncoder(w).Encode(map[string]any{"choices": []map[string]any{{"message": map[string]any{"role": "assistant", "content": "ok"}}}}) })) defer srv.Close() if _, err := New(srv.URL, "", "m", 5*time.Second, opts...).Complete(context.Background(), "s", "u"); err != nil { t.Fatalf("Complete: %v", err) } v, ok := body["temperature"].(float64) return v, ok } func TestClient_DefaultTemperatureIsUnchanged(t *testing.T) { got, ok := capturedTemperature(t) if !ok || got != 0.2 { t.Fatalf("default temperature = %v (present %v), want 0.2: existing callers must not change behaviour", got, ok) } } func TestClient_WithTemperatureZeroSendsExactlyZero(t *testing.T) { // The reconciler's accuracy (92%/97%) was measured at temperature 0. Zero must be // SENT, not treated as "unset" and replaced by the default. got, ok := capturedTemperature(t, WithTemperature(0)) if !ok || got != 0 { t.Fatalf("temperature = %v (present %v), want an explicit 0", got, ok) } } func TestClient_WithTemperatureSendsTheGivenValue(t *testing.T) { got, ok := capturedTemperature(t, WithTemperature(0.7)) if !ok || got != 0.7 { t.Fatalf("temperature = %v (present %v), want 0.7", got, ok) } }