diff --git a/crates/higgs-engine/src/engine.rs b/crates/higgs-engine/src/engine.rs index 53898829..bf949cd5 100644 --- a/crates/higgs-engine/src/engine.rs +++ b/crates/higgs-engine/src/engine.rs @@ -66,7 +66,7 @@ mod tests { completion_tokens: 0, token_logprobs: None, }; - assert!(output.text.is_empty()); + assert_eq!(output.text, ""); assert_eq!(output.prompt_tokens, 0); assert_eq!(output.completion_tokens, 0); } @@ -113,7 +113,7 @@ mod tests { token_logprob: None, prefill_progress: None, }; - assert!(output.new_text.is_empty()); + assert_eq!(output.new_text, ""); assert_eq!(output.prompt_tokens, 0); assert_eq!(output.completion_tokens, 0); } diff --git a/crates/higgs-engine/src/mtp.rs b/crates/higgs-engine/src/mtp.rs index 24b93a9e..9b851dd4 100644 --- a/crates/higgs-engine/src/mtp.rs +++ b/crates/higgs-engine/src/mtp.rs @@ -822,13 +822,13 @@ mod tests { fn prompt_lookup_ignores_current_tail_self_match() { let context = [1, 2, 3, 4]; - assert!(prompt_lookup_draft(&context, 3, 4, 64).is_empty()); + assert_eq!(prompt_lookup_draft(&context, 3, 4, 64), Vec::::new()); } #[test] fn prompt_lookup_respects_search_window() { let context = [1, 2, 3, 4, 5, 1, 2]; - assert!(prompt_lookup_draft(&context, 3, 4, 3).is_empty()); + assert_eq!(prompt_lookup_draft(&context, 3, 4, 3), Vec::::new()); } } diff --git a/crates/higgs-engine/src/reasoning_parser.rs b/crates/higgs-engine/src/reasoning_parser.rs index 6a5abfb6..396e1626 100644 --- a/crates/higgs-engine/src/reasoning_parser.rs +++ b/crates/higgs-engine/src/reasoning_parser.rs @@ -275,7 +275,7 @@ mod tests { fn only_think_block_no_visible() { let input = "All reasoning, no response."; let result = parse_reasoning(input); - assert!(result.text.is_empty()); + assert_eq!(result.text, ""); assert_eq!( result.reasoning.as_deref(), Some("All reasoning, no response.") @@ -287,7 +287,7 @@ mod tests { let mut tracker = StreamingReasoningTracker::new(); let (vis, reas) = tracker.process("thinking"); - assert!(vis.is_empty()); + assert_eq!(vis, ""); assert!(reas.contains("thinking") || tracker.has_reasoning()); let (vis, reas) = tracker.process("answer"); @@ -307,7 +307,7 @@ mod tests { let total_visible = format!("{vis}{vis2}"); let total_reasoning = format!("{reas}{reas2}"); assert!(total_visible.contains("Hello world")); - assert!(total_reasoning.is_empty()); + assert_eq!(total_reasoning, ""); assert!(!tracker.has_reasoning()); } diff --git a/crates/higgs-engine/src/simple.rs b/crates/higgs-engine/src/simple.rs index a08db55b..7e38d3c3 100644 --- a/crates/higgs-engine/src/simple.rs +++ b/crates/higgs-engine/src/simple.rs @@ -3244,18 +3244,24 @@ mod tests { #[test] fn test_extract_eos_tokens_missing_field() { - assert!(eos_from_config(r#"{"model_type": "qwen2"}"#).is_empty()); + assert_eq!( + eos_from_config(r#"{"model_type": "qwen2"}"#), + Vec::::new() + ); } #[test] fn test_extract_eos_tokens_unexpected_type() { - assert!(eos_from_config(r#"{"eos_token_id": "string"}"#).is_empty()); + assert_eq!( + eos_from_config(r#"{"eos_token_id": "string"}"#), + Vec::::new() + ); } #[test] fn test_extract_eos_tokens_missing_config_file() { let dir = tempfile::tempdir().unwrap(); - assert!(super::extract_eos_tokens(dir.path()).is_empty()); + assert_eq!(super::extract_eos_tokens(dir.path()), Vec::::new()); } // -- Additional check_stop_sequences edge cases -- @@ -3293,35 +3299,53 @@ mod tests { #[test] fn test_extract_eos_tokens_float_value() { // serde_json parses 151643.0 as a float, and as_u64() returns None for floats - assert!(eos_from_config(r#"{"eos_token_id": 151643.0}"#).is_empty()); + assert_eq!( + eos_from_config(r#"{"eos_token_id": 151643.0}"#), + Vec::::new() + ); } #[test] fn test_extract_eos_tokens_string_value() { - assert!(eos_from_config(r#"{"eos_token_id": "not_a_number"}"#).is_empty()); + assert_eq!( + eos_from_config(r#"{"eos_token_id": "not_a_number"}"#), + Vec::::new() + ); } #[test] fn test_extract_eos_tokens_nested_array() { // Inner arrays are not numbers, so as_u64() returns None for them - assert!(eos_from_config(r#"{"eos_token_id": [[1, 2], [3, 4]]}"#).is_empty()); + assert_eq!( + eos_from_config(r#"{"eos_token_id": [[1, 2], [3, 4]]}"#), + Vec::::new() + ); } #[test] fn test_extract_eos_tokens_negative_number() { // as_u64() returns None for negative numbers - assert!(eos_from_config(r#"{"eos_token_id": -1}"#).is_empty()); + assert_eq!( + eos_from_config(r#"{"eos_token_id": -1}"#), + Vec::::new() + ); } #[test] fn test_extract_eos_tokens_very_large_number() { // u32::MAX is 4294967295; as_u64() succeeds but u32::try_from fails - assert!(eos_from_config(r#"{"eos_token_id": 4294967296}"#).is_empty()); + assert_eq!( + eos_from_config(r#"{"eos_token_id": 4294967296}"#), + Vec::::new() + ); } #[test] fn test_extract_eos_tokens_empty_array() { - assert!(eos_from_config(r#"{"eos_token_id": []}"#).is_empty()); + assert_eq!( + eos_from_config(r#"{"eos_token_id": []}"#), + Vec::::new() + ); } #[test] diff --git a/crates/higgs-engine/src/tool_parser.rs b/crates/higgs-engine/src/tool_parser.rs index 8fc0289b..7056e97e 100644 --- a/crates/higgs-engine/src/tool_parser.rs +++ b/crates/higgs-engine/src/tool_parser.rs @@ -794,7 +794,7 @@ mod tests { {"name": "get_weather", "arguments": {"city": "London"}} "#; let result = assert_parse(input, 1, None); - assert!(result.text.is_empty()); + assert_eq!(result.text, ""); assert_eq!(first_tool_name(&result), "get_weather"); } @@ -861,7 +861,7 @@ I've requested the weather."#; #[test] fn test_empty_text() { let result = assert_parse("", 0, None); - assert!(result.text.is_empty()); + assert_eq!(result.text, ""); } #[test] @@ -1206,7 +1206,7 @@ After last."#; let tc = result.tool_calls.first().unwrap(); assert_eq!(tc.name, "get_weather"); assert_eq!(tc.arguments, serde_json::json!({ "city": "London" })); - assert!(result.text.is_empty()); + assert_eq!(result.text, ""); } /// Multiple parameters, and a multi-line value: only the single wrapping @@ -1404,7 +1404,7 @@ After last."#; let tc = result.tool_calls.first().unwrap(); assert_eq!(tc.name, "get_weather"); assert_eq!(tc.arguments, serde_json::json!({ "city": "London" })); - assert!(result.text.is_empty()); + assert_eq!(result.text, ""); } /// Multiple consecutive blocks, with text before/between them preserved. @@ -1446,7 +1446,7 @@ After last."#; assert!(code.contains("fn main()")); assert!(code.contains(" not a real close")); assert!(code.contains('\n')); - assert!(result.text.is_empty()); + assert_eq!(result.text, ""); } /// Declared schema coerces `MiniCPM` param values; a `string`-typed `"123"` diff --git a/crates/higgs-models/src/deepseek_v2.rs b/crates/higgs-models/src/deepseek_v2.rs index cb87dd2a..d99571a2 100644 --- a/crates/higgs-models/src/deepseek_v2.rs +++ b/crates/higgs-models/src/deepseek_v2.rs @@ -209,7 +209,7 @@ fn compute_yarn_freqs( let mask = 1.0 - ramp; let inter = freq_inter[i]; let extra = freq_extra[i]; - let denom = inter * mask + extra * (1.0 - mask); + let denom = inter.mul_add(mask, extra * (1.0 - mask)); freqs.push((inter * extra) / denom); } diff --git a/crates/higgs-models/src/qwen3_moe.rs b/crates/higgs-models/src/qwen3_moe.rs index 28f966f8..1933e614 100644 --- a/crates/higgs-models/src/qwen3_moe.rs +++ b/crates/higgs-models/src/qwen3_moe.rs @@ -695,7 +695,7 @@ mod tests { assert_eq!(args.num_experts_per_tok, 8); assert_eq!(args.moe_intermediate_size, 1536); assert_eq!(args.decoder_sparse_step, 1); - assert!(args.mlp_only_layers.is_empty()); + assert_eq!(args.mlp_only_layers, Vec::::new()); assert!(args.norm_topk_prob); assert!(!args.tie_word_embeddings); assert!(!args.attention_bias); @@ -735,7 +735,7 @@ mod tests { assert_eq!(args.num_experts_per_tok, 0); assert_eq!(args.moe_intermediate_size, 0); assert_eq!(args.decoder_sparse_step, 0); - assert!(args.mlp_only_layers.is_empty()); + assert_eq!(args.mlp_only_layers, Vec::::new()); assert!(!args.norm_topk_prob); assert!(args.quantization.is_none()); } diff --git a/crates/higgs-models/src/qwen3_next.rs b/crates/higgs-models/src/qwen3_next.rs index 3541f984..00eb37ec 100644 --- a/crates/higgs-models/src/qwen3_next.rs +++ b/crates/higgs-models/src/qwen3_next.rs @@ -5804,7 +5804,7 @@ mod tests { assert_eq!(args.num_experts_per_tok, 0); assert_eq!(args.decoder_sparse_step, 0); assert!(args.norm_topk_prob); - assert!(args.mlp_only_layers.is_empty()); + assert_eq!(args.mlp_only_layers, Vec::::new()); } #[test] diff --git a/crates/higgs-models/src/turboquant.rs b/crates/higgs-models/src/turboquant.rs index 083d5fe1..78d3ebcb 100644 --- a/crates/higgs-models/src/turboquant.rs +++ b/crates/higgs-models/src/turboquant.rs @@ -21,6 +21,8 @@ const TWO_BIT_CENTROIDS: [f32; 4] = [-1.5104, -0.4528, 0.4528, 1.5104]; const THREE_BIT_CENTROIDS: [f32; 8] = [ -2.1520, -1.3440, -0.7560, -0.2451, 0.2451, 0.7560, 1.3440, 2.1520, ]; +// Lloyd-Max centroids for a unit Gaussian; ±1.6180 matches the golden ratio only by coincidence. +#[allow(clippy::approx_constant)] const FOUR_BIT_CENTROIDS: [f32; 16] = [ -2.7326, -2.0690, -1.6180, -1.2562, -0.9424, -0.6568, -0.3881, -0.1284, 0.1284, 0.3881, 0.6568, 0.9424, 1.2562, 1.6180, 2.0690, 2.7326, diff --git a/crates/higgs-models/src/yarn.rs b/crates/higgs-models/src/yarn.rs index dc403555..b0a2d940 100644 --- a/crates/higgs-models/src/yarn.rs +++ b/crates/higgs-models/src/yarn.rs @@ -91,7 +91,7 @@ pub(crate) fn compute_yarn_freqs( let mask = 1.0 - ramp; let inter = freq_inter[i]; let extra = freq_extra[i]; - let denom = inter * mask + extra * (1.0 - mask); + let denom = inter.mul_add(mask, extra * (1.0 - mask)); freqs.push((inter * extra) / denom); } diff --git a/crates/higgs-models/tests/adapter_registry.rs b/crates/higgs-models/tests/adapter_registry.rs index 7a50bb20..487e0e05 100644 --- a/crates/higgs-models/tests/adapter_registry.rs +++ b/crates/higgs-models/tests/adapter_registry.rs @@ -262,7 +262,7 @@ fn unknown_family_error_lists_supported_ranges() { #[test] fn supported_adapter_ids_are_unique() { let supported = adapter::supported(); - assert!(!supported.is_empty()); + assert_ne!(supported.len(), 0); let mut ids = supported.iter().map(|info| info.id).collect::>(); ids.sort_unstable(); ids.dedup(); diff --git a/crates/higgs/src/daemon.rs b/crates/higgs/src/daemon.rs index 741db539..32691dc9 100644 --- a/crates/higgs/src/daemon.rs +++ b/crates/higgs/src/daemon.rs @@ -118,18 +118,16 @@ pub fn cmd_stop(profile: Option<&str>, force: bool) -> i32 { } remove_pid_file(profile); eprintln!("stopped {label} (pid {pid})"); - 0 } Some(_) => { remove_pid_file(profile); eprintln!("{label} is not running (stale pid file removed)"); - 0 } None => { eprintln!("{label} is not running (no pid file)"); - 0 } } + 0 } #[allow(clippy::print_stderr)] diff --git a/crates/higgs/src/metrics_log.rs b/crates/higgs/src/metrics_log.rs index 4a0f50fe..95c99260 100644 --- a/crates/higgs/src/metrics_log.rs +++ b/crates/higgs/src/metrics_log.rs @@ -173,7 +173,7 @@ mod tests { // The main file should now be empty (new file created after rotation). let main_content = fs::read_to_string(&log_path).unwrap(); - assert!(main_content.is_empty()); + assert_eq!(main_content, ""); } #[test] diff --git a/crates/higgs/src/model_download.rs b/crates/higgs/src/model_download.rs index f1c7f261..133a56a2 100644 --- a/crates/higgs/src/model_download.rs +++ b/crates/higgs/src/model_download.rs @@ -71,7 +71,7 @@ mod tests { fn non_interactive_writes_no_prompt() { let mut out = Vec::new(); let _ = offer_download("org/model", false, &mut out, b"".as_slice(), ok_download); - assert!(out.is_empty()); + assert_eq!(out, Vec::::new()); } #[test] diff --git a/crates/higgs/src/tui/views/mod.rs b/crates/higgs/src/tui/views/mod.rs index 074ccc14..c8a47040 100644 --- a/crates/higgs/src/tui/views/mod.rs +++ b/crates/higgs/src/tui/views/mod.rs @@ -44,7 +44,7 @@ pub fn format_duration(dur: std::time::Duration) -> String { let total_secs = dur.as_secs_f64(); if total_secs >= 60.0 { let mut minutes = (total_secs / 60.0).floor(); - let mut seconds = total_secs - minutes * 60.0; + let mut seconds = minutes.mul_add(-60.0, total_secs); // Clamp to avoid "1m60.0s" from rounding if seconds >= 59.95 { minutes += 1.0; diff --git a/crates/higgs/src/types/openai.rs b/crates/higgs/src/types/openai.rs index 9e866a20..49558de8 100644 --- a/crates/higgs/src/types/openai.rs +++ b/crates/higgs/src/types/openai.rs @@ -675,7 +675,7 @@ mod tests { #[test] fn test_stop_sequence_extract() { - assert!(StopSequence::extract(None).is_empty()); + assert_eq!(StopSequence::extract(None), Vec::::new()); let single = StopSequence::extract(Some(StopSequence::Single("x".to_owned()))); assert_eq!(single, vec!["x"]); diff --git a/crates/higgs/tests/integration/request_validation.rs b/crates/higgs/tests/integration/request_validation.rs index af0b5e1c..a3f9de05 100644 --- a/crates/higgs/tests/integration/request_validation.rs +++ b/crates/higgs/tests/integration/request_validation.rs @@ -103,7 +103,7 @@ fn chat_request_stop_array() { #[test] fn stop_sequence_extract_none() { let result = StopSequence::extract(None); - assert!(result.is_empty()); + assert_eq!(result, Vec::::new()); } #[test] diff --git a/crates/higgs/tests/integration/response_contract.rs b/crates/higgs/tests/integration/response_contract.rs index 59290154..3615ac5d 100644 --- a/crates/higgs/tests/integration/response_contract.rs +++ b/crates/higgs/tests/integration/response_contract.rs @@ -374,7 +374,7 @@ fn anthropic_message_start_event() { let json = assert_event_type(&event, "message_start"); assert_eq!(json["message"]["type"], "message"); assert_eq!(json["message"]["role"], "assistant"); - assert!(json["message"]["content"].as_array().unwrap().is_empty()); + assert_eq!(json["message"]["content"], serde_json::json!([])); assert!(json["message"]["stop_reason"].is_null()); }