(t *testing.T)
| 77 | } |
| 78 | |
| 79 | func 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 | |
| 104 | func TestBootstrapMCPSurvivesMalformedConfig(t *testing.T) { |
| 105 | // 0-byte / malformed mcp_servers.json must not abort init. |
nothing calls this directly
no test coverage detected