MCPcopy Create free account
hub / github.com/diillson/chatcli / TestBootstrapMCPInitsManagerWhenDirExists

Function TestBootstrapMCPInitsManagerWhenDirExists

cli/mcp_bootstrap_test.go:79–102  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

77}
78
79func TestBootstrapMCPInitsManagerWhenDirExists(t *testing.T) {
80 // Mirrors the chatcli first-run experience: ~/.chatcli/ exists
81 // but mcp_servers.json doesn't. bootstrapMCP must still set up
82 // the manager + watcher so a later file creation triggers Reload.
83 dir := t.TempDir()
84 cfgPath := filepath.Join(dir, "mcp_servers.json")
85 t.Setenv("CHATCLI_MCP_ENABLED", "")
86 t.Setenv("CHATCLI_MCP_CONFIG", cfgPath)
87 cli := &ChatCLI{}
88 cli.bootstrapMCP(context.Background(), zap.NewNop())
89 defer cli.stopMCPConfigWatcher()
90 if cli.mcpManager == nil {
91 t.Fatal("manager should be initialized when parent dir exists")
92 }
93 if cli.mcpConfigPath != cfgPath {
94 t.Errorf("mcpConfigPath = %q, want %q", cli.mcpConfigPath, cfgPath)
95 }
96 if cli.mcpWatcher == nil {
97 t.Fatal("watcher should start so hot-reload works once the file appears")
98 }
99 // Allow the goroutine started by bootstrapMCP (StartAll on an
100 // empty server set) to finish so the test doesn't race against it.
101 time.Sleep(50 * time.Millisecond)
102}
103
104func TestBootstrapMCPSurvivesMalformedConfig(t *testing.T) {
105 // 0-byte / malformed mcp_servers.json must not abort init.

Callers

nothing calls this directly

Calls 3

bootstrapMCPMethod · 0.95
stopMCPConfigWatcherMethod · 0.95
ErrorfMethod · 0.80

Tested by

no test coverage detected