39 lines
810 B
Go
39 lines
810 B
Go
package session
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"agent-native/runtime/llm"
|
|
)
|
|
|
|
func TestAppendAndReplay(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "transcript.jsonl")
|
|
st, err := Open(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
msgs := []llm.Message{
|
|
{Role: llm.RoleSystem, Content: "sys"},
|
|
{Role: llm.RoleUser, Content: "hi"},
|
|
{Role: llm.RoleAssistant, Content: "ok", StopReason: llm.StopEnd},
|
|
}
|
|
for _, m := range msgs {
|
|
if err := st.Append(m); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
got, err := st.Load()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(got) != len(msgs) {
|
|
t.Fatalf("len %d", len(got))
|
|
}
|
|
for i := range msgs {
|
|
if got[i].Role != msgs[i].Role || got[i].Content != msgs[i].Content || got[i].StopReason != msgs[i].StopReason {
|
|
t.Fatalf("msg %d %#v", i, got[i])
|
|
}
|
|
}
|
|
}
|