mirror of
https://github.com/openai/codex.git
synced 2026-12-04 00:51:02 +00:00
Use readable plugin mentions without suppressing same-name skills (#51865)
## Why Generated app IDs produce opaque plugin mention labels. A selected `@foo` plugin mention also prevented a separate `$foo` skill mention from being submitted. ## What changed - Use eligible display names, such as `@Postman`, for plugins named `app-` followed by 32 lowercase hexadecimal characters, while preserving the plugin binding. Accept 1–64 ASCII letters, digits, underscores, or hyphens, excluding common environment variable names; otherwise retain the existing naming fallback. - Only `$` mention bindings suppress automatic skill selection, allowing `@foo $foo` to submit both the plugin and the skill. ## Testing Add naming tests for accepted display names and fallback cases, a composer snapshot verifying `@Postman` and its plugin binding, and a submission regression test for a plugin and skill sharing the name `foo`. GitOrigin-RevId: aa8c98f293d12e62d32d43206e076cbe1fcb2a3b
This commit is contained in:
@@ -6873,7 +6873,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn test_plugin_summary(name: &str, description: &str) -> PluginCapabilitySummary {
|
||||
pub(super) fn test_plugin_summary(name: &str, description: &str) -> PluginCapabilitySummary {
|
||||
PluginCapabilitySummary {
|
||||
config_name: format!("{name}@test"),
|
||||
display_name: name.to_string(),
|
||||
|
||||
@@ -1,17 +1,50 @@
|
||||
//! Snapshot coverage for draft text, shortcuts, and live voice controls in the composer.
|
||||
//! Snapshot coverage for draft text, plugin mentions, shortcuts, and live voice controls.
|
||||
|
||||
use super::tests::new_test_composer;
|
||||
use super::tests::snapshot_composer_state_with_width;
|
||||
use super::tests::test_plugin_summary;
|
||||
use crate::bottom_pane::MentionBinding;
|
||||
use crate::bottom_pane::footer::FooterMode;
|
||||
use crate::key_hint;
|
||||
use crate::key_hint::ShortcutHint;
|
||||
use crate::keymap::RuntimeKeymap;
|
||||
use crate::render::renderable::Renderable;
|
||||
use codex_plugin::PluginCapabilitySummary;
|
||||
use crossterm::event::KeyCode;
|
||||
use crossterm::event::KeyEvent;
|
||||
use crossterm::event::KeyModifiers;
|
||||
use pretty_assertions::assert_eq;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::layout::Rect;
|
||||
|
||||
#[test]
|
||||
fn plugin_mention_uses_display_name_for_opaque_id() {
|
||||
snapshot_composer_state_with_width(
|
||||
"plugin_mention_uses_display_name_for_opaque_id",
|
||||
/*width*/ 100,
|
||||
/*enhanced_keys_supported*/ false,
|
||||
|composer| {
|
||||
let plugin_name = "app-6a6b12e06c5c8191ac5d5252fa5f92c8";
|
||||
composer.set_mentions_v2_enabled(/*enabled*/ true);
|
||||
composer.set_plugin_mentions(Some(vec![PluginCapabilitySummary {
|
||||
display_name: "Postman".to_string(),
|
||||
..test_plugin_summary(plugin_name, "")
|
||||
}]));
|
||||
composer.set_text_content("@Postm".to_string(), Vec::new(), Vec::new());
|
||||
composer.handle_key_event(KeyEvent::new(KeyCode::Tab, KeyModifiers::NONE));
|
||||
|
||||
assert_eq!(
|
||||
composer.mention_bindings(),
|
||||
vec![MentionBinding {
|
||||
sigil: '@',
|
||||
mention: "Postman".to_string(),
|
||||
path: format!("plugin://{plugin_name}@test"),
|
||||
}]
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shortcut_footer_displays_configured_chords() {
|
||||
use codex_config::types::KeybindingSpec;
|
||||
|
||||
@@ -132,6 +132,21 @@ fn plugin_mention_name(plugin_name: &str, display_name: &str) -> String {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Generated app IDs have no useful words to title-case; use a bounded mention label instead.
|
||||
if let Some(app_id) = plugin_name.strip_prefix("app-")
|
||||
&& app_id.len() == 32
|
||||
&& app_id
|
||||
.bytes()
|
||||
.all(|byte| matches!(byte, b'0'..=b'9' | b'a'..=b'f'))
|
||||
&& (1..=64).contains(&display_name.len())
|
||||
&& display_name
|
||||
.bytes()
|
||||
.all(crate::mention_codec::is_mention_name_char)
|
||||
&& !crate::mention_codec::is_common_env_var(display_name)
|
||||
{
|
||||
return display_name.to_owned();
|
||||
}
|
||||
|
||||
title_case_plugin_name(plugin_name)
|
||||
}
|
||||
|
||||
@@ -242,6 +257,34 @@ mod tests {
|
||||
plugin_mention_name("google_calendar", "Google Calendar"),
|
||||
"Google_Calendar"
|
||||
);
|
||||
assert_eq!(
|
||||
plugin_mention_name(
|
||||
"app-6a6b12e06c5c8191ac5d5252fa5f92c8",
|
||||
"app_6a6b12e06c5c8191ac5d5252fa5f92c8"
|
||||
),
|
||||
"app-6a6b12e06c5c8191ac5d5252fa5f92c8"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generated_app_mentions_use_bounded_display_names() {
|
||||
let plugin_name = "app-6a6b12e06c5c8191ac5d5252fa5f92c8";
|
||||
for display_name in ["Postman", "foo-bar_baz", &"a".repeat(64)] {
|
||||
assert_eq!(plugin_mention_name(plugin_name, display_name), display_name);
|
||||
}
|
||||
for display_name in [
|
||||
"",
|
||||
"Foo Bar",
|
||||
"Café",
|
||||
"PATH",
|
||||
"XDG_CONFIG_HOME",
|
||||
&"a".repeat(65),
|
||||
] {
|
||||
assert_eq!(
|
||||
plugin_mention_name(plugin_name, display_name),
|
||||
"App-6a6b12e06c5c8191ac5d5252fa5f92c8"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -251,5 +294,19 @@ mod tests {
|
||||
plugin_mention_name("browser-use", "Browser Use"),
|
||||
"Browser-Use"
|
||||
);
|
||||
for (plugin_name, expected) in [
|
||||
("1vault", "1vault"),
|
||||
("app-short", "App-Short"),
|
||||
(
|
||||
"app-6a6b12e06c5c8191ac5d5252fa5f92cg",
|
||||
"App-6a6b12e06c5c8191ac5d5252fa5f92cg",
|
||||
),
|
||||
(
|
||||
"app-6A6B12E06C5C8191AC5D5252FA5F92C8",
|
||||
"App-6A6B12E06C5C8191AC5D5252FA5F92C8",
|
||||
),
|
||||
] {
|
||||
assert_eq!(plugin_mention_name(plugin_name, "Vault"), expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
---
|
||||
source: tui/src/bottom_pane/chat_composer.rs
|
||||
expression: terminal.backend()
|
||||
---
|
||||
" "
|
||||
"› @Postman "
|
||||
" "
|
||||
" "
|
||||
" "
|
||||
" "
|
||||
" "
|
||||
" "
|
||||
" 100% context left "
|
||||
@@ -289,6 +289,7 @@ impl ChatWidget {
|
||||
collect_tool_mentions(reply_text.as_deref().unwrap_or(&text), &HashMap::new());
|
||||
let bound_names: HashSet<String> = mention_bindings
|
||||
.iter()
|
||||
.filter(|binding| binding.sigil == '$')
|
||||
.map(|binding| binding.mention.clone())
|
||||
.collect();
|
||||
let mut skill_names_lower: HashSet<String> = HashSet::new();
|
||||
|
||||
@@ -1011,6 +1011,68 @@ async fn submission_prefers_selected_duplicate_skill_path() {
|
||||
assert_eq!(selected_skill_paths, vec![user_skill_path.to_path_buf()]);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn plugin_mention_does_not_suppress_same_name_skill() {
|
||||
let (mut chat, _rx, mut op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.thread_id = Some(ThreadId::new());
|
||||
chat.set_feature_enabled(Feature::Plugins, /*enabled*/ true);
|
||||
chat.bottom_pane
|
||||
.set_plugin_mentions(Some(vec![PluginCapabilitySummary {
|
||||
config_name: "app-0123456789abcdef0123456789abcdef@test".to_string(),
|
||||
display_name: "foo".to_string(),
|
||||
plugin_namespace: None,
|
||||
description: None,
|
||||
has_skills: true,
|
||||
mcp_server_names: Vec::new(),
|
||||
app_connector_ids: Vec::new(),
|
||||
}]));
|
||||
let skill_path = test_path_buf("/tmp/foo/SKILL.md").abs();
|
||||
chat.set_skills(Some(vec![SkillMetadata {
|
||||
name: "foo".to_string(),
|
||||
description: "Foo skill".to_string(),
|
||||
short_description: None,
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
path: skill_path.clone(),
|
||||
scope: crate::test_support::skill_scope_user(),
|
||||
enabled: true,
|
||||
plugin_id: None,
|
||||
}]));
|
||||
|
||||
chat.submit_user_message(UserMessage {
|
||||
text: "@foo $foo".to_string(),
|
||||
local_images: Vec::new(),
|
||||
remote_image_urls: Vec::new(),
|
||||
text_elements: Vec::new(),
|
||||
mention_bindings: vec![MentionBinding {
|
||||
sigil: '@',
|
||||
mention: "foo".to_string(),
|
||||
path: "plugin://app-0123456789abcdef0123456789abcdef@test".to_string(),
|
||||
}],
|
||||
});
|
||||
|
||||
let Op::UserTurn { items, .. } = next_submit_op(&mut op_rx) else {
|
||||
panic!("expected Op::UserTurn");
|
||||
};
|
||||
assert_eq!(
|
||||
items,
|
||||
vec![
|
||||
UserInput::Text {
|
||||
text: "@foo $foo".to_string(),
|
||||
text_elements: Vec::new(),
|
||||
},
|
||||
UserInput::Skill {
|
||||
name: "foo".to_string(),
|
||||
path: skill_path.to_path_buf(),
|
||||
},
|
||||
UserInput::Mention {
|
||||
name: "foo".to_string(),
|
||||
path: "plugin://app-0123456789abcdef0123456789abcdef@test".to_string(),
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn blocked_image_restore_preserves_mention_bindings() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
|
||||
Reference in New Issue
Block a user