Skip to content

Commit d59f7b1

Browse files
committed
🔧 Fix code formatting
- Run cargo fmt to format code according to Rust standards - Clean up import formatting and line breaks - Ensure CI formatting checks pass
1 parent a1c1300 commit d59f7b1

File tree

2 files changed

+124
-71
lines changed

2 files changed

+124
-71
lines changed

examples/issue_29_demo.rs

Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
//!
33
//! Demonstrates the new provider configuration system for LOCAL and OPENROUTER providers.
44
5-
use agentic::{
6-
settings::{
7-
Settings, SettingsAction, ProviderConfig, ProviderField,
8-
ValidationStatus
9-
},
5+
use agentic::settings::{
6+
ProviderConfig, ProviderField, Settings, SettingsAction, ValidationStatus,
107
};
118

129
fn main() {
@@ -18,56 +15,90 @@ fn main() {
1815
// 1. Create settings with provider configurations
1916
println!("1. Creating settings with default provider configurations...");
2017
let mut settings = Settings::new();
21-
22-
println!(" Local provider configured: {}", settings.local_provider.is_configured());
23-
println!(" OpenRouter provider configured: {}", settings.openrouter_provider.is_configured());
24-
println!(" Selected provider: {}", settings.get_provider_name(settings.selected_provider_index));
18+
19+
println!(
20+
" Local provider configured: {}",
21+
settings.local_provider.is_configured()
22+
);
23+
println!(
24+
" OpenRouter provider configured: {}",
25+
settings.openrouter_provider.is_configured()
26+
);
27+
println!(
28+
" Selected provider: {}",
29+
settings.get_provider_name(settings.selected_provider_index)
30+
);
2531

2632
// 2. Test provider type creation
2733
println!("\n2. Testing provider configuration types...");
2834
let local_config = ProviderConfig::new_local();
2935
let openrouter_config = ProviderConfig::new_openrouter();
30-
36+
3137
println!(" Local default endpoint: {:?}", local_config.endpoint_url);
3238
println!(" Local API key: {:?}", local_config.api_key);
33-
println!(" OpenRouter endpoint: {:?}", openrouter_config.endpoint_url);
39+
println!(
40+
" OpenRouter endpoint: {:?}",
41+
openrouter_config.endpoint_url
42+
);
3443
println!(" OpenRouter API key: {:?}", openrouter_config.api_key);
3544

3645
// 3. Test validation status system
3746
println!("\n3. Testing validation status system...");
3847
for status in [
3948
ValidationStatus::Unchecked,
40-
ValidationStatus::Checking,
49+
ValidationStatus::Checking,
4150
ValidationStatus::Valid,
42-
ValidationStatus::Invalid
51+
ValidationStatus::Invalid,
4352
] {
44-
println!(" Status: {:?} → Icon: {}", status, Settings::get_validation_status_icon(&status));
53+
println!(
54+
" Status: {:?} → Icon: {}",
55+
status,
56+
Settings::get_validation_status_icon(&status)
57+
);
4558
}
4659

4760
// 4. Test field updates
4861
println!("\n4. Testing field update actions...");
4962
settings.handle_action(SettingsAction::UpdateField(
5063
ProviderField::LocalEndpoint,
51-
"http://localhost:8080".to_string()
64+
"http://localhost:8080".to_string(),
5265
));
53-
println!(" Updated local endpoint: {:?}", settings.local_provider.endpoint_url);
66+
println!(
67+
" Updated local endpoint: {:?}",
68+
settings.local_provider.endpoint_url
69+
);
5470

5571
settings.handle_action(SettingsAction::UpdateField(
5672
ProviderField::OpenRouterApiKey,
57-
"sk-or-demo123456789012345".to_string()
73+
"sk-or-demo123456789012345".to_string(),
5874
));
59-
println!(" Updated OpenRouter API key: {:?}", settings.openrouter_provider.api_key);
60-
println!(" Masked API key display: {:?}", settings.openrouter_provider.get_masked_api_key());
75+
println!(
76+
" Updated OpenRouter API key: {:?}",
77+
settings.openrouter_provider.api_key
78+
);
79+
println!(
80+
" Masked API key display: {:?}",
81+
settings.openrouter_provider.get_masked_api_key()
82+
);
6183

6284
// 5. Test provider navigation
6385
println!("\n5. Testing provider navigation...");
64-
println!(" Current provider index: {}", settings.selected_provider_index);
86+
println!(
87+
" Current provider index: {}",
88+
settings.selected_provider_index
89+
);
6590
settings.handle_action(SettingsAction::NavigateProviderNext);
66-
println!(" After next: {} ({})", settings.selected_provider_index,
67-
settings.get_provider_name(settings.selected_provider_index));
91+
println!(
92+
" After next: {} ({})",
93+
settings.selected_provider_index,
94+
settings.get_provider_name(settings.selected_provider_index)
95+
);
6896
settings.handle_action(SettingsAction::NavigateProviderNext);
69-
println!(" After next (wrap): {} ({})", settings.selected_provider_index,
70-
settings.get_provider_name(settings.selected_provider_index));
97+
println!(
98+
" After next (wrap): {} ({})",
99+
settings.selected_provider_index,
100+
settings.get_provider_name(settings.selected_provider_index)
101+
);
71102

72103
// 6. Test validation
73104
println!("\n6. Testing configuration validation...");
@@ -90,7 +121,10 @@ fn main() {
90121
let mut secure_config = ProviderConfig::new_openrouter();
91122
secure_config.set_api_key("sk-or-very-long-secret-key-12345".to_string());
92123
println!(" Full key: {:?}", secure_config.api_key);
93-
println!(" Masked display: {:?}", secure_config.get_masked_api_key());
124+
println!(
125+
" Masked display: {:?}",
126+
secure_config.get_masked_api_key()
127+
);
94128

95129
println!("\n🎯 Success Criteria Verification:");
96130
println!("✅ Provider configuration data structures defined");

src/settings.rs

Lines changed: 65 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ pub enum ProviderType {
2121
#[derive(Debug, Clone)]
2222
pub 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)]
3131
pub 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 {
104104
pub 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

Comments
 (0)