package adminapi import ( "context" "slices" "testing" "gitea.mynodes.xyz/ilker/llmgw/internal/control/catalog" "gitea.mynodes.xyz/ilker/llmgw/internal/mirror" ) type purgeMirrorFake struct { held []mirror.Status removed []string } func (f *purgeMirrorFake) List(context.Context) (mirror.ModelsResponse, error) { return mirror.ModelsResponse{Base: "http://m:8081", Models: f.held}, nil } func (f *purgeMirrorFake) Remove(_ context.Context, model, version string) ([]string, error) { f.removed = append(f.removed, model+"/"+version) return nil, nil } func TestAPurgeRemovesEveryVersionOfTheModelButWhatAnotherUses(t *testing.T) { f := &purgeMirrorFake{held: []mirror.Status{ {Model: "qwen", Version: "v2", File: "a.gguf"}, {Model: "qwen", Version: "v2", File: "b.gguf"}, {Model: "qwen", Version: "v1", File: "a.gguf"}, {Model: "qwen", Version: "v3", File: "a.gguf"}, {Model: "other", Version: "v1", File: "o.gguf"}, {Model: "lora", Version: "t1", File: "l.gguf"}, }} m := catalog.Model{Name: "qwen", Source: "http://m:8081/qwen/v2/a.gguf", Adapters: []catalog.Adapter{{Name: "tone", Source: "http://m:8081/lora/t1/l.gguf"}}} // The canary runs v3: it stays. others := []catalog.Model{{Name: "qwen-canary", Source: "http://other-mirror:8081/qwen/v3/a.gguf"}, {Name: "other", Source: "http://m:8081/other/v1/o.gguf"}} removed, kept, note := purgeFromMirror(t.Context(), f, purgeSources(m), others) if note != "" { t.Fatal(note) } if !slices.Equal(removed, []string{"lora/t1", "qwen/v1", "qwen/v2"}) || !slices.Equal(kept, []string{"qwen/v3"}) { t.Errorf("removed %v, kept %v", removed, kept) } if slices.Contains(f.removed, "other/v1") || len(f.removed) != 3 { t.Errorf("asked to remove %v", f.removed) } } func TestOnlyAMirrorsAddressNamesAPlaceOnIt(t *testing.T) { for src, want := range map[string]string{ "http://10.0.0.146:8081/qwen/abc/q4.gguf": "qwen/abc", "https://huggingface.co/o/r/resolve/main/q4.gguf": "", "/srv/models/q4.gguf": "", "Qwen/Qwen2.5-7B": "", } { model, version, ok := mirrorPlace(src) got := "" if ok { got = model + "/" + version } if got != want { t.Errorf("%s: %q, want %q", src, got, want) } } }