aKode fase 2b-2: rimosso login ChatGPT e tutti i sottosistemi solo-ChatGPT
- Login: resta solo chiave API (+ header, Bedrock). Rimossi OAuth/browser, device code, refresh/revoke su auth.openai.com, PAT, agent/workload identity, runtime agent instance, backend-client e openapi-models, workspace routing. - Rimossi: generazione immagini (ext + skill imagegen), history notes, plugin remoti (catalogo, sync, share), cyber access program, daybreak, cloud config e requirements (config_server ora fail-closed), attestation, frozen cloud skills, EMA MCP auth, Codex Apps/connettori, ricerca ospitata, header/zstd/ routing/cookie del backend Codex, fallback OPENAI_API_KEY del realtime. - Messaggi d'errore senza link a chatgpt.com. - Chiavi di config legacy accettate e ignorate; feature rimosse = Stage::Removed. - Test: cancellati solo quelli del codice rimosso; test di sicurezza (sandbox estensioni, permessi, redazione, auth storage, requirements) adattati. Restano solo fallimenti d'ambiente (code-mode-host/V8, ~/.agents). - Istruzioni di sistema invariate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,14 +10,13 @@ use std::time::Duration;
|
||||
|
||||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use app_test_support::ChatGptAuthFixture;
|
||||
use app_test_support::MockResponsesConfig;
|
||||
use app_test_support::TestAppServer;
|
||||
use app_test_support::create_fake_paginated_rollout;
|
||||
use app_test_support::create_fake_rollout;
|
||||
use app_test_support::create_mock_responses_server_repeating_assistant;
|
||||
use app_test_support::rollout_path;
|
||||
use app_test_support::write_chatgpt_auth;
|
||||
use app_test_support::write_api_key_auth;
|
||||
use axum::Router;
|
||||
use codex_app_server::in_process;
|
||||
use codex_app_server::in_process::InProcessServerEvent;
|
||||
@@ -30,7 +29,6 @@ use codex_app_server_protocol::InitializeParams;
|
||||
use codex_app_server_protocol::McpResourceContent;
|
||||
use codex_app_server_protocol::McpResourceReadParams;
|
||||
use codex_app_server_protocol::McpResourceReadResponse;
|
||||
use codex_app_server_protocol::McpResourceReadTarget;
|
||||
use codex_app_server_protocol::McpServerToolCallParams;
|
||||
use codex_app_server_protocol::McpServerToolCallResponse;
|
||||
use codex_app_server_protocol::ProjectCreateParams;
|
||||
@@ -61,13 +59,11 @@ use codex_app_server_protocol::TurnStartResponse;
|
||||
use codex_app_server_protocol::TurnStatus;
|
||||
use codex_app_server_protocol::UserInput;
|
||||
use codex_arg0::Arg0DispatchPaths;
|
||||
use codex_config::CloudConfigBundleLoader;
|
||||
use codex_config::LoaderOverrides;
|
||||
use codex_config::ThreadConfigContext;
|
||||
use codex_config::ThreadConfigLoader;
|
||||
use codex_config::ThreadConfigLoaderFuture;
|
||||
use codex_config::ThreadConfigSource;
|
||||
use codex_config::types::AuthCredentialsStoreMode;
|
||||
use codex_core::ARCHIVED_SESSIONS_SUBDIR;
|
||||
use codex_core::config::ConfigBuilder;
|
||||
use codex_exec_server::EnvironmentManager;
|
||||
@@ -123,12 +119,11 @@ use tokio::time::timeout;
|
||||
|
||||
#[path = "mcp_resource/caller_metadata.rs"]
|
||||
mod caller_metadata;
|
||||
#[path = "mcp_resource/plugin_metadata_refresh.rs"]
|
||||
mod plugin_metadata_refresh;
|
||||
|
||||
pub(super) const DEFAULT_READ_TIMEOUT: Duration = Duration::from_secs(10);
|
||||
/// User-configured MCP server registration backed by the resource test server.
|
||||
const RESOURCE_SERVER_NAME: &str = "docs";
|
||||
const TEST_RESOURCE_URI: &str = "test://codex/resource";
|
||||
pub(super) const TEST_WIDGET_RESOURCE_URI: &str = "ui://widget/checkout-session.html";
|
||||
const TEST_BLOB_RESOURCE_URI: &str = "test://codex/resource.bin";
|
||||
const TEST_RESOURCE_BLOB: &str = "YmluYXJ5LXJlc291cmNl";
|
||||
const TEST_RESOURCE_TEXT: &str = "Resource body from the MCP server.";
|
||||
@@ -173,79 +168,49 @@ async fn mcp_resource_read_returns_resource_contents() -> Result<()> {
|
||||
})
|
||||
.await?;
|
||||
let metadata_value = json!({"sequence": [1, 2]});
|
||||
let targets = [
|
||||
None,
|
||||
Some(McpResourceReadTarget {
|
||||
connector_id: "calendar".to_string(),
|
||||
link_id: Some("link_calendar".to_string()),
|
||||
}),
|
||||
Some(McpResourceReadTarget {
|
||||
connector_id: "calendar".to_string(),
|
||||
link_id: None,
|
||||
}),
|
||||
];
|
||||
for thread_id in [Some(thread.id.clone()), None] {
|
||||
for target in &targets {
|
||||
let read_response: McpResourceReadResponse = mcp
|
||||
.request(|request_id| ClientRequest::McpResourceRead {
|
||||
request_id,
|
||||
params: McpResourceReadParams {
|
||||
meta: Some(serde_json::Map::from_iter([(
|
||||
"example/trace".into(),
|
||||
metadata_value.clone(),
|
||||
)])),
|
||||
thread_id: thread_id.clone(),
|
||||
origin_call_id: None,
|
||||
server: "codex_apps".to_string(),
|
||||
uri: TEST_RESOURCE_URI.to_string(),
|
||||
connector_id: None,
|
||||
target: target.clone(),
|
||||
},
|
||||
})
|
||||
.await?;
|
||||
assert_eq!(read_response, expected_resource_read_response());
|
||||
let metadata = apps_server_calls
|
||||
.read_metadata
|
||||
.lock()
|
||||
.expect("read metadata lock");
|
||||
let metadata = metadata
|
||||
.last()
|
||||
.expect("resource read reached the MCP server");
|
||||
assert_eq!(metadata.get("example/trace"), Some(&metadata_value));
|
||||
assert_eq!(
|
||||
(
|
||||
metadata.get("connector_id").cloned(),
|
||||
metadata.get("link_id").cloned()
|
||||
),
|
||||
match target {
|
||||
Some(target) => (
|
||||
Some(json!(target.connector_id)),
|
||||
Some(json!(target.link_id)),
|
||||
),
|
||||
None => (None, None),
|
||||
let read_response: McpResourceReadResponse = mcp
|
||||
.request(|request_id| ClientRequest::McpResourceRead {
|
||||
request_id,
|
||||
params: McpResourceReadParams {
|
||||
meta: Some(serde_json::Map::from_iter([(
|
||||
"example/trace".into(),
|
||||
metadata_value.clone(),
|
||||
)])),
|
||||
thread_id: thread_id.clone(),
|
||||
server: RESOURCE_SERVER_NAME.to_string(),
|
||||
uri: TEST_RESOURCE_URI.to_string(),
|
||||
},
|
||||
);
|
||||
}
|
||||
})
|
||||
.await?;
|
||||
assert_eq!(read_response, expected_resource_read_response());
|
||||
let metadata = apps_server_calls
|
||||
.read_metadata
|
||||
.lock()
|
||||
.expect("read metadata lock");
|
||||
let metadata = metadata
|
||||
.last()
|
||||
.expect("resource read reached the MCP server");
|
||||
assert_eq!(metadata.get("example/trace"), Some(&metadata_value));
|
||||
}
|
||||
|
||||
// Reserved Codex metadata keys cannot be spoofed by the caller and never reach the server.
|
||||
let reads_before_invalid_requests = apps_server_calls.read_metadata.lock().unwrap().len();
|
||||
let other_route = json!({"resource_uri": "/calendar/link_other/events"});
|
||||
let [_, pinned, no_auth] = targets;
|
||||
for (key, value, origin_call_id, target) in [
|
||||
("connector_id", json!("spoofed"), None, None),
|
||||
("link_id", json!("spoofed"), Some("call".into()), None),
|
||||
("_codex_apps", other_route.clone(), None, pinned),
|
||||
("_codex_apps", other_route, None, no_auth),
|
||||
for (key, thread_id) in [
|
||||
("threadId", Some(thread.id.clone())),
|
||||
("x-codex-turn-metadata", Some(thread.id.clone())),
|
||||
(
|
||||
codex_mcp::MCP_CONNECTION_LEASE_META_KEY,
|
||||
Some(thread.id.clone()),
|
||||
),
|
||||
("x-codex-turn-metadata", None),
|
||||
] {
|
||||
let request_id = mcp
|
||||
.send_mcp_resource_read_request(McpResourceReadParams {
|
||||
thread_id: Some(thread.id.clone()),
|
||||
origin_call_id,
|
||||
meta: Some(serde_json::Map::from_iter([(key.into(), value)])),
|
||||
server: "codex_apps".into(),
|
||||
thread_id,
|
||||
meta: Some(serde_json::Map::from_iter([(key.into(), json!("spoofed"))])),
|
||||
server: RESOURCE_SERVER_NAME.into(),
|
||||
uri: TEST_RESOURCE_URI.into(),
|
||||
connector_id: None,
|
||||
target,
|
||||
})
|
||||
.await?;
|
||||
let error = timeout(
|
||||
@@ -275,7 +240,7 @@ async fn mcp_resource_read_preserves_protocol_errors(protocol: ProtocolVersion)
|
||||
let (apps_server_url, _calls, apps_server_handle) = start_resource_apps_mcp_server().await?;
|
||||
let codex_home = TempDir::new()?;
|
||||
let config = MockResponsesConfig::new(&responses_server.uri()).with_extra_config(&format!(
|
||||
"[mcp_servers.resource_server]\nurl = \"{apps_server_url}/api/codex/ps/mcp\""
|
||||
"[mcp_servers.resource_server]\nurl = \"{apps_server_url}/mcp\""
|
||||
));
|
||||
let config = if protocol == ProtocolVersion::V_2026_07_28 {
|
||||
config.enable_feature(Feature::Mcp20260728)
|
||||
@@ -298,11 +263,9 @@ async fn mcp_resource_read_preserves_protocol_errors(protocol: ProtocolVersion)
|
||||
"data": {
|
||||
"uri": TEST_ERROR_RESOURCE_URI,
|
||||
"protocolVersion": protocol,
|
||||
"_meta": {"_codex_apps": {"connector_auth_failure": {
|
||||
"is_auth_failure": true,
|
||||
"connector_id": "calendar",
|
||||
"_meta": {"example/auth": {
|
||||
"requested_scopes": ["calendar.read"],
|
||||
}}},
|
||||
}},
|
||||
},
|
||||
}),
|
||||
),
|
||||
@@ -316,11 +279,8 @@ async fn mcp_resource_read_preserves_protocol_errors(protocol: ProtocolVersion)
|
||||
.send_mcp_resource_read_request(McpResourceReadParams {
|
||||
meta: None,
|
||||
thread_id,
|
||||
origin_call_id: None,
|
||||
server: server.to_string(),
|
||||
uri: TEST_ERROR_RESOURCE_URI.to_string(),
|
||||
connector_id: None,
|
||||
target: None,
|
||||
})
|
||||
.await?;
|
||||
let error = timeout(
|
||||
@@ -503,24 +463,16 @@ async fn mcp_resource_read_returns_contents_and_declines_elicitation_without_thr
|
||||
codex_home.path().join("config.toml"),
|
||||
format!(
|
||||
r#"
|
||||
chatgpt_base_url = "{apps_server_url}"
|
||||
mcp_oauth_credentials_store = "file"
|
||||
approval_policy = "never"
|
||||
sandbox_mode = "danger-full-access"
|
||||
|
||||
[features]
|
||||
apps = true
|
||||
[mcp_servers.{RESOURCE_SERVER_NAME}]
|
||||
url = "{apps_server_url}/mcp"
|
||||
"#
|
||||
),
|
||||
)?;
|
||||
write_chatgpt_auth(
|
||||
codex_home.path(),
|
||||
ChatGptAuthFixture::new("chatgpt-token")
|
||||
.account_id("account-123")
|
||||
.chatgpt_user_id("user-123")
|
||||
.chatgpt_account_id("account-123"),
|
||||
AuthCredentialsStoreMode::File,
|
||||
)?;
|
||||
write_api_key_auth(codex_home.path())?;
|
||||
|
||||
let mut mcp = TestAppServer::builder()
|
||||
.with_codex_home(codex_home.path())
|
||||
@@ -533,11 +485,8 @@ apps = true
|
||||
params: McpResourceReadParams {
|
||||
meta: None,
|
||||
thread_id: None,
|
||||
origin_call_id: None,
|
||||
server: "codex_apps".to_string(),
|
||||
server: RESOURCE_SERVER_NAME.to_string(),
|
||||
uri: TEST_RESOURCE_URI.to_string(),
|
||||
connector_id: None,
|
||||
target: None,
|
||||
},
|
||||
})
|
||||
.await?;
|
||||
@@ -548,11 +497,8 @@ apps = true
|
||||
params: McpResourceReadParams {
|
||||
meta: None,
|
||||
thread_id: None,
|
||||
origin_call_id: None,
|
||||
server: "codex_apps".to_string(),
|
||||
server: RESOURCE_SERVER_NAME.to_string(),
|
||||
uri: TEST_ELICITATION_RESOURCE_URI.to_string(),
|
||||
connector_id: None,
|
||||
target: None,
|
||||
},
|
||||
})
|
||||
.await?;
|
||||
@@ -565,7 +511,6 @@ apps = true
|
||||
text: TEST_ELICITATION_RESOURCE_TEXT.to_string(),
|
||||
meta: None,
|
||||
}],
|
||||
origin_call_id: None,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -591,11 +536,8 @@ async fn mcp_resource_read_returns_error_for_unknown_thread() -> Result<()> {
|
||||
params: McpResourceReadParams {
|
||||
meta: None,
|
||||
thread_id: Some("00000000-0000-4000-8000-000000000000".to_string()),
|
||||
origin_call_id: None,
|
||||
server: "codex_apps".to_string(),
|
||||
server: RESOURCE_SERVER_NAME.to_string(),
|
||||
uri: TEST_RESOURCE_URI.to_string(),
|
||||
connector_id: None,
|
||||
target: None,
|
||||
},
|
||||
})
|
||||
.await;
|
||||
@@ -621,7 +563,7 @@ async fn metadata_and_mcp_requests_complete_while_unrelated_resume_loads_config(
|
||||
let codex_home = TempDir::new()?;
|
||||
MockResponsesConfig::new(&responses_server.uri())
|
||||
.with_extra_config(&format!(
|
||||
"[mcp_servers.resource_server]\nurl = \"{mcp_server_url}/api/codex/ps/mcp\""
|
||||
"[mcp_servers.resource_server]\nurl = \"{mcp_server_url}/mcp\""
|
||||
))
|
||||
.write(codex_home.path())?;
|
||||
let thread_id = create_fake_rollout(
|
||||
@@ -698,7 +640,6 @@ async fn metadata_and_mcp_requests_complete_while_unrelated_resume_loads_config(
|
||||
params: ThreadMetadataUpdateParams {
|
||||
thread_id: thread.id.clone(),
|
||||
project_id: None,
|
||||
daybreak_enabled: None,
|
||||
git_info: Some(ThreadMetadataGitInfoUpdateParams {
|
||||
sha: None,
|
||||
branch: Some(Some("feature/viewer".to_string())),
|
||||
@@ -719,11 +660,8 @@ async fn metadata_and_mcp_requests_complete_while_unrelated_resume_loads_config(
|
||||
params: McpResourceReadParams {
|
||||
meta: None,
|
||||
thread_id: Some(thread.id.clone()),
|
||||
origin_call_id: None,
|
||||
server: "resource_server".to_string(),
|
||||
uri: TEST_RESOURCE_URI.to_string(),
|
||||
connector_id: None,
|
||||
target: None,
|
||||
},
|
||||
}),
|
||||
sender.request(ClientRequest::McpServerToolCall {
|
||||
@@ -910,7 +848,6 @@ async fn resume_revalidates_persisted_thread_after_config_load(
|
||||
params: ThreadMetadataUpdateParams {
|
||||
thread_id: thread_id.clone(),
|
||||
project_id: project_id.clone(),
|
||||
daybreak_enabled: None,
|
||||
git_info: None,
|
||||
},
|
||||
})
|
||||
@@ -943,7 +880,6 @@ async fn resume_revalidates_persisted_thread_after_config_load(
|
||||
params: ThreadMetadataUpdateParams {
|
||||
thread_id: thread_id.clone(),
|
||||
project_id: project_id.clone(),
|
||||
daybreak_enabled: None,
|
||||
git_info: Some(ThreadMetadataGitInfoUpdateParams {
|
||||
sha: None,
|
||||
branch: Some(Some("feature/updated-during-resume".to_string())),
|
||||
@@ -1323,7 +1259,6 @@ async fn start_resource_in_process_client(
|
||||
cli_overrides,
|
||||
loader_overrides,
|
||||
strict_config: false,
|
||||
cloud_config_bundle: CloudConfigBundleLoader::default(),
|
||||
embedded_network_policy: Default::default(),
|
||||
thread_config_loader,
|
||||
feedback: CodexFeedback::new(),
|
||||
@@ -1372,22 +1307,12 @@ async fn start_resource_test_app_server_with_extra_config(
|
||||
let codex_home = TempDir::new()?;
|
||||
MockResponsesConfig::new(responses_server_uri)
|
||||
.with_approval_policy("on-request")
|
||||
.with_root_config(&format!(
|
||||
"chatgpt_base_url = \"{apps_server_url}\"\nmcp_oauth_credentials_store = \"file\""
|
||||
))
|
||||
.enable_feature(Feature::Apps)
|
||||
.with_root_config("mcp_oauth_credentials_store = \"file\"")
|
||||
.with_extra_config(&format!(
|
||||
"[skills]\ninclude_instructions = true\n{extra_config}"
|
||||
"[mcp_servers.{RESOURCE_SERVER_NAME}]\nurl = \"{apps_server_url}/mcp\"\n\n[skills]\ninclude_instructions = true\n{extra_config}"
|
||||
))
|
||||
.write(codex_home.path())?;
|
||||
write_chatgpt_auth(
|
||||
codex_home.path(),
|
||||
ChatGptAuthFixture::new("chatgpt-token")
|
||||
.account_id("account-123")
|
||||
.chatgpt_user_id("user-123")
|
||||
.chatgpt_account_id("account-123"),
|
||||
AuthCredentialsStoreMode::File,
|
||||
)?;
|
||||
write_api_key_auth(codex_home.path())?;
|
||||
|
||||
let builder = TestAppServer::builder().with_codex_home(codex_home.path());
|
||||
let builder = match environment {
|
||||
@@ -1421,7 +1346,7 @@ pub(super) async fn start_resource_apps_mcp_server()
|
||||
Arc::new(LocalSessionManager::default()),
|
||||
StreamableHttpServerConfig::default(),
|
||||
);
|
||||
let router = Router::new().nest_service("/api/codex/ps/mcp", mcp_service);
|
||||
let router = Router::new().nest_service("/mcp", mcp_service);
|
||||
let apps_server_handle = tokio::spawn(async move {
|
||||
let _ = axum::serve(listener, router).await;
|
||||
});
|
||||
@@ -1445,7 +1370,6 @@ fn expected_resource_read_response() -> McpResourceReadResponse {
|
||||
meta: None,
|
||||
},
|
||||
],
|
||||
origin_call_id: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1456,7 +1380,6 @@ pub(super) struct ResourceAppsMcpCalls {
|
||||
main_prompt_reads: AtomicUsize,
|
||||
reference_reads: AtomicUsize,
|
||||
pub(super) tools_enabled: AtomicBool,
|
||||
pub(super) best_buy_app_only: AtomicBool,
|
||||
}
|
||||
|
||||
impl ResourceAppsMcpCalls {
|
||||
@@ -1498,31 +1421,12 @@ impl ServerHandler for ResourceAppsMcpServer {
|
||||
) -> Result<ListToolsResult, rmcp::ErrorData> {
|
||||
let tools = ["best_buy", "walmart"]
|
||||
.into_iter()
|
||||
.map(|connector_id| {
|
||||
let mut ui = json!({ "resourceUri": TEST_WIDGET_RESOURCE_URI });
|
||||
if connector_id == "best_buy"
|
||||
&& self.calls.best_buy_app_only.load(Ordering::Relaxed)
|
||||
{
|
||||
ui["visibility"] = json!(["app"]);
|
||||
}
|
||||
.map(|store| {
|
||||
serde_json::from_value(json!({
|
||||
"name": format!("{connector_id}_product_search"),
|
||||
"name": format!("{store}_product_search"),
|
||||
"description": "Search products.",
|
||||
"inputSchema": { "type": "object" },
|
||||
"annotations": { "readOnlyHint": true },
|
||||
"_meta": {
|
||||
"connector_id": connector_id,
|
||||
"connector_name": connector_id,
|
||||
"link_id": format!("link_{connector_id}"),
|
||||
"ui": ui,
|
||||
"openai/outputTemplate": TEST_WIDGET_RESOURCE_URI,
|
||||
"_codex_apps": {
|
||||
"resource_uri": format!(
|
||||
"/{connector_id}/link_{connector_id}/{connector_id}_product_search"
|
||||
),
|
||||
"contains_mcp_source": true,
|
||||
},
|
||||
},
|
||||
}))
|
||||
})
|
||||
.collect::<serde_json::Result<Vec<_>>>()
|
||||
@@ -1611,44 +1515,12 @@ impl ServerHandler for ResourceAppsMcpServer {
|
||||
Some(json!({
|
||||
"uri": uri,
|
||||
"protocolVersion": context.protocol_version(),
|
||||
"_meta": {"_codex_apps": {"connector_auth_failure": {
|
||||
"is_auth_failure": true,
|
||||
"connector_id": "calendar",
|
||||
"_meta": {"example/auth": {
|
||||
"requested_scopes": ["calendar.read"],
|
||||
}}},
|
||||
}},
|
||||
})),
|
||||
));
|
||||
}
|
||||
if uri == TEST_WIDGET_RESOURCE_URI {
|
||||
let request_meta = context
|
||||
.meta
|
||||
.0
|
||||
.0
|
||||
.get("x-codex-turn-metadata")
|
||||
.and_then(|metadata| metadata.get("mcp_request_meta"));
|
||||
let connector_id = request_meta
|
||||
.and_then(|metadata| metadata.pointer("/selected_connector_ids/0"))
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.ok_or_else(|| rmcp::ErrorData::invalid_params("missing app scope", None))?;
|
||||
let expected_link_id = format!("link_{connector_id}");
|
||||
if request_meta
|
||||
.and_then(|metadata| metadata.get("link_id"))
|
||||
.and_then(serde_json::Value::as_str)
|
||||
!= Some(expected_link_id.as_str())
|
||||
{
|
||||
return Err(rmcp::ErrorData::invalid_params("wrong account scope", None));
|
||||
}
|
||||
|
||||
return Ok(
|
||||
ReadResourceResult::new(vec![ResourceContents::TextResourceContents {
|
||||
uri,
|
||||
mime_type: Some("text/html".to_string()),
|
||||
text: format!("<html>{connector_id}</html>"),
|
||||
meta: None,
|
||||
}])
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
if uri == TEST_ELICITATION_RESOURCE_URI {
|
||||
let requested_schema = ElicitationSchema::builder()
|
||||
.build()
|
||||
|
||||
Reference in New Issue
Block a user