-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration_test.go
More file actions
209 lines (185 loc) · 5.59 KB
/
integration_test.go
File metadata and controls
209 lines (185 loc) · 5.59 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
package integration
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
"github.com/isdmx/codebox/config"
"github.com/isdmx/codebox/logger"
"github.com/isdmx/codebox/mcpserver"
"github.com/isdmx/codebox/sandbox"
)
// TestIntegrationConfigLoggerSandbox tests the integration between config, logger, and sandbox packages
func TestIntegrationConfigLoggerSandbox(t *testing.T) {
t.Run("ConfigAndLoggerIntegration", func(t *testing.T) {
// Test that config validation works properly with logger initialization
cfg := &config.Config{
Server: config.ServerConfig{
Transport: "stdio",
HTTPPort: 8080,
},
Sandbox: config.SandboxConfig{
Backend: "docker", // This will fail in sandbox creation if local backend not enabled
TimeoutSec: 30,
MemoryMB: 512,
MaxArtifactSizeMB: 20,
NetworkEnabled: false,
EnableLocalBackend: false,
},
Logging: config.LoggingConfig{
Mode: "development",
Level: "debug",
},
Languages: map[string]config.Language{},
}
// Create logger using config
testLogger, err := logger.New(cfg.Logging.Mode, cfg.Logging.Level)
require.NoError(t, err)
require.NotNil(t, testLogger)
// Test that logger works
testLogger.Info("Integration test started")
_ = testLogger.Sync()
})
t.Run("ConfigLoggerSandboxFactoryIntegration", func(t *testing.T) {
cfg := &config.Config{
Server: config.ServerConfig{
Transport: "stdio",
HTTPPort: 8080,
},
Sandbox: config.SandboxConfig{
Backend: "local", // Use local backend for testing without Docker
TimeoutSec: 10, // Short timeout for tests
MemoryMB: 128, // Lower memory for faster tests
MaxArtifactSizeMB: 5,
NetworkEnabled: false,
EnableLocalBackend: true, // Must be enabled for local backend
},
Logging: config.LoggingConfig{
Mode: "development",
Level: "info",
},
Languages: map[string]config.Language{
"python": {
Image: "python:3.11-slim",
Environment: map[string]string{"PYTHONPATH": "/workdir"},
},
},
}
testLogger, err := logger.New(cfg.Logging.Mode, cfg.Logging.Level)
require.NoError(t, err)
// Create sandbox executor using config and logger
executor, err := sandbox.NewExecutor(testLogger, cfg)
require.NoError(t, err)
require.NotNil(t, executor)
// The factory should work and create a proper executor
assert.NotNil(t, executor)
// This test mainly verifies that the integration between config/logger/sandbox works
// without throwing configuration errors
})
t.Run("FullMCPIntegration", func(t *testing.T) {
cfg := &config.Config{
Server: config.ServerConfig{
Transport: "stdio",
HTTPPort: 8080,
},
Sandbox: config.SandboxConfig{
Backend: "local",
TimeoutSec: 5,
MemoryMB: 128,
MaxArtifactSizeMB: 5,
NetworkEnabled: false,
EnableLocalBackend: true,
},
Logging: config.LoggingConfig{
Mode: "development",
Level: "info",
},
Languages: map[string]config.Language{
"python": {
Environment: map[string]string{},
},
"nodejs": {
Environment: map[string]string{},
},
"go": {
Environment: map[string]string{},
},
"cpp": {
Environment: map[string]string{},
},
},
}
mcpLogger, err := logger.New(cfg.Logging.Mode, cfg.Logging.Level)
require.NoError(t, err)
// Create sandbox executor
executor, err := sandbox.NewExecutor(mcpLogger, cfg)
require.NoError(t, err)
// Create MCP server
server, err := mcpserver.New(cfg, mcpLogger, executor)
require.NoError(t, err)
require.NotNil(t, server)
// Test that the server creates successfully without panicking
assert.NotNil(t, server)
// Test that tools are registered
mcpServer := server.GetMCPServer()
require.NotNil(t, mcpServer)
// Note: We can't easily verify tool registration without mcp library internals
})
}
// TestIntegrationSandboxExecution tests sandbox functionality without expecting specific execution results
func TestIntegrationSandboxExecution(t *testing.T) {
testLogger := zaptest.NewLogger(t)
t.Run("LocalExecutorCreation", func(t *testing.T) {
cfg := &config.Config{
Sandbox: config.SandboxConfig{
Backend: "local",
TimeoutSec: 5,
MemoryMB: 128,
MaxArtifactSizeMB: 5,
NetworkEnabled: false,
EnableLocalBackend: true,
},
Languages: map[string]config.Language{
"python": {
Environment: map[string]string{},
},
},
}
executor, err := sandbox.NewExecutor(testLogger, cfg)
require.NoError(t, err)
require.NotNil(t, executor)
// This test verifies that executor can be created properly with config and logger
assert.NotNil(t, executor)
})
t.Run("ExecutorWithDifferentLanguages", func(t *testing.T) {
cfg := &config.Config{
Sandbox: config.SandboxConfig{
Backend: "local",
TimeoutSec: 5,
MemoryMB: 128,
MaxArtifactSizeMB: 5,
NetworkEnabled: false,
EnableLocalBackend: true,
},
Languages: map[string]config.Language{
"python": {
Environment: map[string]string{},
},
"nodejs": {
Environment: map[string]string{},
},
"go": {
Environment: map[string]string{},
},
"cpp": {
Environment: map[string]string{},
},
},
}
executor, err := sandbox.NewExecutor(testLogger, cfg)
require.NoError(t, err)
require.NotNil(t, executor)
// Test that executor can be created with multiple language configurations
assert.NotNil(t, executor)
})
}