feat(archied): warn at boot when the config file has unrecognised keys

Surfaces configuration.Document.UnknownKeys as a warning naming the
offending keys. Stays a warning, not a boot failure, per
docs/architecture/configuration.md's startup policy: only an invalid
config is fatal, and a stray key is far more likely an operator typo in an
otherwise-working file.
This commit is contained in:
sam committed 2026-09-15 05:07:57 +10:00
1 parent 9b2fb4a82c
commit d4e7d67051
2 files changed
+60

No files matched your search

+8
View File
@@ -251,6 +251,14 @@ func (b *boot) loadConfig(ctx context.Context, cfgPath, overlayPath string, noCo
return err
}
b.doc = doc
// A stray/misspelled key parses and validates cleanly (unknown TOML
// keys are otherwise silently discarded), so it must be visible
// somewhere rather than just quietly doing nothing -- see
// docs/architecture/configuration.md's startup policy: an invalid
// config is fatal, but a typo like this is not that, only a warning.
if len(doc.UnknownKeys) > 0 {
b.log.Warn("config file has unrecognised keys; check for typos", "keys", doc.UnknownKeys)
}
// Runtime config overlay: dashboard-edited overrides layered over the
// file config from their own SQLite file (own user_version and
// migrator, no contention with the task store). Skipped under
@@ -0,0 +1,52 @@
package archied
import (
"log/slog"
"path/filepath"
"strings"
"testing"
)
// TestLoadConfigWarnsOnUnknownKeys pins plan-config-drift.md step 3: a
// stray/misspelled config key must be visible to the operator, not just
// silently parsed, validated and dropped. noConfigOverlay:true keeps the
// test to the file-load path alone, matching the recovery-hatch boot the
// daemon uses when it cannot or should not touch the runtime overlay
// store.
func TestLoadConfigWarnsOnUnknownKeys(t *testing.T) {
path := filepath.Join(t.TempDir(), "config.toml")
writeConfig(t, path, minimalConfigTOML("widget")+"[containers]\nmax_concurrancy = 4\n")
var sb strings.Builder
log := slog.New(slog.NewTextHandler(&sb, &slog.HandlerOptions{Level: slog.LevelWarn}))
b := &boot{log: log}
if err := b.loadConfig(t.Context(), path, "", true); err != nil {
t.Fatalf("loadConfig: %v (an unknown key must not fail the boot)", err)
}
out := sb.String()
if !strings.Contains(out, "containers.max_concurrancy") {
t.Errorf("log does not name the unknown key: %s", out)
}
}
// TestLoadConfigDoesNotWarnOnAKnownConfig is the negative case: a config
// with no unknown keys must produce no warning, so the new check cannot
// itself become log noise for a working deployment.
func TestLoadConfigDoesNotWarnOnAKnownConfig(t *testing.T) {
path := filepath.Join(t.TempDir(), "config.toml")
writeConfig(t, path, minimalConfigTOML("widget"))
var sb strings.Builder
log := slog.New(slog.NewTextHandler(&sb, &slog.HandlerOptions{Level: slog.LevelWarn}))
b := &boot{log: log}
if err := b.loadConfig(t.Context(), path, "", true); err != nil {
t.Fatalf("loadConfig: %v", err)
}
if out := sb.String(); strings.Contains(out, "unrecognised") || strings.Contains(out, "unknown") {
t.Errorf("unexpected warning for a config with no unknown keys: %s", out)
}
}