mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-30 06:43:27 +00:00
Messages describe their own layer and every cause is a typed source, predicates match exhaustively, and boundaries render with litellm_error::Report. Media downloads no longer count as dispatched, Error::upstream bounds the provider body itself, and a forwarded header SigV4 cannot sign is the caller's fault. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
1.4 KiB
Rust
48 lines
1.4 KiB
Rust
use std::collections::BTreeMap;
|
|
|
|
use litellm_cache::{CacheCodec, Error, JsonCodec};
|
|
use rstest::rstest;
|
|
use serde::{Deserialize, Serialize};
|
|
use serde_json::json;
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
struct RoutingState {
|
|
deployment: String,
|
|
cooldown_seconds: u64,
|
|
}
|
|
|
|
#[rstest]
|
|
fn json_codec_round_trips_typed_domain_values() {
|
|
let codec = JsonCodec::<RoutingState>::new();
|
|
let value = RoutingState {
|
|
deployment: "deployment-a".into(),
|
|
cooldown_seconds: 30,
|
|
};
|
|
let bytes = codec.encode(&value).unwrap();
|
|
assert_eq!(codec.decode(&bytes).unwrap(), value);
|
|
assert_eq!(
|
|
serde_json::from_slice::<serde_json::Value>(&bytes).unwrap(),
|
|
json!({"deployment": "deployment-a", "cooldown_seconds": 30})
|
|
);
|
|
}
|
|
|
|
#[rstest]
|
|
#[case::malformed(b"not json")]
|
|
#[case::wrongly_typed(br#"{"deployment":12}"#)]
|
|
fn json_codec_rejects_malformed_and_wrongly_typed_entries(#[case] bytes: &[u8]) {
|
|
let codec = JsonCodec::<RoutingState>::new();
|
|
assert!(matches!(
|
|
codec.decode(bytes),
|
|
Err(Error::InvalidEntry(Some(_)))
|
|
));
|
|
}
|
|
|
|
#[rstest]
|
|
fn json_codec_propagates_encoding_errors() {
|
|
let codec = JsonCodec::<BTreeMap<(u8, u8), String>>::new();
|
|
let value = BTreeMap::from([((1, 2), "invalid JSON object key".into())]);
|
|
assert!(matches!(
|
|
codec.encode(&value),
|
|
Err(Error::InvalidEntry(Some(_)))
|
|
));
|
|
}
|