diff --git a/internal/config/config.go b/internal/config/config.go index d25ce26be..4135b300d 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -388,11 +388,6 @@ type Config struct { // Curators are curator definitions seeded from [[curators]]. Curators []CuratorDefinition `toml:"curators" yaml:"curators" json:"curators,omitempty"` - - // Extra holds additional feature configuration from conf.d/ files that - // don't match a known feature name. Keys are the filename stem (e.g. - // "custom-tool" for conf.d/custom-tool.yaml). - Extra map[string]any `toml:"-" yaml:"-" json:"extra,omitempty"` } // IdentityConfig is a per-identity configuration subset. Each identity @@ -541,7 +536,6 @@ func (c Config) Clone() Config { c.Tools.WebFetch.Enabled = &v } c.DiffCapLines = cloneIntPtr(c.DiffCapLines) - c.Extra = maps.Clone(c.Extra) return c } diff --git a/internal/infrastructure/configuration/decode.go b/internal/infrastructure/configuration/decode.go index 4bc0c54fa..a72c47c3d 100644 --- a/internal/infrastructure/configuration/decode.go +++ b/internal/infrastructure/configuration/decode.go @@ -93,16 +93,3 @@ func decodeFeature(cfg *config.Config, feature Feature, path string, layer Layer } return decodeYAML(path, target) } - -// decodeExtra decodes an unrecognised conf.d/ file into cfg.Extra[name]. -func decodeExtra(cfg *config.Config, name, path string) error { - var value any - if err := decodeYAML(path, &value); err != nil { - return err - } - if cfg.Extra == nil { - cfg.Extra = make(map[string]any) - } - cfg.Extra[name] = value - return nil -} diff --git a/internal/infrastructure/configuration/discovery.go b/internal/infrastructure/configuration/discovery.go index 8dc513b72..dcf0e7336 100644 --- a/internal/infrastructure/configuration/discovery.go +++ b/internal/infrastructure/configuration/discovery.go @@ -12,12 +12,11 @@ import ( const confDirName = "conf.d" // fileSet is the result of scanning a configuration directory: the main -// file, feature files and extras. +// file and feature files. type fileSet struct { mainYAML string mainTOML string features map[Feature]string - extras map[string]string } // main returns the daemon-level config file and its format. YAML wins when @@ -44,16 +43,6 @@ func (fs fileSet) sortedFeatures() []Feature { return names } -// sortedExtras returns extra names in a stable order. -func (fs fileSet) sortedExtras() []string { - names := make([]string, 0, len(fs.extras)) - for n := range fs.extras { - names = append(names, n) - } - sort.Strings(names) - return names -} - // discover scans dir and classifies its entries. func discover(dir string) (fileSet, error) { entries, err := os.ReadDir(dir) @@ -63,7 +52,6 @@ func discover(dir string) (fileSet, error) { fs := fileSet{ features: map[Feature]string{}, - extras: map[string]string{}, } var unknown []string @@ -111,8 +99,7 @@ func (fs fileSet) classify(dir, name string, unknown *[]string) error { return fs.addFeature(feature, filepath.Join(dir, name)) } -// scanConfDir reads dir/conf.d/, routing recognised names to features and -// the rest to extras. +// scanConfDir reads dir/conf.d/ and refuses files without a known consumer. func (fs fileSet) scanConfDir(dir string) error { confDir := filepath.Join(dir, confDirName) entries, err := os.ReadDir(confDir) @@ -124,14 +111,13 @@ func (fs fileSet) scanConfDir(dir string) error { } for _, e := range entries { name := e.Name() - if e.IsDir() || !isYAML(name) { + if e.IsDir() { continue } path := filepath.Join(confDir, name) feature := Feature(trimYAMLSuffix(name)) if !feature.known() { - fs.extras[string(feature)] = path - continue + return fmt.Errorf("%w: unknown configuration file %s", ErrUnreadable, path) } if err := fs.addFeature(feature, path); err != nil { return err diff --git a/internal/infrastructure/configuration/discovery_test.go b/internal/infrastructure/configuration/discovery_test.go new file mode 100644 index 000000000..17d8336df --- /dev/null +++ b/internal/infrastructure/configuration/discovery_test.go @@ -0,0 +1,37 @@ +package configuration + +import ( + "os" + "path/filepath" + "strings" + "testing" +) + +func TestUnknownConfFile(t *testing.T) { + for _, name := range []string{"custom.yaml", "custom.yml", "custom.toml", "custom.txt", "tools.yaml"} { + t.Run(name, func(t *testing.T) { + dir := t.TempDir() + if err := os.WriteFile(filepath.Join(dir, "config.toml"), []byte("bot_user = \"test\"\n"), 0o600); err != nil { + t.Fatal(err) + } + conf := filepath.Join(dir, "conf.d") + if err := os.Mkdir(conf, 0o700); err != nil { + t.Fatal(err) + } + path := filepath.Join(conf, name) + if err := os.WriteFile(path, []byte("setting: ignored\n"), 0o600); err != nil { + t.Fatal(err) + } + _, err := New(nil).Dir(dir, "") + if name == "tools.yaml" { + if err != nil { + t.Fatal(err) + } + return + } + if err == nil || !strings.Contains(err.Error(), path) { + t.Fatalf("config load error = %v, want unknown file %s", err, path) + } + }) + } +} diff --git a/internal/infrastructure/configuration/loader.go b/internal/infrastructure/configuration/loader.go index 29087b72a..a4206d9e1 100644 --- a/internal/infrastructure/configuration/loader.go +++ b/internal/infrastructure/configuration/loader.go @@ -331,14 +331,6 @@ func (l *Loader) loadDir(doc *Document, dir string, layer Layer) error { doc.Provenance.record(Origin{Path: path, Role: RoleFeature, Layer: layer, Feature: feature}) } - for _, name := range files.sortedExtras() { - path := files.extras[name] - if err := decodeExtra(&doc.Config, name, path); err != nil { - return err - } - doc.Provenance.record(Origin{Path: path, Role: RoleExtra, Layer: layer, Feature: Feature(name)}) - } - return nil } diff --git a/internal/infrastructure/configuration/provenance.go b/internal/infrastructure/configuration/provenance.go index 2cf3a1fcf..aa1496d4b 100644 --- a/internal/infrastructure/configuration/provenance.go +++ b/internal/infrastructure/configuration/provenance.go @@ -12,7 +12,6 @@ type Role string const ( RoleMain Role = "main" // config.yaml / config.toml RoleFeature Role = "feature" // config..yaml or conf.d/.yaml - RoleExtra Role = "extra" // conf.d/*.yaml for an unrecognised name ) // Layer distinguishes the base configuration from an overlay applied on top. @@ -28,7 +27,7 @@ type Origin struct { Path string Role Role Layer Layer - Feature Feature // set when Role is RoleFeature or RoleExtra + Feature Feature // set when Role is RoleFeature } // String renders an origin for logs and error messages.