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:
@@ -3,18 +3,10 @@ use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use app_test_support::ChatGptAuthFixture;
|
||||
use app_test_support::TestAppServer;
|
||||
use app_test_support::to_response;
|
||||
use app_test_support::write_chatgpt_auth;
|
||||
use axum::Json;
|
||||
use app_test_support::write_api_key_auth;
|
||||
use axum::Router;
|
||||
use axum::extract::State;
|
||||
use axum::http::HeaderMap;
|
||||
use axum::http::StatusCode;
|
||||
use axum::http::Uri;
|
||||
use axum::http::header::AUTHORIZATION;
|
||||
use axum::routing::get;
|
||||
use codex_app_server_protocol::ApprovalsReviewer;
|
||||
use codex_app_server_protocol::AskForApproval;
|
||||
use codex_app_server_protocol::ClientInfo;
|
||||
@@ -39,8 +31,6 @@ use codex_app_server_protocol::TurnStartParams;
|
||||
use codex_app_server_protocol::TurnStartResponse;
|
||||
use codex_app_server_protocol::TurnStatus;
|
||||
use codex_app_server_protocol::UserInput as V2UserInput;
|
||||
use codex_config::types::AuthCredentialsStoreMode;
|
||||
use codex_mcp::MCP_TOOL_CODEX_APPS_META_KEY;
|
||||
use codex_protocol::mcp::OPENAI_STANDARD_FORM_INPUT_EXTENSION_ID;
|
||||
use codex_protocol::mcp_approval_meta as approval_meta;
|
||||
use core_test_support::assert_regex_match;
|
||||
@@ -92,12 +82,10 @@ use super::connection_handling_websocket::send_request;
|
||||
use super::connection_handling_websocket::spawn_websocket_server;
|
||||
|
||||
const DEFAULT_READ_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(10);
|
||||
const CONNECTOR_ID: &str = "calendar";
|
||||
const CONNECTOR_NAME: &str = "Calendar";
|
||||
const CONNECTED_ACCOUNT_EMAIL: &str = "calendar-owner@example.com";
|
||||
const TOOL_NAMESPACE: &str = "mcp__codex_apps__calendar";
|
||||
const CALLABLE_TOOL_NAME: &str = "_confirm_action";
|
||||
const SERVER_NAME: &str = "calendar";
|
||||
const TOOL_NAMESPACE: &str = "mcp__calendar";
|
||||
const TOOL_NAME: &str = "calendar_confirm_action";
|
||||
const CALLABLE_TOOL_NAME: &str = TOOL_NAME;
|
||||
const TOOL_CALL_ID: &str = "call-calendar-confirm";
|
||||
const NEXT_TURN_TOOL_CALL_ID: &str = "call-calendar-next-turn";
|
||||
const ELICITATION_MESSAGE: &str = "Allow this request?";
|
||||
@@ -126,12 +114,6 @@ enum StrictReviewScenario {
|
||||
GuardianDisabled,
|
||||
ManagedGuardianDisabled,
|
||||
ManagedReviewerForbidden,
|
||||
AppReviewerUser,
|
||||
AppReviewerNoncanonicalId,
|
||||
AppReviewerSpoofedId,
|
||||
AppReviewerSpoofedAction,
|
||||
AppReviewerMissingCallId,
|
||||
AppDefaultReviewerUser,
|
||||
Persistent,
|
||||
}
|
||||
|
||||
@@ -148,12 +130,6 @@ impl StrictReviewScenario {
|
||||
| Self::GuardianDisabled
|
||||
| Self::ManagedGuardianDisabled
|
||||
| Self::ManagedReviewerForbidden
|
||||
| Self::AppReviewerUser
|
||||
| Self::AppReviewerNoncanonicalId
|
||||
| Self::AppReviewerSpoofedId
|
||||
| Self::AppReviewerSpoofedAction
|
||||
| Self::AppReviewerMissingCallId
|
||||
| Self::AppDefaultReviewerUser
|
||||
| Self::Persistent => &[],
|
||||
}
|
||||
}
|
||||
@@ -199,7 +175,7 @@ async fn assert_standard_form_elicitation_round_trip(
|
||||
McpServerElicitationRequestParams {
|
||||
thread_id: fixture.thread_id.clone(),
|
||||
turn_id: Some(fixture.turn_id.clone()),
|
||||
server_name: "codex_apps".to_string(),
|
||||
server_name: SERVER_NAME.to_string(),
|
||||
request: McpServerElicitationRequest::Form {
|
||||
meta: None,
|
||||
message: ELICITATION_MESSAGE.to_string(),
|
||||
@@ -245,7 +221,7 @@ async fn mcp_server_openai_form_elicitation_round_trip() -> Result<()> {
|
||||
McpServerElicitationRequestParams {
|
||||
thread_id: fixture.thread_id.clone(),
|
||||
turn_id: Some(fixture.turn_id.clone()),
|
||||
server_name: "codex_apps".to_string(),
|
||||
server_name: SERVER_NAME.to_string(),
|
||||
request: McpServerElicitationRequest::OpenAiForm {
|
||||
meta: None,
|
||||
message: OPENAI_FORM_MESSAGE.to_string(),
|
||||
@@ -284,7 +260,7 @@ async fn mcp_server_openai_elicitation_form_round_trip() -> Result<()> {
|
||||
McpServerElicitationRequestParams {
|
||||
thread_id: fixture.thread_id.clone(),
|
||||
turn_id: Some(fixture.turn_id.clone()),
|
||||
server_name: "codex_apps".to_string(),
|
||||
server_name: SERVER_NAME.to_string(),
|
||||
request: McpServerElicitationRequest::OpenAiElicitationForm {
|
||||
meta: Some(json!({ "example/request": "template-picker" })),
|
||||
message: OPENAI_FORM_MESSAGE.to_string(),
|
||||
@@ -315,12 +291,6 @@ async fn mcp_server_openai_elicitation_form_round_trip() -> Result<()> {
|
||||
#[test_case(Review::GuardianDisabled; "guardian_disabled")]
|
||||
#[test_case(Review::ManagedGuardianDisabled; "managed_guardian_disabled")]
|
||||
#[test_case(Review::ManagedReviewerForbidden; "managed_reviewer_forbidden")]
|
||||
#[test_case(Review::AppReviewerUser; "app_reviewer_user")]
|
||||
#[test_case(Review::AppReviewerNoncanonicalId; "app_reviewer_noncanonical_id")]
|
||||
#[test_case(Review::AppReviewerSpoofedId; "app_reviewer_spoofed_id")]
|
||||
#[test_case(Review::AppReviewerSpoofedAction; "app_reviewer_spoofed_action")]
|
||||
#[test_case(Review::AppReviewerMissingCallId; "app_reviewer_missing_call_id")]
|
||||
#[test_case(Review::AppDefaultReviewerUser; "app_default_reviewer_user")]
|
||||
#[test_case(Review::Persistent; "persistent")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
||||
async fn mcp_server_strict_auto_review(scenario: Review) -> Result<()> {
|
||||
@@ -347,14 +317,7 @@ async fn openai_form_capability_follows_the_turn_starting_connection() -> Result
|
||||
start_elicitation_services(ElicitationScenario::OpenAiForm).await?;
|
||||
let codex_home = TempDir::new()?;
|
||||
write_config_toml(codex_home.path(), &responses_server.uri(), &apps_server_url)?;
|
||||
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 process, bind_addr) = spawn_websocket_server(codex_home.path()).await?;
|
||||
let mut supported_client = connect_websocket(bind_addr).await?;
|
||||
@@ -641,27 +604,10 @@ impl ElicitationRoundTripFixture {
|
||||
.filter(|strict| *strict == Review::FullAccess)
|
||||
.map(|_| SandboxMode::DangerFullAccess),
|
||||
config: strict.map(|strict| {
|
||||
let mut config = HashMap::from([(
|
||||
HashMap::from([(
|
||||
"features.guardian_approval".to_string(),
|
||||
json!(strict != Review::GuardianDisabled),
|
||||
)]);
|
||||
if matches!(
|
||||
strict,
|
||||
Review::AppReviewerUser
|
||||
| Review::AppReviewerNoncanonicalId
|
||||
| Review::AppReviewerSpoofedId
|
||||
) {
|
||||
config.insert(
|
||||
format!("apps.{CONNECTOR_ID}.approvals_reviewer"),
|
||||
json!("user"),
|
||||
);
|
||||
} else if strict == Review::AppDefaultReviewerUser {
|
||||
config.insert(
|
||||
"apps._default.approvals_reviewer".to_string(),
|
||||
json!("user"),
|
||||
);
|
||||
}
|
||||
config
|
||||
)])
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
@@ -690,14 +636,7 @@ impl ElicitationRoundTripFixture {
|
||||
if !requirements.is_empty() {
|
||||
std::fs::write(codex_home.path().join("requirements.toml"), requirements)?;
|
||||
}
|
||||
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())
|
||||
@@ -861,13 +800,17 @@ impl ElicitationRoundTripFixture {
|
||||
}
|
||||
"item/autoApprovalReview/started" | "item/autoApprovalReview/completed" => {
|
||||
guardian_review_events += 1;
|
||||
assert_eq!(
|
||||
notification
|
||||
.params
|
||||
.as_ref()
|
||||
.and_then(|params| params.get("targetItemId"))
|
||||
.and_then(Value::as_str),
|
||||
Some(TOOL_CALL_ID),
|
||||
// An ordinary server's elicitation is reviewed as its own action, not as
|
||||
// the enclosing tool call.
|
||||
let target_item_id = notification
|
||||
.params
|
||||
.as_ref()
|
||||
.and_then(|params| params.get("targetItemId"))
|
||||
.and_then(Value::as_str)
|
||||
.expect("auto-review notification should name its target");
|
||||
assert!(
|
||||
target_item_id.starts_with(&format!("mcp_elicitation:{SERVER_NAME}:")),
|
||||
"{target_item_id}"
|
||||
);
|
||||
}
|
||||
"turn/completed" => {
|
||||
@@ -903,27 +846,26 @@ impl ElicitationRoundTripFixture {
|
||||
requests.len(),
|
||||
3 + review_outcomes.len() + usize::from(self.next_turn) * 2 - usize::from(denied_burst)
|
||||
);
|
||||
for guardian_request in requests.iter().skip(2).take(review_outcomes.len()) {
|
||||
for (index, guardian_request) in requests
|
||||
.iter()
|
||||
.skip(2)
|
||||
.take(review_outcomes.len())
|
||||
.enumerate()
|
||||
{
|
||||
// A follow-up review reuses the guardian transcript, so take the latest action.
|
||||
let action = guardian_request
|
||||
.message_input_texts("user")
|
||||
.into_iter()
|
||||
.rev()
|
||||
.find_map(|text| serde_json::from_str::<Value>(&text).ok())
|
||||
.expect("Guardian prompt must include the reviewed action JSON");
|
||||
assert_eq!(
|
||||
action,
|
||||
json!({
|
||||
"tool": "mcp_tool_call",
|
||||
"server": "codex_apps",
|
||||
"server": SERVER_NAME,
|
||||
"tool_name": TOOL_NAME,
|
||||
"arguments": {},
|
||||
"connector_id": CONNECTOR_ID,
|
||||
"connector_name": CONNECTOR_NAME,
|
||||
"connected_account_email": CONNECTED_ACCOUNT_EMAIL,
|
||||
"annotations": {
|
||||
"destructive_hint": false,
|
||||
"open_world_hint": false,
|
||||
"read_only_hint": true,
|
||||
},
|
||||
"arguments": {"request_nonce": format!("strict-review-{index}")},
|
||||
}),
|
||||
);
|
||||
assert!(
|
||||
@@ -1004,12 +946,6 @@ impl ElicitationRoundTripFixture {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct AppsServerState {
|
||||
expected_bearer: String,
|
||||
expected_account_id: String,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct ElicitationAppsMcpServer {
|
||||
scenario: ElicitationScenario,
|
||||
@@ -1078,17 +1014,6 @@ impl ServerHandler for ElicitationAppsMcpServer {
|
||||
.open_world(false),
|
||||
);
|
||||
|
||||
let mut meta = MetaObject::new();
|
||||
meta.0
|
||||
.insert("connector_id".to_string(), json!(CONNECTOR_ID));
|
||||
meta.0
|
||||
.insert("connector_name".to_string(), json!(CONNECTOR_NAME));
|
||||
meta.0.insert(
|
||||
MCP_TOOL_CODEX_APPS_META_KEY.to_string(),
|
||||
json!({ "connected_account_email": CONNECTED_ACCOUNT_EMAIL }),
|
||||
);
|
||||
tool.meta = Some(meta);
|
||||
|
||||
Ok(ListToolsResult::with_all_items(vec![tool]))
|
||||
}
|
||||
|
||||
@@ -1111,27 +1036,15 @@ impl ServerHandler for ElicitationAppsMcpServer {
|
||||
match scenario {
|
||||
ElicitationScenario::StandardForm | ElicitationScenario::Strict(_) => {
|
||||
if let ElicitationScenario::Strict(strict) = scenario {
|
||||
let connector_id = match strict {
|
||||
Review::AppReviewerNoncanonicalId => "calendar ",
|
||||
Review::AppReviewerSpoofedId => "another-connector",
|
||||
_ => CONNECTOR_ID,
|
||||
};
|
||||
for index in 0..strict.review_outcomes().len().max(1) {
|
||||
let tool_name = if strict == Review::AppReviewerSpoofedAction {
|
||||
"calendar_harmless_action"
|
||||
} else {
|
||||
TOOL_NAME
|
||||
};
|
||||
let apps_meta = context.meta.0.0.get(MCP_TOOL_CODEX_APPS_META_KEY);
|
||||
let mut meta = MetaObject(
|
||||
json!({
|
||||
(approval_meta::REQUEST_TYPE_KEY): approval_meta::REQUEST_TYPE_APPROVAL_REQUEST,
|
||||
(approval_meta::APPROVAL_KIND_KEY): approval_meta::APPROVAL_KIND_MCP_TOOL_CALL,
|
||||
(approval_meta::STRICT_AUTO_REVIEW_KEY): true,
|
||||
(approval_meta::CONNECTOR_ID_KEY): connector_id,
|
||||
(MCP_TOOL_CODEX_APPS_META_KEY): apps_meta
|
||||
.filter(|_| strict != Review::AppReviewerMissingCallId),
|
||||
(approval_meta::TOOL_NAME_KEY): tool_name,
|
||||
"callId": context.meta.0.0.get("callId"),
|
||||
(approval_meta::TOOL_NAME_KEY): TOOL_NAME,
|
||||
(approval_meta::TOOL_DESCRIPTION_KEY): "Confirm a calendar action.",
|
||||
(approval_meta::TOOL_PARAMS_KEY): {
|
||||
"request_nonce": format!("strict-review-{index}"),
|
||||
},
|
||||
@@ -1404,11 +1317,6 @@ fn sep1034_defaults() -> Value {
|
||||
}
|
||||
|
||||
async fn start_apps_server(scenario: ElicitationScenario) -> Result<(String, JoinHandle<()>)> {
|
||||
let state = Arc::new(AppsServerState {
|
||||
expected_bearer: "Bearer chatgpt-token".to_string(),
|
||||
expected_account_id: "account-123".to_string(),
|
||||
});
|
||||
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await?;
|
||||
let addr = listener.local_addr()?;
|
||||
|
||||
@@ -1418,14 +1326,7 @@ async fn start_apps_server(scenario: ElicitationScenario) -> Result<(String, Joi
|
||||
StreamableHttpServerConfig::default(),
|
||||
);
|
||||
|
||||
let router = Router::new()
|
||||
.route("/connectors/directory/list", get(list_directory_connectors))
|
||||
.route(
|
||||
"/connectors/directory/list_workspace",
|
||||
get(list_directory_connectors),
|
||||
)
|
||||
.with_state(state)
|
||||
.nest_service("/api/codex/ps/mcp", mcp_service);
|
||||
let router = Router::new().nest_service("/mcp", mcp_service);
|
||||
|
||||
let handle = tokio::spawn(async move {
|
||||
let _ = axum::serve(listener, router).await;
|
||||
@@ -1434,48 +1335,6 @@ async fn start_apps_server(scenario: ElicitationScenario) -> Result<(String, Joi
|
||||
Ok((format!("http://{addr}"), handle))
|
||||
}
|
||||
|
||||
async fn list_directory_connectors(
|
||||
State(state): State<Arc<AppsServerState>>,
|
||||
headers: HeaderMap,
|
||||
uri: Uri,
|
||||
) -> Result<Json<serde_json::Value>, StatusCode> {
|
||||
let bearer_ok = headers
|
||||
.get(AUTHORIZATION)
|
||||
.and_then(|value| value.to_str().ok())
|
||||
.is_some_and(|value| value == state.expected_bearer);
|
||||
let account_ok = headers
|
||||
.get("chatgpt-account-id")
|
||||
.and_then(|value| value.to_str().ok())
|
||||
.is_some_and(|value| value == state.expected_account_id);
|
||||
let external_logos_ok = uri
|
||||
.query()
|
||||
.is_some_and(|query| query.split('&').any(|pair| pair == "external_logos=true"));
|
||||
|
||||
if !bearer_ok || !account_ok {
|
||||
Err(StatusCode::UNAUTHORIZED)
|
||||
} else if !external_logos_ok {
|
||||
Err(StatusCode::BAD_REQUEST)
|
||||
} else {
|
||||
Ok(Json(json!({
|
||||
"apps": [{
|
||||
"id": CONNECTOR_ID,
|
||||
"name": CONNECTOR_NAME,
|
||||
"description": "Calendar connector",
|
||||
"logo_url": null,
|
||||
"logo_url_dark": null,
|
||||
"distribution_channel": null,
|
||||
"branding": null,
|
||||
"app_metadata": null,
|
||||
"labels": null,
|
||||
"install_url": null,
|
||||
"is_accessible": false,
|
||||
"is_enabled": true
|
||||
}],
|
||||
"next_token": null
|
||||
})))
|
||||
}
|
||||
}
|
||||
|
||||
fn write_config_toml(
|
||||
codex_home: &std::path::Path,
|
||||
responses_server_uri: &str,
|
||||
@@ -1490,11 +1349,10 @@ approval_policy = "on-request"
|
||||
sandbox_mode = "read-only"
|
||||
|
||||
model_provider = "mock_provider"
|
||||
chatgpt_base_url = "{apps_server_url}"
|
||||
mcp_oauth_credentials_store = "file"
|
||||
|
||||
[features]
|
||||
apps = true
|
||||
[mcp_servers.calendar]
|
||||
url = "{apps_server_url}/mcp"
|
||||
|
||||
[model_providers.mock_provider]
|
||||
name = "Mock provider for test"
|
||||
|
||||
Reference in New Issue
Block a user