From 00fad982d624b3d64ac92e146ee2dd4f7f8091b6 Mon Sep 17 00:00:00 2001 From: flemming-it Date: Thu, 30 Apr 2026 10:04:08 +0200 Subject: [PATCH] fix(llm): scope LLM module to where it is actually reachable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The dead-code lint Stefan flagged was a real signal — pretending otherwise with #[allow(dead_code)] would have hidden a future genuinely-dead helper. Two structural changes: 1. Gate `mod llm;` in lib.rs to `cfg(any(target_arch = "wasm32", test))`. The LLM client only has callers on wasm32 (WakiClient) and in the host test harness; on a host non-test build the module is genuinely unreachable, so we don't compile it. 2. Add a test that covers every LlmError Display message so the `Status` and `MissingInput` variants are constructed in the test build (they were used by WakiClient on wasm32 but never touched by host tests). The test doubles as a regression net for the user-facing error strings. 18 host tests green (was 17). Drops the previous allow(dead_code) escape hatch entirely. Signed-off-by: flemming-it --- src/lib.rs | 5 +++++ src/llm.rs | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 6 deletions(-) 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 =