@@ -49,25 +49,25 @@ func newProfileTestEnv(t *testing.T) *profileTestEnv {
4949 // Extract the base URL (without /mcp suffix)
5050 baseURL := strings .TrimSuffix (env .proxyAddr , "/mcp" )
5151
52- // Update runtime config to include both servers + profiles
53- cfg := env .proxyServer .runtime .Config ()
54- researchEnabled := true
55- deployEnabled := true
56- quarFalse := false
57- cfg .Servers = append (cfg . Servers ,
52+ // Build a new config to avoid mutating the live pointer (prevents data races).
53+ old := env .proxyServer .runtime .Config ()
54+ cfgCopy := * old // shallow copy of the struct
55+ cfg := & cfgCopy
56+ // Append new servers to a fresh slice (don't alias the original).
57+ cfg .Servers = append (append ([] * config. ServerConfig {}, old . Servers ... ) ,
5858 & config.ServerConfig {
5959 Name : "research-srv" ,
6060 URL : researchMS .addr ,
6161 Protocol : "streamable-http" ,
62- Enabled : researchEnabled ,
63- Quarantined : quarFalse ,
62+ Enabled : true ,
63+ Quarantined : false ,
6464 },
6565 & config.ServerConfig {
6666 Name : "deploy-srv" ,
6767 URL : deployMS .addr ,
6868 Protocol : "streamable-http" ,
69- Enabled : deployEnabled ,
70- Quarantined : quarFalse ,
69+ Enabled : true ,
70+ Quarantined : false ,
7171 },
7272 )
7373 cfg .Profiles = []config.ProfileConfig {
@@ -344,25 +344,25 @@ func TestProfile_PolicyIntersection(t *testing.T) {
344344 ctx := context .Background ()
345345
346346 // Add a third server and a third profile that includes it.
347- cfg := env .proxyServer .runtime .Config ()
348347 sharedMS := env .CreateMockUpstreamServer ("shared-srv" , []mcp.Tool {
349348 {Name : "shared_action" , Description : "Shared tool" },
350349 })
351- sharedEnabled := true
352- sharedQuar := false
353- cfg .Servers = append (cfg .Servers , & config.ServerConfig {
350+ old2 := env .proxyServer .runtime .Config ()
351+ cfgCopy2 := * old2
352+ cfg2 := & cfgCopy2
353+ cfg2 .Servers = append (append ([]* config.ServerConfig {}, old2 .Servers ... ), & config.ServerConfig {
354354 Name : "shared-srv" ,
355355 URL : sharedMS .addr ,
356356 Protocol : "streamable-http" ,
357- Enabled : sharedEnabled ,
358- Quarantined : sharedQuar ,
357+ Enabled : true ,
358+ Quarantined : false ,
359359 })
360- cfg .Profiles = append (cfg . Profiles , config.ProfileConfig {
360+ cfg2 .Profiles = append (append ([]config. ProfileConfig {}, old2 . Profiles ... ) , config.ProfileConfig {
361361 Name : "shared" ,
362362 Servers : []string {"shared-srv" , "research-srv" },
363363 })
364- env .proxyServer .runtime .UpdateConfig (cfg , "" )
365- _ = env .proxyServer .runtime .LoadConfiguredServers (cfg )
364+ env .proxyServer .runtime .UpdateConfig (cfg2 , "" )
365+ _ = env .proxyServer .runtime .LoadConfiguredServers (cfg2 )
366366 time .Sleep (2 * time .Second )
367367
368368 baseURL := strings .TrimSuffix (env .proxyAddr , "/mcp" )
@@ -414,16 +414,21 @@ func TestProfile_PerServerDisabledToolsRespected(t *testing.T) {
414414 env := newProfileTestEnv (t )
415415 ctx := context .Background ()
416416
417- // Disable "rollback" on deploy-srv.
418- cfg := env .proxyServer .runtime .Config ()
419- for _ , s := range cfg .Servers {
417+ // Disable "rollback" on deploy-srv (copy config first to avoid data race).
418+ old3 := env .proxyServer .runtime .Config ()
419+ cfgCopy3 := * old3
420+ cfg3 := & cfgCopy3
421+ newServers := make ([]* config.ServerConfig , len (old3 .Servers ))
422+ for i , s := range old3 .Servers {
423+ sc := * s
420424 if s .Name == "deploy-srv" {
421- s .DisabledTools = []string {"rollback" }
422- break
425+ sc .DisabledTools = []string {"rollback" }
423426 }
427+ newServers [i ] = & sc
424428 }
425- env .proxyServer .runtime .UpdateConfig (cfg , "" )
426- _ = env .proxyServer .runtime .LoadConfiguredServers (cfg )
429+ cfg3 .Servers = newServers
430+ env .proxyServer .runtime .UpdateConfig (cfg3 , "" )
431+ _ = env .proxyServer .runtime .LoadConfiguredServers (cfg3 )
427432 time .Sleep (1 * time .Second )
428433 _ = env .proxyServer .runtime .DiscoverAndIndexTools (context .Background ())
429434 time .Sleep (2 * time .Second )
0 commit comments