Everything in server.yaml that is not one machine's own is now a versioned document in the store (cluster_settings), the same on every control plane. The first start against a store imports the file's cluster keys, with the baseline guard policy when there is none; after that those keys in a file are ignored, with a warning. Each control plane polls the document's version and its own server.yaml's hash. A change is validated and applied: guard live (Gate.Replace), anything else by a graceful restart that systemd brings back, standbys first and the leader 30s later. A version that does not load on a machine is not applied; at start the newest one that loads is used, so a bad edit cannot keep every control plane down. llmgw ctl config show/get/set/unset/edit/history/rollback, the admin API under /api/v1/settings, and the console's Settings screen, which layers the store's document over the machine's file, write it. Commands beside the control plane that read cluster keys (init, node add, server add, backup, upgrade) read the layered configuration; init --bundle writes offline to the store once it holds the settings. A standby that becomes the leader re-reads models, engine choices and facility holds from the store. Retires appendGuardIfMissing: the import does it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
100 lines
3.1 KiB
Go
100 lines
3.1 KiB
Go
package config
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
const machineFile = `
|
|
listen: ":8080"
|
|
agent_listen: ":7443"
|
|
agent_insecure: true
|
|
auth:
|
|
enabled: true
|
|
store: /var/lib/llmgw/llmgw.db
|
|
default_rpm: 60
|
|
mirror:
|
|
api: http://127.0.0.1:8082
|
|
update_check: 6h
|
|
guard:
|
|
default: [baseline]
|
|
policies:
|
|
baseline:
|
|
input:
|
|
injection: flag
|
|
router:
|
|
retries: 2
|
|
`
|
|
|
|
func TestAFileSplitsIntoTheMachinesAndTheClusters(t *testing.T) {
|
|
file, err := Parse([]byte(machineFile))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
local, cluster := Split(file)
|
|
for _, k := range []string{"listen", "agent_listen", "agent_insecure"} {
|
|
if _, ok := local[k]; !ok {
|
|
t.Errorf("%s is not the machine's", k)
|
|
}
|
|
}
|
|
if local["auth"].(map[string]any)["store"] == nil || cluster["auth"].(map[string]any)["store"] != nil {
|
|
t.Errorf("auth.store went to the cluster: local %v cluster %v", local["auth"], cluster["auth"])
|
|
}
|
|
if cluster["auth"].(map[string]any)["default_rpm"] != 60 {
|
|
t.Errorf("auth's policy stayed with the machine: %v", cluster["auth"])
|
|
}
|
|
if local["mirror"].(map[string]any)["api"] == nil || cluster["mirror"].(map[string]any)["update_check"] == nil {
|
|
t.Errorf("mirror split wrong: local %v cluster %v", local["mirror"], cluster["mirror"])
|
|
}
|
|
for _, k := range []string{"guard", "router"} {
|
|
if _, ok := cluster[k]; !ok {
|
|
t.Errorf("%s is not the cluster's", k)
|
|
}
|
|
}
|
|
if err := CheckCluster(cluster); err != nil {
|
|
t.Errorf("the cluster half is refused: %v", err)
|
|
}
|
|
if err := CheckCluster(file); err == nil || !strings.Contains(err.Error(), "auth.store") {
|
|
t.Errorf("a cluster document with a machine's keys: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestTheClustersSettingsTakeThePlaceOfTheFiles(t *testing.T) {
|
|
file, _ := Parse([]byte(machineFile))
|
|
cluster, _ := Parse([]byte("router:\n retries: 5\nauth:\n enabled: true\n default_rpm: 10\n"))
|
|
eff := Layer(file, cluster)
|
|
cfg, err := FromMap(eff)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg.Router.Retries != 5 || cfg.Auth.DefaultRPM != 10 {
|
|
t.Errorf("cluster values not in force: retries %d rpm %d", cfg.Router.Retries, cfg.Auth.DefaultRPM)
|
|
}
|
|
if cfg.Auth.Store != "/var/lib/llmgw/llmgw.db" || cfg.Mirror.API != "http://127.0.0.1:8082" || cfg.Listen != ":8080" {
|
|
t.Errorf("the machine's own keys lost: %+v", cfg.Auth)
|
|
}
|
|
if len(cfg.Guard.Policies) != 0 {
|
|
t.Error("the file's guard applies though the cluster has settings without one")
|
|
}
|
|
if got := Ignored(file); !slices.Contains(got, "guard") || !slices.Contains(got, "auth.default_rpm") ||
|
|
slices.Contains(got, "auth.store") {
|
|
t.Errorf("ignored: %v", got)
|
|
}
|
|
}
|
|
|
|
func TestChangedNamesWhatMoved(t *testing.T) {
|
|
a, _ := Parse([]byte(machineFile))
|
|
b, _ := Parse([]byte(strings.Replace(machineFile, "retries: 2", "retries: 3", 1)))
|
|
if got := Changed(a, b); !slices.Equal(got, []string{"router"}) {
|
|
t.Errorf("changed %v", got)
|
|
}
|
|
c, _ := Parse([]byte(strings.Replace(machineFile, "store: /var/lib/llmgw/llmgw.db", "store: /x.db", 1)))
|
|
if got := Changed(a, c); !slices.Equal(got, []string{"auth.store"}) {
|
|
t.Errorf("changed %v", got)
|
|
}
|
|
if got := Changed(a, a); len(got) != 0 {
|
|
t.Errorf("unchanged: %v", got)
|
|
}
|
|
}
|