mirror of
https://github.com/openai/codex.git
synced 2026-10-25 18:28:38 +00:00
## Why PR #13783 moved the `codex.rs` unit tests into `codex_tests.rs`. This applies the same extraction pattern across the rest of `codex-rs/core` so the production modules stay focused on runtime code instead of large inline test blocks. Keeping the tests in sibling files also makes follow-up edits easier to review because product changes no longer have to share a file with hundreds or thousands of lines of test scaffolding. ## What changed - replaced each inline `mod tests { ... }` in `codex-rs/core/src/**` with a path-based module declaration - moved each extracted unit test module into a sibling `*_tests.rs` file, using `mod_tests.rs` for `mod.rs` modules - preserved the existing `cfg(...)` guards and module-local structure so the refactor remains structural rather than behavioral ## Testing - `cargo test -p codex-core --lib` (`1653 passed; 0 failed; 5 ignored`) - `just fix -p codex-core` - `cargo fmt --check` - `cargo shear`
51 lines
1.6 KiB
Rust
51 lines
1.6 KiB
Rust
use super::*;
|
|
use crate::tools::context::ToolInvocation;
|
|
use async_trait::async_trait;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
struct TestHandler;
|
|
|
|
#[async_trait]
|
|
impl ToolHandler for TestHandler {
|
|
type Output = crate::tools::context::FunctionToolOutput;
|
|
|
|
fn kind(&self) -> ToolKind {
|
|
ToolKind::Function
|
|
}
|
|
|
|
async fn handle(&self, _invocation: ToolInvocation) -> Result<Self::Output, FunctionCallError> {
|
|
unreachable!("test handler should not be invoked")
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn handler_looks_up_namespaced_aliases_explicitly() {
|
|
let plain_handler = Arc::new(TestHandler) as Arc<dyn AnyToolHandler>;
|
|
let namespaced_handler = Arc::new(TestHandler) as Arc<dyn AnyToolHandler>;
|
|
let namespace = "mcp__codex_apps__gmail";
|
|
let tool_name = "gmail_get_recent_emails";
|
|
let namespaced_name = tool_handler_key(tool_name, Some(namespace));
|
|
let registry = ToolRegistry::new(HashMap::from([
|
|
(tool_name.to_string(), Arc::clone(&plain_handler)),
|
|
(namespaced_name, Arc::clone(&namespaced_handler)),
|
|
]));
|
|
|
|
let plain = registry.handler(tool_name, None);
|
|
let namespaced = registry.handler(tool_name, Some(namespace));
|
|
let missing_namespaced = registry.handler(tool_name, Some("mcp__codex_apps__calendar"));
|
|
|
|
assert_eq!(plain.is_some(), true);
|
|
assert_eq!(namespaced.is_some(), true);
|
|
assert_eq!(missing_namespaced.is_none(), true);
|
|
assert!(
|
|
plain
|
|
.as_ref()
|
|
.is_some_and(|handler| Arc::ptr_eq(handler, &plain_handler))
|
|
);
|
|
assert!(
|
|
namespaced
|
|
.as_ref()
|
|
.is_some_and(|handler| Arc::ptr_eq(handler, &namespaced_handler))
|
|
);
|
|
}
|