History

fix(config): avoid adding new keys when merging

hkfires committed 10 months ago

Commit 2e88c481 parent 3f50da81 file · +2 −35Browse files

Unified · Split

internal/config/config.go+2−35
@@ -829,7 +829,7 @@ func mergeMappingPreserve(dst, src *yaml.Node) { · 828 unmodified lines
829829 copyNodeShallow(dst, src)
830830 return
831831 }
832− // Build a lookup of existing keys in dst
832+ // Only update existing keys in dst, do not add new keys
833833 for i := 0; i+1 < len(src.Content); i += 2 {
834834 sk := src.Content[i]
835835 sv := src.Content[i+1]
@@ -838,13 +838,8 @@ func mergeMappingPreserve(dst, src *yaml.Node) { · 2 unmodified lines
838838 // Merge into existing value node
839839 dv := dst.Content[idx+1]
840840 mergeNodePreserve(dv, sv)
841− } else {
842− if shouldSkipEmptyCollectionOnPersist(sk.Value, sv) {
843− continue
844− }
845− // Append new key/value pair by deep-copying from src
846− dst.Content = append(dst.Content, deepCopyNode(sk), deepCopyNode(sv))
847841 }
842+ // Keys not in dst are skipped - preserves original config structure
848843 }
849844 }
850845
@@ -925,34 +920,6 @@ func findMapKeyIndex(mapNode *yaml.Node, key string) int { · 74 unmodified lines
925920 return -1
926921 }
927922
928−func shouldSkipEmptyCollectionOnPersist(key string, node *yaml.Node) bool {
929− switch key {
930− case "generative-language-api-key",
931− "gemini-api-key",
932− "vertex-api-key",
933− "claude-api-key",
934− "codex-api-key",
935− "openai-compatibility":
936− return isEmptyCollectionNode(node)
937− default:
938− return false
939− }
940−}
941−
942−func isEmptyCollectionNode(node *yaml.Node) bool {
943− if node == nil {
944− return true
945− }
946− switch node.Kind {
947− case yaml.SequenceNode:
948− return len(node.Content) == 0
949− case yaml.ScalarNode:
950− return node.Tag == "!!null"
951− default:
952− return false
953− }
954−}
955−
956923 // deepCopyNode creates a deep copy of a yaml.Node graph.
957924 func deepCopyNode(n *yaml.Node) *yaml.Node {
958925 if n == nil {