mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
258 lines
7.1 KiB
Rust
258 lines
7.1 KiB
Rust
use std::collections::HashSet;
|
|
|
|
use codex_protocol::user_input::UserInput;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
use super::ExplicitPluginMention;
|
|
use super::collect_explicit_app_ids;
|
|
use super::collect_explicit_plugin_mentions;
|
|
use crate::plugins::PluginCapabilitySummary;
|
|
|
|
fn text_input(text: &str) -> UserInput {
|
|
UserInput::Text {
|
|
text: text.to_string(),
|
|
text_elements: Vec::new(),
|
|
}
|
|
}
|
|
|
|
fn plugin(config_name: &str, display_name: &str) -> PluginCapabilitySummary {
|
|
PluginCapabilitySummary {
|
|
config_name: config_name.to_string(),
|
|
display_name: display_name.to_string(),
|
|
description: None,
|
|
has_skills: true,
|
|
mcp_server_names: Vec::new(),
|
|
app_connector_ids: Vec::new(),
|
|
}
|
|
}
|
|
|
|
fn explicit_plugin_mention(
|
|
plugin: PluginCapabilitySummary,
|
|
has_computer_use_native_fallback: bool,
|
|
) -> ExplicitPluginMention {
|
|
ExplicitPluginMention {
|
|
plugin,
|
|
has_computer_use_native_fallback,
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn collect_explicit_app_ids_from_linked_text_mentions() {
|
|
let input = vec")];
|
|
|
|
let app_ids = collect_explicit_app_ids(&input);
|
|
|
|
assert_eq!(app_ids, HashSet::from(["calendar".to_string()]));
|
|
}
|
|
|
|
#[test]
|
|
fn collect_explicit_app_ids_dedupes_structured_and_linked_mentions() {
|
|
let input = vec"),
|
|
UserInput::Mention {
|
|
name: "calendar".to_string(),
|
|
path: "app://calendar".to_string(),
|
|
computer_use_native_app_bundle_id: None,
|
|
},
|
|
];
|
|
|
|
let app_ids = collect_explicit_app_ids(&input);
|
|
|
|
assert_eq!(app_ids, HashSet::from(["calendar".to_string()]));
|
|
}
|
|
|
|
#[test]
|
|
fn collect_explicit_app_ids_ignores_non_app_paths() {
|
|
let input = vec and [$skill](skill://team/skill) and [$file](/tmp/file.txt)",
|
|
),
|
|
UserInput::Mention {
|
|
name: "docs".to_string(),
|
|
path: "mcp://docs".to_string(),
|
|
computer_use_native_app_bundle_id: None,
|
|
},
|
|
UserInput::Mention {
|
|
name: "skill".to_string(),
|
|
path: "skill://team/skill".to_string(),
|
|
computer_use_native_app_bundle_id: None,
|
|
},
|
|
UserInput::Mention {
|
|
name: "file".to_string(),
|
|
path: "/tmp/file.txt".to_string(),
|
|
computer_use_native_app_bundle_id: None,
|
|
},
|
|
];
|
|
|
|
let app_ids = collect_explicit_app_ids(&input);
|
|
|
|
assert_eq!(app_ids, HashSet::<String>::new());
|
|
}
|
|
|
|
#[test]
|
|
fn collect_explicit_plugin_mentions_from_structured_paths() {
|
|
let plugins = vec![
|
|
plugin("sample@test", "sample"),
|
|
plugin("other@test", "other"),
|
|
];
|
|
|
|
let mentioned = collect_explicit_plugin_mentions(
|
|
&[UserInput::Mention {
|
|
name: "sample".to_string(),
|
|
path: "plugin://sample@test".to_string(),
|
|
computer_use_native_app_bundle_id: None,
|
|
}],
|
|
&plugins,
|
|
);
|
|
|
|
assert_eq!(
|
|
mentioned,
|
|
vec![explicit_plugin_mention(
|
|
plugin("sample@test", "sample"),
|
|
/*has_computer_use_native_fallback*/ false,
|
|
)]
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn collect_explicit_plugin_mentions_from_linked_text_mentions() {
|
|
let plugins = vec![
|
|
plugin("sample@test", "sample"),
|
|
plugin("other@test", "other"),
|
|
];
|
|
|
|
let mentioned = collect_explicit_plugin_mentions(
|
|
&[text_input("use [@sample](plugin://sample@test)")],
|
|
&plugins,
|
|
);
|
|
|
|
assert_eq!(
|
|
mentioned,
|
|
vec![explicit_plugin_mention(
|
|
plugin("sample@test", "sample"),
|
|
/*has_computer_use_native_fallback*/ false,
|
|
)]
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn collect_explicit_plugin_mentions_dedupes_structured_and_linked_mentions() {
|
|
let plugins = vec![
|
|
plugin("sample@test", "sample"),
|
|
plugin("other@test", "other"),
|
|
];
|
|
|
|
let mentioned = collect_explicit_plugin_mentions(
|
|
&[
|
|
text_input("use [@sample](plugin://sample@test)"),
|
|
UserInput::Mention {
|
|
name: "sample".to_string(),
|
|
path: "plugin://sample@test".to_string(),
|
|
computer_use_native_app_bundle_id: None,
|
|
},
|
|
],
|
|
&plugins,
|
|
);
|
|
|
|
assert_eq!(
|
|
mentioned,
|
|
vec![explicit_plugin_mention(
|
|
plugin("sample@test", "sample"),
|
|
/*has_computer_use_native_fallback*/ false,
|
|
)]
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn collect_explicit_plugin_mentions_ignores_non_plugin_paths() {
|
|
let plugins = vec![plugin("sample@test", "sample")];
|
|
|
|
let mentioned = collect_explicit_plugin_mentions(
|
|
&[text_input(
|
|
"use [$app](app://calendar) and [$skill](skill://team/skill) and [$file](/tmp/file.txt)",
|
|
)],
|
|
&plugins,
|
|
);
|
|
|
|
assert_eq!(mentioned, Vec::<ExplicitPluginMention>::new());
|
|
}
|
|
|
|
#[test]
|
|
fn collect_explicit_plugin_mentions_ignores_dollar_linked_plugin_mentions() {
|
|
let plugins = vec![plugin("sample@test", "sample")];
|
|
|
|
let mentioned = collect_explicit_plugin_mentions(
|
|
&[text_input("use [$sample](plugin://sample@test)")],
|
|
&plugins,
|
|
);
|
|
|
|
assert_eq!(mentioned, Vec::<ExplicitPluginMention>::new());
|
|
}
|
|
|
|
#[test]
|
|
fn collect_explicit_plugin_mentions_marks_structured_native_fallbacks() {
|
|
let zoom = plugin("zoom@test", "Zoom");
|
|
let mentioned = collect_explicit_plugin_mentions(
|
|
&[UserInput::Mention {
|
|
name: "Zoom".to_string(),
|
|
path: "plugin://zoom@test".to_string(),
|
|
computer_use_native_app_bundle_id: Some("us.zoom.xos".to_string()),
|
|
}],
|
|
std::slice::from_ref(&zoom),
|
|
);
|
|
|
|
assert_eq!(
|
|
mentioned,
|
|
vec![explicit_plugin_mention(
|
|
zoom, /*has_computer_use_native_fallback*/ true
|
|
)]
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn collect_explicit_plugin_mentions_preserves_computer_use_context_for_native_fallbacks() {
|
|
let zoom = plugin("zoom@test", "Zoom");
|
|
let computer_use = plugin("computer-use@openai-bundled", "Computer Use");
|
|
|
|
let mentioned = collect_explicit_plugin_mentions(
|
|
&[UserInput::Mention {
|
|
name: "Zoom".to_string(),
|
|
path: "plugin://zoom@test".to_string(),
|
|
computer_use_native_app_bundle_id: Some("us.zoom.xos".to_string()),
|
|
}],
|
|
&[zoom.clone(), computer_use.clone()],
|
|
);
|
|
|
|
assert_eq!(
|
|
mentioned,
|
|
vec![
|
|
explicit_plugin_mention(zoom, /*has_computer_use_native_fallback*/ true),
|
|
explicit_plugin_mention(
|
|
computer_use,
|
|
/*has_computer_use_native_fallback*/ false
|
|
),
|
|
]
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn collect_explicit_plugin_mentions_ignores_empty_native_fallback_markers() {
|
|
let zoom = plugin("zoom@test", "Zoom");
|
|
|
|
let mentioned = collect_explicit_plugin_mentions(
|
|
&[UserInput::Mention {
|
|
name: "Zoom".to_string(),
|
|
path: "plugin://zoom@test".to_string(),
|
|
computer_use_native_app_bundle_id: Some(" ".to_string()),
|
|
}],
|
|
std::slice::from_ref(&zoom),
|
|
);
|
|
|
|
assert_eq!(
|
|
mentioned,
|
|
vec![explicit_plugin_mention(
|
|
zoom, /*has_computer_use_native_fallback*/ false
|
|
)]
|
|
);
|
|
}
|