package agent import ( "os" "slices" "testing" llmgwv1 "gitea.mynodes.xyz/ilker/llmgw/api/gen/llmgw/v1" ) func TestAnAgentConfigNeedsOnlyWhereTheControlPlaneIs(t *testing.T) { // Every node carried its own name, its own address and the same two // directories written out by hand, so no two agent files were alike and a // copy taken from one node registered the next as the first. cfg := Config{Server: "127.0.0.1:7443"} if err := cfg.normalize(); err != nil { t.Fatal(err) } host, _ := os.Hostname() if cfg.NodeID != host || cfg.Hostname != host { t.Errorf("node_id %q, hostname %q; expected the machine's name %q", cfg.NodeID, cfg.Hostname, host) } if cfg.MgmtAddr != "127.0.0.1" { t.Errorf("mgmt_addr %q, expected the address on the route to the control plane", cfg.MgmtAddr) } if cfg.WeightsCache != DefaultWeightsCache { t.Errorf("weights land in %q", cfg.WeightsCache) } if !slices.Contains(cfg.ModelDirs, cfg.WeightsCache) { t.Errorf("the download directory %q is not looked in: %v", cfg.WeightsCache, cfg.ModelDirs) } } func TestWhatIsWrittenStillWins(t *testing.T) { cfg := Config{ Server: "127.0.0.1:7443", NodeID: "gpu-a-01", MgmtAddr: "10.9.9.9", ModelDirs: []string{"/lustre/models"}, WeightsCache: "/scratch/w", } if err := cfg.normalize(); err != nil { t.Fatal(err) } if cfg.NodeID != "gpu-a-01" || cfg.MgmtAddr != "10.9.9.9" { t.Errorf("configured identity overridden: %q %q", cfg.NodeID, cfg.MgmtAddr) } if !slices.Equal(cfg.ModelDirs, []string{"/lustre/models", "/scratch/w"}) { t.Errorf("model dirs %v", cfg.ModelDirs) } } func TestAHeartbeatSaysWhenTheEnginesChanged(t *testing.T) { cfg := Config{Server: "127.0.0.1:7443", NodeID: "n1", WeightsCache: t.TempDir()} cfg.Superv.WorkDir = t.TempDir() a, err := New(cfg, nil, nil) if err != nil { t.Fatal(err) } engines := func(m *llmgwv1.AgentMessage) *llmgwv1.Heartbeat { return m.GetHeartbeat() } a.mu.Lock() a.engineVers = map[string]string{"llamacpp": "unknown"} a.enginesSent = enginesFingerprint(a.engineVers) a.mu.Unlock() if hb := engines(a.heartbeat()); hb.GetEnginesChanged() { t.Errorf("unchanged engines were resent") } a.mu.Lock() a.engineVers = map[string]string{"llamacpp": "unknown", "vllm": "unknown"} a.mu.Unlock() hb := engines(a.heartbeat()) if !hb.GetEnginesChanged() || len(hb.GetEngineVersions()) != 2 { t.Errorf("an installed engine was not reported: %v", hb.GetEngineVersions()) } if engines(a.heartbeat()).GetEnginesChanged() { t.Errorf("reported again on the next heartbeat") } }