diff --git a/src/lib.rs b/src/lib.rs index eae652c..7f6ba6e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,11 @@ // ships a fix. #![cfg_attr(target_arch = "wasm32", allow(unsafe_op_in_unsafe_fn))] +// The LLM client is only used by the wasm32 production code +// (WakiClient) and by the host-side test harness. Gating the +// module declaration keeps the host non-test build honest about +// what is actually reachable on each target. +#[cfg(any(target_arch = "wasm32", test))] mod llm; mod plan; diff --git a/src/llm.rs b/src/llm.rs index 7876fef..735cff0 100644 --- a/src/llm.rs +++ b/src/llm.rs @@ -6,12 +6,13 @@ //! All HTTP I/O lives behind a `LlmClient` trait so unit tests can //! exercise the prompt-building and response-parsing logic on the //! host without making real network calls. - -// On the host build, the LLM functions only have callers in -// #[cfg(test)] code; the production caller (WakiClient) is -// wasm32-only. Suppress dead-code warnings for the non-wasm32 -// non-test build that cargo runs as part of --all-targets. -#![cfg_attr(not(target_arch = "wasm32"), allow(dead_code))] +//! +//! This module is only compiled when the production caller +//! (wasm32) or the host test harness needs it — gated at the +//! `mod llm;` declaration in `lib.rs`. That way the host +//! `cargo build --all-targets` does not flag the helpers as +//! dead code; they genuinely have no host-side caller outside +//! `#[cfg(test)]`. use serde::Serialize; @@ -228,6 +229,30 @@ mod tests { assert_eq!(messages[1]["content"], "user-text"); } + #[test] + fn each_error_variant_renders_a_useful_message() { + // Documents the expected Display output for every variant + // and ensures none drift to silent. Also exercises Status + // and MissingInput, which the WakiClient path constructs + // but tests do not otherwise reach. + assert!( + LlmError::MissingInput("llm_model") + .to_string() + .contains("llm_model") + ); + assert!( + LlmError::Http("connection refused".into()) + .to_string() + .contains("connection refused") + ); + assert!(LlmError::Status(503).to_string().contains("503")); + assert!( + LlmError::Decode("bad json".into()) + .to_string() + .contains("bad json") + ); + } + #[test] fn extracts_content_from_well_formed_response() { let body =