mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Tailor TUI cyber refusal notices to Daybreak eligibility (#42667)
## What changed - Prefetch ChatGPT account eligibility in the background and cache it across TUI widget replacements. - Show an application link when Daybreak is available but not enabled, an Astra-specific explanation for unsupported models, and neutral copy when access is already present or eligibility cannot be determined. - Refresh eligibility after account changes and reconnects without changing the selected model or delaying refusal handling. ## Testing - Cover eligibility responses, account changes, model-specific notices, fallback behavior, and rendered notice snapshots. GitOrigin-RevId: 7ae8613a946cb46b8f0b46bf47e5e15ae258ed86
This commit is contained in:
1 parent
a7ab2d66d7
commit
ff2f01b0c2
21 files changed
+469
-80
No files matched your search
@@ -225,6 +225,7 @@ impl App {
|
||||
return;
|
||||
}
|
||||
ServerNotification::AccountUpdated(notification) => {
|
||||
self.chat_widget.cyber_policy_notice = Default::default();
|
||||
self.rate_limit_hard_stop_generation =
|
||||
self.rate_limit_hard_stop_generation.wrapping_add(1);
|
||||
self.rate_limit_refresh_state.invalidate_recovery();
|
||||
@@ -252,6 +253,13 @@ impl App {
|
||||
.is_some_and(AuthMode::has_chatgpt_account),
|
||||
has_codex_backend_auth,
|
||||
);
|
||||
if self.chat_widget.has_chatgpt_account() {
|
||||
crate::daybreak::prefetch_notice(
|
||||
&self.config,
|
||||
app_server_client,
|
||||
self.chat_widget.cyber_policy_notice.clone(),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
ServerNotification::ExternalAgentConfigImportCompleted(notification) => {
|
||||
|
||||
@@ -244,6 +244,7 @@ impl App {
|
||||
self.rate_limit_refresh_state.invalidate_recovery();
|
||||
session.inherit_task_tool_capabilities(app_server);
|
||||
*app_server = session;
|
||||
self.chat_widget.cyber_policy_notice = Default::default();
|
||||
self.chat_widget.requires_openai_auth = bootstrap.requires_openai_auth;
|
||||
self.chat_widget.remote_connection =
|
||||
crate::status::remote_connection::remote_connection_status_value(
|
||||
@@ -389,6 +390,13 @@ impl App {
|
||||
bootstrap.has_chatgpt_account,
|
||||
matches!(bootstrap.auth_mode, Some(TelemetryAuthMode::Chatgpt)),
|
||||
);
|
||||
if self.chat_widget.has_chatgpt_account() {
|
||||
crate::daybreak::prefetch_notice(
|
||||
&self.config,
|
||||
app_server,
|
||||
self.chat_widget.cyber_policy_notice.clone(),
|
||||
);
|
||||
}
|
||||
self.feedback_audience = bootstrap.feedback_audience;
|
||||
self.chat_widget.add_info_message(
|
||||
"Reconnected. No input was resent. Review uncertain submissions before retrying; recovered queues remain paused.".into(), /*hint*/ None,
|
||||
|
||||
@@ -475,6 +475,7 @@ impl App {
|
||||
/// This helper copies every known nickname/role from `AgentNavigationState` into the
|
||||
/// replacement widget so that replayed collab items render agent names immediately.
|
||||
pub(super) fn replace_chat_widget(&mut self, mut chat_widget: ChatWidget) {
|
||||
chat_widget.cyber_policy_notice = self.chat_widget.cyber_policy_notice.clone();
|
||||
self.commit_animation = None;
|
||||
// Transfer the last-written terminal title to the replacement widget
|
||||
// so it knows what OSC title is currently displayed. Without this, the
|
||||
|
||||
@@ -707,6 +707,11 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
// already has data and available reset credits can be surfaced, without
|
||||
// delaying the initial frame render.
|
||||
if requires_openai_auth && has_chatgpt_account {
|
||||
crate::daybreak::prefetch_notice(
|
||||
&app.config,
|
||||
&app_server,
|
||||
app.chat_widget.cyber_policy_notice.clone(),
|
||||
);
|
||||
let reset_hint_request_id = app.chat_widget.start_rate_limit_reset_startup_check();
|
||||
app.refresh_rate_limits(
|
||||
&app_server,
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
//! App-level orchestration tests for the TUI.
|
||||
|
||||
#[path = "tests/daybreak_tests.rs"]
|
||||
mod daybreak_tests;
|
||||
|
||||
#[path = "tests/advanced_reasoning_tests.rs"]
|
||||
mod advanced_reasoning_tests;
|
||||
#[path = "tests/agents_navigation_tests.rs"]
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
use super::*;
|
||||
use crate::daybreak::Notice;
|
||||
use app_test_support::ChatGptAuthFixture;
|
||||
use app_test_support::write_chatgpt_auth;
|
||||
use codex_app_server_client::AppServerEvent;
|
||||
use codex_app_server_protocol::AccountUpdatedNotification;
|
||||
use codex_app_server_protocol::AuthMode;
|
||||
use codex_app_server_protocol::CodexErrorInfo;
|
||||
use codex_app_server_protocol::ErrorNotification;
|
||||
use codex_login::AuthCredentialsStoreMode;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
|
||||
#[tokio::test]
|
||||
async fn cyber_refusal_reads_eligibility_without_changing_the_model() -> Result<()> {
|
||||
let (mut app, mut events, _ops) = make_test_app_with_channels().await;
|
||||
let backend = wiremock::MockServer::start().await;
|
||||
app.config.chatgpt_base_url = backend.uri();
|
||||
app.config.cli_auth_credentials_store_mode = AuthCredentialsStoreMode::File;
|
||||
write_chatgpt_auth(
|
||||
&app.config.codex_home,
|
||||
ChatGptAuthFixture::new("test-token")
|
||||
.account_id("account")
|
||||
.chatgpt_user_id("user"),
|
||||
AuthCredentialsStoreMode::File,
|
||||
)
|
||||
.expect("write synthetic auth");
|
||||
let server = Box::pin(crate::start_embedded_app_server_for_picker(&app.config)).await?;
|
||||
let thread_id = ThreadId::new();
|
||||
app.enqueue_primary_thread_session(
|
||||
test_thread_session(thread_id, app.config.cwd.to_path_buf()),
|
||||
Vec::new(),
|
||||
)
|
||||
.await?;
|
||||
for (status, enrolled, model, replace_account, expected) in [
|
||||
(200, true, "gpt-5.6-sol", false, Notice::Limited),
|
||||
(200, false, "gpt-5.6-sol", false, Notice::Apply),
|
||||
(503, false, "gpt-5.6-sol", false, Notice::Limited),
|
||||
(200, true, "gpt-6-astra", false, Notice::Astra),
|
||||
(200, false, "gpt-6-astra", false, Notice::Astra),
|
||||
(503, false, "gpt-6-astra", false, Notice::Astra),
|
||||
(200, true, "gpt-6-astra-wm", false, Notice::Astra),
|
||||
(200, true, "unmapped-model", false, Notice::Limited),
|
||||
(200, false, "gpt-5.6-sol", true, Notice::Limited),
|
||||
] {
|
||||
backend.reset().await;
|
||||
let codex_home = app.config.codex_home.clone();
|
||||
let response = wiremock::ResponseTemplate::new(status)
|
||||
.set_delay(if model == "gpt-5.6-sol" && enrolled { Duration::from_secs(1) } else { Duration::ZERO })
|
||||
.set_body_json(json!({"programs": [{"program":"cyber", "state": if enrolled { "active" } else { "inactive" }, "grants": if enrolled { json!([{"level":"tac2"}]) } else { json!([]) }}]}));
|
||||
wiremock::Mock::given(wiremock::matchers::path("/accounts/verified_access"))
|
||||
.and(wiremock::matchers::header(
|
||||
"authorization",
|
||||
"Bearer test-token",
|
||||
))
|
||||
.respond_with(move |_: &wiremock::Request| {
|
||||
if replace_account {
|
||||
write_chatgpt_auth(
|
||||
&codex_home,
|
||||
ChatGptAuthFixture::new("test-token").account_id("other-account"),
|
||||
AuthCredentialsStoreMode::File,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
response.clone()
|
||||
})
|
||||
.expect(1)
|
||||
.mount(&backend)
|
||||
.await;
|
||||
// Account discovery starts before a subsequent model switch to Sol.
|
||||
app.chat_widget.set_model("gpt-6-astra");
|
||||
app.handle_app_server_event(
|
||||
&server,
|
||||
AppServerEvent::ServerNotification(Box::new(ServerNotification::AccountUpdated(
|
||||
AccountUpdatedNotification {
|
||||
auth_mode: Some(AuthMode::Chatgpt),
|
||||
plan_type: None,
|
||||
},
|
||||
))),
|
||||
)
|
||||
.await;
|
||||
if model != "gpt-5.6-sol" || !enrolled {
|
||||
wait_for_notice(&app.chat_widget.cyber_policy_notice).await;
|
||||
}
|
||||
app.active_thread_id = Some(thread_id);
|
||||
app.chat_widget.set_model(model);
|
||||
while events.try_recv().is_ok() {}
|
||||
// In the slow Sol case, discovery is still pending: do not block input on it.
|
||||
tokio::time::timeout(
|
||||
Duration::from_millis(250),
|
||||
app.handle_app_server_event(
|
||||
&server,
|
||||
AppServerEvent::ServerNotification(Box::new(ServerNotification::Error(
|
||||
ErrorNotification {
|
||||
error: AppServerTurnError {
|
||||
misalignment: None,
|
||||
message: "server fallback".into(),
|
||||
codex_error_info: Some(CodexErrorInfo::CyberPolicy),
|
||||
additional_details: None,
|
||||
},
|
||||
will_retry: false,
|
||||
thread_id: thread_id.to_string(),
|
||||
turn_id: "turn".into(),
|
||||
},
|
||||
))),
|
||||
),
|
||||
)
|
||||
.await
|
||||
.expect("refusal must not wait for eligibility");
|
||||
let event = app.active_thread_rx.as_mut().unwrap().recv().await.unwrap();
|
||||
app.handle_thread_event_now(event);
|
||||
let cell = std::iter::from_fn(|| events.try_recv().ok())
|
||||
.find_map(|event| match event {
|
||||
AppEvent::InsertHistoryCell(cell) => Some(cell),
|
||||
_ => None,
|
||||
})
|
||||
.expect("cyber refusal cell");
|
||||
assert_eq!(
|
||||
cell.display_lines(/*width*/ 80),
|
||||
history_cell::new_cyber_policy_error_event(expected).display_lines(/*width*/ 80),
|
||||
"{model}"
|
||||
);
|
||||
assert_eq!(
|
||||
wait_for_notice(&app.chat_widget.cyber_policy_notice)
|
||||
.await
|
||||
.for_model(model),
|
||||
expected
|
||||
);
|
||||
backend.verify().await;
|
||||
assert_eq!(app.chat_widget.current_model(), model);
|
||||
}
|
||||
server.shutdown().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn wait_for_notice(cache: &crate::daybreak::NoticeCache) -> Notice {
|
||||
tokio::time::timeout(Duration::from_secs(3), async {
|
||||
loop {
|
||||
if let Some(notice) = cache.get() {
|
||||
return *notice;
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(10)).await;
|
||||
}
|
||||
})
|
||||
.await
|
||||
.expect("eligibility should finish")
|
||||
}
|
||||
Reference in new issue
Block a user