package cli import ( "bytes" "context" "encoding/binary" "net/http" "net/http/httptest" "strings" "testing" "time" "gitea.mynodes.xyz/ilker/llmgw/internal/control/catalog" ) func ggufAt(t *testing.T, arch string) string { t.Helper() var b bytes.Buffer w := func(v any) { _ = binary.Write(&b, binary.LittleEndian, v) } str := func(s string) { w(uint64(len(s))); b.WriteString(s) } b.WriteString("GGUF") w(uint32(3)) w(uint64(0)) w(uint64(1)) str("general.architecture") w(uint32(8)) str(arch) body := b.Bytes() srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { http.ServeContent(rw, r, "m.gguf", time.Time{}, bytes.NewReader(body)) })) t.Cleanup(srv.Close) return srv.URL + "/m.gguf" } func TestAModelTheNodesCannotLoadIsNotCatalogued(t *testing.T) { check := servableCheck("b10991") llama := []catalog.Profile{{Name: "cpu", Engine: "llamacpp"}} err := check(context.Background(), catalog.Model{Name: "kev", Source: ggufAt(t, "ggmlc"), Profiles: llama}) if err == nil || !strings.Contains(err.Error(), "ggmlc") { t.Errorf("a ggmlc model was accepted: %v", err) } if err := check(context.Background(), catalog.Model{Name: "q", Source: ggufAt(t, "qwen2"), Profiles: llama}); err != nil { t.Errorf("a qwen2 model was refused: %v", err) } // Not llama.cpp's to judge: vLLM reads a repository, not a GGUF header. vllm := []catalog.Profile{{Name: "gpu", Engine: "vllm"}} if err := check(context.Background(), catalog.Model{Name: "v", Source: ggufAt(t, "ggmlc"), Profiles: vllm}); err != nil { t.Errorf("a vLLM profile was judged by llama.cpp's list: %v", err) } }