fix(config): deep-copy Image.Hosted/Image.Local in Config.Clone
Clone's own doc comment promises mutating the clone cannot touch memory shared with the original, but Image.Hosted/Image.Local were left as a shallow map copy -- a runtime overlay or dashboard PATCH decoding into the clone could mutate the published config's image provider maps.
This commit is contained in:
1 parent
bc430fa50d
commit
ce4f43dd8d
2 files changed
+14
No files matched your search
@@ -28,6 +28,10 @@ func TestConfigCloneDeepCopiesReferenceFields(t *testing.T) {
|
||||
LegacyAgent: LegacyAgent{Env: []string{"HOME"}},
|
||||
Extra: map[string]any{"custom": 1},
|
||||
Bindings: BindingsConfig{PreviousEncryptionKeys: []SecretRef{{Engine: "env", Key: "K0"}}},
|
||||
Image: ImageConfig{
|
||||
Hosted: map[string]ImageHostedProvider{"openai": {Enabled: true}},
|
||||
Local: map[string]ImageLocalProvider{"sdxl": {Enabled: true}},
|
||||
},
|
||||
}
|
||||
|
||||
got := orig.Clone()
|
||||
@@ -46,6 +50,8 @@ func TestConfigCloneDeepCopiesReferenceFields(t *testing.T) {
|
||||
got.Extra["custom"] = 2
|
||||
got.Bindings.PreviousEncryptionKeys[0] = SecretRef{Engine: "env", Key: "changed"}
|
||||
*got.Tools.WebFetch.Enabled = false
|
||||
got.Image.Hosted["openai"] = ImageHostedProvider{Enabled: false}
|
||||
got.Image.Local["sdxl"] = ImageLocalProvider{Enabled: false}
|
||||
|
||||
if orig.Models["builder"] != "m" {
|
||||
t.Error("Models map is shared")
|
||||
@@ -83,4 +89,10 @@ func TestConfigCloneDeepCopiesReferenceFields(t *testing.T) {
|
||||
if !*orig.Tools.WebFetch.Enabled {
|
||||
t.Error("WebFetch.Enabled pointer is shared")
|
||||
}
|
||||
if !orig.Image.Hosted["openai"].Enabled {
|
||||
t.Error("Image.Hosted map is shared")
|
||||
}
|
||||
if !orig.Image.Local["sdxl"].Enabled {
|
||||
t.Error("Image.Local map is shared")
|
||||
}
|
||||
}
|
||||
@@ -662,6 +662,8 @@ func (c Config) Clone() Config {
|
||||
c.Bindings.PreviousEncryptionKeys = append([]SecretRef(nil), c.Bindings.PreviousEncryptionKeys...)
|
||||
c.Tools.MCPServers = cloneMCPServers(c.Tools.MCPServers)
|
||||
c.Memory.ProviderConfig = maps.Clone(c.Memory.ProviderConfig)
|
||||
c.Image.Hosted = maps.Clone(c.Image.Hosted)
|
||||
c.Image.Local = maps.Clone(c.Image.Local)
|
||||
if c.Tools.WebFetch.Enabled != nil {
|
||||
v := *c.Tools.WebFetch.Enabled
|
||||
c.Tools.WebFetch.Enabled = &v
|
||||
|
||||
Reference in new issue
Block a user