From 8943339af796b42da4ebaf2aa1b9337cda156fec Mon Sep 17 00:00:00 2001 From: liuying1297 Date: Tue, 12 May 2026 18:20:13 +0800 Subject: [PATCH] fix: make stats pricing model match case-insensitive --- src/cortex-cli/src/stats_cmd.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/cortex-cli/src/stats_cmd.rs b/src/cortex-cli/src/stats_cmd.rs index 1e407503e..0b7d28781 100644 --- a/src/cortex-cli/src/stats_cmd.rs +++ b/src/cortex-cli/src/stats_cmd.rs @@ -218,7 +218,7 @@ fn get_model_pricing(model: &str) -> ModelPricing { // Fall back to default pricing (may be outdated - users can override via CORTEX_PRICING_*) // Pricing per 1M tokens (as of late 2024/early 2025 - may change) - match model { + match model_lower.as_str() { // Anthropic m if m.contains("claude-opus-4") || m.contains("opus-4") => ModelPricing { input_per_million: 15.0, @@ -735,6 +735,14 @@ mod tests { assert!((cost - 12.5).abs() < 0.001); } + #[test] + fn test_calculate_cost_is_case_insensitive_for_builtin_pricing() { + let lowercase_cost = calculate_cost("gpt-4o", 1_000_000, 1_000_000); + let uppercase_cost = calculate_cost("GPT-4O", 1_000_000, 1_000_000); + + assert!((uppercase_cost - lowercase_cost).abs() < f64::EPSILON); + } + #[test] fn test_validate_days_range() { // Valid values