mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
## Why Identical instructions and tool descriptions can appear in multiple model catalog records. Each decode or clone previously allocated its own copy of that text. ## What changed Use `CodexCachedStr` for catalog instructions, messages, and tool overrides. It stores short strings inline and interns longer strings so independent decodes and clones can share storage. Resolved incremental tool messages also reuse cached text from overrides and bundled defaults. JSON and generated TypeScript still represent these values as strings. ## Testing Add tests for shared storage across catalog fields, independent decodes, clones, and incremental tool defaults. Cover plain JSON string round trips and borrowed access to short inline UTF-8 strings. GitOrigin-RevId: 6f53b4e19f01f6ed52a8fd364279b924cf794be2
86 lines
2.8 KiB
Rust
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(Into::into),
|
|
parameters: schema.map(Into::into),
|
|
};
|
|
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,
|
|
);
|
|
}
|
|
}
|