Skip to content

Commit e0dc41d

Browse files
committed
fix(config): ignore yaml backup files in model loader
Only load files whose real extension is .yaml or .yml so backup files like model.yaml.bak do not override active configs. Add a regression test covering plain and timestamped backup files. Assisted-by: Codex:gpt-5.4 docker
1 parent 6480715 commit e0dc41d

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

core/config/model_config_loader.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,9 @@ func (bcl *ModelConfigLoader) LoadModelConfigsFromPath(path string, opts ...Conf
373373
files = append(files, info)
374374
}
375375
for _, file := range files {
376-
// Skip templates, YAML and .keep files
377-
if !strings.Contains(file.Name(), ".yaml") && !strings.Contains(file.Name(), ".yml") ||
378-
strings.HasPrefix(file.Name(), ".") {
376+
// Only load real YAML config files and ignore dotfiles or backup variants
377+
ext := strings.ToLower(filepath.Ext(file.Name()))
378+
if (ext != ".yaml" && ext != ".yml") || strings.HasPrefix(file.Name(), ".") {
379379
continue
380380
}
381381

core/config/model_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package config
22

33
import (
44
"os"
5+
"path/filepath"
56

67
. "github.com/onsi/ginkgo/v2"
78
. "github.com/onsi/gomega"
@@ -109,5 +110,50 @@ options:
109110
Expect(testModel.Options).To(ContainElements("foo", "bar", "baz"))
110111

111112
})
113+
114+
It("Only loads files ending with yaml or yml", func() {
115+
tmpdir, err := os.MkdirTemp("", "model-config-loader")
116+
Expect(err).ToNot(HaveOccurred())
117+
defer os.RemoveAll(tmpdir)
118+
119+
err = os.WriteFile(filepath.Join(tmpdir, "foo.yaml"), []byte(
120+
`name: "foo-model"
121+
description: "formal config"
122+
backend: "llama-cpp"
123+
parameters:
124+
model: "foo.gguf"
125+
`), 0644)
126+
Expect(err).ToNot(HaveOccurred())
127+
128+
err = os.WriteFile(filepath.Join(tmpdir, "foo.yaml.bak"), []byte(
129+
`name: "foo-model"
130+
description: "backup config"
131+
backend: "llama-cpp"
132+
parameters:
133+
model: "foo-backup.gguf"
134+
`), 0644)
135+
Expect(err).ToNot(HaveOccurred())
136+
137+
err = os.WriteFile(filepath.Join(tmpdir, "foo.yaml.bak.123"), []byte(
138+
`name: "foo-backup-only"
139+
description: "timestamped backup config"
140+
backend: "llama-cpp"
141+
parameters:
142+
model: "foo-timestamped.gguf"
143+
`), 0644)
144+
Expect(err).ToNot(HaveOccurred())
145+
146+
bcl := NewModelConfigLoader(tmpdir)
147+
err = bcl.LoadModelConfigsFromPath(tmpdir)
148+
Expect(err).ToNot(HaveOccurred())
149+
150+
configs := bcl.GetAllModelsConfigs()
151+
Expect(configs).To(HaveLen(1))
152+
Expect(configs[0].Name).To(Equal("foo-model"))
153+
Expect(configs[0].Description).To(Equal("formal config"))
154+
155+
_, exists := bcl.GetModelConfig("foo-backup-only")
156+
Expect(exists).To(BeFalse())
157+
})
112158
})
113159
})

0 commit comments

Comments
 (0)