Second adversarial pass findings, fixed:
BLOCKER -- PATCH silently dropped every dotted key. The UI sends
dotted keys ('budgets.max_steps') but ApplyOverlayValues fed them
straight to yaml.Unmarshal, which cannot decode a dotted key as a
struct field and silently ignored it: 200 OK, zero effect, and the row
still persisted (poisoning later reloads with an unvalidated value).
The reload path worked only because overlay.Snapshot nests first. Fix:
applyDottedOverlay nests dotted keys via overlay.Nest before decode --
the same nesting Snapshot performs -- and is pinned by
TestApplyDottedOverlayNestsBeforeDecode, which fails against the old
behaviour.
MAJOR -- shallow copies let overlay decode mutate the published
snapshot. Holder.Get and *doc are shallow; yaml decodes maps in place,
so a crafted nested update (or a failed boot overlay apply) mutated
shared maps of the published config before validation. Fix: config.Clone
deep-copies every reference field (Models, Providers, Repos, Identities,
Dispatch.Labels, Agent.Env, Chat/Telegram slices, Tools.MCPServers,
Memory.ProviderConfig, WebFetch.Enabled pointer, Extra), used by the
PATCH path (next := d.Cfg.Get().Clone()) and by Loader.ApplyOverlay,
which now never mutates its input (clones Config and the provenance
chain internally), so boot and reload pass the base document directly
and a failed apply leaves it exactly as it was. Pinned by
TestConfigCloneDeepCopiesReferenceFields.
MAJOR -- data races on captured main.go variables. bootOverlayErr and
currentProvenance were plain values written by the SIGHUP goroutine and
the PATCH/Reset handlers and read by every GET /api/config; -race passed
only because no test exercised the composition root concurrently. Both
are now atomic.Pointer; the LastReload closure and the provenance
dedup read them atomically.
MINOR -- MaxConcurrency removed from the reloadable allowlist. The
dispatchers re-read it but the startup-built container pool captures it
(container/pool.go:94,163), so 'every consumer re-reads it' is false and
a change only partially applies. It now warns requires-restart; the
criterion comment on reloadableFields documents the pool capture.
MINOR -- ResetConfig now resolves and validates the target state BEFORE
deleting the row, so a broken file cannot leave the store and the
running config disagreeing; the provenance chain no longer grows
unboundedly (the runtime-overlay origin replaces, not appends).
Also: holder.go no longer references a file watcher that does not exist.
Verified: task check clean; -race clean on cmd/archied, webui, daemon,
config; new findings from the second adversarial pass are closed.
35 lines
1.2 KiB
Go
35 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
)
|
|
|
|
// TestApplyDottedOverlayNestsBeforeDecode pins the PATCH-path fix: the
|
|
// UI sends dotted keys ("budgets.max_steps") and yaml cannot decode a
|
|
// dotted key as a struct field, so the updates must be nested first. A
|
|
// regression here silently drops every dotted update while returning 200.
|
|
func TestApplyDottedOverlayNestsBeforeDecode(t *testing.T) {
|
|
cfg := config.Config{Budgets: config.Budgets{MaxSteps: 10}}
|
|
if err := applyDottedOverlay(&cfg, map[string]any{"budgets.max_steps": 20}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg.Budgets.MaxSteps != 20 {
|
|
t.Fatalf("MaxSteps = %d, want 20 (dotted key must be nested before decode)", cfg.Budgets.MaxSteps)
|
|
}
|
|
// A field the update does not name keeps its value.
|
|
if cfg.Budgets.MaxTokens != 0 {
|
|
t.Errorf("MaxTokens = %d, want 0 (untouched)", cfg.Budgets.MaxTokens)
|
|
}
|
|
}
|
|
|
|
// TestApplyDottedOverlayRejectsEmptyKey pins that a malformed dotted key
|
|
// fails instead of silently nesting under a synthetic root.
|
|
func TestApplyDottedOverlayRejectsEmptyKey(t *testing.T) {
|
|
cfg := config.Config{}
|
|
if err := applyDottedOverlay(&cfg, map[string]any{"": 1}); err == nil {
|
|
t.Fatal("empty dotted key accepted")
|
|
}
|
|
}
|