Download
36 lines 1.1 KiBGoModified 2026-10-26 raw
123456789101112131415161718192021222324252627282930313233343536
package history

import (
	"testing"
	"time"

	"blinker/internal/llm"
)

func TestSaveLoadPrompts(t *testing.T) {
	dir := t.TempDir()
	call := llm.ToolCall{ID: "c1", Type: "function"}
	call.Function.Name, call.Function.Arguments = "Read", `{"path":"a<b>&.go"}`
	msgs := []llm.Message{
		{Role: "system", Content: "sys"},
		{Role: "user", Content: "fix the \x1b[31mbug"},
		{Role: "assistant", Content: "ok", Reasoning: "hmm", ToolCalls: []llm.ToolCall{call}},
		{Role: "tool", ToolCallID: "c1", Content: "1\tpackage a"},
		{Role: "user", Content: "thanks"},
	}
	s := &Session{Project: "/p", Model: "m", Started: time.Now(), Messages: FromLLM(msgs)}
	if err := s.Save(dir); err != nil {
		t.Fatal(err)
	}
	got, err := Load(s.Path(dir))
	if err != nil {
		t.Fatal(err)
	}
	if len(got.Messages) != 5 || got.Messages[2].ToolCalls[0].Arguments != `{"path":"a<b>&.go"}` {
		t.Fatalf("round trip lost data: %+v", got.Messages)
	}
	prompts, err := Prompts(dir, "/p", 10)
	if err != nil || len(prompts) != 2 || prompts[1] != "thanks" {
		t.Errorf("Prompts = %q, %v", prompts, err)
	}
}