mirror of
https://github.com/openai/codex.git
synced 2026-04-26 15:45:02 +00:00
Add ALL_TOOLS export to code mode (#14294)
So code mode can search for tools.
This commit is contained in:
committed by
Michael Bolin
parent
7b2cee53db
commit
65b325159d
@@ -495,38 +495,74 @@ contentLength=0"
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn code_mode_can_access_namespaced_mcp_tool_from_flat_tools_namespace() -> Result<()> {
|
||||
async fn code_mode_exports_all_tools_metadata_for_builtin_tools() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let server = responses::start_mock_server().await;
|
||||
let code = r#"
|
||||
import { tools } from "tools.js";
|
||||
import { ALL_TOOLS } from "tools.js";
|
||||
|
||||
const { structuredContent, isError } = await tools["mcp__rmcp__echo"]({
|
||||
message: "ping",
|
||||
});
|
||||
add_content(
|
||||
`echo=${structuredContent?.echo ?? "missing"}\n` +
|
||||
`env=${structuredContent?.env ?? "missing"}\n` +
|
||||
`isError=${String(isError)}`
|
||||
);
|
||||
const tool = ALL_TOOLS.find(({ module, name }) => module === "tools.js" && name === "view_image");
|
||||
add_content(JSON.stringify(tool));
|
||||
"#;
|
||||
|
||||
let (_test, second_mock) =
|
||||
run_code_mode_turn_with_rmcp(&server, "use exec to run the rmcp echo tool", code).await?;
|
||||
run_code_mode_turn(&server, "use exec to inspect ALL_TOOLS", code, false).await?;
|
||||
|
||||
let req = second_mock.single_request();
|
||||
let (output, success) = custom_tool_output_body_and_success(&req, "call-1");
|
||||
assert_ne!(
|
||||
success,
|
||||
Some(false),
|
||||
"exec rmcp echo call failed unexpectedly: {output}"
|
||||
"exec ALL_TOOLS lookup failed unexpectedly: {output}"
|
||||
);
|
||||
|
||||
let parsed: Value = serde_json::from_str(&output)?;
|
||||
assert_eq!(
|
||||
output,
|
||||
"echo=ECHOING: ping
|
||||
env=propagated-env
|
||||
isError=false"
|
||||
parsed,
|
||||
serde_json::json!({
|
||||
"module": "tools.js",
|
||||
"name": "view_image",
|
||||
"description": "View a local image from the filesystem (only use if given a full filepath by the user, and the image isn't already attached to the thread context within <image ...> tags).\n\nCode mode declaration:\n```ts\nimport { view_image } from \"tools.js\";\ndeclare function view_image(args: {\n path: string;\n}): Promise<unknown>;\n```",
|
||||
})
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn code_mode_exports_all_tools_metadata_for_namespaced_mcp_tools() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let server = responses::start_mock_server().await;
|
||||
let code = r#"
|
||||
import { ALL_TOOLS } from "tools.js";
|
||||
|
||||
const tool = ALL_TOOLS.find(
|
||||
({ module, name }) => module === "tools/mcp/rmcp.js" && name === "echo"
|
||||
);
|
||||
add_content(JSON.stringify(tool));
|
||||
"#;
|
||||
|
||||
let (_test, second_mock) =
|
||||
run_code_mode_turn_with_rmcp(&server, "use exec to inspect ALL_TOOLS", code).await?;
|
||||
|
||||
let req = second_mock.single_request();
|
||||
let (output, success) = custom_tool_output_body_and_success(&req, "call-1");
|
||||
assert_ne!(
|
||||
success,
|
||||
Some(false),
|
||||
"exec ALL_TOOLS MCP lookup failed unexpectedly: {output}"
|
||||
);
|
||||
|
||||
let parsed: Value = serde_json::from_str(&output)?;
|
||||
assert_eq!(
|
||||
parsed,
|
||||
serde_json::json!({
|
||||
"module": "tools/mcp/rmcp.js",
|
||||
"name": "echo",
|
||||
"description": "Echo back the provided message and include environment data.\n\nCode mode declaration:\n```ts\nimport { echo } from \"tools/mcp/rmcp.js\";\ndeclare function echo(args: {\n env_var?: string;\n message: string;\n}): Promise<{\n _meta?: unknown;\n content: Array<unknown>;\n isError?: boolean;\n structuredContent?: unknown;\n}>;\n```",
|
||||
})
|
||||
);
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user