Files
leleka/crates/deploy/src/steps/tests.rs
T
Pavlo Ratushnyi 84880a1a6d STRA-338 S12a (fix): rustfmt the moved test files of the format-gated crates
The dedent by four spaces changed how rustfmt wraps some test lines; the 25 affected tests.rs files (strata-control, desktop-core, runtime-client, deploy, gateway-text and the strict crates) are formatted so cargo fmt --check stays clean for the crates that CI gates on. Only test files change.
2026-11-05 15:00:36 +01:00

104 lines
3.6 KiB
Rust

//! Unit tests of this module (moved out of the file by STRA-338; the test ids are unchanged).
use super::*;
fn temp(name: &str) -> PathBuf {
let dir = std::env::temp_dir().join(format!("leleka-steps-{}-{name}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
dir
}
#[test]
fn stamps_track_size_and_mtime() {
let dir = temp("stamp");
let (a, b) = (dir.join("a.gguf"), dir.join("b.gguf"));
std::fs::write(&a, b"aaaa").unwrap();
std::fs::write(&b, b"bb").unwrap();
let stamp = dir.join("model.json");
assert!(!stamp_current(&stamp, &[a.clone(), b.clone()]));
write_stamp(&stamp, "test", &[a.clone(), b.clone()]).unwrap();
assert!(stamp_current(&stamp, &[a.clone(), b.clone()]));
std::fs::write(&b, b"bbb").unwrap();
assert!(
!stamp_current(&stamp, &[a.clone(), b.clone()]),
"a changed size must invalidate the stamp"
);
assert!(!stamp_current(&stamp, std::slice::from_ref(&a)));
std::fs::remove_file(&a).unwrap();
assert!(!stamp_current(&stamp, &[a, b]));
std::fs::remove_dir_all(dir).unwrap();
}
#[test]
fn mtp_pack_root_is_found_in_a_subdirectory() {
let dir = temp("mtp");
let nested = dir.join("data/mtp-rt");
std::fs::create_dir_all(&nested).unwrap();
assert_eq!(find_pack_root(&dir), None);
for name in MTP_FILES {
std::fs::write(nested.join(name), b"x").unwrap();
}
assert_eq!(find_pack_root(&dir), Some(nested));
std::fs::remove_dir_all(dir).unwrap();
}
/// Live: the real download path (curl, https only, size cap) through `provision` against the pinned upstream sources.
/// `cargo test -p leleka-deploy --lib -- --ignored provisions_the_pinned_table_from_upstream`
#[test]
#[ignore = "network"]
fn provisions_the_pinned_table_from_upstream() {
use crate::expert_profile::{
FileState, Outcome, PINNED_BYTES, PINNED_SHA256, Request, SOURCES, file_state, provision,
};
let dir = temp("live");
let dest = dir.join("data").join("expert-profile.bin");
let log = dir.join("install.log");
let tool = "curl";
let request = Request {
dest: &dest,
expected: PINNED_SHA256,
local: None,
embedded: None,
sources: &SOURCES,
};
let outcome = provision(&request, &mut |url, part| {
download_small(tool, url, part, &log)
})
.unwrap();
assert!(matches!(outcome, Outcome::Installed { .. }), "{outcome:?}");
assert_eq!(file_state(&dest, PINNED_SHA256), FileState::Valid);
assert_eq!(std::fs::metadata(&dest).unwrap().len(), PINNED_BYTES);
assert!(!dest.with_extension("bin.part").exists());
// A source that answers with something else fails closed: an https URL that is not the table.
let other = dir.join("other.bin");
let bad = Request {
dest: &other,
expected: PINNED_SHA256,
local: None,
embedded: None,
sources: &[
"https://raw.githubusercontent.com/Niko1221/Strata/41cf05a06a25dd29103b7b27a2279a3f60c21876/LICENSE",
],
};
let error =
provision(&bad, &mut |url, part| download_small(tool, url, part, &log)).unwrap_err();
assert!(
error.contains("is not the expected") && !other.exists(),
"{error}"
);
std::fs::remove_dir_all(dir).unwrap();
}
#[test]
fn sha256_of_a_file() {
let dir = temp("sha");
let file = dir.join("f");
std::fs::write(&file, b"abc").unwrap();
assert_eq!(
sha256_file(&file).unwrap(),
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
);
std::fs::remove_dir_all(dir).unwrap();
}