aKode fase 5: test e snapshot adeguati alla rinomina, 429 distinto (ProviderRateLimited), cargo fmt dopo il cambio dei prefissi

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
andrea.difonzo
2026-11-11 12:47:01 +01:00
parent 8b73331037
commit ad43f9281a
919 changed files with 2358 additions and 2430 deletions

View File

@@ -2,9 +2,9 @@ use std::collections::HashMap;
use std::sync::Arc;
use std::time::Duration;
use anyhow::Result;
use akode_exec_server::HttpClient;
use akode_protocol::protocol::McpAuthStatus;
use anyhow::Result;
use futures::FutureExt;
use http::HeaderMap;
use http::header::AUTHORIZATION;
@@ -307,11 +307,6 @@ fn normalize_scopes(scopes_supported: Vec<String>) -> Option<Vec<String>> {
#[cfg(test)]
mod tests {
use super::*;
use axum::Json;
use axum::Router;
use axum::http::StatusCode;
use axum::http::header::WWW_AUTHENTICATE;
use axum::routing::get;
use akode_exec_server::ExecServerError;
use akode_exec_server::HttpRedirectPolicy;
use akode_exec_server::HttpRequestParams;
@@ -320,6 +315,11 @@ mod tests {
use akode_exec_server::RouteAwareHttpClient;
use akode_http_client::HttpClientFactory;
use akode_http_client::OutboundProxyPolicy;
use axum::Json;
use axum::Router;
use axum::http::StatusCode;
use axum::http::header::WWW_AUTHENTICATE;
use axum::routing::get;
use futures::future::BoxFuture;
use pretty_assertions::assert_eq;
use serial_test::serial;

View File

@@ -24,7 +24,6 @@ use std::sync::Arc;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
use bytes::BytesMut;
use akode_exec_server::ExecOutputStream;
use akode_exec_server::ExecProcess;
use akode_exec_server::ExecProcessEvent;
@@ -32,6 +31,7 @@ use akode_exec_server::ExecProcessEventReceiver;
use akode_exec_server::ProcessId;
use akode_exec_server::ProcessOutputChunk;
use akode_exec_server::WriteStatus;
use bytes::BytesMut;
use memchr::memchr;
use rmcp::service::RoleClient;
use rmcp::service::RxJsonRpcMessage;

View File

@@ -1,4 +1,3 @@
use bytes::BytesMut;
use akode_exec_server::ExecOutputStream;
use akode_exec_server::ExecProcess;
use akode_exec_server::ExecProcessEventReceiver;
@@ -9,6 +8,7 @@ use akode_exec_server::ProcessSignal;
use akode_exec_server::ReadResponse;
use akode_exec_server::WriteResponse;
use akode_exec_server::WriteStatus;
use bytes::BytesMut;
use pretty_assertions::assert_eq;
use rmcp::service::RoleClient;
use rmcp::service::TxJsonRpcMessage;

View File

@@ -16,13 +16,13 @@ use std::time::Duration;
use std::time::Instant;
use crate::AuthProviderResolver;
use bytes::Bytes;
use akode_exec_server::ExecServerError;
use akode_exec_server::HttpClient;
use akode_exec_server::HttpHeader;
use akode_exec_server::HttpRedirectPolicy;
use akode_exec_server::HttpRequestParams;
use akode_exec_server::HttpResponseBodyStream;
use bytes::Bytes;
use futures::StreamExt;
use futures::stream;
use futures::stream::BoxStream;

View File

@@ -10,8 +10,6 @@ use std::sync::Mutex;
use std::sync::PoisonError;
use std::time::Duration;
use anyhow::Result;
use anyhow::anyhow;
use akode_exec_server::ExecServerError;
use akode_exec_server::HttpClient;
use akode_exec_server::HttpHeader;
@@ -21,6 +19,8 @@ use akode_exec_server::HttpRequestResponse;
use akode_exec_server::HttpResponseBodyStream;
#[cfg(unix)]
use akode_utils_pty::process_group::kill_process_group;
use anyhow::Result;
use anyhow::anyhow;
use futures::FutureExt;
use futures::future::BoxFuture;
use futures::future::Shared;

View File

@@ -198,14 +198,14 @@ async fn failed_refresh_is_shared_without_replacing_credentials() {
#[cfg(unix)]
#[tokio::test]
async fn connection_headers_are_cached_and_origin_bound() {
use akode_exec_server::RouteAwareHttpClient;
use akode_http_client::HttpClientFactory;
use akode_http_client::OutboundProxyPolicy;
use axum::Router;
use axum::http::StatusCode;
use axum::response::Redirect;
use axum::routing::get;
use axum::routing::post;
use akode_exec_server::RouteAwareHttpClient;
use akode_http_client::HttpClientFactory;
use akode_http_client::OutboundProxyPolicy;
use std::sync::Arc;
use tempfile::tempdir;
use tokio::net::TcpListener;
@@ -300,13 +300,13 @@ async fn connection_headers_are_cached_and_origin_bound() {
#[cfg(unix)]
#[tokio::test]
async fn concurrent_rejected_posts_share_one_headers_refresh() {
use akode_exec_server::RouteAwareHttpClient;
use akode_http_client::HttpClientFactory;
use akode_http_client::OutboundProxyPolicy;
use axum::Router;
use axum::extract::State;
use axum::http::StatusCode;
use axum::routing::post;
use akode_exec_server::RouteAwareHttpClient;
use akode_http_client::HttpClientFactory;
use akode_http_client::OutboundProxyPolicy;
use tempfile::tempdir;
use tokio::net::TcpListener;
use tokio::sync::Barrier;

View File

@@ -33,6 +33,7 @@ mod user_verification;
mod utils;
mod www_authenticate;
pub use akode_protocol::protocol::McpAuthStatus;
pub use auth_status::McpAuthState;
pub use auth_status::McpLoginRequirement;
pub use auth_status::OAuthDiscoveryTimeout;
@@ -40,7 +41,6 @@ pub use auth_status::StreamableHttpOAuthDiscovery;
pub use auth_status::determine_streamable_http_auth_status;
pub use auth_status::determine_streamable_http_auth_status_from_credentials;
pub use auth_status::discover_streamable_http_oauth;
pub use akode_protocol::protocol::McpAuthStatus;
pub use event_notification_transport::EventNotificationReceiver;
pub use http_client_adapter::StreamableHttpRedirectMode;
pub use http_headers::with_http_headers_helper;

View File

@@ -29,9 +29,6 @@ mod telemetry;
#[path = "oauth/test_support.rs"]
pub(crate) mod test_support;
use anyhow::Context;
use anyhow::Error;
use anyhow::Result;
use akode_config::types::AuthKeyringBackendKind;
use akode_config::types::OAuthCredentialsStoreMode;
use akode_otel::auth_storage::Operation;
@@ -41,6 +38,9 @@ use akode_secrets::SecretName;
use akode_secrets::SecretScope;
use akode_secrets::SecretsBackendKind;
use akode_secrets::SecretsManager;
use anyhow::Context;
use anyhow::Error;
use anyhow::Result;
use oauth2::AccessToken;
use oauth2::RefreshToken;
use oauth2::Scope;
@@ -1165,9 +1165,9 @@ fn sha_256_prefix(value: &Value) -> Result<String> {
#[cfg(test)]
mod tests {
use super::*;
use anyhow::Result;
use akode_keyring_store::tests::MockKeyringStore;
use akode_secrets::compute_keyring_account;
use anyhow::Result;
use keyring::Error as KeyringError;
use pretty_assertions::assert_eq;
use std::sync::Arc;

View File

@@ -19,12 +19,12 @@
use std::sync::Arc;
use std::sync::Weak;
use anyhow::Context;
use anyhow::Result;
use akode_config::McpServerOAuthConfig;
use akode_config::types::AuthKeyringBackendKind;
use akode_keyring_store::DefaultKeyringStore;
use akode_keyring_store::KeyringStore;
use anyhow::Context;
use anyhow::Result;
use futures::future::BoxFuture;
use oauth2::Scope;
use oauth2::TokenResponse;

View File

@@ -5,10 +5,10 @@
//! rotating refresh token or observing a partially persisted transaction.
//! EMA uses the same lock only for short credential reads and generation checks.
use akode_utils_home_dir::find_codex_home;
use anyhow::Context;
use anyhow::Result;
use anyhow::anyhow;
use akode_utils_home_dir::find_codex_home;
use sha2::Digest;
use sha2::Sha256;
use std::fs;

View File

@@ -4,12 +4,12 @@ use std::time::Duration;
use std::time::SystemTime;
use std::time::UNIX_EPOCH;
use anyhow::Context;
use anyhow::Error;
use anyhow::Result;
use akode_config::McpServerOAuthConfig;
use akode_keyring_store::DefaultKeyringStore;
use akode_keyring_store::KeyringStore;
use anyhow::Context;
use anyhow::Error;
use anyhow::Result;
use oauth2::TokenResponse;
use rmcp::transport::auth::AuthError;
use rmcp::transport::auth::AuthorizationManager;

View File

@@ -2,14 +2,14 @@
//! Retains the originating client for later background storage observations.
use super::telemetry;
use anyhow::Context;
use anyhow::Result;
use akode_config::types::AuthKeyringBackendKind;
use akode_config::types::OAuthCredentialsStoreMode;
use akode_keyring_store::KeyringStore;
use akode_otel::auth_storage::AuthStorageOriginator;
use akode_otel::auth_storage::Operation;
use akode_otel::auth_storage::Store;
use anyhow::Context;
use anyhow::Result;
use super::OAuthKeyringLoadError;
use super::OAuthStore;

View File

@@ -4,8 +4,8 @@ use std::time::Duration;
use std::time::SystemTime;
use std::time::UNIX_EPOCH;
use anyhow::Result;
use akode_config::types::AuthKeyringBackendKind;
use anyhow::Result;
use keyring::Error as KeyringError;
use oauth2::AccessToken;
use oauth2::RefreshToken;

View File

@@ -2,14 +2,14 @@ use std::sync::Arc;
use std::sync::mpsc;
use std::time::Duration;
use anyhow::Context;
use anyhow::Result;
use akode_config::types::AuthKeyringBackendKind;
use akode_config::types::OAuthCredentialsStoreMode;
use akode_exec_server::RouteAwareHttpClient;
use akode_http_client::HttpClientFactory;
use akode_http_client::OutboundProxyPolicy;
use akode_keyring_store::DefaultKeyringStore;
use anyhow::Context;
use anyhow::Result;
use http::HeaderMap;
use keyring::Error as KeyringError;
use oauth2::AccessToken;

View File

@@ -3,11 +3,11 @@ use std::sync::mpsc;
use std::time::Duration;
use std::time::Instant;
use anyhow::Context;
use anyhow::Result;
use akode_config::types::AuthKeyringBackendKind;
use akode_keyring_store::KeyringStore;
use akode_keyring_store::tests::MockKeyringStore;
use anyhow::Context;
use anyhow::Result;
use oauth2::AccessToken;
use oauth2::RefreshToken;
use oauth2::Scope;

View File

@@ -9,14 +9,14 @@ use super::OauthLoginFlow;
use crate::McpOAuthClientRegistration;
use crate::StreamableHttpRedirectMode;
use crate::save_oauth_tokens;
use anyhow::Context;
use anyhow::Result;
use anyhow::anyhow;
use anyhow::bail;
use akode_config::McpServerOAuthConfig;
use akode_config::types::AuthKeyringBackendKind;
use akode_config::types::OAuthCredentialsStoreMode;
use akode_exec_server::HttpClient;
use anyhow::Context;
use anyhow::Result;
use anyhow::anyhow;
use anyhow::bail;
use std::collections::HashMap;
use std::future::Future;
use std::sync::Arc;

View File

@@ -1,10 +1,10 @@
//! Applies configured OAuth client secrets to login and refresh without persisting them.
//! A confidential client must never reuse tokens issued to a different client ID.
use akode_config::McpServerOAuthConfig;
use anyhow::Context;
use anyhow::Result;
use anyhow::bail;
use akode_config::McpServerOAuthConfig;
use oauth2::ClientSecret;
use rmcp::transport::AuthorizationManager;
use rmcp::transport::auth::AuthError;

View File

@@ -45,7 +45,9 @@ pub(crate) async fn start_authorization(
) -> Result<PreparedOAuthLogin> {
// aKode: CIMD is disabled because its client identifier was a ChatGPT-hosted document.
if client_registration == McpOAuthClientRegistration::Cimd {
bail!("MCP OAuth CIMD client registration is not supported; use dynamic client registration");
bail!(
"MCP OAuth CIMD client registration is not supported; use dynamic client registration"
);
}
let mut auth_manager =

View File

@@ -1,12 +1,12 @@
use std::collections::HashMap;
use std::sync::Arc;
use anyhow::Result;
use base64::Engine;
use base64::engine::general_purpose::STANDARD;
use akode_exec_server::RouteAwareHttpClient;
use akode_http_client::HttpClientFactory;
use akode_http_client::OutboundProxyPolicy;
use anyhow::Result;
use base64::Engine;
use base64::engine::general_purpose::STANDARD;
use http::HeaderMap;
use pretty_assertions::assert_eq;
use rmcp::transport::auth::AuthorizationMetadata;
@@ -477,7 +477,11 @@ async fn explicit_cimd_is_rejected_without_contacting_the_server() {
.await
.err()
.expect("CIMD should be rejected");
assert!(error.to_string().contains("CIMD client registration is not supported"));
assert!(
error
.to_string()
.contains("CIMD client registration is not supported")
);
assert!(
server
.received_requests()

View File

@@ -2,7 +2,6 @@ use std::collections::HashMap;
use std::sync::Arc;
use std::time::Duration;
use anyhow::Result;
use akode_exec_server::ExecServerError;
use akode_exec_server::HttpClient;
use akode_exec_server::HttpRequestParams;
@@ -11,6 +10,7 @@ use akode_exec_server::HttpResponseBodyStream;
use akode_exec_server::RouteAwareHttpClient;
use akode_http_client::HttpClientFactory;
use akode_http_client::OutboundProxyPolicy;
use anyhow::Result;
use futures::future::BoxFuture;
use pretty_assertions::assert_eq;
use rmcp::transport::auth::AuthorizationManager;

View File

@@ -4,13 +4,13 @@ use std::string::String;
use std::sync::Arc;
use std::time::Duration;
use akode_config::McpServerOAuthConfig;
use akode_exec_server::HttpClient;
use akode_otel::auth_storage::AuthStorageOriginator;
use anyhow::Context;
use anyhow::Result;
use anyhow::anyhow;
use anyhow::bail;
use akode_config::McpServerOAuthConfig;
use akode_exec_server::HttpClient;
use akode_otel::auth_storage::AuthStorageOriginator;
use rmcp::transport::AuthorizationManager;
use rmcp::transport::AuthorizationSession;
use rmcp::transport::auth::AuthorizationMetadata;
@@ -578,10 +578,7 @@ impl OauthLoginFlow {
redirect_mode,
)?);
let registered_authorization = if oauth_client_id.is_some() {
Some(
resolve_authorization_manager(server_url, Arc::clone(&oauth_http_client))
.await?,
)
Some(resolve_authorization_manager(server_url, Arc::clone(&oauth_http_client)).await?)
} else {
None
};
@@ -589,7 +586,8 @@ impl OauthLoginFlow {
.as_ref()
.map(|(_, metadata)| callback_mode(metadata))
.transpose()?;
let use_legacy_fallback = registered_callback_mode == Some(McpOAuthCallbackMode::CallbackSpecific)
let use_legacy_fallback = registered_callback_mode
== Some(McpOAuthCallbackMode::CallbackSpecific)
&& configured_callback.as_ref().is_some_and(|callback_url| {
callback_url
.path_segments()
@@ -853,10 +851,6 @@ mod tests {
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
use axum::Json;
use axum::Router;
use axum::routing::get;
use axum::routing::post;
use akode_config::McpServerOAuthConfig;
use akode_config::types::AuthKeyringBackendKind;
use akode_config::types::OAuthCredentialsStoreMode;
@@ -868,6 +862,10 @@ mod tests {
use akode_exec_server::RouteAwareHttpClient;
use akode_http_client::HttpClientFactory;
use akode_http_client::OutboundProxyPolicy;
use axum::Json;
use axum::Router;
use axum::routing::get;
use axum::routing::post;
use futures::future::BoxFuture;
use http::HeaderMap;
use oauth2::TokenResponse;

View File

@@ -15,15 +15,15 @@ use std::time::Duration;
use std::time::Instant;
use crate::AuthProviderResolver;
use anyhow::Context;
use anyhow::Result;
use anyhow::anyhow;
use akode_config::McpServerOAuthConfig;
use akode_config::types::AuthKeyringBackendKind;
use akode_config::types::McpServerEnvVar;
use akode_exec_server::HttpClient;
use akode_keyring_store::DefaultKeyringStore;
use akode_otel::auth_storage::AuthStorageOriginator;
use anyhow::Context;
use anyhow::Result;
use anyhow::anyhow;
use futures::FutureExt;
use futures::future::BoxFuture;
use http::HeaderMap;

View File

@@ -1,5 +1,5 @@
use anyhow::Error;
use akode_exec_server::ExecServerError;
use anyhow::Error;
use rmcp::service::ClientInitializeError;
use rmcp::service::ServiceError;
use rmcp::transport::DynamicTransportError;

View File

@@ -35,8 +35,6 @@ use std::time::Duration;
use crate::local_stdio_io;
use crate::local_stdio_transport::DiscoveryOutcome;
use anyhow::Result;
use anyhow::anyhow;
use akode_config::types::McpServerEnvVar;
use akode_exec_server::ExecBackend;
use akode_exec_server::ExecEnvPolicy;
@@ -57,6 +55,8 @@ use akode_utils_pty::process_group::kill_process_group;
use akode_utils_pty::process_group::terminate_process_group;
#[cfg(unix)]
use akode_utils_pty::process_group::wait_for_process_group_exit;
use anyhow::Result;
use anyhow::anyhow;
use futures::FutureExt;
use futures::future::BoxFuture;
use futures::future::Shared;

View File

@@ -2,9 +2,9 @@ use std::sync::Arc;
use std::time::Duration;
use std::time::Instant;
use akode_exec_server::ExecServerError;
use anyhow::Result;
use anyhow::anyhow;
use akode_exec_server::ExecServerError;
use http::StatusCode;
use rmcp::service::RoleClient;
use rmcp::service::RunningService;

View File

@@ -1,8 +1,8 @@
use anyhow::Result;
use anyhow::anyhow;
use akode_config::types::McpServerEnvVar;
use akode_network_proxy::CUSTOM_CA_ENV_KEYS;
use akode_protocol::shell_environment::is_non_inheritable_env_var;
use anyhow::Result;
use anyhow::anyhow;
use http::HeaderMap;
use http::HeaderName;
use http::HeaderValue;

View File

@@ -2,7 +2,6 @@ use std::collections::HashMap;
use std::sync::Arc;
use std::time::Duration;
use anyhow::Context as _;
use akode_config::types::AuthKeyringBackendKind;
use akode_config::types::OAuthCredentialsStoreMode;
use akode_exec_server::Environment;
@@ -14,6 +13,7 @@ use akode_rmcp_client::StreamableHttpOAuthDiscovery;
use akode_rmcp_client::StreamableHttpRedirectMode;
use akode_rmcp_client::discover_streamable_http_oauth;
use akode_rmcp_client::perform_oauth_login_return_url;
use anyhow::Context as _;
use pretty_assertions::assert_eq;
use rmcp::transport::auth::AuthError;
use serde_json::json;

View File

@@ -6,6 +6,13 @@ use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
use std::time::Duration;
use akode_api::AuthError;
use akode_api::AuthProvider;
use akode_api::SharedAuthProvider;
use akode_config::types::AuthKeyringBackendKind;
use akode_config::types::OAuthCredentialsStoreMode;
use akode_exec_server::Environment;
use akode_rmcp_client::RmcpClient;
use anyhow::Context as _;
use axum::Json;
use axum::Router;
@@ -14,13 +21,6 @@ use axum::response::IntoResponse;
use axum::response::sse::Event;
use axum::response::sse::Sse;
use axum::routing::post;
use akode_api::AuthError;
use akode_api::AuthProvider;
use akode_api::SharedAuthProvider;
use akode_config::types::AuthKeyringBackendKind;
use akode_config::types::OAuthCredentialsStoreMode;
use akode_exec_server::Environment;
use akode_rmcp_client::RmcpClient;
use futures::StreamExt as _;
use futures::stream;
use http::HeaderMap;

View File

@@ -7,12 +7,12 @@ use std::path::Path;
use std::sync::Arc;
use std::time::Duration;
use anyhow::Context;
use anyhow::Result;
use akode_rmcp_client::ElicitationAction;
use akode_rmcp_client::ElicitationResponse;
use akode_rmcp_client::LocalStdioServerLauncher;
use akode_rmcp_client::RmcpClient;
use anyhow::Context;
use anyhow::Result;
use futures::FutureExt as _;
use rmcp::model::ClientCapabilities;
use rmcp::model::Implementation;

View File

@@ -13,11 +13,11 @@ use std::process::Command;
use std::sync::Arc;
use std::time::Duration;
use anyhow::Result;
use akode_rmcp_client::ElicitationAction;
use akode_rmcp_client::ElicitationResponse;
use akode_rmcp_client::LocalStdioServerLauncher;
use akode_rmcp_client::RmcpClient;
use anyhow::Result;
use futures::FutureExt as _;
use pretty_assertions::assert_eq;
use rmcp::model::ClientCapabilities;

View File

@@ -10,11 +10,11 @@ use std::sync::Arc;
use std::sync::Mutex;
use std::time::Duration;
use anyhow::Result;
use akode_rmcp_client::ElicitationAction;
use akode_rmcp_client::ElicitationResponse;
use akode_rmcp_client::LocalStdioServerLauncher;
use akode_rmcp_client::RmcpClient;
use anyhow::Result;
use futures::FutureExt as _;
use pretty_assertions::assert_eq;
use rmcp::model::ClientCapabilities;

View File

@@ -8,7 +8,6 @@ use std::time::Duration;
use std::time::SystemTime;
use std::time::UNIX_EPOCH;
use base64::Engine;
use akode_config::McpServerOAuthConfig;
use akode_config::types::AuthKeyringBackendKind;
use akode_config::types::OAuthCredentialsStoreMode;
@@ -27,6 +26,7 @@ use akode_rmcp_client::is_authentication_required_error;
use akode_rmcp_client::save_oauth_tokens;
use akode_rmcp_client::with_http_headers_helper;
use akode_utils_cargo_bin::cargo_bin;
use base64::Engine;
use oauth2::AccessToken;
use oauth2::RefreshToken;
use oauth2::basic::BasicTokenType;

View File

@@ -9,13 +9,13 @@ mod streamable_http_test_support;
use std::sync::Arc;
use std::time::Duration;
use anyhow::Context;
use akode_config::types::AuthKeyringBackendKind;
use akode_config::types::OAuthCredentialsStoreMode;
use akode_rmcp_client::ElicitationAction;
use akode_rmcp_client::ElicitationResponse;
use akode_rmcp_client::McpProtocolMode;
use akode_rmcp_client::RmcpClient;
use anyhow::Context;
use futures::FutureExt as _;
use pretty_assertions::assert_eq;
use rmcp::model::ClientCapabilities;

View File

@@ -18,7 +18,6 @@ use std::sync::Arc;
use std::time::Duration;
use std::time::Instant;
use anyhow::Context as _;
use akode_config::types::AuthKeyringBackendKind;
use akode_config::types::OAuthCredentialsStoreMode;
use akode_exec_server::Environment;
@@ -31,6 +30,7 @@ use akode_rmcp_client::ElicitationAction;
use akode_rmcp_client::ElicitationResponse;
use akode_rmcp_client::RmcpClient;
use akode_utils_cargo_bin::CargoBinError;
use anyhow::Context as _;
use futures::FutureExt as _;
use pretty_assertions::assert_eq;
use rmcp::model::CallToolResult;