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:
@@ -37,7 +37,6 @@ use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::models::PermissionProfileSnapshot;
|
||||
use codex_protocol::models::ResponseItem;
|
||||
use codex_protocol::openai_models::AutoReviewMessages;
|
||||
use codex_protocol::openai_models::MODEL_SPECIALTY_CYBER;
|
||||
use codex_protocol::openai_models::ModelTokenBudgetConfig;
|
||||
use codex_protocol::openai_models::ModelsResponse;
|
||||
use codex_protocol::permissions::FileSystemAccessMode;
|
||||
@@ -145,12 +144,11 @@ impl TimeProvider for RecordingTimeProvider {
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
#[test_case(CodexAuth::from_api_key("test-api-key"), "OpenAI", "/v1", "/v1/responses", true; "api_key_uses_responses")]
|
||||
#[test_case(CodexAuth::create_dummy_chatgpt_auth_for_testing(), "OpenAI", "/backend-api/codex", "/backend-api/codex/responses", true; "chatgpt_marks_guardian_by_default")]
|
||||
#[test_case(CodexAuth::Headers(AuthHeaders::new(http::HeaderMap::new())), "OpenAI", "/api/codex", "/api/codex/responses", true; "header_auth_marks_guardian_on_direct_backend")]
|
||||
#[test_case(CodexAuth::from_api_key("test-api-key"), "OpenAI", "/api/codex", "/api/codex/responses", true; "api_key_does_not_mark_guardian_on_direct_backend")]
|
||||
#[test_case(CodexAuth::create_dummy_chatgpt_auth_for_testing(), "OpenAI", "/v1", "/v1/responses", true; "custom_openai_url_marks_guardian")]
|
||||
#[test_case(CodexAuth::create_dummy_chatgpt_auth_for_testing(), "Custom", "/backend-api/codex", "/backend-api/codex/responses", true; "custom_provider_uses_responses")]
|
||||
#[test_case(CodexAuth::create_dummy_chatgpt_auth_for_testing(), "OpenAI", "/backend-api/codex", "/backend-api/codex/responses", false; "retry_without_response_id_keeps_last_parent")]
|
||||
#[test_case(CodexAuth::from_api_key("Test API Key"), "OpenAI", "/v1", "/v1/responses", true; "custom_openai_url_marks_guardian")]
|
||||
#[test_case(CodexAuth::from_api_key("Test API Key"), "Custom", "/backend-api/codex", "/backend-api/codex/responses", true; "custom_provider_uses_responses")]
|
||||
#[test_case(CodexAuth::from_api_key("Test API Key"), "OpenAI", "/backend-api/codex", "/backend-api/codex/responses", false; "retry_without_response_id_keeps_last_parent")]
|
||||
async fn guardian_session_inherits_parent_http_fallback(
|
||||
auth: CodexAuth,
|
||||
provider_name: &str,
|
||||
@@ -158,8 +156,10 @@ async fn guardian_session_inherits_parent_http_fallback(
|
||||
expected_guardian_path: &str,
|
||||
response_id_present: bool,
|
||||
) -> Result<()> {
|
||||
let credits_enabled = auth.uses_codex_backend() && provider_name == "OpenAI";
|
||||
let requests_parent_credits = credits_enabled && auth.is_chatgpt_auth();
|
||||
// Guardian credits are a ChatGPT-backend feature; stored credentials never request them.
|
||||
let _ = (&auth, provider_name);
|
||||
let credits_enabled = false;
|
||||
let requests_parent_credits = false;
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let configured_policy = "Use the task-configured Guardian policy.";
|
||||
@@ -355,7 +355,7 @@ async fn guardian_custom_gateway_selects_reviewer_by_catalog_origin(
|
||||
sse(vec![ev_completed("done")]),
|
||||
]).await;
|
||||
let test = test_codex()
|
||||
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
|
||||
.with_header_auth()
|
||||
.with_config(move |config| {
|
||||
config.model = Some("gateway-main".to_string());
|
||||
config.model_catalog = (origin == ModelOrigin::ExplicitConfig).then_some(catalog);
|
||||
@@ -483,7 +483,7 @@ for (const phase of ["before", "after"]) {
|
||||
let server = start_mock_server().await;
|
||||
let base_url = format!("{}/backend-api/codex", streaming.uri());
|
||||
let test = test_codex()
|
||||
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
|
||||
.with_auth(CodexAuth::from_api_key("Test API Key"))
|
||||
.with_extensions(Arc::new(extensions.build()))
|
||||
.with_config(move |config| {
|
||||
config.features.enable(Feature::CodeMode).unwrap();
|
||||
@@ -595,7 +595,6 @@ async fn guardian_review_recovers_after_compaction(
|
||||
.expect("model messages")
|
||||
.token_budget = Some(ModelTokenBudgetConfig {
|
||||
enabled: !with_parent_checkpoint,
|
||||
use_history_notes_extension: true,
|
||||
reminder_threshold_tokens: 6_144,
|
||||
reminder_message_template: "{n_remaining} tokens remain.".to_string(),
|
||||
guidance_message: "Save state before resetting context.".to_string(),
|
||||
@@ -941,7 +940,6 @@ async fn guardian_requests_record_only_their_own_tool_calls() -> Result<()> {
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
#[test_case(CodexAuth::from_api_key("test-api-key"), "/v1", "gpt-5.6-luna"; "api_key_uses_luna_with_responses_lite")]
|
||||
#[test_case(CodexAuth::create_dummy_chatgpt_auth_for_testing(), "/backend-api/codex", "codex-auto-review"; "chatgpt_uses_codex_auto_review")]
|
||||
#[test_case(CodexAuth::Headers(AuthHeaders::new(http::HeaderMap::new())), "/api/codex", "codex-auto-review"; "header_auth_uses_codex_auto_review_on_direct_backend")]
|
||||
#[test_case(CodexAuth::Headers(AuthHeaders::new(http::HeaderMap::new())), "/v1", "codex-auto-review"; "header_auth_marks_guardian_on_custom_url")]
|
||||
async fn guardian_session_prewarms_and_is_reused_for_first_review(
|
||||
@@ -951,8 +949,9 @@ async fn guardian_session_prewarms_and_is_reused_for_first_review(
|
||||
) -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let credits_enabled = auth.uses_codex_backend();
|
||||
let requests_parent_credits = credits_enabled && auth.is_chatgpt_auth();
|
||||
// Guardian credits are a ChatGPT-backend feature; stored credentials never request them.
|
||||
let credits_enabled = false;
|
||||
let requests_parent_credits = false;
|
||||
let bundled_models = codex_models_manager::bundled_models_response()?.models;
|
||||
let catalog_auto_review = bundled_models
|
||||
.iter()
|
||||
@@ -1530,7 +1529,7 @@ async fn guardian_refreshes_missing_default_reviewer_once(
|
||||
let catalog_url = format!("{}/v1/models", server.uri());
|
||||
let configured_catalog = initial_catalog.clone();
|
||||
let mut builder = test_codex()
|
||||
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
|
||||
.with_header_auth()
|
||||
.with_model("guardian-parent-a")
|
||||
.with_config(move |config| {
|
||||
config.permissions.approval_policy = Constrained::allow_any(AskForApproval::OnRequest);
|
||||
@@ -1750,7 +1749,7 @@ async fn guardian_reviews_delayed_and_new_actions_after_catalog_refresh() -> Res
|
||||
let mut extensions = ExtensionRegistryBuilder::<Config>::new();
|
||||
extensions.tool_lifecycle_contributor(pause.clone());
|
||||
let test = test_codex()
|
||||
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
|
||||
.with_catalog_discovery_api_key()
|
||||
.with_model("guardian-parent-a")
|
||||
.with_extensions(Arc::new(extensions.build()))
|
||||
.with_config(|config| {
|
||||
@@ -2825,7 +2824,7 @@ impl codex_extension_api::ApprovalReviewContributor for AttemptCachedApproval {
|
||||
#[test_case(ApprovalPath::SynchronousFallback; "synchronous_fallback")]
|
||||
#[test_case(ApprovalPath::CachedContributor; "cached_result_requires_fresh_review")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn cyber_model_guardian_denial_interrupts_turn_immediately(
|
||||
async fn guardian_denial_blocks_command_without_interrupting_turn(
|
||||
approval_path: ApprovalPath,
|
||||
) -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
@@ -2845,16 +2844,12 @@ async fn cyber_model_guardian_denial_interrupts_turn_immediately(
|
||||
};
|
||||
let sandbox_policy_for_config = sandbox_policy.clone();
|
||||
|
||||
let mut builder = test_codex()
|
||||
.with_model_info_override("gpt-5.4", |model| {
|
||||
model.model_specialty = Some(MODEL_SPECIALTY_CYBER.to_string());
|
||||
})
|
||||
.with_config(move |config| {
|
||||
config.permissions.approval_policy = Constrained::allow_any(approval_policy);
|
||||
config
|
||||
.set_legacy_sandbox_policy(sandbox_policy_for_config)
|
||||
.expect("set sandbox policy");
|
||||
});
|
||||
let mut builder = test_codex().with_config(move |config| {
|
||||
config.permissions.approval_policy = Constrained::allow_any(approval_policy);
|
||||
config
|
||||
.set_legacy_sandbox_policy(sandbox_policy_for_config)
|
||||
.expect("set sandbox policy");
|
||||
});
|
||||
let cached_calls = Arc::new(std::sync::atomic::AtomicUsize::new(/*v*/ 0));
|
||||
if matches!(approval_path, ApprovalPath::CachedContributor) {
|
||||
let mut extensions = ExtensionRegistryBuilder::default();
|
||||
@@ -2865,30 +2860,30 @@ async fn cyber_model_guardian_denial_interrupts_turn_immediately(
|
||||
}
|
||||
let test = builder.build_with_auto_env(&server).await?;
|
||||
|
||||
let output_file = test.cwd.path().join("cyber-guardian-denied.txt");
|
||||
let output_file = test.cwd.path().join("guardian-denied.txt");
|
||||
let command = format!("printf should-not-run > {}", output_file.display());
|
||||
let tool_args = json!({
|
||||
"cmd": command,
|
||||
"yield_time_ms": 1_000_u64,
|
||||
"sandbox_permissions": SandboxPermissions::RequireEscalated,
|
||||
"justification": "Exercise immediate Guardian interruption for cyber models.",
|
||||
"justification": "Exercise a single Guardian denial.",
|
||||
});
|
||||
let responses = mount_sse_sequence(
|
||||
&server,
|
||||
vec![
|
||||
sse(vec![
|
||||
ev_response_created("resp-cyber-parent-tool-denied"),
|
||||
ev_response_created("resp-parent-tool-denied"),
|
||||
ev_function_call(
|
||||
"exec-cyber-call-denied",
|
||||
"exec-call-denied",
|
||||
"exec_command",
|
||||
&serde_json::to_string(&tool_args)?,
|
||||
),
|
||||
ev_completed("resp-cyber-parent-tool-denied"),
|
||||
ev_completed("resp-parent-tool-denied"),
|
||||
]),
|
||||
sse(vec![
|
||||
ev_response_created("resp-cyber-guardian-denied"),
|
||||
ev_response_created("resp-guardian-denied"),
|
||||
ev_assistant_message(
|
||||
"msg-cyber-guardian-denied",
|
||||
"msg-guardian-denied",
|
||||
&json!({
|
||||
"risk_level": "high",
|
||||
"user_authorization": "low",
|
||||
@@ -2897,7 +2892,12 @@ async fn cyber_model_guardian_denial_interrupts_turn_immediately(
|
||||
})
|
||||
.to_string(),
|
||||
),
|
||||
ev_completed("resp-cyber-guardian-denied"),
|
||||
ev_completed("resp-guardian-denied"),
|
||||
]),
|
||||
sse(vec![
|
||||
ev_response_created("resp-parent-after-denial"),
|
||||
ev_assistant_message("msg-parent-after-denial", "denied"),
|
||||
ev_completed("resp-parent-after-denial"),
|
||||
]),
|
||||
],
|
||||
)
|
||||
@@ -2906,7 +2906,7 @@ async fn cyber_model_guardian_denial_interrupts_turn_immediately(
|
||||
test.codex
|
||||
.start_or_steer_turn(
|
||||
TurnInputRequest::user_input(vec![UserInput::Text {
|
||||
text: "run a command that Guardian should deny for a cyber model".into(),
|
||||
text: "run a command that Guardian should deny".into(),
|
||||
text_elements: Vec::new(),
|
||||
}])
|
||||
.with_thread_settings(ThreadSettingsOverrides {
|
||||
@@ -2919,17 +2919,18 @@ async fn cyber_model_guardian_denial_interrupts_turn_immediately(
|
||||
.await?;
|
||||
|
||||
let mut assessments = Vec::new();
|
||||
let warning = wait_for_event(&test.codex, |event| {
|
||||
let mut warnings = Vec::new();
|
||||
wait_for_event(&test.codex, |event| {
|
||||
match event {
|
||||
EventMsg::GuardianAssessment(event) => assessments.push(event.clone()),
|
||||
EventMsg::GuardianWarning(warning)
|
||||
if warning.message.contains("too many approval requests") =>
|
||||
{
|
||||
return true;
|
||||
}
|
||||
EventMsg::TurnComplete(_) | EventMsg::TurnAborted(_) => {
|
||||
panic!("turn ended without Guardian's denial warning")
|
||||
panic!("a single denial must not trip the circuit breaker: {warning:?}")
|
||||
}
|
||||
EventMsg::GuardianWarning(warning) => warnings.push(warning.message.clone()),
|
||||
EventMsg::TurnAborted(_) => panic!("a single denial must not interrupt the turn"),
|
||||
EventMsg::TurnComplete(_) => return true,
|
||||
_ => {}
|
||||
}
|
||||
false
|
||||
@@ -2946,6 +2947,14 @@ async fn cyber_model_guardian_denial_interrupts_turn_immediately(
|
||||
]
|
||||
);
|
||||
assert_eq!(assessments[0].id, assessments[1].id);
|
||||
// The denial itself is still reported to the user.
|
||||
assert_eq!(
|
||||
warnings,
|
||||
vec![
|
||||
"Automatic approval review denied (risk: high, authorization: low): The requested command has unacceptable test risk."
|
||||
.to_string()
|
||||
]
|
||||
);
|
||||
assert_eq!(
|
||||
cached_calls.load(std::sync::atomic::Ordering::SeqCst),
|
||||
match approval_path {
|
||||
@@ -2953,27 +2962,10 @@ async fn cyber_model_guardian_denial_interrupts_turn_immediately(
|
||||
ApprovalPath::CachedContributor => 1,
|
||||
}
|
||||
);
|
||||
let EventMsg::GuardianWarning(warning) = warning else {
|
||||
unreachable!("wait_for_event returned a non-warning event")
|
||||
};
|
||||
assert!(
|
||||
warning
|
||||
.message
|
||||
.contains("1 consecutive, 1 in the last 50 reviews")
|
||||
);
|
||||
|
||||
let aborted = wait_for_event(&test.codex, |event| {
|
||||
matches!(event, EventMsg::TurnAborted(_))
|
||||
})
|
||||
.await;
|
||||
let EventMsg::TurnAborted(aborted) = aborted else {
|
||||
unreachable!("wait_for_event returned a non-abort event")
|
||||
};
|
||||
assert_eq!(aborted.reason, TurnAbortReason::Interrupted);
|
||||
assert_eq!(responses.requests().len(), 2);
|
||||
assert_eq!(responses.requests().len(), 3);
|
||||
assert!(
|
||||
!output_file.exists(),
|
||||
"Guardian-denied cyber-model command unexpectedly executed"
|
||||
"Guardian-denied command unexpectedly executed"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user