fix(llm): scope LLM module to where it is actually reachable
All checks were successful
CI / Linux x86_64 (Forgejo) (push) Successful in 1m33s
All checks were successful
CI / Linux x86_64 (Forgejo) (push) Successful in 1m33s
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 <sf@flemming.it>
This commit is contained in:
parent
a50e99d248
commit
00fad982d6
2 changed files with 36 additions and 6 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
37
src/llm.rs
37
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 =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue