@@ -21,18 +21,18 @@ pub enum ProviderType {
2121#[ derive( Debug , Clone ) ]
2222pub struct ProviderConfig {
2323 pub provider_type : ProviderType ,
24- pub endpoint_url : Option < String > , // For LOCAL
25- pub api_key : Option < String > , // For OPENROUTER
24+ pub endpoint_url : Option < String > , // For LOCAL
25+ pub api_key : Option < String > , // For OPENROUTER
2626 pub validation_status : ValidationStatus ,
2727}
2828
2929/// Validation status for provider connections
3030#[ derive( Debug , Clone , PartialEq ) ]
3131pub enum ValidationStatus {
32- Unchecked , // Initial state
33- Checking , // Validation in progress
34- Valid , // ✅ Connection successful
35- Invalid , // ❌ Connection failed
32+ Unchecked , // Initial state
33+ Checking , // Validation in progress
34+ Valid , // ✅ Connection successful
35+ Invalid , // ❌ Connection failed
3636}
3737
3838/// Provider field types for input focus management
@@ -85,7 +85,7 @@ impl ProviderConfig {
8585 if key. len ( ) <= 13 {
8686 "*" . repeat ( key. len ( ) )
8787 } else {
88- format ! ( "{}...{}" , & key[ ..10 ] , & key[ key. len( ) - 3 ..] )
88+ format ! ( "{}...{}" , & key[ ..10 ] , & key[ key. len( ) - 3 ..] )
8989 }
9090 } )
9191 }
@@ -104,11 +104,11 @@ impl ProviderConfig {
104104pub struct Settings {
105105 /// Current theme variant selection
106106 pub theme_variant : ThemeVariant ,
107-
107+
108108 // Provider configuration
109109 pub local_provider : ProviderConfig ,
110110 pub openrouter_provider : ProviderConfig ,
111- pub selected_provider_index : usize , // For UI navigation
111+ pub selected_provider_index : usize , // For UI navigation
112112 pub focused_field : Option < ProviderField > ,
113113}
114114
@@ -169,7 +169,7 @@ impl Settings {
169169 theme_variant : ThemeVariant :: EverforestDark ,
170170 local_provider : ProviderConfig :: new_local ( ) ,
171171 openrouter_provider : ProviderConfig :: new_openrouter ( ) ,
172- selected_provider_index : 0 , // Start with Local provider selected
172+ selected_provider_index : 0 , // Start with Local provider selected
173173 focused_field : None ,
174174 }
175175 }
@@ -190,9 +190,9 @@ impl Settings {
190190 // This will be handled by SettingsModalState
191191 }
192192 SettingsAction :: NavigateThemeNext => {
193- // This will be handled by SettingsModalState
193+ // This will be handled by SettingsModalState
194194 }
195-
195+
196196 // Provider actions
197197 SettingsAction :: NavigateProviderPrevious => {
198198 if self . selected_provider_index > 0 {
@@ -213,16 +213,14 @@ impl Settings {
213213 SettingsAction :: FocusField ( field) => {
214214 self . focused_field = Some ( field) ;
215215 }
216- SettingsAction :: UpdateField ( field, value) => {
217- match field {
218- ProviderField :: LocalEndpoint => {
219- self . local_provider . set_endpoint_url ( value) ;
220- }
221- ProviderField :: OpenRouterApiKey => {
222- self . openrouter_provider . set_api_key ( value) ;
223- }
216+ SettingsAction :: UpdateField ( field, value) => match field {
217+ ProviderField :: LocalEndpoint => {
218+ self . local_provider . set_endpoint_url ( value) ;
224219 }
225- }
220+ ProviderField :: OpenRouterApiKey => {
221+ self . openrouter_provider . set_api_key ( value) ;
222+ }
223+ } ,
226224 SettingsAction :: ValidateProvider ( provider_type) => {
227225 match provider_type {
228226 ProviderType :: Local => {
@@ -301,25 +299,28 @@ impl Settings {
301299 // Validate that at least one provider is configured
302300 if !self . has_configured_provider ( ) {
303301 return Err ( SettingsError :: ValidationFailed (
304- "At least one provider must be configured" . to_string ( )
302+ "At least one provider must be configured" . to_string ( ) ,
305303 ) ) ;
306304 }
307305
308306 // Validate local provider endpoint URL format if configured
309307 if let Some ( ref url) = self . local_provider . endpoint_url
310- && !url. starts_with ( "http://" ) && !url. starts_with ( "https://" ) {
311- return Err ( SettingsError :: ValidationFailed (
312- "Local endpoint must be a valid HTTP/HTTPS URL" . to_string ( )
313- ) ) ;
314- }
308+ && !url. starts_with ( "http://" )
309+ && !url. starts_with ( "https://" )
310+ {
311+ return Err ( SettingsError :: ValidationFailed (
312+ "Local endpoint must be a valid HTTP/HTTPS URL" . to_string ( ) ,
313+ ) ) ;
314+ }
315315
316316 // Validate OpenRouter API key format if configured
317317 if let Some ( ref key) = self . openrouter_provider . api_key
318- && key. trim ( ) . is_empty ( ) {
319- return Err ( SettingsError :: ValidationFailed (
320- "OpenRouter API key cannot be empty" . to_string ( )
321- ) ) ;
322- }
318+ && key. trim ( ) . is_empty ( )
319+ {
320+ return Err ( SettingsError :: ValidationFailed (
321+ "OpenRouter API key cannot be empty" . to_string ( ) ,
322+ ) ) ;
323+ }
323324
324325 Ok ( ( ) )
325326 }
@@ -338,7 +339,7 @@ pub enum SettingsAction {
338339 ChangeTheme ( ThemeVariant ) ,
339340 NavigateThemePrevious ,
340341 NavigateThemeNext ,
341-
342+
342343 // Provider actions
343344 NavigateProviderPrevious ,
344345 NavigateProviderNext ,
@@ -613,30 +614,42 @@ mod tests {
613614 assert_eq ! ( local_config. validation_status, ValidationStatus :: Unchecked ) ;
614615
615616 let openrouter_config = ProviderConfig :: new_openrouter ( ) ;
616- assert ! ( matches!( openrouter_config. provider_type, ProviderType :: OpenRouter ) ) ;
617+ assert ! ( matches!(
618+ openrouter_config. provider_type,
619+ ProviderType :: OpenRouter
620+ ) ) ;
617621 assert ! ( openrouter_config. endpoint_url. is_none( ) ) ;
618622 assert ! ( openrouter_config. api_key. is_none( ) ) ;
619- assert_eq ! ( openrouter_config. validation_status, ValidationStatus :: Unchecked ) ;
623+ assert_eq ! (
624+ openrouter_config. validation_status,
625+ ValidationStatus :: Unchecked
626+ ) ;
620627 }
621628
622629 #[ test]
623630 fn test_provider_config_updates ( ) {
624631 let mut local_config = ProviderConfig :: new_local ( ) ;
625632 local_config. set_endpoint_url ( "http://localhost:8080" . to_string ( ) ) ;
626- assert_eq ! ( local_config. endpoint_url. as_ref( ) . unwrap( ) , "http://localhost:8080" ) ;
633+ assert_eq ! (
634+ local_config. endpoint_url. as_ref( ) . unwrap( ) ,
635+ "http://localhost:8080"
636+ ) ;
627637 assert_eq ! ( local_config. validation_status, ValidationStatus :: Unchecked ) ;
628638
629639 let mut openrouter_config = ProviderConfig :: new_openrouter ( ) ;
630640 openrouter_config. set_api_key ( "sk-or-test123" . to_string ( ) ) ;
631641 assert_eq ! ( openrouter_config. api_key. as_ref( ) . unwrap( ) , "sk-or-test123" ) ;
632- assert_eq ! ( openrouter_config. validation_status, ValidationStatus :: Unchecked ) ;
642+ assert_eq ! (
643+ openrouter_config. validation_status,
644+ ValidationStatus :: Unchecked
645+ ) ;
633646 }
634647
635648 #[ test]
636649 fn test_api_key_masking ( ) {
637650 let mut config = ProviderConfig :: new_openrouter ( ) ;
638651 config. set_api_key ( "sk-or-123456789012345" . to_string ( ) ) ;
639-
652+
640653 let masked = config. get_masked_api_key ( ) . unwrap ( ) ;
641654 assert_eq ! ( masked, "sk-or-1234...345" ) ;
642655
@@ -649,7 +662,7 @@ mod tests {
649662 #[ test]
650663 fn test_provider_configuration_actions ( ) {
651664 let mut settings = Settings :: new ( ) ;
652-
665+
653666 // Test provider navigation
654667 assert_eq ! ( settings. selected_provider_index, 0 ) ;
655668 settings. handle_action ( SettingsAction :: NavigateProviderNext ) ;
@@ -659,22 +672,28 @@ mod tests {
659672
660673 // Test field updates
661674 settings. handle_action ( SettingsAction :: UpdateField (
662- ProviderField :: LocalEndpoint ,
663- "http://localhost:9090" . to_string ( )
675+ ProviderField :: LocalEndpoint ,
676+ "http://localhost:9090" . to_string ( ) ,
664677 ) ) ;
665- assert_eq ! ( settings. local_provider. endpoint_url. as_ref( ) . unwrap( ) , "http://localhost:9090" ) ;
678+ assert_eq ! (
679+ settings. local_provider. endpoint_url. as_ref( ) . unwrap( ) ,
680+ "http://localhost:9090"
681+ ) ;
666682
667683 settings. handle_action ( SettingsAction :: UpdateField (
668- ProviderField :: OpenRouterApiKey ,
669- "test-key-123" . to_string ( )
684+ ProviderField :: OpenRouterApiKey ,
685+ "test-key-123" . to_string ( ) ,
670686 ) ) ;
671- assert_eq ! ( settings. openrouter_provider. api_key. as_ref( ) . unwrap( ) , "test-key-123" ) ;
687+ assert_eq ! (
688+ settings. openrouter_provider. api_key. as_ref( ) . unwrap( ) ,
689+ "test-key-123"
690+ ) ;
672691 }
673692
674693 #[ test]
675694 fn test_provider_validation ( ) {
676695 let mut settings = Settings :: new ( ) ;
677-
696+
678697 // Should fail validation - no providers configured beyond defaults
679698 settings. local_provider . endpoint_url = None ;
680699 settings. openrouter_provider . api_key = None ;
0 commit comments