use kernel::install::InstallProviderId;
use kernel::install::file_selection::{file_extension, is_weight_path};
use kernel::install::plan::{InstallPlan, InstallPlanFile};
#[test]
fn file_extension_takes_the_last_dot_and_lowercases() {
assert_eq!(file_extension("model.SafeTensors"), "safetensors");
assert_eq!(file_extension("a/b/model.gguf"), "gguf");
assert_eq!(file_extension("archive.tar.gz"), "gz");
assert_eq!(file_extension("README"), "");
assert_eq!(file_extension(".gitignore"), "");
assert_eq!(file_extension("dir/plainfile"), "");
assert_eq!(file_extension("file."), "");
assert_eq!(file_extension("dir/.hidden"), "hidden");
}
#[test]
fn is_weight_path_recognizes_weight_extensions() {
for path in [
"model.safetensors",
"model.gguf",
"pytorch_model.bin",
"sd.ckpt",
"weights.pt",
"weights.pth",
"shard/00001.gguf",
"model.GGUF",
] {
assert!(is_weight_path(path), "{path} should be a weight");
}
for path in ["config.json", "README.md", "tokenizer.model.txt", "noext"] {
assert!(!is_weight_path(path), "{path} should not be a weight");
}
}
#[test]
fn plan_file_reports_whether_it_is_a_weight() {
assert!(InstallPlanFile::new("model.gguf", Some(1024)).is_weight());
assert!(!InstallPlanFile::new("config.json", None).is_weight());
}
#[test]
fn install_plan_new_defaults_the_optional_fields() {
let plan = InstallPlan::new(
InstallProviderId::huggingface(),
"org/model",
"Org Model",
"/cache/org/model",
);
assert_eq!(plan.provider, InstallProviderId::huggingface());
assert_eq!(plan.reference, "org/model");
assert_eq!(plan.display_name, "Org Model");
assert_eq!(plan.destination, "/cache/org/model");
assert_eq!(plan.revision, None);
assert!(plan.files.is_empty());
assert_eq!(plan.total_bytes, None);
assert_eq!(plan.remaining_bytes, None);
assert!(!plan.requires_auth);
}