#![cfg_attr(coverage_nightly, coverage(off))]
include!("core_tools.rs");
include!("extended_tools.rs");
#[cfg(test)]
mod tests {
}
#[cfg(test)]
mod r22_1_d101_cwd_guard_tests {
use super::*;
use serde_json::json;
fn assert_invalid_params(response: &McpResponse, context: &str) {
assert!(
response.error.is_some(),
"{context}: expected an error response, got success: {response:?}"
);
let err = response.error.as_ref().unwrap();
assert_eq!(
err.code, -32602,
"{context}: expected JSON-RPC -32602 (Invalid params), got {}: message={}",
err.code, err.message
);
assert!(
err.message.contains("project_path"),
"{context}: error message should name the offending field: {}",
err.message
);
}
#[tokio::test]
async fn analyze_complexity_rejects_missing_project_path() {
let response = handle_analyze_complexity(json!(1), json!({})).await;
assert_invalid_params(&response, "analyze_complexity / missing");
}
#[tokio::test]
async fn analyze_complexity_rejects_null_project_path() {
let response = handle_analyze_complexity(json!(1), json!({ "project_path": null })).await;
assert_invalid_params(&response, "analyze_complexity / null");
}
#[tokio::test]
async fn analyze_complexity_rejects_empty_project_path() {
let response = handle_analyze_complexity(json!(1), json!({ "project_path": "" })).await;
assert_invalid_params(&response, "analyze_complexity / empty");
}
#[tokio::test]
async fn analyze_complexity_rejects_whitespace_project_path() {
let response = handle_analyze_complexity(json!(1), json!({ "project_path": " " })).await;
assert_invalid_params(&response, "analyze_complexity / whitespace");
}
#[tokio::test]
async fn analyze_code_churn_rejects_missing_project_path() {
let response = handle_analyze_code_churn(json!(1), json!({})).await;
assert_invalid_params(&response, "analyze_code_churn / missing");
}
#[tokio::test]
async fn analyze_code_churn_rejects_empty_project_path() {
let response = handle_analyze_code_churn(json!(1), json!({ "project_path": "" })).await;
assert_invalid_params(&response, "analyze_code_churn / empty");
}
#[tokio::test]
async fn analyze_dag_rejects_missing_project_path() {
let response = handle_analyze_dag(json!(1), json!({})).await;
assert_invalid_params(&response, "analyze_dag / missing");
}
#[tokio::test]
async fn analyze_dag_rejects_empty_project_path() {
let response = handle_analyze_dag(json!(1), json!({ "project_path": "" })).await;
assert_invalid_params(&response, "analyze_dag / empty");
}
#[tokio::test]
async fn generate_context_rejects_missing_project_path() {
let response = handle_generate_context(json!(1), json!({})).await;
assert_invalid_params(&response, "generate_context / missing");
}
#[tokio::test]
async fn generate_context_rejects_empty_project_path() {
let response = handle_generate_context(json!(1), json!({ "project_path": "" })).await;
assert_invalid_params(&response, "generate_context / empty");
}
#[tokio::test]
async fn analyze_system_architecture_rejects_missing_project_path() {
let response = handle_analyze_system_architecture(json!(1), json!({})).await;
assert_invalid_params(&response, "analyze_system_architecture / missing");
}
#[tokio::test]
async fn analyze_system_architecture_rejects_empty_project_path() {
let response =
handle_analyze_system_architecture(json!(1), json!({ "project_path": "" })).await;
assert_invalid_params(&response, "analyze_system_architecture / empty");
}
#[test]
fn require_project_path_accepts_nonempty() {
let out = require_project_path(Some("/tmp/x".to_string())).unwrap();
assert_eq!(out, std::path::PathBuf::from("/tmp/x"));
}
#[test]
fn require_project_path_rejects_none() {
let err = require_project_path(None).unwrap_err();
assert!(err.contains("project_path"), "{err}");
assert!(err.contains("D101"), "{err}");
}
#[test]
fn require_project_path_rejects_empty() {
let err = require_project_path(Some(String::new())).unwrap_err();
assert!(err.contains("non-empty"), "{err}");
}
#[test]
fn require_project_path_rejects_whitespace() {
let err = require_project_path(Some(" \n\t ".to_string())).unwrap_err();
assert!(err.contains("non-empty"), "{err}");
}
}