package catalog import ( "encoding/json" "strings" "testing" "time" ) func TestAnEnvironmentOfTwoGetsOneHiddenEntryThatServesBoth(t *testing.T) { // flux and a mesh model on one card took turns, each loading ComfyUI // from nothing; in one environment one replica answers for both. flux := comfyModel("/w/flux.safetensors", &ComfyUI{Environment: "art", Workflow: "flux-schnell"}) flux.Scaling = Scaling{Max: 1, IdleTimeout: 15 * time.Minute} sf3d := inEnv("sf3d", "art", "/w/sf3d/", CustomNode{Repo: "https://example.com/sf3d", Commit: commitA}) sf3d.ComfyUI.HuggingFaceRepo = "stabilityai/stable-fast-3d" sf3d.ComfyUI.Checkpoint = "model.safetensors" sf3d.Scaling = Scaling{Max: 1, IdleTimeout: 10 * time.Minute} cat, err := New([]Model{flux, sf3d, inEnv("alone", "solo", "/w/alone.ckpt")}) if err != nil { t.Fatal(err) } host, ok := cat.SharedBy("sf3d") if !ok || host != "comfyui-env-art" { t.Fatalf("sf3d shared by %q %v", host, ok) } if _, ok := cat.SharedBy("alone"); ok { t.Error("an environment of one got a hidden entry") } em, _ := cat.Resolve(host) if !em.IsEnvironment() || em.MakesImages() || em.MakesMeshes() || em.Scaling.IdleTimeout != 15*time.Minute || len(em.Shared.Members) != 2 || em.Shared.Members[1].HFRepo != "stabilityai/stable-fast-3d" { t.Errorf("entry %+v", em) } p, ok := em.EngineProfile(em.Profiles[0].Name) if !ok { t.Fatal("no engine profile") } var ms []map[string]string if err := json.Unmarshal([]byte(p.Env[SharedModelsEnv]), &ms); err != nil || len(ms) != 2 || ms[1]["source"] != "/w/sf3d/" { t.Errorf("members for the agent %q %v", p.Env[SharedModelsEnv], err) } if !strings.Contains(p.Env[NodesEnv], "sf3d") { t.Errorf("nodes %q", p.Env[NodesEnv]) } // A catalog built again from its own models is the same catalog. again, err := New(cat.Models()) if err != nil || len(again.Models()) != len(cat.Models()) { t.Errorf("rebuilt: %v, %d models vs %d", err, len(again.Models()), len(cat.Models())) } }