mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-18 09:45:23 +00:00
test(cost): run every test through rstest
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e16cc34a76
commit
d56892eea8
10 changed files with 93 additions and 86 deletions
|
|
@ -817,6 +817,7 @@ pub struct ImageResponseInput {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use rstest::rstest;
|
||||
|
||||
fn entry(fields: &[(&str, Value)]) -> RawCatalogEntry {
|
||||
RawCatalogEntry(Map::from_iter(
|
||||
|
|
@ -826,7 +827,7 @@ mod tests {
|
|||
))
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn overlay_merges_fields_into_existing_entries_and_adds_new_ones() {
|
||||
let base = BTreeMap::from([(
|
||||
"synthetic-base".to_string(),
|
||||
|
|
@ -865,14 +866,14 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn embedded_catalog_excludes_generalizations_meta_key() {
|
||||
let catalog = LazyLock::force(&EMBEDDED_CATALOG);
|
||||
assert!(!catalog.is_empty());
|
||||
assert!(!catalog.contains_key("fallback_generalizations"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn chat_usage_reads_lenient_counts_and_cost_projection() {
|
||||
let usage: ChatUsageInput = serde_json::from_value(serde_json::json!({
|
||||
"prompt_tokens": true,
|
||||
|
|
@ -889,7 +890,7 @@ mod tests {
|
|||
assert_eq!(usage.cache_read_input_tokens, Some(7));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn chat_usage_rejects_negative_and_garbage_counts() {
|
||||
assert!(
|
||||
serde_json::from_value::<ChatUsageInput>(serde_json::json!({
|
||||
|
|
@ -905,7 +906,7 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn usage_input_dispatches_on_format_tag_not_key_shapes() {
|
||||
let chat: UsageInput = serde_json::from_value(serde_json::json!({
|
||||
"format": "chat",
|
||||
|
|
@ -942,7 +943,7 @@ mod tests {
|
|||
assert_eq!((input_tokens, output_tokens), (100, 200));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn hidden_params_read_wire_number_header_costs() {
|
||||
let hidden: HiddenParamsInput = serde_json::from_value(serde_json::json!({
|
||||
"custom_llm_provider": "openai",
|
||||
|
|
@ -957,7 +958,7 @@ mod tests {
|
|||
assert_eq!(header.and_then(WireNumber::cost), Some(0.0123));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn query_count_counts_arrays_and_defaults_non_arrays_to_one() {
|
||||
let params: OptionalParamsInput =
|
||||
serde_json::from_value(serde_json::json!({"query": ["a", "b", "c"]})).unwrap();
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use litellm_cost::non_token::{
|
|||
};
|
||||
use rstest::rstest;
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn combines_non_token_charges_without_losing_components() {
|
||||
let charges = [
|
||||
Charge {
|
||||
|
|
@ -51,7 +51,7 @@ fn combines_non_token_charges_without_losing_components() {
|
|||
assert!((result.total - 0.16).abs() < 1e-12);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn supports_prices_per_thousand_units_and_free_usage() {
|
||||
let charges = [
|
||||
Charge {
|
||||
|
|
@ -74,7 +74,7 @@ fn supports_prices_per_thousand_units_and_free_usage() {
|
|||
assert_eq!(result.total, 1.5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn rejects_invalid_inputs_and_overflow() {
|
||||
let valid = Charge {
|
||||
unit: Unit::Credit,
|
||||
|
|
@ -114,7 +114,7 @@ fn rejects_invalid_inputs_and_overflow() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn image_price_uses_first_priced_table_and_preserves_zero() {
|
||||
let deployment = ImageRates {
|
||||
input_per_image: Rate::Missing,
|
||||
|
|
@ -146,7 +146,7 @@ fn image_price_uses_first_priced_table_and_preserves_zero() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn ocr_credits_take_precedence_and_annotation_uses_page_fallback() {
|
||||
let rates = OcrRates {
|
||||
per_credit: Rate::Value(0.2),
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
|
|||
|
||||
use litellm_cost::pricing::{Metric, ModelPricing, ServiceTier};
|
||||
use litellm_cost::wire::RawCatalogEntry;
|
||||
use rstest::rstest;
|
||||
|
||||
static ALLOCATIONS: AtomicUsize = AtomicUsize::new(0);
|
||||
|
||||
|
|
@ -46,7 +47,7 @@ fn parsed_pricing() -> ModelPricing {
|
|||
entry.pricing()
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn model_pricing_lookups_allocate_nothing_on_the_request_path() {
|
||||
let pricing = parsed_pricing();
|
||||
let tiers = [
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@ use std::sync::LazyLock;
|
|||
|
||||
use litellm_cost::pricing::{Metric, Rate, ServiceTier, tokenize};
|
||||
use litellm_cost::wire::{EMBEDDED_CATALOG, rate};
|
||||
use rstest::rstest;
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn every_embedded_key_is_recognized_by_the_tokenizer() {
|
||||
let mut offenders: Vec<String> = Vec::new();
|
||||
for (model, entry) in EMBEDDED_CATALOG.iter() {
|
||||
|
|
@ -21,7 +22,7 @@ fn every_embedded_key_is_recognized_by_the_tokenizer() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn embedded_catalog_yields_decorated_and_plain_rates() {
|
||||
let mut thresholds = 0_usize;
|
||||
let mut tiers = 0_usize;
|
||||
|
|
@ -40,7 +41,7 @@ fn embedded_catalog_yields_decorated_and_plain_rates() {
|
|||
assert!(plain > 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn tokenizer_applies_the_rate_key_grammar() {
|
||||
let plain = tokenize("input_cost_per_token").expect("plain rate key");
|
||||
assert_eq!(plain.metric, Metric::InputPerToken);
|
||||
|
|
@ -89,7 +90,7 @@ fn tokenizer_applies_the_rate_key_grammar() {
|
|||
assert!(batch.batch);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn tokenizer_rejects_unknown_metrics_and_malformed_decorations() {
|
||||
assert!(tokenize("input_cost_per_gadget").is_err());
|
||||
assert!(tokenize("input_cost_per_token_standard").is_err());
|
||||
|
|
@ -98,7 +99,7 @@ fn tokenizer_rejects_unknown_metrics_and_malformed_decorations() {
|
|||
assert!(tokenize("max_tokens").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn rate_parser_mirrors_get_cost_per_unit_coercions() {
|
||||
use serde_json::json;
|
||||
assert_eq!(rate(None), Rate::Missing);
|
||||
|
|
@ -113,7 +114,7 @@ fn rate_parser_mirrors_get_cost_per_unit_coercions() {
|
|||
assert_eq!(rate(Some(&json!({"cost": 1}))), Rate::Invalid);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn parsed_pricing_buckets_a_synthetic_overlay_entry() {
|
||||
let entry: litellm_cost::wire::RawCatalogEntry = serde_json::from_value(serde_json::json!({
|
||||
"input_cost_per_token": 3e-6,
|
||||
|
|
@ -180,7 +181,7 @@ fn parsed_pricing_buckets_a_synthetic_overlay_entry() {
|
|||
let _: LazyLock<()> = LazyLock::new(|| ());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn checked_rates_reject_negative_and_non_finite_where_python_bills_them() {
|
||||
use litellm_cost::error::CostError;
|
||||
use litellm_cost::pricing::Rate;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ use litellm_cost::prompt_caching_savings::{
|
|||
};
|
||||
use litellm_cost::provider_cache::apply_provider_cache_read_default;
|
||||
use litellm_cost::usage_dispatch::get_usage_object;
|
||||
use rstest::rstest;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
fn fixtures() -> Value {
|
||||
|
|
@ -44,7 +45,7 @@ fn assert_close(actual: f64, expected: f64, id: &str) {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn generic_token_costs_match_executed_python_fixtures() {
|
||||
for row in fixtures().get("generic").unwrap().as_array().unwrap() {
|
||||
let id = row.get("id").and_then(Value::as_str).unwrap();
|
||||
|
|
@ -76,7 +77,7 @@ fn generic_token_costs_match_executed_python_fixtures() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn billed_token_rates_match_executed_python_fixtures() {
|
||||
for row in fixtures().get("billed_rates").unwrap().as_array().unwrap() {
|
||||
let id = row.get("id").and_then(Value::as_str).unwrap();
|
||||
|
|
@ -131,7 +132,7 @@ fn billed_token_rates_match_executed_python_fixtures() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn batch_cost_rates_match_executed_python_fixtures() {
|
||||
for row in fixtures().get("batch").unwrap().as_array().unwrap() {
|
||||
let id = row.get("id").and_then(Value::as_str).unwrap();
|
||||
|
|
@ -164,7 +165,7 @@ fn batch_cost_rates_match_executed_python_fixtures() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn off_peak_decisions_match_executed_python_fixtures() {
|
||||
for row in fixtures().get("off_peak").unwrap().as_array().unwrap() {
|
||||
let id = row.get("id").and_then(Value::as_str).unwrap();
|
||||
|
|
@ -175,7 +176,7 @@ fn off_peak_decisions_match_executed_python_fixtures() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn responses_usage_transforms_match_executed_python_fixtures() {
|
||||
for row in fixtures()
|
||||
.get("responses_usage")
|
||||
|
|
@ -191,7 +192,7 @@ fn responses_usage_transforms_match_executed_python_fixtures() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn anthropic_usage_transforms_match_executed_python_fixtures() {
|
||||
for row in fixtures()
|
||||
.get("anthropic_usage")
|
||||
|
|
@ -312,7 +313,7 @@ fn count_of(details: Option<&Value>, key: &str) -> u64 {
|
|||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn prompt_caching_savings_match_executed_python_fixtures() {
|
||||
for row in fixtures()
|
||||
.get("caching_savings")
|
||||
|
|
@ -339,7 +340,7 @@ fn prompt_caching_savings_match_executed_python_fixtures() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn fixture_ids_are_unique_per_surface() {
|
||||
let mut seen: HashMap<String, usize> = HashMap::new();
|
||||
let root = fixtures();
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
use jiff::Timestamp;
|
||||
use litellm_cost::generic_cost::calculate_generic_cost_from_model_info_with_region;
|
||||
use litellm_cost::responses_usage::ChatUsage;
|
||||
use rstest::rstest;
|
||||
use serde_json::Value;
|
||||
|
||||
fn chat_usage(prompt: u64, completion: u64, cache_read: u64, cache_write: u64) -> ChatUsage {
|
||||
|
|
@ -38,7 +39,7 @@ fn model_info(fields: &[(&str, String)]) -> Value {
|
|||
Value::Object(object)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn generic_path_matches_executed_python_reference_cases() {
|
||||
for row in include_str!("python_reference.tsv")
|
||||
.lines()
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use litellm_cost::call_type::CallTypes;
|
|||
use litellm_cost::pricing::{Metric, ServiceTier, tokenize};
|
||||
use litellm_cost::provider::LlmProviders;
|
||||
use litellm_cost::wire::{RawCatalogEntry, cost_per_unit};
|
||||
use rstest::rstest;
|
||||
use strum::VariantArray;
|
||||
|
||||
fn fixture() -> Value {
|
||||
|
|
@ -19,7 +20,7 @@ fn pinning() -> Value {
|
|||
fixture()["pinning"].clone()
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn tokenizer_agrees_with_parse_above_token_threshold_where_python_parses() {
|
||||
for row in pinning()["thresholds"].as_array().expect("threshold rows") {
|
||||
let key = row["key"].as_str().expect("key");
|
||||
|
|
@ -48,7 +49,7 @@ fn tokenizer_agrees_with_parse_above_token_threshold_where_python_parses() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn service_tier_suffixes_match_python() {
|
||||
let pinning = pinning();
|
||||
let pinned: Vec<&str> = pinning["service_tier_suffixes"]
|
||||
|
|
@ -64,7 +65,7 @@ fn service_tier_suffixes_match_python() {
|
|||
assert_eq!(rust, pinned);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn batch_tier_grammar_matches_python_regex_language() {
|
||||
let pattern = pinning()["batch_tier_key"]
|
||||
.as_str()
|
||||
|
|
@ -99,7 +100,7 @@ fn batch_tier_grammar_matches_python_regex_language() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn cost_per_unit_replays_python_coercion_and_tier_fallback() {
|
||||
for row in pinning()["cost_per_unit"]
|
||||
.as_array()
|
||||
|
|
@ -114,7 +115,7 @@ fn cost_per_unit_replays_python_coercion_and_tier_fallback() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn model_info_projection_passes_rate_keys_the_tokenizer_recognizes() {
|
||||
let fixture = fixture();
|
||||
let projected = fixture["model_info_projection"]["projected"]
|
||||
|
|
@ -145,7 +146,7 @@ fn model_info_projection_passes_rate_keys_the_tokenizer_recognizes() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn registered_entry_parses_into_model_pricing_with_projected_rates() {
|
||||
let entry: RawCatalogEntry = serde_json::from_value(serde_json::json!({
|
||||
"input_cost_per_token": 1e-6,
|
||||
|
|
@ -176,7 +177,7 @@ fn registered_entry_parses_into_model_pricing_with_projected_rates() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn provider_and_call_type_enums_mirror_python() {
|
||||
let pinning = pinning();
|
||||
let python_providers: std::collections::BTreeSet<&str> = pinning["llm_providers"]
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ fn zeroed_with_flag(
|
|||
zeroed_ptu_pricing(model_info, declared, enabled)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn a_complete_reservation_is_accepted() {
|
||||
let terms = ptu_terms(&valid_model_info()).expect("terms");
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ fn merge(base: &Value, override_value: &Value) -> Value {
|
|||
Value::Object(merged)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn a_naive_start_is_read_as_utc() {
|
||||
let model_info = merge(
|
||||
&valid_model_info(),
|
||||
|
|
@ -91,7 +91,7 @@ fn a_naive_start_is_read_as_utc() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn an_offset_start_is_converted_rather_than_relabelled() {
|
||||
let model_info = merge(
|
||||
&valid_model_info(),
|
||||
|
|
@ -108,7 +108,7 @@ fn an_offset_start_is_converted_rather_than_relabelled() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn nothing_is_zeroed_while_the_feature_is_off() {
|
||||
assert_eq!(
|
||||
zeroed_with_flag(&valid_model_info(), &json!({}), false),
|
||||
|
|
@ -116,7 +116,7 @@ fn nothing_is_zeroed_while_the_feature_is_off() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn the_standing_rates_are_all_zeroed() {
|
||||
let override_pricing =
|
||||
zeroed_with_flag(&valid_model_info(), &json!({}), true).expect("pricing");
|
||||
|
|
@ -128,7 +128,7 @@ fn the_standing_rates_are_all_zeroed() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn tiered_pricing_is_emptied_rather_than_zeroed() {
|
||||
let declared = json!({"tiered_pricing": [{"range": [0, 1000], "input_cost_per_token": 0.003}]});
|
||||
|
||||
|
|
@ -137,7 +137,7 @@ fn tiered_pricing_is_emptied_rather_than_zeroed() {
|
|||
assert_eq!(override_pricing.get("tiered_pricing"), Some(&json!([])));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn the_search_context_table_is_zeroed_in_place_on_every_deployment() {
|
||||
let override_pricing =
|
||||
zeroed_with_flag(&valid_model_info(), &json!({}), true).expect("pricing");
|
||||
|
|
@ -152,7 +152,7 @@ fn the_search_context_table_is_zeroed_in_place_on_every_deployment() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn the_maps_grounding_rate_is_zeroed_on_every_deployment() {
|
||||
let override_pricing =
|
||||
zeroed_with_flag(&valid_model_info(), &json!({}), true).expect("pricing");
|
||||
|
|
@ -163,7 +163,7 @@ fn the_maps_grounding_rate_is_zeroed_on_every_deployment() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn a_declared_table_does_not_become_a_scalar() {
|
||||
let declared = json!({"search_context_cost_per_query": {"search_context_size_medium": 0.05}});
|
||||
|
||||
|
|
@ -179,7 +179,7 @@ fn a_declared_table_does_not_become_a_scalar() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn a_rate_the_deployment_declares_itself_is_zeroed_too() {
|
||||
let extra = "input_cost_per_token_above_200k_tokens";
|
||||
let declared = json!({extra: 9e-06});
|
||||
|
|
@ -189,7 +189,7 @@ fn a_rate_the_deployment_declares_itself_is_zeroed_too() {
|
|||
assert_eq!(override_pricing.get(extra), Some(&json!(0.0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn a_setting_that_is_not_a_charge_is_left_alone() {
|
||||
let declared = json!({"output_vector_size": 1536});
|
||||
|
||||
|
|
@ -198,12 +198,12 @@ fn a_setting_that_is_not_a_charge_is_left_alone() {
|
|||
assert_eq!(override_pricing.get("output_vector_size"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn a_complete_reservation_has_no_error() {
|
||||
assert_eq!(ptu_config_error(&valid_model_info(), None), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn a_deployment_with_no_ptu_fields_is_not_a_ptu_deployment() {
|
||||
assert_eq!(
|
||||
ptu_config_error(&json!({"team_id": "team-alpha"}), None),
|
||||
|
|
@ -231,7 +231,7 @@ fn an_incoherent_reservation_names_its_reason(
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn a_missing_start_is_explained_rather_than_inferred() {
|
||||
let model_info = json!({
|
||||
"team_id": "team-alpha",
|
||||
|
|
@ -243,7 +243,7 @@ fn a_missing_start_is_explained_rather_than_inferred() {
|
|||
assert!(error.starts_with("ptu_effective_from is required when PTU fields are set"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn an_inverted_window_is_caught_before_the_count_and_rate_gate() {
|
||||
let window_only = json!({
|
||||
"ptu_effective_from": "2026-01-01T00:00:00Z",
|
||||
|
|
@ -256,7 +256,7 @@ fn an_inverted_window_is_caught_before_the_count_and_rate_gate() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn a_declared_unique_id_is_accepted() {
|
||||
assert_eq!(
|
||||
ptu_identity_error(Some("azure-ptu-eastus"), false, None, None),
|
||||
|
|
@ -273,35 +273,35 @@ fn a_reservation_without_an_id_is_refused(#[case] missing: Option<&str>) {
|
|||
assert!(error.starts_with("model_info.id is required when PTU fields are set"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn the_refusal_names_the_id_the_deployment_already_uses() {
|
||||
let error = ptu_identity_error(None, false, Some("0ba149287615"), None).expect("error");
|
||||
|
||||
assert!(error.contains("0ba149287615"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn the_refusal_points_at_the_model_info_route_when_the_current_id_is_unknown() {
|
||||
let error = ptu_identity_error(None, false, None, None).expect("error");
|
||||
|
||||
assert!(error.contains("GET /model/info"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn an_id_declared_twice_is_refused() {
|
||||
let error = ptu_identity_error(Some("azure-ptu-eastus"), true, None, None).expect("error");
|
||||
|
||||
assert!(error.contains("declared on more than one deployment"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn the_deployment_is_named_when_the_caller_supplies_one() {
|
||||
let error = ptu_identity_error(None, false, None, Some("azure-ptu")).expect("error");
|
||||
|
||||
assert!(error.starts_with("PTU configuration on model 'azure-ptu' is invalid:"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn a_bare_yaml_date_bound_is_read_as_that_day_opening() {
|
||||
let model_info = merge(
|
||||
&valid_model_info(),
|
||||
|
|
@ -319,7 +319,7 @@ fn a_bare_yaml_date_bound_is_read_as_that_day_opening() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn a_bare_yaml_date_start_is_read_as_that_day_opening() {
|
||||
let model_info = merge(
|
||||
&valid_model_info(),
|
||||
|
|
@ -336,19 +336,19 @@ fn a_bare_yaml_date_start_is_read_as_that_day_opening() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn the_string_zero_is_a_declared_id() {
|
||||
assert_eq!(ptu_identity_error(Some("0"), false, None, None), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn an_empty_id_is_no_id() {
|
||||
let error = ptu_identity_error(Some(""), false, None, None).expect("error");
|
||||
|
||||
assert!(error.starts_with("model_info.id is required"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn the_spillover_header_marks_the_request_as_pay_as_you_go() {
|
||||
assert!(is_spilled_over_ptu_request(
|
||||
&valid_model_info(),
|
||||
|
|
@ -358,7 +358,7 @@ fn the_spillover_header_marks_the_request_as_pay_as_you_go() {
|
|||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn no_spillover_marker_keeps_the_zeroed_ptu_rates() {
|
||||
assert!(!is_spilled_over_ptu_request(
|
||||
&valid_model_info(),
|
||||
|
|
@ -374,7 +374,7 @@ fn no_spillover_marker_keeps_the_zeroed_ptu_rates() {
|
|||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn azure_spillover_carries_the_source_deployment_from_raw_headers() {
|
||||
assert_eq!(
|
||||
azure_spillover(
|
||||
|
|
@ -390,7 +390,7 @@ fn azure_spillover_carries_the_source_deployment_from_raw_headers() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn azure_spillover_from_processed_headers_has_no_source_when_absent() {
|
||||
assert_eq!(
|
||||
azure_spillover(
|
||||
|
|
@ -403,7 +403,7 @@ fn azure_spillover_from_processed_headers_has_no_source_when_absent() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn no_spillover_marker_returns_none() {
|
||||
assert_eq!(
|
||||
azure_spillover(Some(&json!({"x-ms-is-spilled-over": "false"})), None),
|
||||
|
|
@ -412,7 +412,7 @@ fn no_spillover_marker_returns_none() {
|
|||
assert_eq!(azure_spillover(None, None), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn a_boolean_spillover_marker_matches_pythons_string_coercion() {
|
||||
assert!(is_spilled_over_ptu_request(
|
||||
&valid_model_info(),
|
||||
|
|
@ -428,7 +428,7 @@ fn a_boolean_spillover_marker_matches_pythons_string_coercion() {
|
|||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn spillover_requires_both_the_terms_and_the_feature_flag() {
|
||||
let headers = Some(&json!({"x-ms-is-spilled-over": "true"}));
|
||||
|
||||
|
|
@ -468,14 +468,14 @@ fn coercions_and_bounds_match_python(
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn a_numeric_team_id_is_stringified_like_python() {
|
||||
let model_info = merge(&valid_model_info(), &json!({"team_id": 7}));
|
||||
|
||||
assert_eq!(ptu_terms(&model_info).expect("terms").team_id, "7");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn a_declared_512k_cache_read_rate_is_zeroed_too() {
|
||||
let extra = "cache_read_input_token_cost_above_512k_tokens";
|
||||
let declared = json!({extra: 1e-06});
|
||||
|
|
@ -494,7 +494,7 @@ fn a_null_or_absent_effective_to_leaves_the_window_open(#[case] override_value:
|
|||
assert_eq!(ptu_terms(&model_info).expect("terms").effective_to, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn a_blank_current_id_falls_back_to_the_model_info_route() {
|
||||
let error = ptu_identity_error(None, false, Some(""), None).expect("error");
|
||||
|
||||
|
|
@ -502,7 +502,7 @@ fn a_blank_current_id_falls_back_to_the_model_info_route() {
|
|||
assert!(!error.contains("uses, ,"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn a_null_spillover_source_is_absent_not_the_string_none() {
|
||||
assert_eq!(
|
||||
azure_spillover(
|
||||
|
|
@ -518,7 +518,7 @@ fn a_null_spillover_source_is_absent_not_the_string_none() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn a_config_error_names_the_model_when_supplied() {
|
||||
let model_info = merge(&valid_model_info(), &json!({"team_id": ""}));
|
||||
|
||||
|
|
@ -528,7 +528,7 @@ fn a_config_error_names_the_model_when_supplied() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn the_zeroed_pricing_map_carries_exactly_the_python_fields() {
|
||||
let override_pricing =
|
||||
zeroed_with_flag(&valid_model_info(), &json!({}), true).expect("pricing");
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ fn get_usage_object_maps_interactions_shape() {
|
|||
assert_eq!(usage.total_tokens, 120);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn chat_usage_coerces_numeric_strings_and_bools_like_pydantic() {
|
||||
let usage = get_usage_object(&json!({"usage": {
|
||||
"prompt_tokens": "150",
|
||||
|
|
@ -118,7 +118,7 @@ fn chat_usage_coerces_numeric_strings_and_bools_like_pydantic() {
|
|||
assert!(!usage.extra.contains_key("_cache_read_input_tokens"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn chat_usage_folds_deepseek_prompt_cache_hit_tokens() {
|
||||
let usage = get_usage_object(&json!({"usage": {
|
||||
"prompt_tokens": 100,
|
||||
|
|
@ -138,7 +138,7 @@ fn chat_usage_folds_deepseek_prompt_cache_hit_tokens() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn chat_usage_reasoning_string_parses_where_python_raises() {
|
||||
let usage = get_usage_object(&json!({"usage": {
|
||||
"prompt_tokens": 100,
|
||||
|
|
@ -155,7 +155,7 @@ fn chat_usage_reasoning_string_parses_where_python_raises() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn chat_usage_still_rejects_uncoercible_counts() {
|
||||
assert!(get_usage_object(&json!({"usage": {"prompt_tokens": "not-a-number"}})).is_err());
|
||||
assert!(get_usage_object(&json!({"usage": {"prompt_tokens": 12.5}})).is_err());
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use litellm_cost::wire::{
|
|||
ChatUsageInput, DataLen, HiddenParamsInput, ImageResponseInput, OptionalParamsInput,
|
||||
QueryCount, ReportedCostInput, ResponseInput, TranscriptionUsageInput, UsageInput, WireNumber,
|
||||
};
|
||||
use rstest::rstest;
|
||||
|
||||
fn fixture() -> Value {
|
||||
serde_json::from_str(include_str!("python_fixtures.json")).expect("fixture parses")
|
||||
|
|
@ -18,7 +19,7 @@ fn usage_input(payload: &Value) -> UsageInput {
|
|||
serde_json::from_value(payload.clone()).expect("wire usage payload deserializes")
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn wire_usage_payloads_match_their_declared_format() {
|
||||
for row in fixture()["wire_usage"].as_array().expect("wire_usage rows") {
|
||||
let payload = &row["payload"];
|
||||
|
|
@ -35,7 +36,7 @@ fn wire_usage_payloads_match_their_declared_format() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn chat_wire_usage_carries_every_field_the_cost_path_reads() {
|
||||
let input = usage_input(&fixture()["wire_usage"][0]["payload"]);
|
||||
let UsageInput::Chat { usage } = input else {
|
||||
|
|
@ -71,7 +72,7 @@ fn chat_wire_usage_carries_every_field_the_cost_path_reads() {
|
|||
assert_eq!(usage.citation_tokens, Some(1_500));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn chat_wire_usage_with_gateway_merged_token_keys_stays_chat() {
|
||||
let input = usage_input(&fixture()["wire_usage"][2]["payload"]);
|
||||
let UsageInput::Chat { usage } = input else {
|
||||
|
|
@ -81,7 +82,7 @@ fn chat_wire_usage_with_gateway_merged_token_keys_stays_chat() {
|
|||
assert_eq!(usage.completion_tokens, 50);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn responses_wire_usage_reads_both_detail_spellings() {
|
||||
let singular = usage_input(&fixture()["wire_usage"][3]["payload"]);
|
||||
let UsageInput::Responses { usage } = singular else {
|
||||
|
|
@ -104,7 +105,7 @@ fn responses_wire_usage_reads_both_detail_spellings() {
|
|||
assert_eq!(usage.cost.map(ReportedCostInput::cost), Some(Some(0.25)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn anthropic_wire_usage_types_iterations_and_cache_breakdown() {
|
||||
let full = usage_input(&fixture()["wire_usage"][5]["payload"]);
|
||||
let UsageInput::Anthropic { usage } = full else {
|
||||
|
|
@ -149,7 +150,7 @@ fn anthropic_wire_usage_types_iterations_and_cache_breakdown() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn interactions_wire_usage_types_modality_and_grounding_counts() {
|
||||
let input = usage_input(&fixture()["wire_usage"][7]["payload"]);
|
||||
let UsageInput::Interactions { usage } = input else {
|
||||
|
|
@ -171,7 +172,7 @@ fn interactions_wire_usage_types_modality_and_grounding_counts() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn transcription_wire_usage_types_duration_and_tokens_variants() {
|
||||
let tokens = usage_input(&fixture()["wire_usage"][8]["payload"]);
|
||||
let UsageInput::Transcription { usage } = tokens else {
|
||||
|
|
@ -207,7 +208,7 @@ fn wire_response_rows() -> Vec<Value> {
|
|||
.clone()
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn wire_response_rows_deserialize_into_typed_structs() {
|
||||
let rows = wire_response_rows();
|
||||
let chat = serde_json::from_value::<ResponseInput>(rows[0]["response"].clone())
|
||||
|
|
@ -295,7 +296,7 @@ fn wire_response_rows_deserialize_into_typed_structs() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[rstest]
|
||||
fn chat_usage_input_leniently_accepts_bool_string_and_integral_float_counts() {
|
||||
let usage: ChatUsageInput = serde_json::from_value(serde_json::json!({
|
||||
"prompt_tokens": true,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue