Files
reddit-reader/internal/llm/integration_test.go

76 lines
2.6 KiB
Go

package llm_test
import (
"context"
"net/http"
"os"
"testing"
"time"
"somegit.dev/vikingowl/reddit-reader/internal/domain"
"somegit.dev/vikingowl/reddit-reader/internal/llm"
)
func ollamaAvailable() bool {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
req, _ := http.NewRequestWithContext(ctx, "GET", "http://localhost:11434/api/tags", nil)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return false
}
resp.Body.Close()
return resp.StatusCode == http.StatusOK
}
func TestIntegrationOllamaScore(t *testing.T) {
if os.Getenv("INTEGRATION") == "" {
t.Skip("set INTEGRATION=1 to run Ollama integration tests")
}
if !ollamaAvailable() {
t.Skip("Ollama not running at localhost:11434")
}
client := llm.NewOpenAIClient("http://localhost:11434", "ministral-3:8b")
post := domain.Post{
Title: "Go 1.26 introduces new iterator patterns for range-over-func",
SelfText: "The Go team has released version 1.26 with significant improvements to the iterator protocol. Range-over-func now supports push and pull iterators natively, eliminating the need for channel-based iteration patterns that were common before.",
}
interests := domain.Interests{
Description: "Go programming, systems programming, Linux, NixOS",
}
score, err := client.Score(context.Background(), post, interests)
if err != nil {
t.Fatalf("Score: %v", err)
}
t.Logf("Score: %.2f", score)
if score < 0.0 || score > 1.0 {
t.Errorf("score %.2f out of range [0, 1]", score)
}
}
func TestIntegrationOllamaSummarize(t *testing.T) {
if os.Getenv("INTEGRATION") == "" {
t.Skip("set INTEGRATION=1 to run Ollama integration tests")
}
if !ollamaAvailable() {
t.Skip("Ollama not running at localhost:11434")
}
client := llm.NewOpenAIClient("http://localhost:11434", "ministral-3:8b")
post := domain.Post{
Title: "Systemd 256 brings major changes to socket activation",
SelfText: "The latest systemd release includes reworked socket activation logic, new unit file directives for resource management, improved journal performance, and better container integration. The socket activation changes affect how services handle inherited file descriptors, with a new API for querying activation state. Container support now includes native OCI image pulling and integrated rootless operation. The journal subsystem saw a 40% improvement in write throughput through batched fsync operations.",
}
summary, err := client.Summarize(context.Background(), post)
if err != nil {
t.Fatalf("Summarize: %v", err)
}
t.Logf("Summary:\n%s", summary)
if len(summary) < 20 {
t.Error("summary too short")
}
}