Files
codex/codex-rs/mcp-server/src/active_turn_registry_tests.rs
T
felixxia-oai 5548c95d66 Enable skills in the MCP server (#36339)
## What changed

- Install the skills extension for MCP Codex tool sessions so host skills are
  included in the developer instructions.
- Route extension warnings to the matching active MCP turn as `codex/event`
  notifications, preserving request and thread metadata and ordering warnings
  before the final tool response.
- Track reply turns independently and bound forwarded warning messages to 256
  UTF-8 bytes.

## Testing

- Add unit coverage for active-turn routing, request ID collisions, warning
  ordering, filtering, and truncation.
- Add an MCP integration test for host skill instructions and skills context
  budget warnings.

GitOrigin-RevId: 9e5c699665f6889bf1103e78c3d6ca53824a10a0
2026-07-31 14:40:40 +00:00

71 lines
2.4 KiB
Rust

use codex_protocol::ThreadId;
use pretty_assertions::assert_eq;
use rmcp::model::RequestId;
use super::ActiveTurnRegistry;
#[test]
fn colliding_request_id_strings_use_independent_turn_routes() {
let active_turns = ActiveTurnRegistry::default();
let thread_id = ThreadId::new();
let numeric_request_id = RequestId::Number(7);
let string_request_id = RequestId::String("7".into());
let numeric_turn_id = "numeric-turn".to_string();
let string_turn_id = "string-turn".to_string();
active_turns.register(
numeric_request_id.clone(),
thread_id,
numeric_turn_id.clone(),
);
active_turns.register(string_request_id.clone(), thread_id, string_turn_id.clone());
let mut routed_request_ids = Vec::new();
assert!(
active_turns.with_request_id(thread_id, &numeric_turn_id, |request_id| {
routed_request_ids.push(request_id.clone());
})
);
assert!(
active_turns.with_request_id(thread_id, &string_turn_id, |request_id| {
routed_request_ids.push(request_id.clone());
})
);
assert_eq!(
routed_request_ids,
vec![numeric_request_id.clone(), string_request_id.clone()]
);
active_turns.unregister(&numeric_request_id);
assert!(!active_turns.with_request_id(thread_id, &numeric_turn_id, |_| {}));
let mut remaining_request_id = None;
assert!(
active_turns.with_request_id(thread_id, &string_turn_id, |request_id| {
remaining_request_id = Some(request_id.clone());
})
);
assert_eq!(remaining_request_id, Some(string_request_id));
}
#[test]
fn reused_request_id_replaces_the_previous_turn_route() {
let active_turns = ActiveTurnRegistry::default();
let thread_id = ThreadId::new();
let request_id = RequestId::Number(7);
let first_turn_id = "first-turn".to_string();
let second_turn_id = "second-turn".to_string();
active_turns.register(request_id.clone(), thread_id, first_turn_id.clone());
active_turns.register(request_id.clone(), thread_id, second_turn_id.clone());
assert!(!active_turns.with_request_id(thread_id, &first_turn_id, |_| {}));
let mut routed_request_id = None;
assert!(
active_turns.with_request_id(thread_id, &second_turn_id, |request_id| {
routed_request_id = Some(request_id.clone());
})
);
assert_eq!(routed_request_id, Some(request_id));
}