From 8b489d429a6b255e6f716c9c32141e7eaa55ea6a Mon Sep 17 00:00:00 2001 From: vikingowl Date: Sun, 5 Apr 2026 23:35:25 +0200 Subject: [PATCH] test: snapshot JSON round-trip with multi-turn conversation --- internal/session/snapshot_test.go | 86 +++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 internal/session/snapshot_test.go diff --git a/internal/session/snapshot_test.go b/internal/session/snapshot_test.go new file mode 100644 index 0000000..068a73c --- /dev/null +++ b/internal/session/snapshot_test.go @@ -0,0 +1,86 @@ +package session_test + +import ( + "encoding/json" + "testing" + "time" + + "somegit.dev/Owlibou/gnoma/internal/message" + "somegit.dev/Owlibou/gnoma/internal/session" +) + +func TestSnapshot_RoundTrip(t *testing.T) { + now := time.Now().UTC().Truncate(time.Second) + snap := session.Snapshot{ + ID: "snap-test-001", + Metadata: session.Metadata{ + ID: "snap-test-001", + Provider: "anthropic", + Model: "claude-3-5-sonnet", + TurnCount: 2, + UpdatedAt: now, + CreatedAt: now.Add(-5 * time.Minute), + MessageCount: 5, + }, + Messages: []message.Message{ + message.NewUserText("what files are in this dir?"), + message.NewAssistantContent( + message.NewTextContent("I'll check that for you."), + message.NewToolCallContent(message.ToolCall{ + ID: "toolu_01abc", + Name: "bash", + Arguments: json.RawMessage(`{"command":"ls -la"}`), + }), + ), + message.NewToolResults(message.ToolResult{ + ToolCallID: "toolu_01abc", + Content: "total 42\ndrwxr-xr-x ...", + IsError: false, + }), + message.NewAssistantContent( + message.NewThinkingContent(message.Thinking{ + Text: "The directory contains source files.", + Signature: "sig_abc123", + }), + message.NewTextContent("Here are the files."), + ), + message.NewUserText("thanks"), + }, + } + + data, err := json.Marshal(snap) + if err != nil { + t.Fatalf("marshal: %v", err) + } + + var got session.Snapshot + if err := json.Unmarshal(data, &got); err != nil { + t.Fatalf("unmarshal: %v", err) + } + + if got.ID != snap.ID { + t.Errorf("ID: got %q, want %q", got.ID, snap.ID) + } + if got.Metadata.Provider != "anthropic" { + t.Errorf("provider: got %q", got.Metadata.Provider) + } + if len(got.Messages) != 5 { + t.Fatalf("messages: got %d, want 5", len(got.Messages)) + } + // Verify tool call round-trip + tc := got.Messages[1].Content[1] + if tc.Type != message.ContentToolCall || tc.ToolCall == nil { + t.Errorf("tool call content wrong: %+v", tc) + } + if tc.ToolCall.ID != "toolu_01abc" { + t.Errorf("tool call ID: got %q", tc.ToolCall.ID) + } + // Verify thinking round-trip + th := got.Messages[3].Content[0] + if th.Type != message.ContentThinking || th.Thinking == nil { + t.Errorf("thinking content wrong: %+v", th) + } + if th.Thinking.Signature != "sig_abc123" { + t.Errorf("thinking signature: got %q", th.Thinking.Signature) + } +}