TestMCPScriptsTimeoutInJSON tests that timeout is included in the generated tools.json
(t *testing.T)
| 233 | |
| 234 | // TestMCPScriptsTimeoutInJSON tests that timeout is included in the generated tools.json |
| 235 | func TestMCPScriptsTimeoutInJSON(t *testing.T) { |
| 236 | config := &MCPScriptsConfig{ |
| 237 | Tools: map[string]*MCPScriptToolConfig{ |
| 238 | "fast-tool": { |
| 239 | Name: "fast-tool", |
| 240 | Description: "Fast tool", |
| 241 | Script: "return 'fast';", |
| 242 | Timeout: 30, |
| 243 | }, |
| 244 | "slow-tool": { |
| 245 | Name: "slow-tool", |
| 246 | Description: "Slow tool", |
| 247 | Run: "echo 'slow'", |
| 248 | Timeout: 120, |
| 249 | }, |
| 250 | "default-tool": { |
| 251 | Name: "default-tool", |
| 252 | Description: "Default timeout tool", |
| 253 | Py: "print('default')", |
| 254 | Timeout: 60, |
| 255 | }, |
| 256 | "go-tool": { |
| 257 | Name: "go-tool", |
| 258 | Description: "Go timeout tool", |
| 259 | Go: "fmt.Println(\"hello\")", |
| 260 | Timeout: 180, |
| 261 | }, |
| 262 | }, |
| 263 | } |
| 264 | |
| 265 | jsonStr := GenerateMCPScriptsToolsConfig(config) |
| 266 | |
| 267 | // Parse the JSON to verify structure |
| 268 | var parsedConfig MCPScriptsConfigJSON |
| 269 | if err := json.Unmarshal([]byte(jsonStr), &parsedConfig); err != nil { |
| 270 | t.Fatalf("Failed to parse generated JSON: %v", err) |
| 271 | } |
| 272 | |
| 273 | // Verify timeouts are present |
| 274 | toolTimeouts := make(map[string]int) |
| 275 | for _, tool := range parsedConfig.Tools { |
| 276 | toolTimeouts[tool.Name] = tool.Timeout |
| 277 | } |
| 278 | |
| 279 | expected := map[string]int{ |
| 280 | "fast-tool": 30, |
| 281 | "slow-tool": 120, |
| 282 | "default-tool": 60, |
| 283 | "go-tool": 180, |
| 284 | } |
| 285 | |
| 286 | for toolName, expectedTimeout := range expected { |
| 287 | actualTimeout, exists := toolTimeouts[toolName] |
| 288 | if !exists { |
| 289 | t.Errorf("Tool %s not found in generated JSON", toolName) |
| 290 | continue |
| 291 | } |
| 292 | if actualTimeout != expectedTimeout { |
nothing calls this directly
no test coverage detected