-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes_test.go
More file actions
264 lines (225 loc) · 8.13 KB
/
types_test.go
File metadata and controls
264 lines (225 loc) · 8.13 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
package codexsdk
import (
"testing"
"github.com/stretchr/testify/require"
)
// TestUserMessage_Creation tests user message creation.
func TestUserMessage_Creation(t *testing.T) {
msg := &UserMessage{
Type: "user",
Content: NewUserMessageContent("Hello, Claude!"),
}
require.Equal(t, "user", msg.Type)
require.Equal(t, "user", msg.MessageType())
require.True(t, msg.Content.IsString())
require.Equal(t, "Hello, Claude!", msg.Content.String())
blocks := msg.Content.Blocks()
require.Len(t, blocks, 1)
textBlock, ok := blocks[0].(*TextBlock)
require.True(t, ok)
require.Equal(t, "text", textBlock.Type)
require.Equal(t, "Hello, Claude!", textBlock.Text)
}
// TestUserMessage_CreationWithBlocks tests user message creation with content blocks.
func TestUserMessage_CreationWithBlocks(t *testing.T) {
msg := &UserMessage{
Type: "user",
Content: NewUserMessageContentBlocks([]ContentBlock{
&TextBlock{Type: "text", Text: "Hello, Claude!"},
}),
}
require.Equal(t, "user", msg.Type)
require.Equal(t, "user", msg.MessageType())
require.False(t, msg.Content.IsString())
blocks := msg.Content.Blocks()
require.Len(t, blocks, 1)
textBlock, ok := blocks[0].(*TextBlock)
require.True(t, ok)
require.Equal(t, "text", textBlock.Type)
require.Equal(t, "Hello, Claude!", textBlock.Text)
}
// TestAssistantMessage_WithTextContent tests assistant message with text content.
func TestAssistantMessage_WithTextContent(t *testing.T) {
msg := &AssistantMessage{
Type: "assistant",
Model: "claude-3-5-sonnet-20241022",
Content: []ContentBlock{
&TextBlock{Type: "text", Text: "Hello! How can I help you?"},
},
}
require.Equal(t, "assistant", msg.Type)
require.Equal(t, "assistant", msg.MessageType())
require.Equal(t, "claude-3-5-sonnet-20241022", msg.Model)
require.Len(t, msg.Content, 1)
textBlock, ok := msg.Content[0].(*TextBlock)
require.True(t, ok)
require.Equal(t, "Hello! How can I help you?", textBlock.Text)
}
// TestAssistantMessage_WithThinkingContent tests assistant message with thinking content.
func TestAssistantMessage_WithThinkingContent(t *testing.T) {
msg := &AssistantMessage{
Type: "assistant",
Model: "claude-opus-4-5-20251101",
Content: []ContentBlock{
&ThinkingBlock{
Type: "thinking",
Thinking: "Let me think about this problem...",
Signature: "sig_abc123",
},
&TextBlock{Type: "text", Text: "The answer is 42."},
},
}
require.Equal(t, "assistant", msg.MessageType())
require.Len(t, msg.Content, 2)
thinkingBlock, ok := msg.Content[0].(*ThinkingBlock)
require.True(t, ok)
require.Equal(t, "thinking", thinkingBlock.Type)
require.Equal(t, "thinking", thinkingBlock.BlockType())
require.Equal(t, "Let me think about this problem...", thinkingBlock.Thinking)
require.Equal(t, "sig_abc123", thinkingBlock.Signature)
textBlock, ok := msg.Content[1].(*TextBlock)
require.True(t, ok)
require.Equal(t, "The answer is 42.", textBlock.Text)
}
// TestToolUseBlock_Creation tests tool use block creation.
func TestToolUseBlock_Creation(t *testing.T) {
block := &ToolUseBlock{
Type: "tool_use",
ID: "tool_abc123",
Name: "Bash",
Input: map[string]any{
"command": "ls -la",
"description": "List files",
},
}
require.Equal(t, "tool_use", block.Type)
require.Equal(t, "tool_use", block.BlockType())
require.Equal(t, "tool_abc123", block.ID)
require.Equal(t, "Bash", block.Name)
require.Equal(t, "ls -la", block.Input["command"])
require.Equal(t, "List files", block.Input["description"])
}
// TestToolResultBlock_Creation tests tool result block creation.
func TestToolResultBlock_Creation(t *testing.T) {
block := &ToolResultBlock{
Type: "tool_result",
ToolUseID: "tool_abc123",
IsError: false,
Content: []ContentBlock{
&TextBlock{Type: "text", Text: "file1.txt\nfile2.txt"},
},
}
require.Equal(t, "tool_result", block.Type)
require.Equal(t, "tool_result", block.BlockType())
require.Equal(t, "tool_abc123", block.ToolUseID)
require.False(t, block.IsError)
require.Len(t, block.Content, 1)
}
// TestResultMessage_Creation tests result message creation.
func TestResultMessage_Creation(t *testing.T) {
msg := &ResultMessage{
Type: "result",
Subtype: "success",
IsError: false,
SessionID: "session_abc123",
Usage: &Usage{
InputTokens: 1000,
OutputTokens: 500,
CachedInputTokens: 200,
ReasoningOutputTokens: 50,
},
}
require.Equal(t, "result", msg.Type)
require.Equal(t, "result", msg.MessageType())
require.Equal(t, "success", msg.Subtype)
require.False(t, msg.IsError)
require.Equal(t, "session_abc123", msg.SessionID)
require.NotNil(t, msg.Usage)
require.Equal(t, 1000, msg.Usage.InputTokens)
require.Equal(t, 500, msg.Usage.OutputTokens)
require.Equal(t, 200, msg.Usage.CachedInputTokens)
require.Equal(t, 50, msg.Usage.ReasoningOutputTokens)
}
// TestCodexAgentOptions_DefaultValues tests default option values.
func TestCodexAgentOptions_DefaultValues(t *testing.T) {
options := &CodexAgentOptions{}
require.Empty(t, options.SystemPrompt)
require.Empty(t, options.Model)
require.Empty(t, options.PermissionMode)
require.Empty(t, options.Cwd)
require.Empty(t, options.CliPath)
require.Nil(t, options.Env)
require.Nil(t, options.Hooks)
}
// TestCodexAgentOptions_WithTools tests options with tools.
func TestCodexAgentOptions_WithTools(t *testing.T) {
options := &CodexAgentOptions{
AllowedTools: []string{"Bash", "Read"},
DisallowedTools: []string{"Write"},
}
require.Len(t, options.AllowedTools, 2)
require.Contains(t, options.AllowedTools, "Bash")
require.Contains(t, options.AllowedTools, "Read")
require.Len(t, options.DisallowedTools, 1)
require.Contains(t, options.DisallowedTools, "Write")
}
// TestCodexAgentOptions_WithPermissionMode tests options with permission mode.
func TestCodexAgentOptions_WithPermissionMode(t *testing.T) {
options := &CodexAgentOptions{
PermissionMode: string(PermissionModeAcceptEdits),
}
require.Equal(t, string(PermissionModeAcceptEdits), options.PermissionMode)
}
// TestCodexAgentOptions_WithSystemPromptString tests options with system prompt string.
func TestCodexAgentOptions_WithSystemPromptString(t *testing.T) {
options := &CodexAgentOptions{
SystemPrompt: "You are a helpful coding assistant.",
}
require.Equal(t, "You are a helpful coding assistant.", options.SystemPrompt)
require.Nil(t, options.SystemPromptPreset)
}
// TestCodexAgentOptions_WithSystemPromptPreset tests options with system prompt preset.
func TestCodexAgentOptions_WithSystemPromptPreset(t *testing.T) {
options := &CodexAgentOptions{
SystemPromptPreset: &SystemPromptPreset{
Type: "preset",
Preset: "claude_code",
},
}
require.NotNil(t, options.SystemPromptPreset)
require.Equal(t, "preset", options.SystemPromptPreset.Type)
require.Equal(t, "claude_code", options.SystemPromptPreset.Preset)
}
// TestCodexAgentOptions_WithSystemPromptPresetAndAppend tests options with system prompt preset and append.
func TestCodexAgentOptions_WithSystemPromptPresetAndAppend(t *testing.T) {
options := &CodexAgentOptions{
SystemPromptPreset: &SystemPromptPreset{
Type: "preset",
Preset: "claude_code",
Append: new("\n\nAdditional instructions here."),
},
}
require.NotNil(t, options.SystemPromptPreset)
require.Equal(t, "preset", options.SystemPromptPreset.Type)
require.Equal(t, "claude_code", options.SystemPromptPreset.Preset)
require.NotNil(t, options.SystemPromptPreset.Append)
require.Equal(t, "\n\nAdditional instructions here.", *options.SystemPromptPreset.Append)
}
// TestCodexAgentOptions_WithSessionContinuation tests options with session continuation.
func TestCodexAgentOptions_WithSessionContinuation(t *testing.T) {
options := &CodexAgentOptions{
Resume: "session_previous_123",
ContinueConversation: true,
ForkSession: true,
}
require.Equal(t, "session_previous_123", options.Resume)
require.True(t, options.ContinueConversation)
require.True(t, options.ForkSession)
}
// TestCodexAgentOptions_WithModel tests options with model specification.
func TestCodexAgentOptions_WithModel(t *testing.T) {
options := &CodexAgentOptions{
Model: "claude-opus-4-5-20251101",
}
require.Equal(t, "claude-opus-4-5-20251101", options.Model)
}