| 1 | use codewhale_telemetry::counters::http_status_counter; |
| 2 | use codewhale_telemetry::{ErrorCounter, session_counters}; |
| 3 | |
| 4 | #[test] |
| 5 | fn a_custom_provider_is_recorded_as_the_literal_custom() { |
| 6 | // This is the single most likely leak in the feature: the persistence |
| 7 | // identity, the exec stream meta, and the planned route's effective |
| 8 | // label all return the customer's own `[providers.<name>]` table key |
| 9 | // when the route is custom, and `/status` already prints it. The |
| 10 | // recording API takes a `ProviderKind` by value so none of them fit. |
| 11 | crate::client::record_provider_response(crate::config::ApiProvider::Custom, 200); |
| 12 | let providers = session_counters().providers(); |
| 13 | assert!( |
| 14 | providers.iter().any(|name| name == "custom"), |
| 15 | "expected the literal `custom`, got {providers:?}" |
| 16 | ); |
| 17 | |
| 18 | let closed: std::collections::BTreeSet<&str> = codewhale_config::ProviderKind::ALL |
| 19 | .iter() |
| 20 | .map(|kind| kind.as_str()) |
| 21 | .collect(); |
| 22 | for name in &providers { |
| 23 | assert!( |
| 24 | closed.contains(name.as_str()), |
| 25 | "`{name}` is not a ProviderKind; a table name reached the provider set" |
| 26 | ); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | #[test] |
| 31 | fn http_status_classes_land_in_the_right_error_counter() { |
| 32 | // Captured from the response, before any `LlmError` is built: every |
| 33 | // variant of that error carries the raw provider body verbatim. |
| 34 | assert_eq!(http_status_counter(200), None); |
| 35 | assert_eq!(http_status_counter(304), None); |
| 36 | assert_eq!( |
| 37 | http_status_counter(429), |
| 38 | Some(ErrorCounter::ProviderHttp4xx) |
| 39 | ); |
| 40 | assert_eq!( |
| 41 | http_status_counter(503), |
| 42 | Some(ErrorCounter::ProviderHttp5xx) |
| 43 | ); |
| 44 | } |
| 45 | |
| 46 | #[test] |
| 47 | fn the_turn_wall_histogram_buckets_by_wall_clock_not_per_turn_events() { |
| 48 | // A histogram, never a timestamped series: a stream of per-turn |
| 49 | // durations reconstructs a session's working rhythm. |
| 50 | let mut wall = codewhale_telemetry::TurnWall::default(); |
| 51 | wall.observe_secs(0); |
| 52 | wall.observe_secs(4); |
| 53 | wall.observe_secs(5); |
| 54 | wall.observe_secs(119); |
| 55 | wall.observe_secs(120); |
| 56 | assert_eq!(wall.lt_5s, 2); |
| 57 | assert_eq!(wall.five_to_thirty, 1); |
| 58 | assert_eq!(wall.thirty_to_onetwenty, 1); |
| 59 | assert_eq!(wall.gte_120s, 1); |
| 60 | } |
| 61 |