|
| 1 | +// / ctx: https://ctx.ist |
| 2 | +// ,'`./ do you remember? |
| 3 | +// `.,'\ |
| 4 | +// \ Copyright 2026-present Context contributors. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 |
| 6 | + |
| 7 | +package entity |
| 8 | + |
| 9 | +import ( |
| 10 | + "testing" |
| 11 | + "time" |
| 12 | +) |
| 13 | + |
| 14 | +func TestNewMCPSession(t *testing.T) { |
| 15 | + s := NewMCPSession() |
| 16 | + if s.ToolCalls != 0 { |
| 17 | + t.Errorf("ToolCalls = %d, want 0", s.ToolCalls) |
| 18 | + } |
| 19 | + if s.AddsPerformed == nil { |
| 20 | + t.Fatal("AddsPerformed should be initialized") |
| 21 | + } |
| 22 | + if len(s.AddsPerformed) != 0 { |
| 23 | + t.Errorf( |
| 24 | + "AddsPerformed length = %d, want 0", |
| 25 | + len(s.AddsPerformed), |
| 26 | + ) |
| 27 | + } |
| 28 | + if s.SessionStartedAt.IsZero() { |
| 29 | + t.Error("SessionStartedAt should be set") |
| 30 | + } |
| 31 | + if len(s.PendingFlush) != 0 { |
| 32 | + t.Errorf( |
| 33 | + "PendingFlush length = %d, want 0", |
| 34 | + len(s.PendingFlush), |
| 35 | + ) |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +func TestRecordToolCall(t *testing.T) { |
| 40 | + s := NewMCPSession() |
| 41 | + s.RecordToolCall() |
| 42 | + if s.ToolCalls != 1 { |
| 43 | + t.Errorf("ToolCalls = %d, want 1", s.ToolCalls) |
| 44 | + } |
| 45 | + s.RecordToolCall() |
| 46 | + s.RecordToolCall() |
| 47 | + if s.ToolCalls != 3 { |
| 48 | + t.Errorf("ToolCalls = %d, want 3", s.ToolCalls) |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +func TestRecordAdd(t *testing.T) { |
| 53 | + s := NewMCPSession() |
| 54 | + s.RecordAdd("task") |
| 55 | + s.RecordAdd("task") |
| 56 | + s.RecordAdd("decision") |
| 57 | + if s.AddsPerformed["task"] != 2 { |
| 58 | + t.Errorf( |
| 59 | + "task adds = %d, want 2", |
| 60 | + s.AddsPerformed["task"], |
| 61 | + ) |
| 62 | + } |
| 63 | + if s.AddsPerformed["decision"] != 1 { |
| 64 | + t.Errorf( |
| 65 | + "decision adds = %d, want 1", |
| 66 | + s.AddsPerformed["decision"], |
| 67 | + ) |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +func TestQueuePendingUpdate(t *testing.T) { |
| 72 | + s := NewMCPSession() |
| 73 | + now := time.Now() |
| 74 | + s.QueuePendingUpdate(PendingUpdate{ |
| 75 | + Type: "task", |
| 76 | + Content: "Build feature", |
| 77 | + QueuedAt: now, |
| 78 | + }) |
| 79 | + if len(s.PendingFlush) != 1 { |
| 80 | + t.Fatalf( |
| 81 | + "PendingFlush length = %d, want 1", |
| 82 | + len(s.PendingFlush), |
| 83 | + ) |
| 84 | + } |
| 85 | + pu := s.PendingFlush[0] |
| 86 | + if pu.Type != "task" { |
| 87 | + t.Errorf( |
| 88 | + "Type = %q, want %q", |
| 89 | + pu.Type, "task", |
| 90 | + ) |
| 91 | + } |
| 92 | + if pu.Content != "Build feature" { |
| 93 | + t.Errorf( |
| 94 | + "Content = %q, want %q", |
| 95 | + pu.Content, "Build feature", |
| 96 | + ) |
| 97 | + } |
| 98 | +} |
0 commit comments