server init adds the guardrails to a server.yaml from before them

An upgrade replaces the binary and leaves server.yaml alone, so a control
plane installed before guardrails stayed unguarded. Run again, init now
appends the baseline guard section (and so fetches the judge) when the file
has no guard key at all, keeping the old file as server.yaml.bak-<time>.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-10-05 12:39:28 +02:00
1 parent 3558dba485
commit dc65ea6899
5 files changed
+103 -3

No files matched your search

+37
View File
@@ -207,3 +207,40 @@ func TestInitSaysAtOnceWhenAModelFitsNowhere(t *testing.T) {
t.Errorf("took %s to say so", time.Since(start))
}
}
func TestAnOldConfigurationGetsGuardrailsOnce(t *testing.T) {
body := fmt.Sprintf(serverConfigTemplate, "/etc/llmgw", "/etc/llmgw", "/etc/llmgw",
"/var/lib/llmgw/llmgw.db", "ops@example.com", "")
path := filepath.Join(t.TempDir(), "server.yaml")
if err := os.WriteFile(path, []byte(body), 0o640); err != nil {
t.Fatal(err)
}
added, err := appendGuardIfMissing(path, true)
if err != nil || !added {
t.Fatalf("added=%v err=%v, want the guard section added", added, err)
}
cfg, err := config.Load(path)
if err != nil {
t.Fatal(err)
}
if err := cfg.Validate(); err != nil {
t.Fatal(err)
}
if len(cfg.Guard.Default) != 1 || cfg.Guard.Policies["baseline"].Judge == nil {
t.Errorf("guard = %+v, want the baseline with its judge", cfg.Guard)
}
if backups, _ := filepath.Glob(path + ".bak-*"); len(backups) != 1 {
t.Errorf("backups = %v, want the old file kept", backups)
}
if added, err := appendGuardIfMissing(path, true); err != nil || added {
t.Errorf("second run: added=%v err=%v, want nothing changed", added, err)
}
// guard: written by hand, even empty, is a decision and stays.
if err := os.WriteFile(path, []byte(body+"guard: {}\n"), 0o640); err != nil {
t.Fatal(err)
}
if added, err := appendGuardIfMissing(path, true); err != nil || added {
t.Errorf("empty guard: added=%v err=%v, want it left alone", added, err)
}
}