package engines import ( "slices" "testing" ) func TestAModelDownloadedByTheEngineIsReadAsSafetensorsOnly(t *testing.T) { for path, want := range map[string]bool{ "Qwen/Qwen2.5-7B-Instruct": true, "/var/lib/llmgw/weights/abc/": false, "./local": false, "http://m/q/v/": false, "q.gguf": false, } { got := slices.Contains(safetensorsOnly(Profile{ModelPath: path}), "safetensors") if got != want { t.Errorf("%q: safetensors only = %v, want %v", path, got, want) } } if len(safetensorsOnly(Profile{ModelPath: "Qwen/Qwen2.5-7B-Instruct", AllowPickle: true})) != 0 { t.Error("allow_pickle still forced safetensors") } } func TestAForbiddenFlagIsKnownHoweverItIsSpelled(t *testing.T) { for engine, args := range map[string][]string{ "vllm": {"--trust_remote_code"}, "sglang": {"--load-format", "pt"}, } { if UnsafeArgs(engine, args) == nil { t.Errorf("%s %v was let through", engine, args) } } for _, a := range [][]string{{"--load_format", "pt"}, {"--trust-remote"}, {"--load-form=pt"}} { if UnsafeArgs("vllm", a) == nil { t.Errorf("vllm %v was let through", a) } } // What is not one of them, nor the start of one, still passes. for _, a := range [][]string{{"--max-model-len", "8192"}, {"--tokenizer-mode", "mistral"}, {"--gpu-memory-utilization=0.9"}} { if err := UnsafeArgs("vllm", a); err != nil { t.Errorf("vllm %v was refused: %v", a, err) } } // Short flags are matched as written; llama.cpp takes no abbreviations, // so its --chat-template is not taken for --chat-template-file. for _, a := range [][]string{{"-m", "x"}, {"-hf", "o/r"}, {"-mu", "http://x"}} { if UnsafeArgs("llamacpp", a) == nil { t.Errorf("llamacpp %v was let through", a) } } if err := UnsafeArgs("llamacpp", []string{"--chat-template", "chatml"}); err != nil { t.Errorf("llama.cpp's own --chat-template was refused: %v", err) } // ComfyUI's argparse reads --li as --listen. if UnsafeArgs("comfyui", []string{"--li", "0.0.0.0"}) == nil { t.Error("comfyui --li was let through") } }