Files
codex/codex-rs/tools/src/catalog_tool_message_tests.rs
T
rhan-oai e103bbc06f Apply model catalog overrides to history, notes, and context tools (#56313)
## What changed

- Read optional tool descriptions and parameter schemas for `history`, `notes`, `new_context`, and `get_context_remaining` from the acting model's catalog messages.
- Support catalog namespace descriptions for history and notes, preserving explicit empty and whitespace descriptions.
- Share catalog override handling across native tools and MCP resource helpers. Keep bundled schemas when overrides are invalid, preserve encrypted parameters, and leave tool identity and transport fields unchanged.

## Testing

Add coverage for sparse catalog serialization, schema fallback and encryption preservation, per-step tool definitions, and context tool updates when switching models. Extend outgoing-request tests to verify history and notes overrides while retaining history image attachments.

GitOrigin-RevId: 1adac8b5009f95c91adba491f20a4e2e2dc91475
2026-10-23 00:46:28 +00:00

86 lines
2.8 KiB
Rust

use super::*;
use crate::JsonSchema;
use pretty_assertions::assert_eq;
use serde_json::json;
#[test]
fn catalog_overrides_preserve_tool_fields_and_encryption_with_independent_fallbacks() {
let bundled = ResponsesApiTool {
name: "example".to_string(),
description: "Bundled guidance.".to_string(),
strict: true,
defer_loading: Some(true),
parameters: serde_json::from_value(json!({
"type": "object",
"properties": {
"text": {"type": "string", "encrypted": true},
"title": {"type": "string", "encrypted": true},
"path": {"type": "string"}
}
}))
.unwrap(),
output_schema: Some(json!({"type": "string"}).into()),
};
assert_eq!(
with_catalog_tool_message(bundled.clone(), /*messages*/ None),
bundled,
);
let mut catalog = json!({
"type": "object",
"properties": {
"text": {"type": "string", "description": "Catalog guidance.", "encrypted": false},
"title": {"type": "string"},
"path": {"type": "string"}
}
});
let parameters = catalog.to_string();
catalog["properties"]["text"]["encrypted"] = json!(true);
catalog["properties"]["title"]["encrypted"] = json!(true);
let expected_parameters: JsonSchema = serde_json::from_value(catalog).unwrap();
for (description, schema, expected_schema) in [
(None, None, None),
(Some(""), None, None),
(None, Some(parameters.as_str()), Some(&expected_parameters)),
(
Some(" Catalog {{literal}} guidance.\n"),
Some(parameters.as_str()),
Some(&expected_parameters),
),
(Some("Catalog guidance."), Some("invalid JSON"), None),
(None, Some(r#"{"type":"string"}"#), None),
(
None,
Some(r#"{"type":"object","properties":{"text":{"type":"unsupported"}}}"#),
None,
),
(
Some(""),
Some(r#"{"type":"object","properties":{"title":{"type":"string"}}}"#),
None,
),
(
Some("Catalog guidance."),
Some(r#"{"type":"object","properties":{"text":{"type":"string"}}}"#),
None,
),
] {
let messages = ToolMessage {
description: description.map(str::to_owned),
parameters: schema.map(str::to_owned),
};
let mut expected = bundled.clone();
if let Some(description) = description {
expected.description = description.to_owned();
}
if let Some(parameters) = expected_schema {
expected.parameters = parameters.clone();
}
assert_eq!(
with_catalog_tool_message(bundled.clone(), Some(&messages)),
expected,
);
}
}