Files
Memoh/internal/memory/llm_client_test.go
T
BBQ dcce0617a3 fix(memory): correct mock server path in LLM client test
The LLM client's callChat method appends "/chat/completions" to the base URL.
The test's mock server was expecting "/v1/chat/completions", causing a 404
error during testing. This commit aligns the mock server path with the
actual client implementation.
2026-02-01 15:53:13 +08:00

34 lines
830 B
Go

package memory
import (
"context"
"net/http"
"net/http/httptest"
"testing"
)
func TestLLMClientExtract(t *testing.T) {
t.Parallel()
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/chat/completions" {
w.WriteHeader(http.StatusNotFound)
return
}
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"choices":[{"message":{"content":"{\"facts\":[\"hello\"]}"}}]}`))
}))
defer server.Close()
client := NewLLMClient(server.URL, "test-key", "gpt-4.1-nano-2025-04-14", 0)
resp, err := client.Extract(context.Background(), ExtractRequest{
Messages: []Message{{Role: "user", Content: "hi"}},
})
if err != nil {
t.Fatalf("extract: %v", err)
}
if len(resp.Facts) != 1 || resp.Facts[0] != "hello" {
t.Fatalf("unexpected response: %+v", resp)
}
}