(t *testing.T)
| 101 | } |
| 102 | |
| 103 | func TestAddServerMergesExistingFile(t *testing.T) { |
| 104 | home := t.TempDir() |
| 105 | t.Setenv("HOME", home) |
| 106 | client, _ := mcp.ClientByName("claude") |
| 107 | path := filepath.Join(home, ".claude.json") |
| 108 | preexisting := map[string]any{"theme": "dark"} |
| 109 | raw, _ := json.MarshalIndent(preexisting, "", " ") |
| 110 | if err := os.WriteFile(path, raw, 0o600); err != nil { |
| 111 | t.Fatal(err) |
| 112 | } |
| 113 | _, err := mcp.AddServer(client, mcp.UserScope, mcp.Server{Name: "x", Command: "y"}) |
| 114 | if err != nil { |
| 115 | t.Fatal(err) |
| 116 | } |
| 117 | data, _ := os.ReadFile(path) |
| 118 | var got map[string]any |
| 119 | if err := json.Unmarshal(data, &got); err != nil { |
| 120 | t.Fatal(err) |
| 121 | } |
| 122 | if got["theme"] != "dark" { |
| 123 | t.Fatalf("theme overwritten: %v", got) |
| 124 | } |
| 125 | if _, ok := got["mcpServers"]; !ok { |
| 126 | t.Fatalf("missing mcpServers: %v", got) |
| 127 | } |
| 128 | } |
nothing calls this directly
no test coverage detected