@@ -36,6 +36,38 @@ func TestConfig_LoadFromBytes(t *testing.T) {
3636 require.Equal(t, "https://api.openai.com/v2", pc.BaseURL)
3737}
3838
39+func TestLoadFromConfigPaths_InvalidJSON(t *testing.T) {
40+ t.Parallel()
41+
42+ t.Run("identifies the offending file", func(t *testing.T) {
43+ t.Parallel()
44+ tmpDir := t.TempDir()
45+ good := filepath.Join(tmpDir, "good.json")
46+ bad := filepath.Join(tmpDir, "bad.json")
47+ require.NoError(t, os.WriteFile(good, []byte(`{"providers":{}}`), 0o644))
48+ require.NoError(t, os.WriteFile(bad, []byte(`{not valid json}`), 0o644))
49+
50+ _, _, err := loadFromConfigPaths([]string{good, bad})
51+ require.Error(t, err)
52+ require.Contains(t, err.Error(), "invalid JSON in config file")
53+ require.Contains(t, err.Error(), "bad.json")
54+ })
55+
56+ t.Run("skips missing and empty files", func(t *testing.T) {
57+ t.Parallel()
58+ tmpDir := t.TempDir()
59+ empty := filepath.Join(tmpDir, "empty.json")
60+ require.NoError(t, os.WriteFile(empty, []byte(""), 0o644))
61+
62+ cfg, _, err := loadFromConfigPaths([]string{
63+ filepath.Join(tmpDir, "nonexistent.json"),
64+ empty,
65+ })
66+ require.NoError(t, err)
67+ require.NotNil(t, cfg)
68+ })
69+}
70+
3971// testStore wraps a Config in a minimal ConfigStore for testing.
4072func testStore(cfg *Config) *ConfigStore {
4173 return &ConfigStore{config: cfg}