candding 0.1.0

Pure candle embeddings for Rust with no ONNX: dense, sparse, multi-vector and rerank models today, image models on the roadmap
Documentation
use std::fs;

use tempfile::tempdir;

use super::ID;
use super::REPO;
use super::SHA;
use super::config;
use super::hub;
use super::layout::blob_name;
use super::server::Server;
use crate::hub::download::fetch;
use crate::hub::download::listing::ListedFile;
use crate::hub::download::verify;
use crate::registry::WeightsFormat;

#[cfg(unix)]
#[test]
fn a_pointer_linked_outside_the_cache_is_replaced_and_its_target_kept() {
  let root = tempdir().unwrap();
  let own = root.path().join("finetune/model.safetensors");
  fs::create_dir_all(own.parent().unwrap()).unwrap();
  fs::write(&own, "the user's own weights").unwrap();
  let cache = root.path().join("cache");
  let snapshot = cache.join(REPO).join("snapshots").join(SHA);
  fs::create_dir_all(&snapshot).unwrap();
  std::os::unix::fs::symlink(&own, snapshot.join("model.safetensors")).unwrap();
  let server = Server::start(hub);
  fetch(
    &config(&cache, &server.url),
    ID,
    "main",
    WeightsFormat::Safetensors,
  )
  .unwrap();
  assert_eq!(fs::read_to_string(&own).unwrap(), "the user's own weights");
  let pointer = fs::read_link(snapshot.join("model.safetensors")).unwrap();
  let blob = format!("../../blobs/{}", blob_name("model.safetensors"));
  assert_eq!(pointer.to_string_lossy(), blob);
}

#[test]
fn a_directory_where_a_file_belongs_is_never_intact() {
  let dir = tempdir().unwrap();
  let pointer = dir.path().join("model.safetensors");
  fs::create_dir(&pointer).unwrap();
  let file = ListedFile {
    path: "model.safetensors".to_string(),
    size: fs::metadata(&pointer).unwrap().len(),
    oid: "an LFS pointer".to_string(),
    in_git: false,
  };
  assert!(!verify::intact(&pointer, &file).unwrap());
}