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:
andrea.difonzo
2026-11-10 16:20:15 +01:00
parent 82347a58ed
commit 6089fbde91
1573 changed files with 10289 additions and 177679 deletions

View File

@@ -1,6 +1,5 @@
use codex_git_utils::SanitizedGitUrl;
use codex_git_utils::collect_git_info;
use codex_login::CODEX_ACCESS_TOKEN_ENV_VAR;
use codex_login::CODEX_API_KEY_ENV_VAR;
use codex_protocol::protocol::GitInfo;
use core_test_support::fs_wait;
@@ -18,18 +17,8 @@ use std::thread;
use std::time::Duration;
use tempfile::TempDir;
use uuid::Uuid;
use wiremock::Mock;
use wiremock::MockServer;
use wiremock::ResponseTemplate;
use wiremock::matchers::header;
use wiremock::matchers::method;
use wiremock::matchers::path;
const PERSONAL_ACCESS_TOKEN: &str = "at-cli-test";
const PERSONAL_ACCESS_TOKEN_AUTHORIZATION: &str = "Bearer at-cli-test";
const PERSONAL_ACCESS_TOKEN_ACCOUNT_ID: &str = "account-pat";
const WHOAMI_PATH: &str = "/v1/user-auth-credential/whoami";
const CLOUD_CONFIG_BUNDLE_PATH: &str = "/backend-api/wham/config/bundle";
const CLI_TIMEOUT: Duration = Duration::from_secs(30);
fn repo_root() -> std::path::PathBuf {
@@ -44,50 +33,6 @@ fn cli_sse_response() -> String {
])
}
async fn mount_personal_access_token_startup(server: &MockServer) {
Mock::given(method("GET"))
.and(path(WHOAMI_PATH))
.and(header("authorization", PERSONAL_ACCESS_TOKEN_AUTHORIZATION))
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
"email": "user@example.com",
"chatgpt_user_id": "user-pat",
"chatgpt_account_id": PERSONAL_ACCESS_TOKEN_ACCOUNT_ID,
"chatgpt_plan_type": "enterprise",
"chatgpt_account_is_fedramp": true,
})))
.expect(1..)
.mount(server)
.await;
Mock::given(method("GET"))
.and(path(CLOUD_CONFIG_BUNDLE_PATH))
.and(header("authorization", PERSONAL_ACCESS_TOKEN_AUTHORIZATION))
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({})))
.expect(1)
.mount(server)
.await;
}
#[expect(clippy::unwrap_used)]
fn personal_access_token_exec_command(server: &MockServer, home: &TempDir) -> Command {
let bin = codex_utils_cargo_bin::cargo_bin("codex").unwrap();
let mut cmd = Command::new(bin);
cmd.arg("exec")
.arg("--skip-git-repo-check")
.arg("-c")
.arg(format!("openai_base_url=\"{}/api/codex\"", server.uri()))
.arg("-c")
.arg(format!("chatgpt_base_url=\"{}/backend-api\"", server.uri()))
.arg("-C")
.arg(repo_root())
.arg("hello?");
cmd.env("CODEX_HOME", home.path())
.env(CODEX_ACCESS_TOKEN_ENV_VAR, PERSONAL_ACCESS_TOKEN)
.env("CODEX_AUTHAPI_BASE_URL", server.uri())
.env_remove(CODEX_API_KEY_ENV_VAR)
.env_remove("OPENAI_API_KEY");
cmd
}
struct ChildProcessCleanupGuard(u32);
impl Drop for ChildProcessCleanupGuard {
@@ -144,72 +89,6 @@ fn run_cli_command(command: &mut Command) -> io::Result<Output> {
}
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn responses_mode_stream_cli_supports_personal_access_tokens() {
skip_if_no_network!();
let server = MockServer::start().await;
mount_personal_access_token_startup(&server).await;
let resp_mock = responses::mount_sse_once(&server, cli_sse_response()).await;
let home = TempDir::new().unwrap();
let mut cmd = personal_access_token_exec_command(&server, &home);
let output = run_cli_command(&mut cmd).unwrap();
assert!(
output.status.success(),
"codex-cli exec failed: {}",
String::from_utf8_lossy(&output.stderr)
);
let request = resp_mock.single_request();
assert_eq!(request.path(), "/api/codex/responses");
assert_eq!(
request.header("authorization").as_deref(),
Some("Bearer at-cli-test")
);
assert_eq!(
request.header("chatgpt-account-id").as_deref(),
Some(PERSONAL_ACCESS_TOKEN_ACCOUNT_ID)
);
assert_eq!(request.header("x-openai-fedramp").as_deref(), Some("true"));
server.verify().await;
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn responses_mode_stream_cli_does_not_attempt_oauth_refresh_for_personal_access_tokens_after_401()
{
skip_if_no_network!();
let server = MockServer::start().await;
mount_personal_access_token_startup(&server).await;
Mock::given(method("POST"))
.and(path("/api/codex/responses"))
.and(header("authorization", PERSONAL_ACCESS_TOKEN_AUTHORIZATION))
.and(header(
"chatgpt-account-id",
PERSONAL_ACCESS_TOKEN_ACCOUNT_ID,
))
.and(header("x-openai-fedramp", "true"))
.respond_with(ResponseTemplate::new(401).set_body_string("unauthorized"))
.expect(1..)
.mount(&server)
.await;
Mock::given(method("POST"))
.and(path("/oauth/token"))
.respond_with(ResponseTemplate::new(500))
.expect(0)
.mount(&server)
.await;
let home = TempDir::new().unwrap();
let mut cmd = personal_access_token_exec_command(&server, &home);
let output = run_cli_command(&mut cmd).unwrap();
assert!(!output.status.success());
server.verify().await;
}
/// Tests streaming the Responses API through the CLI using a mock server.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn responses_mode_stream_cli() {
skip_if_no_network!();