//! L3 on the **hybrid safetensors families** — NemotronH / Granite-4.0-H / //! Falcon-H1 behind one auto-detecting backend. //! //! Proves the wave-57/58 surface end to end: a real Mamba2/attention hybrid, //! loaded from its BF16 safetensors checkpoint and driven through //! `hybrid_lm::generate`, closes a Joule Code cascade at tier L3 with a //! content-addressed `CodingOp` and a joules-class receipt. //! //! `#[ignore]` because it needs a real checkpoint on disk. Run with: //! //! JOULE_HYBRID=/path/to/snapshot-dir \ //! cargo test -p l3-jouleclaw-binding --release --test hybrid_l3 -- --ignored --nocapture //! //! (defaults to the Falcon-H1-0.5B-Instruct snapshot on the external drive — //! the smallest of the hybrid set.) use joule_code_cascade::{Cascade, L0Cache, Request, Stage}; use joule_code_schema::Tier; use jouleclaw_llm::{LlmBackend, LlmRequest}; use l3_jouleclaw_binding::hybrid_backend::HybridBackend; use l3_jouleclaw_binding::jouleclaw_l3_stage; fn snapshot_dir() -> String { std::env::var("JOULE_HYBRID").unwrap_or_else(|_| { "/Volumes/macos_4TB_external_1/hf_hub/falcon-h1-0.5b-instruct".to_string() }) } #[test] #[ignore] fn hybrid_backend_completes_in_process() { let backend = HybridBackend::from_dir(snapshot_dir()).expect("load hybrid checkpoint"); eprintln!("model: {}", backend.model_name()); let mut req = LlmRequest::from_prompt("The capital of France is", 6); req.temperature = 0.0; // greedy — deterministic let resp = backend.complete(&req).expect("complete"); eprintln!( " in={} out={} text={:?}", resp.input_tokens, resp.output_tokens, resp.text ); assert!(resp.input_tokens > 0, "prompt tokenized"); assert!(resp.output_tokens > 0, "tokens generated"); assert!( resp.text.contains("Paris"), "smoke answer should mention Paris, got {:?}", resp.text ); // Energy contract: with the fabric on, the call reports // the attribution ledger's projection, graded by its // weakest priced input; otherwise honest None. match resp.energy_joules { Some(j) => { assert!(j > 0.0); let window = jouleclaw_loader_gguf::fabric_dispatch::ledger_snapshot(); let grade = l3_jouleclaw_binding::projection_grade(&window); eprintln!(" fabric-priced energy: {j:.1} J ({grade:?})"); } None => eprintln!(" energy: None (fabric off — honest)"), } } #[test] #[ignore] fn hybrid_backend_closes_the_cascade_at_l3() { let backend = HybridBackend::from_dir(snapshot_dir()).expect("load hybrid checkpoint"); let cascade = Cascade::new([ Box::new(L0Cache::new()) as Box, Box::new(jouleclaw_l3_stage(Box::new(backend))), ]); let req = Request { prior: "tree-hash".into(), intent: "Summarize: the capital of France is".into(), }; let res = cascade.resolve(&req).expect("L3 closes"); assert_eq!(res.receipt.tier, Tier::L3); let op = res.op.expect("coding op produced"); assert_eq!(op.tier, Tier::L3); assert!(!op.edits.is_empty()); eprintln!( " op_id={} estimated_uj={}", op.op_id().unwrap(), res.receipt.energy.estimated_uj ); }