Files
archie/internal/app/archied/unknown_config_keys_test.go
T
sam 31622ec5c2 refactor(config): delete the runtime config overlay
The control plane replaces this, rather than extending it
(docs/prds/runtime-control-plane.md, "First implementation"). Until now both
paths existed: overlay kept dashboard edits in its own SQLite file beside
archie.db and layered them over the file config at boot and on every reload,
which is the duplicate configuration authority the PRD set out to remove.

Gone with it: the --no-config-overlay flag and ARCHIE_SKIP_CONFIG_OVERLAY
recovery hatch, which existed because a bad overlay row could brick the boot;
ReloadStatus.OverlayUnavailable; and the reload controller's overlay source.
The -config-overlay file overlay is a different thing and stays.

The dashboard's three write seams went too. UpdateConfig, ResetConfig and
UpdateRepoField were assigned only in internal/webui's own tests, so in
production they answered 503 and ConfigView.Editable was permanently false
(archie-core-j28m). Removing Editable would otherwise have flipped the SPA's
controls on, since configEditable read a missing field as true, so the config
pages become what they already were in practice: a read of what each process
is running with. Configuration is written through the control plane.

apply.go survives this deliberately; archie-core-xrux carries the question of
whether its map merge is still guarding the file overlay path.
2026-09-21 08:57:55 +10:00

63 lines
2.0 KiB
Go

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.
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, ""); 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, ""); 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)
}
}
func TestLoadConfigMakesRuntimeSettingsAvailableBeforeSubsystemSetup(t *testing.T) {
path := filepath.Join(t.TempDir(), "config.toml")
writeConfig(t, path, minimalConfigTOML("widget"))
b := &boot{log: slog.Default()}
if err := b.loadConfig(t.Context(), path, ""); err != nil {
t.Fatalf("loadConfig: %v", err)
}
if b.cfgHolder == nil {
t.Fatal("runtime config holder is nil before control-plane settings load")
}
}