1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//! End-to-end test for `CeraEngine::from_bundle_id` against the real
//! LiquidAI/LeapBundles catalog on HuggingFace.
//!
//! Proves the full chain: bundle ID + quant → canonical LeapBundles
//! manifest URL → fetch + cache manifest → parse → resolve primary-
//! model URL (which points back at the model's own HF repo) → mmap-
//! open → load engine. If any link silently produces junk (truncated
//! download, wrong URL, manifest-schema drift), the engine load fails
//! loudly.
//!
//! Gating: `#[ignore]` + `CERA_TEST_DOWNLOAD=1`. To opt in:
//!
//! ```sh
//! CERA_TEST_DOWNLOAD=1 cargo test -p cera --features remote \
//! --test bundle_from_id -- --ignored
//! ```
//!
//! Shares the `target/tmp/cera-test-models/` cache with
//! `shift_real_model` and `bundle_download` — the GGUF URL resolves to
//! the same file across all three, so repeat runs pay only a HEAD probe.
#![cfg(all(feature = "remote", feature = "mmap"))]
mod common;
use cera::bundle::BundleRepo;
use cera::engine::{BackendPreference, CeraEngine, EngineConfig};
#[test]
#[ignore = "downloads ~210 MB; set CERA_TEST_DOWNLOAD=1 and pass --ignored"]
fn from_bundle_id_loads_lfm2_q4_0() {
if std::env::var("CERA_TEST_DOWNLOAD").is_err() {
eprintln!("skipping: CERA_TEST_DOWNLOAD not set");
return;
}
let repo = BundleRepo::new(common::download::cache_dir());
let engine = CeraEngine::from_bundle_id(
"LFM2-350M-Extract-GGUF",
"Q4_0",
EngineConfig {
context_size: 128,
backend: BackendPreference::Cpu,
draft_model: None,
gpu_depthformer: false,
bundle_repo: Some(repo),
},
)
.expect("load engine from bundle id");
let meta = engine.metadata();
assert!(
meta.max_seq_len > 0,
"engine metadata missing max_seq_len: model parse failed silently"
);
assert!(
!meta.architecture.is_empty(),
"engine metadata missing architecture"
);
}
#[test]
fn from_bundle_id_fails_without_bundle_repo() {
// Fast negative test: no network, no feature gate needed at
// runtime. Catches the "did we remember to require bundle_repo?"
// regression cheaply.
// Can't use `.expect_err()` because `CeraEngine` holds a
// `Box<dyn Model>` and therefore doesn't derive `Debug`.
let result = CeraEngine::from_bundle_id(
"LFM2-350M-Extract-GGUF",
"Q4_0",
EngineConfig {
context_size: 128,
backend: BackendPreference::Cpu,
draft_model: None,
gpu_depthformer: false,
bundle_repo: None,
},
);
match result {
Ok(_) => panic!("missing bundle_repo must be an error, but got Ok"),
Err(e) => {
let msg = format!("{e}");
assert!(
msg.contains("bundle_repo"),
"error should name the missing config field; got `{msg}`"
);
}
}
}