package engines import ( "slices" "strings" "testing" ) func TestAVLLMShardWithKVEventsPublishesToTheAgentOnLoopback(t *testing.T) { s := singleNodeSpec() s.Profile.KVEvents = true s.KVEventsPort = 5999 s.Profile.Args = []string{"--max-model-len", "8192"} cmd := buildOne(t, &VLLM{}, s) i := slices.Index(cmd.Args, "--kv-events-config") if i < 0 || !strings.Contains(cmd.Args[i+1], `"endpoint":"tcp://127.0.0.1:5999"`) { t.Fatalf("args %v should name the agent's loopback port", cmd.Args) } if j := slices.Index(cmd.Args, "--prefix-caching-hash-algo"); j < 0 || cmd.Args[j+1] != "sha256_cbor" { t.Fatalf("args %v should pin the hashing the router computes", cmd.Args) } if slices.Index(cmd.Args, "--max-model-len") < i { t.Fatal("profile arguments come last, so an operator can still override") } if !slices.Contains(cmd.Env, "PYTHONHASHSEED=1729") { t.Fatalf("env %v should fix the hash seed", cmd.Env) } } func TestNoKVEventsWithoutAPortOrOffTheLeader(t *testing.T) { s := singleNodeSpec() s.Profile.KVEvents = true // but the agent could not listen if cmd := buildOne(t, &VLLM{}, s); slices.Contains(cmd.Args, "--kv-events-config") { t.Fatal("an engine told to publish where nobody listens only fills a queue") } w := multiNodeSpec(1) w.Profile.KVEvents, w.KVEventsPort = true, 5999 if cmd := buildEngine(t, &VLLM{}, w); slices.Contains(cmd.Args, "--kv-events-config") { t.Fatal("a headless worker has no scheduler to publish from") } off := singleNodeSpec() off.KVEventsPort = 5999 if cmd := buildOne(t, &VLLM{}, off); slices.Contains(cmd.Args, "--kv-events-config") { t.Fatal("kv_events is opt-in") } }