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>
77 lines
2.4 KiB
Rust
77 lines
2.4 KiB
Rust
//! Integration test for the MCP prompt rendering server.
|
|
|
|
use owlen_core::Result;
|
|
use owlen_core::config::McpServerConfig;
|
|
use owlen_core::mcp::client::RemoteMcpClient;
|
|
use owlen_core::mcp::{McpToolCall, McpToolResponse};
|
|
use serde_json::json;
|
|
use std::path::PathBuf;
|
|
|
|
#[tokio::test]
|
|
async fn test_render_prompt_via_external_server() -> Result<()> {
|
|
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
|
let workspace_root = manifest_dir
|
|
.parent()
|
|
.and_then(|p| p.parent())
|
|
.expect("workspace root");
|
|
|
|
let candidates = [
|
|
workspace_root
|
|
.join("target")
|
|
.join("debug")
|
|
.join("owlen-mcp-prompt-server"),
|
|
workspace_root
|
|
.join("owlen-mcp-prompt-server")
|
|
.join("target")
|
|
.join("debug")
|
|
.join("owlen-mcp-prompt-server"),
|
|
];
|
|
|
|
let binary = if let Some(path) = candidates.iter().find(|path| path.exists()) {
|
|
path.clone()
|
|
} else {
|
|
eprintln!(
|
|
"Skipping prompt server integration test: binary not found. \
|
|
Build it with `cargo build -p owlen-mcp-prompt-server`. Tried {:?}",
|
|
candidates
|
|
);
|
|
return Ok(());
|
|
};
|
|
|
|
let config = McpServerConfig {
|
|
name: "prompt_server".into(),
|
|
command: binary.to_string_lossy().into_owned(),
|
|
args: Vec::new(),
|
|
transport: "stdio".into(),
|
|
env: std::collections::HashMap::new(),
|
|
oauth: None,
|
|
rpc_timeout_secs: None,
|
|
};
|
|
|
|
let client = match RemoteMcpClient::new_with_config(&config).await {
|
|
Ok(client) => client,
|
|
Err(err) => {
|
|
eprintln!(
|
|
"Skipping prompt server integration test: failed to launch {} ({err})",
|
|
config.command
|
|
);
|
|
return Ok(());
|
|
}
|
|
};
|
|
|
|
let call = McpToolCall {
|
|
name: "render_prompt".into(),
|
|
arguments: json!({
|
|
"template_name": "example",
|
|
"variables": {"name": "Alice", "role": "Tester"}
|
|
}),
|
|
};
|
|
|
|
let resp: McpToolResponse = client.call_tool(call).await?;
|
|
assert!(resp.success, "Tool reported failure: {:?}", resp);
|
|
let output = resp.output.as_str().unwrap_or("");
|
|
assert!(output.contains("Alice"), "Output missing name: {}", output);
|
|
assert!(output.contains("Tester"), "Output missing role: {}", output);
|
|
Ok(())
|
|
}
|