use ignition_core::module::GIT_MODULE;
use ignition_core::module::fetch::{ArtifactSource, FetchPolicy, ModuleFeed};
const KNOWN_BYTES: u64 = 7_704_578;
const KNOWN_DIGEST: &str = "b74070346e587b1e1c14ff5093cc70625f7bfa14c2d24b24e7a0888a619b33eb";
fn live_enabled() -> bool {
std::env::var("IGNITION_LIVE_MODULE_FETCH").ok().as_deref() == Some("1")
}
fn skip(message: &str) {
eprintln!("skipping: {message}");
}
#[tokio::test]
#[ignore = "opt-in: set IGNITION_LIVE_MODULE_FETCH=1 to fetch the real release artifact"]
async fn live_fetches_and_verifies_git_module() {
if !live_enabled() {
skip("IGNITION_LIVE_MODULE_FETCH not set to 1");
return;
}
let cache_root = tempfile::tempdir().expect("tempdir");
let feed = ModuleFeed::github().expect("feed builds");
let fetched = feed
.fetch_and_verify(
&GIT_MODULE,
"2.3.4",
cache_root.path(),
FetchPolicy::CacheFirst,
)
.await
.expect("live fetch of the real Git-2.3.4-signed.modl must succeed");
assert_eq!(
fetched.source,
ArtifactSource::Download,
"the first call against an empty cache must download"
);
assert_eq!(
fetched.bytes, KNOWN_BYTES,
"artifact size disagrees with the recorded identity — the fixture may have drifted"
);
assert_eq!(
fetched.digest_sha256, KNOWN_DIGEST,
"digest disagrees with the recorded identity — the fixture may have drifted"
);
assert_eq!(
fetched.path.file_name().and_then(|name| name.to_str()),
Some(format!("2.3.4-{KNOWN_DIGEST}.modl").as_str()),
"persisted filename must carry the digest"
);
assert!(fetched.path.exists(), "persisted file must exist");
let second = feed
.fetch_and_verify(
&GIT_MODULE,
"2.3.4",
cache_root.path(),
FetchPolicy::CacheFirst,
)
.await
.expect("second fetch must serve from cache");
assert_eq!(second.source, ArtifactSource::Cache);
assert_eq!(second.digest_sha256, KNOWN_DIGEST);
assert_eq!(second.path, fetched.path);
}