package kiwix

import (
	"context"
	"os"
	"testing"
	"time"

	"github.com/kami/maven/internal/llm"
)

// Opt-in: needs a live Kiwix server AND a live llama-server.
// MAVEN_KIWIX_URL=http://127.0.0.1:8034 MAVEN_LLM_URL=http://127.0.0.1:18099 \
//
//	no_proxy=127.0.0.1,localhost go test -run RewriteEval -v ./internal/kiwix/
func TestRewriteEval(t *testing.T) {
	kbase, lbase := os.Getenv("MAVEN_KIWIX_URL"), os.Getenv("MAVEN_LLM_URL")
	if kbase == "" || lbase == "" {
		t.Skip("set MAVEN_KIWIX_URL and MAVEN_LLM_URL to run the rewrite eval")
	}
	noProxyLoopback(t)

	ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
	defer cancel()

	rw := NewRewriter(llm.New(lbase, 3*time.Minute))
	rep, err := RunRewriteEval(ctx, New(kbase), rw, 5)
	if err != nil {
		t.Fatalf("eval: %v", err)
	}
	// No pass bar on purpose: the number is the finding.
	t.Log("\n" + rep.String() + rep.Detail())
}
