Migrate all remaining collapsible_if patterns to Rust 2024 let-chain syntax across the entire codebase. This modernizes conditional logic by replacing nested if statements with single-level expressions using the && operator with let patterns. Changes: - storage.rs: 2 let-chain conversions (database dir creation, legacy archiving) - session.rs: 3 let-chain conversions (empty content check, ledger dir creation, consent flow) - ollama.rs: 8 let-chain conversions (socket parsing, cloud validation, model caching, capabilities) - main.rs: 2 let-chain conversions (API key validation, provider enablement) - owlen-tui: ~50 let-chain conversions across app/mod.rs, chat_app.rs, ui.rs, highlight.rs, and state modules Test fixes: - prompt_server.rs: Add missing .await on async RemoteMcpClient::new_with_config - presets.rs, prompt_server.rs: Add missing rpc_timeout_secs field to McpServerConfig - file_write.rs: Update error assertion to accept new "escapes workspace boundary" message Verification: - cargo build --all: ✅ succeeds - cargo clippy --all -- -D clippy::collapsible_if: ✅ zero warnings - cargo test --all: ✅ 109+ tests pass Net result: -46 lines of code, improved readability and maintainability. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
63 lines
1.9 KiB
Rust
63 lines
1.9 KiB
Rust
use owlen_core::config::Config;
|
|
use owlen_core::mcp::presets::{PresetTier, apply_preset, audit_preset};
|
|
|
|
#[test]
|
|
fn standard_preset_produces_spec_compliant_servers() {
|
|
let configs = Config::preset_servers(PresetTier::Standard);
|
|
assert!(
|
|
!configs.is_empty(),
|
|
"expected standard preset to contain connectors"
|
|
);
|
|
for server in configs {
|
|
assert!(
|
|
server
|
|
.name
|
|
.chars()
|
|
.all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '-'),
|
|
"server '{}' failed identifier validation",
|
|
server.name
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn apply_preset_adds_missing_servers() {
|
|
let mut config = Config::default();
|
|
let report = apply_preset(&mut config, PresetTier::Standard, false).expect("apply preset");
|
|
assert!(!report.added.is_empty(), "expected connectors to be added");
|
|
assert!(report.updated.is_empty());
|
|
assert!(report.removed.is_empty());
|
|
|
|
let audit = audit_preset(&config, PresetTier::Standard);
|
|
assert!(
|
|
audit.missing.is_empty(),
|
|
"expected no missing connectors after install"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn prune_preset_removes_extra_entries() {
|
|
let mut config = Config::default();
|
|
// Seed with an extra entry
|
|
config
|
|
.mcp_servers
|
|
.push(owlen_core::config::McpServerConfig {
|
|
name: "custom_tool".into(),
|
|
command: "custom-cmd".into(),
|
|
args: vec![],
|
|
transport: "stdio".into(),
|
|
env: Default::default(),
|
|
oauth: None,
|
|
rpc_timeout_secs: None,
|
|
});
|
|
|
|
let report = apply_preset(&mut config, PresetTier::Standard, true).expect("apply preset");
|
|
assert!(report.removed.contains(&"custom_tool".to_string()));
|
|
assert!(
|
|
config
|
|
.mcp_servers
|
|
.iter()
|
|
.all(|srv| srv.name != "custom_tool")
|
|
);
|
|
}
|