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