Rinomina: crate akode-*, cartelle akode-rs/ e akode-cli/, binario akode, ~/.akode, AKODE_* (A)
Riapplica la fase 5 di aKode (86e7c72e) sulla base ripulita:
- crate codex-* -> akode-*, codex-rs -> akode-rs, codex-cli -> akode-cli, binario e ausiliari akode;
- ~/.codex -> ~/.akode, CODEX_HOME -> AKODE_HOME, variabili CODEX_* -> AKODE_*, .codex/ -> .akode/ di progetto;
nessun fallback a ~/.codex o a CODEX_*;
- testi per l'utente "Codex" -> "aKode"; testi verso il modello e istruzioni di sistema invariati;
- snapshot insta rinominati (non ancora rigenerati).
I conflitti con la base ripulita sono stati risolti riapplicando la rinomina ai file senza le
funzioni di imeAI (script di mappa dei token per file).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
279
akode-rs/rmcp-client/tests/mcp_2026_stdio.rs
Normal file
279
akode-rs/rmcp-client/tests/mcp_2026_stdio.rs
Normal file
@@ -0,0 +1,279 @@
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::OsString;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::time::Duration;
|
||||
|
||||
use akode_exec_server::Environment;
|
||||
use akode_rmcp_client::Elicitation;
|
||||
use akode_rmcp_client::ElicitationAction;
|
||||
use akode_rmcp_client::ElicitationResponse;
|
||||
use akode_rmcp_client::ExecutorStdioServerLauncher;
|
||||
use akode_rmcp_client::LocalStdioServerLauncher;
|
||||
use akode_rmcp_client::McpProtocolMode;
|
||||
use akode_rmcp_client::RmcpClient;
|
||||
use akode_rmcp_client::StdioServerLauncher;
|
||||
use futures::FutureExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
use rmcp::model::ClientCapabilities;
|
||||
use rmcp::model::ElicitRequestParams;
|
||||
use rmcp::model::ElicitationCapability;
|
||||
use rmcp::model::FormElicitationCapability;
|
||||
use rmcp::model::Implementation;
|
||||
use rmcp::model::InitializeRequestParams;
|
||||
use rmcp::model::ProtocolVersion;
|
||||
use serde_json::json;
|
||||
|
||||
async fn exercise_stdio_server(
|
||||
server_mode: &str,
|
||||
protocol_mode: McpProtocolMode,
|
||||
opt_in: bool,
|
||||
use_executor: bool,
|
||||
) -> anyhow::Result<()> {
|
||||
let server = akode_utils_cargo_bin::cargo_bin("test_mcp_2026_stdio_server")?;
|
||||
let launcher: Arc<dyn StdioServerLauncher> = if use_executor {
|
||||
Arc::new(ExecutorStdioServerLauncher::new(
|
||||
Environment::default_for_tests().get_exec_backend(),
|
||||
))
|
||||
} else {
|
||||
Arc::new(LocalStdioServerLauncher::new(std::env::current_dir()?))
|
||||
};
|
||||
let mut env = HashMap::new();
|
||||
if opt_in {
|
||||
env.insert(
|
||||
OsString::from("AKODE_MCP_PROTOCOL_VERSION"),
|
||||
OsString::from("2026-07-28"),
|
||||
);
|
||||
}
|
||||
let root = tempfile::tempdir()?;
|
||||
let cwd = if use_executor {
|
||||
std::env::current_dir()?
|
||||
} else {
|
||||
root.path().to_path_buf()
|
||||
};
|
||||
#[cfg(unix)]
|
||||
let server = if use_executor {
|
||||
server
|
||||
} else {
|
||||
let wrapper = root.path().join("server");
|
||||
let script = "#!/bin/sh\nprintf '%s' \"$0\" > argv0\nexec \"$MCP_SERVER\" \"$@\"\n";
|
||||
akode_utils_cargo_bin::write_executable(&wrapper, script)?;
|
||||
env.insert(OsString::from("MCP_SERVER"), server.into_os_string());
|
||||
std::path::PathBuf::from("./server")
|
||||
};
|
||||
let client = RmcpClient::new_stdio_client_with_protocol_mode(
|
||||
server.into(),
|
||||
vec![OsString::from(server_mode)],
|
||||
Some(env),
|
||||
&[],
|
||||
Some(cwd.to_string_lossy().into_owned()),
|
||||
launcher,
|
||||
protocol_mode,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let mut capabilities = ClientCapabilities::default();
|
||||
capabilities.elicitation =
|
||||
Some(ElicitationCapability::new().with_form(FormElicitationCapability::new()));
|
||||
let elicitation_count = Arc::new(AtomicUsize::new(0));
|
||||
let observed_elicitations = Arc::clone(&elicitation_count);
|
||||
let legacy_session = server_mode.starts_with("legacy");
|
||||
let initialized = client
|
||||
.initialize(
|
||||
InitializeRequestParams::new(
|
||||
capabilities,
|
||||
Implementation::new("codex-mcp-client", "0.0.0-test"),
|
||||
)
|
||||
.with_protocol_version(ProtocolVersion::V_2025_06_18),
|
||||
Some(Duration::from_secs(if server_mode.ends_with("-late") {
|
||||
30
|
||||
} else {
|
||||
5
|
||||
})),
|
||||
Box::new(move |_request_id, request| {
|
||||
let observed_elicitations = Arc::clone(&observed_elicitations);
|
||||
async move {
|
||||
observed_elicitations.fetch_add(1, Ordering::Relaxed);
|
||||
let Elicitation::Mcp(ElicitRequestParams::FormElicitationParams {
|
||||
requested_schema,
|
||||
..
|
||||
}) = request
|
||||
else {
|
||||
anyhow::bail!("expected a standard MCP form elicitation");
|
||||
};
|
||||
let content = if legacy_session {
|
||||
assert_eq!(
|
||||
serde_json::to_value(requested_schema)?,
|
||||
json!({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {"type": "string", "default": "John Doe"},
|
||||
"age": {"type": "integer", "default": 30},
|
||||
"score": {"type": "number", "default": 95.5},
|
||||
"status": {
|
||||
"type": "string",
|
||||
"enum": ["active", "inactive"],
|
||||
"default": "active",
|
||||
},
|
||||
"verified": {"type": "boolean", "default": true},
|
||||
},
|
||||
"required": [],
|
||||
}),
|
||||
);
|
||||
json!({
|
||||
"name": "John Doe",
|
||||
"age": 30,
|
||||
"score": 95.5,
|
||||
"status": "active",
|
||||
"verified": true,
|
||||
})
|
||||
} else {
|
||||
json!({"approved": true})
|
||||
};
|
||||
Ok(ElicitationResponse {
|
||||
action: ElicitationAction::Accept,
|
||||
content: Some(content),
|
||||
meta: None,
|
||||
})
|
||||
}
|
||||
.boxed()
|
||||
}),
|
||||
)
|
||||
.await?;
|
||||
|
||||
let expected_version = if legacy_session {
|
||||
ProtocolVersion::V_2025_06_18
|
||||
} else {
|
||||
ProtocolVersion::V_2026_07_28
|
||||
};
|
||||
assert_eq!(initialized.protocol_version, expected_version);
|
||||
assert_eq!(
|
||||
initialized
|
||||
.server_info
|
||||
.as_ref()
|
||||
.map(|server_info| server_info.name.as_str()),
|
||||
Some(if legacy_session {
|
||||
"legacy-stdio-test"
|
||||
} else {
|
||||
"strict-stdio-test"
|
||||
})
|
||||
);
|
||||
let tools = client
|
||||
.list_tools(/*params*/ None, Some(Duration::from_secs(5)))
|
||||
.await?;
|
||||
assert_eq!(
|
||||
tools
|
||||
.tools
|
||||
.iter()
|
||||
.map(|tool| tool.name.as_ref())
|
||||
.collect::<Vec<_>>(),
|
||||
vec!["echo"]
|
||||
);
|
||||
let result = client
|
||||
.call_tool(
|
||||
"echo".to_owned(),
|
||||
Some(json!({"message": "hello stdio"})),
|
||||
|_| Ok(None),
|
||||
Some(Duration::from_secs(5)),
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(
|
||||
result.content[0].as_text().map(|text| text.text.as_str()),
|
||||
Some(if legacy_session {
|
||||
"legacy approved"
|
||||
} else {
|
||||
"modern approved"
|
||||
})
|
||||
);
|
||||
assert_eq!(elicitation_count.load(Ordering::Relaxed), 1);
|
||||
#[cfg(unix)]
|
||||
if !use_executor {
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(root.path().join("argv0"))?,
|
||||
"./server"
|
||||
);
|
||||
}
|
||||
client.shutdown().await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn modern_local_stdio_discovers_metadata_only_identity_and_drives_mrtr() -> anyhow::Result<()>
|
||||
{
|
||||
exercise_stdio_server(
|
||||
"modern",
|
||||
McpProtocolMode::V20260728,
|
||||
/*opt_in*/ true,
|
||||
/*use_executor*/ false,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn modern_executor_stdio_discovers_metadata_only_identity_and_drives_mrtr()
|
||||
-> anyhow::Result<()> {
|
||||
exercise_stdio_server(
|
||||
"modern",
|
||||
McpProtocolMode::V20260728,
|
||||
/*opt_in*/ true,
|
||||
/*use_executor*/ true,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn legacy_stdio_supports_sep1034_defaults_without_the_rollout_flag() -> anyhow::Result<()> {
|
||||
exercise_stdio_server(
|
||||
"legacy",
|
||||
McpProtocolMode::Legacy,
|
||||
/*opt_in*/ false,
|
||||
/*use_executor*/ false,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn rollout_flag_alone_preserves_legacy_stdio_and_sep1034_defaults() -> anyhow::Result<()> {
|
||||
exercise_stdio_server(
|
||||
"legacy",
|
||||
McpProtocolMode::V20260728,
|
||||
/*opt_in*/ false,
|
||||
/*use_executor*/ false,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn unmarked_stdio_helpers_recover_from_failed_or_late_discovery() -> anyhow::Result<()> {
|
||||
for mode in [
|
||||
"legacy",
|
||||
"legacy-init-first",
|
||||
"legacy-reject-late-initialize",
|
||||
"legacy-reject-and-exit",
|
||||
"legacy-late",
|
||||
"legacy-silent",
|
||||
"legacy-versions",
|
||||
"modern-late",
|
||||
] {
|
||||
exercise_stdio_server(
|
||||
mode,
|
||||
McpProtocolMode::DiscoverLocalStdio,
|
||||
/*opt_in*/ false,
|
||||
/*use_executor*/ false,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn modern_stdio_safely_falls_back_to_legacy_elicitation() -> anyhow::Result<()> {
|
||||
exercise_stdio_server(
|
||||
"legacy-fallback",
|
||||
McpProtocolMode::V20260728,
|
||||
/*opt_in*/ true,
|
||||
/*use_executor*/ false,
|
||||
)
|
||||
.await
|
||||
}
|
||||
Reference in New Issue
Block a user