diff --git a/.crumb b/.crumb index 5af7743d..b8601086 100644 --- a/.crumb +++ b/.crumb @@ -125,14 +125,14 @@ } ], "children_root": "sha256:9336db0a6669d32e68cee16900dfe9fc9e27304c00dc48daee6578317bf57d2c", - "compiled_at": "2026-10-31T05:29:08Z", + "compiled_at": "2026-10-31T05:53:04Z", "compiler": "crumb-compile/1", - "digest": "sha256:568c0cb1be7be888227411530811d7bebf9e62473ad2ffde25b65f7f5c69f006", + "digest": "sha256:7133cd75c7085a708d7b9d83f05e280ca63893285c11692e093465d6f2fa463f", "evidence_files": 3602, "evidence_root": "sha256:1b8069934a4cc67803874ebd2ad5de32671fae5ccce1a3ea70aeb532fe8ea86b", "files": 8117, - "generated_at_commit": "9eebe089902cb27c15ca878881bb36756cd45fd2", - "source_tree": "sha256:9d392cd752f0900d75cf181610c112b24183259e26694da3f475797aeccda8b6" + "generated_at_commit": "eb22bc7f74e0a5d1da4c480c6818939b8a5df539", + "source_tree": "sha256:46093659b54787818b1575947e90381bba9cbbec6e8f945a5d2b3b5de27510d7" } }, "history": [], diff --git a/crates/aien-inference-abi/tests/tinyllama_parity.rs b/crates/aien-inference-abi/tests/tinyllama_parity.rs index e5286025..30c3d651 100644 --- a/crates/aien-inference-abi/tests/tinyllama_parity.rs +++ b/crates/aien-inference-abi/tests/tinyllama_parity.rs @@ -73,10 +73,22 @@ fn find_fixtures_dir() -> PathBuf { manifest_dir.join("fixtures") } +/// The default Hugging Face cache snapshot entry for the checkpoint, unresolved. It is a symlink +/// into the cache's `blobs/` store when the model is cached. +fn default_snapshot_entry() -> PathBuf { + PathBuf::from(format!("{}/.cache/huggingface/hub/models--TinyLlama--TinyLlama-1.1B-Chat-v1.0/snapshots/fe8a4ea1ffedaf415f4da2f062534de366a451e6/model.safetensors", std::env::var("HOME").unwrap_or_default())) +} + +/// The checkpoint to load, resolved to a regular file. The loader refuses symlinked checkpoint +/// files on purpose (`loader_still_refuses_a_symlinked_checkpoint` pins that refusal), so the +/// harness resolves its own trusted paths before loading. fn find_model_checkpoint_path() -> Option { + // An explicit TINYLLAMA_MODEL_PATH is resolved the same way as the default snapshot entry: + // pointing it at a snapshot entry (or any symlink to the checkpoint) would otherwise hit the + // loader's symlink refusal. canonicalize fails when the path is absent or dangling, matching + // the old exists() skip. if let Ok(p) = std::env::var("TINYLLAMA_MODEL_PATH") { - let path = PathBuf::from(p); - if path.exists() { + if let Ok(path) = std::fs::canonicalize(PathBuf::from(p)) { return Some(path); } } @@ -85,7 +97,7 @@ fn find_model_checkpoint_path() -> Option { // checkpoint loader refuses symlinks by design. Resolve the snapshot entry to its blob so // the loader receives the regular file it requires; the loader opens only this one path. // canonicalize fails when the entry is absent or dangling, matching the old exists() skip. - let default_snap = PathBuf::from(format!("{}/.cache/huggingface/hub/models--TinyLlama--TinyLlama-1.1B-Chat-v1.0/snapshots/fe8a4ea1ffedaf415f4da2f062534de366a451e6/model.safetensors", std::env::var("HOME").unwrap_or_default())); + let default_snap = default_snapshot_entry(); if let Ok(blob) = std::fs::canonicalize(&default_snap) { return Some(blob); } @@ -838,3 +850,38 @@ fn test_all_5_stages_parity_suite() { test_stage4_logit_and_greedy_parity(); test_stage5_multi_step_generation_parity(); } + +/// Negative control for the path resolution above: the loader itself still refuses a checkpoint +/// reached through a symlink: a fresh one, plus the Hugging Face snapshot entry and an explicit +/// TINYLLAMA_MODEL_PATH whenever either is a symlink. +#[cfg(unix)] +#[test] +fn loader_still_refuses_a_symlinked_checkpoint() { + let target = + find_model_checkpoint_path().unwrap_or_else(|| find_fixtures_dir().join("tokenizer.json")); + let target = std::fs::canonicalize(&target).expect("symlink target must exist"); + let dir = std::env::temp_dir().join(format!("tinyllama-symlink-{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let link = dir.join("model.safetensors"); + let _ = std::fs::remove_file(&link); + std::os::unix::fs::symlink(&target, &link).unwrap(); + let mut links = vec![link]; + let env_entry = std::env::var("TINYLLAMA_MODEL_PATH") + .ok() + .map(PathBuf::from); + for entry in env_entry.into_iter().chain([default_snapshot_entry()]) { + if std::fs::symlink_metadata(&entry).is_ok_and(|m| m.file_type().is_symlink()) { + links.push(entry); + } + } + for link in &links { + match load_safetensors_checkpoint(link) { + Ok(_) => panic!("loader accepted symlinked checkpoint {}", link.display()), + Err(e) => { + let e = format!("{e:?}"); + assert!(e.contains("symlink"), "refusal names the symlink: {e}"); + } + } + } + std::fs::remove_dir_all(&dir).unwrap(); +}