mirror of
https://github.com/openai/codex.git
synced 2026-11-24 23:20:47 +00:00
## Why MCP tools can return structured data alongside a JSON text fallback for clients that need it. Printing the whole result in Code Mode can show the same data twice. ## What changed Enable `features.code_mode_mcp_result_dedup` to let `text()` omit `content` when it prints an original, successful MCP result whose only content block is a plain text fallback that parses to the same JSON as `structuredContent`. The JavaScript result retains both fields. Carry the result format through gRPC so the host can distinguish MCP results from ordinary JSON. The feature is off by default. ## Testing Add coverage for both feature flag settings, for printing original MCP results and copies through gRPC, and for comparing equivalent JSON. GitOrigin-RevId: a8b0b42f5375d9744c235a0e663090dd5982e37e
48 lines
1.5 KiB
Rust
48 lines
1.5 KiB
Rust
use codex_code_mode_protocol::CodeModeToolResult;
|
|
use codex_code_mode_protocol::grpc;
|
|
use pretty_assertions::assert_eq;
|
|
use prost::Message;
|
|
|
|
use super::request;
|
|
use super::request_with_maximum;
|
|
|
|
#[test]
|
|
fn completion_size_includes_the_protobuf_envelope() {
|
|
let output = serde_json::Value::String("a".repeat(100));
|
|
let raw_json_bytes = serde_json::to_vec(&output).expect("valid JSON").len();
|
|
let completion = request_with_maximum(
|
|
"session",
|
|
"invocation",
|
|
Ok(CodeModeToolResult::from(output)),
|
|
raw_json_bytes,
|
|
);
|
|
|
|
assert!(matches!(
|
|
completion.outcome,
|
|
Some(grpc::complete_tool_call_request::Outcome::Failed(grpc::ToolCallFailed {
|
|
message,
|
|
})) if message.contains("encoded bytes exceeds the gRPC message limit")
|
|
));
|
|
}
|
|
|
|
#[test]
|
|
fn delegate_errors_larger_than_64_kib_are_preserved() {
|
|
let error = "🦀".repeat(64 * 1024);
|
|
let completion = request("session", "invocation", Err(error.clone()));
|
|
let Some(grpc::complete_tool_call_request::Outcome::Failed(failure)) = completion.outcome
|
|
else {
|
|
panic!("expected a failed tool completion");
|
|
};
|
|
|
|
assert_eq!(failure.message, error);
|
|
}
|
|
|
|
#[test]
|
|
fn completion_at_exact_message_limit_is_accepted() {
|
|
let value = CodeModeToolResult::McpCallToolResult(serde_json::json!({ "content": [] }));
|
|
let expected = request("session", "invocation", Ok(value.clone()));
|
|
let actual = request_with_maximum("session", "invocation", Ok(value), expected.encoded_len());
|
|
|
|
assert_eq!(actual, expected);
|
|
}
|