MCPcopy Create free account
hub / github.com/coder/coder / TestManager_ToolsStartupGate

Function TestManager_ToolsStartupGate

agent/x/agentmcp/manager_internal_test.go:282–560  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

280}
281
282func TestManager_ToolsStartupGate(t *testing.T) {
283 t.Parallel()
284
285 if os.Getenv("TEST_MCP_FAKE_SERVER") == "1" {
286 runFakeMCPServer()
287 return
288 }
289
290 t.Run("MissingBeforeStartupCanAppearBeforeSettlement", func(t *testing.T) {
291 t.Parallel()
292 ctx := testutil.Context(t, testutil.WaitLong)
293 logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
294 dir := t.TempDir()
295 configPath := filepath.Join(dir, ".mcp.json")
296
297 m := NewManager(ctx, logger, agentexec.DefaultExecer, nil)
298 t.Cleanup(func() { _ = m.Close() })
299
300 type result struct {
301 tools []workspacesdk.MCPToolInfo
302 err error
303 }
304 done := make(chan result, 1)
305 go func() {
306 tools, err := m.Tools(ctx, []string{configPath})
307 done <- result{tools: tools, err: err}
308 }()
309
310 _, entry := fakeMCPServerConfig(t, "srv")
311 writeMCPConfig(t, dir, map[string]mcpServerEntry{"srv": entry})
312 m.MarkStartupSettled()
313
314 select {
315 case got := <-done:
316 require.NoError(t, got.err)
317 require.Len(t, got.tools, 1)
318 assert.Contains(t, got.tools[0].Name, "echo")
319 case <-ctx.Done():
320 t.Fatalf("Tools did not return after startup settled: %v", ctx.Err())
321 }
322 })
323
324 t.Run("MissingAfterStartupReturnsEmptyAndMarksFirstSync", func(t *testing.T) {
325 t.Parallel()
326 ctx := testutil.Context(t, testutil.WaitLong)
327 logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
328 dir := t.TempDir()
329 configPath := filepath.Join(dir, ".mcp.json")
330
331 m := NewManager(ctx, logger, agentexec.DefaultExecer, nil)
332 m.MarkStartupSettled()
333 t.Cleanup(func() { _ = m.Close() })
334
335 tools, err := m.Tools(ctx, []string{configPath})
336 require.NoError(t, err)
337 assert.Empty(t, tools)
338
339 m.mu.RLock()

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
ToolsMethod · 0.95
MarkStartupSettledMethod · 0.95
SnapshotChangedMethod · 0.95
ContextFunction · 0.92
EventuallyFunction · 0.92
runFakeMCPServerFunction · 0.85
fakeMCPServerConfigFunction · 0.85
writeMCPConfigFunction · 0.85
ErrMethod · 0.80
GoMethod · 0.80
NewManagerFunction · 0.70

Tested by

no test coverage detected