mirror of
https://github.com/openai/codex.git
synced 2026-11-18 23:02:23 +00:00
Use installed callable apps for TUI mentions (#39051)
## Why The app directory is a discovery catalog and can include apps that are not callable in the active thread. Using it for `$` suggestions can therefore offer mentions that cannot be used. ## What changed - Load mention candidates from `app/installed`, enrich callable apps through bounded `app/read` batches, and retain compatibility with app servers that do not support `app/installed`. - Keep the mention catalog separate from the `/apps` directory cache and scope results to the current thread, workspace, and account. - Refresh mentions after app notifications, enablement changes, configuration updates, and apps MCP readiness, while immediately removing disabled apps. ## Testing Add coverage for batching and fallback behavior, stale scoped results, notification refreshes, enablement changes, MCP startup races, and filtering non-callable apps from mentions. GitOrigin-RevId: 4d9e20794aed30cc97120170792fb555b86fe1e7
This commit is contained in:
1 parent
d7d526b81d
commit
fe5889928c
17 files changed
+759
-116
No files matched your search
@@ -344,21 +344,17 @@ async fn thread_settings_updated_updates_visible_state_without_transcript() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(Some("gpt-5.2")).await;
|
||||
set_chatgpt_auth(&mut chat);
|
||||
set_fast_mode_test_catalog(&mut chat);
|
||||
chat.set_feature_enabled(Feature::Apps, /*enabled*/ true);
|
||||
let thread_id = ThreadId::new();
|
||||
let mut session = configured_thread_session(thread_id);
|
||||
session.cwd = test_path_buf("/tmp/original-workspace").abs();
|
||||
chat.handle_thread_session(session);
|
||||
let generation = chat.connector_scope_generation();
|
||||
chat.on_connectors_loaded(
|
||||
Ok(crate::app_event::ConnectorsSnapshot {
|
||||
connectors: vec![
|
||||
serde_json::from_str(r#"{"id":"old","name":"Old","isAccessible":true}"#)
|
||||
.expect("valid app"),
|
||||
],
|
||||
}),
|
||||
/*is_final*/ true,
|
||||
);
|
||||
chat.prefetch_connectors();
|
||||
let previous_generation = chat.connector_scope_generation();
|
||||
let old_app = serde_json::from_str(r#"{"id":"old","name":"Old","isAccessible":true}"#)
|
||||
.expect("valid app");
|
||||
chat.connectors.mention_snapshot = Some(crate::app_event::ConnectorsSnapshot {
|
||||
connectors: vec![old_app],
|
||||
});
|
||||
let _ = drain_insert_history(&mut rx);
|
||||
|
||||
chat.handle_server_notification(
|
||||
@@ -366,9 +362,9 @@ async fn thread_settings_updated_updates_visible_state_without_transcript() {
|
||||
/*replay_kind*/ None,
|
||||
);
|
||||
|
||||
assert_ne!(chat.connector_scope_generation(), generation);
|
||||
assert_ne!(chat.connector_scope_generation(), previous_generation);
|
||||
assert!(chat.connectors_for_mentions().is_none());
|
||||
assert!(chat.connectors.prefetch_in_flight);
|
||||
assert!(chat.connectors.mention_refresh_in_flight);
|
||||
assert_eq!(chat.current_model(), "gpt-5.4");
|
||||
assert_eq!(
|
||||
chat.current_reasoning_effort(),
|
||||
|
||||
@@ -69,6 +69,28 @@ async fn mcp_startup_ignores_status_for_other_thread() {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn mcp_apps_readiness_retries_an_in_flight_installed_mention_lookup() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.thread_id = Some(ThreadId::new());
|
||||
set_chatgpt_auth(&mut chat);
|
||||
chat.set_feature_enabled(Feature::Apps, /*enabled*/ true);
|
||||
|
||||
chat.refresh_connector_mentions(/*force_refresh*/ false);
|
||||
chat.on_mcp_server_status_updated(McpServerStatusUpdatedNotification {
|
||||
thread_id: None,
|
||||
name: "codex_apps".to_string(),
|
||||
status: McpServerStartupState::Ready,
|
||||
error: None,
|
||||
failure_reason: None,
|
||||
});
|
||||
|
||||
assert_eq!(chat.connectors.mention_refresh_pending, Some(false));
|
||||
let snapshot = crate::app_event::ConnectorsSnapshot { connectors: vec![] };
|
||||
chat.on_connector_mentions_loaded(chat.connector_scope_generation(), Ok(snapshot));
|
||||
assert!(chat.connectors.mention_refresh_in_flight);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn mcp_startup_dedupes_same_round_duplicate_failure_warning() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
|
||||
@@ -2087,7 +2087,8 @@ async fn plugins_popup_search_no_matches_and_backspace_restores_results() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn apps_popup_stays_loading_until_final_snapshot_updates() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.thread_id = Some(ThreadId::new());
|
||||
set_chatgpt_auth(&mut chat);
|
||||
chat.config
|
||||
.features
|
||||
@@ -2124,6 +2125,14 @@ async fn apps_popup_stays_loading_until_final_snapshot_updates() {
|
||||
chat.connectors.prefetch_in_flight,
|
||||
"expected /apps to trigger a forced connectors refresh"
|
||||
);
|
||||
assert_matches!(
|
||||
rx.try_recv(),
|
||||
Ok(AppEvent::FetchConnectorsList { force_refetch, .. }) if force_refetch
|
||||
);
|
||||
assert_matches!(
|
||||
rx.try_recv(),
|
||||
Ok(AppEvent::FetchInstalledConnectorMentions { force_refresh, .. }) if force_refresh
|
||||
);
|
||||
|
||||
let before = render_bottom_popup(&chat, /*width*/ 80);
|
||||
assert!(
|
||||
@@ -2187,7 +2196,8 @@ async fn apps_popup_stays_loading_until_final_snapshot_updates() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn apps_notification_update_excludes_inaccessible_apps_from_mentions() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
let (mut chat, _rx, mut op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.thread_id = Some(ThreadId::new());
|
||||
set_chatgpt_auth(&mut chat);
|
||||
chat.config
|
||||
.features
|
||||
@@ -2230,7 +2240,7 @@ async fn apps_notification_update_excludes_inaccessible_apps_from_mentions() {
|
||||
app_metadata: None,
|
||||
labels: None,
|
||||
install_url: Some("https://example.test/arabica".to_string()),
|
||||
is_accessible: false,
|
||||
is_accessible: true,
|
||||
is_enabled: true,
|
||||
plugin_display_names: Vec::new(),
|
||||
},
|
||||
@@ -2239,44 +2249,116 @@ async fn apps_notification_update_excludes_inaccessible_apps_from_mentions() {
|
||||
/*is_final*/ false,
|
||||
);
|
||||
|
||||
assert_matches!(
|
||||
&chat.connectors.partial_snapshot,
|
||||
Some(snapshot)
|
||||
if snapshot
|
||||
.connectors
|
||||
.iter()
|
||||
.find(|connector| connector.id == "arabica_uae")
|
||||
.is_some_and(|connector| !connector.is_accessible)
|
||||
assert!(chat.connectors_for_mentions().is_none());
|
||||
|
||||
let mut installed = chat
|
||||
.connectors
|
||||
.partial_snapshot
|
||||
.as_ref()
|
||||
.expect("directory notification should remain available to /apps")
|
||||
.connectors
|
||||
.clone();
|
||||
installed[1].is_enabled = false;
|
||||
chat.on_connector_mentions_loaded(
|
||||
chat.connector_scope_generation(),
|
||||
Ok(ConnectorsSnapshot {
|
||||
connectors: installed,
|
||||
}),
|
||||
);
|
||||
|
||||
let popup = render_bottom_popup(&chat, /*width*/ 80);
|
||||
assert!(
|
||||
popup.contains("Google Drive"),
|
||||
"expected accessible apps to appear in the mention popup, got:\n{popup}"
|
||||
"expected callable installed apps to appear in the mention popup, got:\n{popup}"
|
||||
);
|
||||
assert!(
|
||||
!popup.contains("% Arabica UAE"),
|
||||
"did not expect an inaccessible directory app in the mention popup, got:\n{popup}"
|
||||
"directory accessibility must not make an app callable, got:\n{popup}"
|
||||
);
|
||||
chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
|
||||
chat.insert_str("$arabica-uae ");
|
||||
chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
|
||||
assert_matches!(
|
||||
next_submit_op(&mut op_rx),
|
||||
Op::UserTurn { items, .. }
|
||||
if matches!(items.as_slice(), [
|
||||
UserInput::Text { .. },
|
||||
UserInput::Mention { name, path },
|
||||
] if name == "Google Drive" && path == "app://google_drive")
|
||||
);
|
||||
|
||||
chat.connectors.partial_snapshot = None;
|
||||
assert_matches!(&chat.connectors.cache, ConnectorsCacheState::Uninitialized);
|
||||
for (app_id, app_name) in [
|
||||
("arabica_uae", "% Arabica UAE"),
|
||||
("google_drive", "Google Drive"),
|
||||
] {
|
||||
chat.on_plugin_install_loaded(
|
||||
chat.config.cwd.to_path_buf(),
|
||||
crate::app_event::PluginLocation::Remote {
|
||||
marketplace_name: "marketplace".to_string(),
|
||||
},
|
||||
"plugin".to_string(),
|
||||
"Plugin".to_string(),
|
||||
Ok(serde_json::from_value(serde_json::json!({
|
||||
"authPolicy": "ON_INSTALL",
|
||||
"appsNeedingAuth": [{ "id": app_id, "name": app_name }],
|
||||
}))
|
||||
.expect("valid plugin installation response")),
|
||||
);
|
||||
let auth_popup = render_bottom_popup(&chat, /*width*/ 80);
|
||||
assert!(auth_popup.contains("Already installed") && auth_popup.contains("Continue"));
|
||||
if app_id == "arabica_uae" {
|
||||
let snapshot = normalize_snapshot_paths(format!(
|
||||
"{popup}\n\n--- plugin authentication ---\n{auth_popup}"
|
||||
));
|
||||
assert_chatwidget_snapshot!("apps_mentions_only_callable_installed", snapshot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn account_changes_revoke_app_directory_and_restart_scoped_requests() {
|
||||
async fn apps_installed_mentions_revoke_access_and_reject_stale_account_results() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.thread_id = Some(ThreadId::new());
|
||||
set_chatgpt_auth(&mut chat);
|
||||
chat.on_connectors_loaded(
|
||||
Ok(ConnectorsSnapshot {
|
||||
connectors: vec![
|
||||
serde_json::from_str(
|
||||
r#"{"id":"old-account","name":"Old Account","isAccessible":true}"#,
|
||||
)
|
||||
.expect("valid app"),
|
||||
],
|
||||
}),
|
||||
/*is_final*/ true,
|
||||
);
|
||||
chat.set_feature_enabled(Feature::Apps, /*enabled*/ true);
|
||||
let generation = chat.connector_scope_generation();
|
||||
let connector_id = "account-app";
|
||||
let connector =
|
||||
serde_json::from_str(r#"{"id":"account-app","name":"Account app","isAccessible":true}"#)
|
||||
.expect("valid installed app");
|
||||
let snapshot = ConnectorsSnapshot {
|
||||
connectors: vec![connector],
|
||||
};
|
||||
chat.on_connector_mentions_loaded(generation, Ok(snapshot.clone()));
|
||||
assert!(chat.connectors.installed_app_ids.contains(connector_id));
|
||||
|
||||
chat.refresh_connector_mentions(/*force_refresh*/ false);
|
||||
rx.try_recv().expect("pre-disable mention refresh");
|
||||
chat.update_connector_enabled(connector_id, /*enabled*/ false);
|
||||
chat.on_connector_mentions_loaded(generation, Ok(snapshot.clone()));
|
||||
assert_eq!(chat.connectors_for_mentions(), Some([].as_slice()));
|
||||
rx.try_recv().expect("post-disable mention refresh");
|
||||
chat.on_connector_mentions_loaded(generation, Ok(snapshot.clone()));
|
||||
assert_eq!(
|
||||
chat.connectors_for_mentions(),
|
||||
Some(snapshot.connectors.as_slice())
|
||||
);
|
||||
|
||||
chat.on_connectors_loaded(Ok(snapshot.clone()), /*is_final*/ true);
|
||||
for enabled in [false, true] {
|
||||
chat.update_connector_enabled(connector_id, enabled);
|
||||
assert_eq!(chat.connectors_for_mentions(), Some([].as_slice()));
|
||||
assert_matches!(
|
||||
rx.try_recv(),
|
||||
Ok(AppEvent::FetchInstalledConnectorMentions { force_refresh, .. })
|
||||
if force_refresh == enabled
|
||||
);
|
||||
let mut refreshed = snapshot.clone();
|
||||
refreshed.connectors[0].is_enabled = enabled;
|
||||
chat.on_connector_mentions_loaded(generation, Ok(refreshed));
|
||||
}
|
||||
|
||||
chat.update_account_state(
|
||||
/*status_account_display*/ None, /*plan_type*/ None,
|
||||
@@ -2284,15 +2366,14 @@ async fn account_changes_revoke_app_directory_and_restart_scoped_requests() {
|
||||
);
|
||||
|
||||
assert_ne!(chat.connector_scope_generation(), generation);
|
||||
assert_matches!(&chat.connectors.cache, ConnectorsCacheState::Uninitialized);
|
||||
assert!(chat.connectors_for_mentions().is_none());
|
||||
assert!(chat.connectors.prefetch_in_flight);
|
||||
assert_matches!(
|
||||
rx.try_recv(),
|
||||
Ok(AppEvent::FetchConnectorsList {
|
||||
force_refetch: false,
|
||||
generation
|
||||
}) if generation == chat.connector_scope_generation()
|
||||
);
|
||||
assert!(chat.connectors.mention_refresh_in_flight);
|
||||
|
||||
chat.on_connector_mentions_loaded(generation, Ok(snapshot));
|
||||
assert!(chat.connectors_for_mentions().is_none());
|
||||
assert!(chat.connectors.mention_refresh_in_flight);
|
||||
assert!(chat.connectors.installed_app_ids.is_empty());
|
||||
|
||||
let (mut replacement, _, _) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
replacement.invalidate_connector_scope();
|
||||
|
||||
Reference in new issue
Block a user