From eb00a48b55394786b5c008e77c614fa2464de332 Mon Sep 17 00:00:00 2001 From: Spherrrical Date: Tue, 31 Mar 2026 17:17:14 -0700 Subject: [PATCH] Add tests for default selection policy behavior in routing preferences --- .../src/handlers/routing_service.rs | 37 +++++++++++++++++++ crates/common/src/configuration.rs | 1 + 2 files changed, 38 insertions(+) diff --git a/crates/brightstaff/src/handlers/routing_service.rs b/crates/brightstaff/src/handlers/routing_service.rs index e5d50fcf..6566a324 100644 --- a/crates/brightstaff/src/handlers/routing_service.rs +++ b/crates/brightstaff/src/handlers/routing_service.rs @@ -283,6 +283,43 @@ mod tests { assert_eq!(prefs[0].selection_policy.prefer, SelectionPreference::None); } + #[test] + fn extract_routing_policy_selection_policy_missing_defaults_to_none() { + let policy = r#""routing_preferences": [ + { + "name": "coding", + "description": "code generation, writing functions, debugging", + "models": ["openai/gpt-4o", "openai/gpt-4o-mini"] + } + ]"#; + let body = make_chat_body(policy); + let (_cleaned, prefs) = extract_routing_policy(&body).unwrap(); + + let prefs = + prefs.expect("should parse routing_preferences when selection_policy is missing"); + assert_eq!(prefs.len(), 1); + assert_eq!(prefs[0].selection_policy.prefer, SelectionPreference::None); + } + + #[test] + fn extract_routing_policy_prefer_empty_string_defaults_to_none() { + let policy = r#""routing_preferences": [ + { + "name": "coding", + "description": "code generation, writing functions, debugging", + "models": ["openai/gpt-4o", "openai/gpt-4o-mini"], + "selection_policy": {"prefer": ""} + } + ]"#; + let body = make_chat_body(policy); + let (_cleaned, prefs) = extract_routing_policy(&body).unwrap(); + + let prefs = + prefs.expect("should parse routing_preferences when selection_policy.prefer is empty"); + assert_eq!(prefs.len(), 1); + assert_eq!(prefs[0].selection_policy.prefer, SelectionPreference::None); + } + #[test] fn routing_decision_response_serialization() { let response = RoutingDecisionResponse { diff --git a/crates/common/src/configuration.rs b/crates/common/src/configuration.rs index e46c06a5..ac95185b 100644 --- a/crates/common/src/configuration.rs +++ b/crates/common/src/configuration.rs @@ -111,6 +111,7 @@ pub enum SelectionPreference { Fastest, /// Return models in the same order they were defined — no reordering. #[default] + #[serde(alias = "")] None, }