mirror of
https://github.com/openai/codex.git
synced 2026-05-15 16:53:05 +00:00
changes
This commit is contained in:
@@ -29,7 +29,15 @@ fn parse_dynamic_tool_sanitizes_input_schema() {
|
||||
input_schema: JsonSchema::object(
|
||||
BTreeMap::from([(
|
||||
"id".to_string(),
|
||||
JsonSchema::string(Some("Ticket identifier".to_string()),),
|
||||
JsonSchema {
|
||||
schema_type: Some(crate::JsonSchemaType::Single(
|
||||
crate::JsonSchemaPrimitiveType::Object,
|
||||
)),
|
||||
description: Some("Ticket identifier".to_string()),
|
||||
properties: Some(BTreeMap::new()),
|
||||
additional_properties: Some(true.into()),
|
||||
..Default::default()
|
||||
},
|
||||
)]),
|
||||
/*required*/ None,
|
||||
/*additional_properties*/ None
|
||||
|
||||
@@ -228,7 +228,10 @@ fn sanitize_json_schema(value: &mut JsonValue) {
|
||||
{
|
||||
schema_types.push(JsonSchemaPrimitiveType::Number);
|
||||
} else {
|
||||
schema_types.push(JsonSchemaPrimitiveType::String);
|
||||
// With no schema hints, fall back to an open object so unknown
|
||||
// tool argument shapes can still carry arbitrary named fields.
|
||||
schema_types.push(JsonSchemaPrimitiveType::Object);
|
||||
map.insert("additionalProperties".to_string(), JsonValue::Bool(true));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ fn parse_tool_input_schema_infers_object_shape_and_defaults_properties() {
|
||||
//
|
||||
// Expected normalization behavior:
|
||||
// - `properties` implies an object schema when `type` is omitted.
|
||||
// - The child property keeps its description and defaults to a string type.
|
||||
// - The child property keeps its description and defaults to an open object.
|
||||
let schema = parse_tool_input_schema(&serde_json::json!({
|
||||
"properties": {
|
||||
"query": {"description": "search query"}
|
||||
@@ -47,7 +47,13 @@ fn parse_tool_input_schema_infers_object_shape_and_defaults_properties() {
|
||||
JsonSchema::object(
|
||||
BTreeMap::from([(
|
||||
"query".to_string(),
|
||||
JsonSchema::string(Some("search query".to_string())),
|
||||
JsonSchema {
|
||||
schema_type: Some(JsonSchemaType::Single(JsonSchemaPrimitiveType::Object)),
|
||||
description: Some("search query".to_string()),
|
||||
properties: Some(BTreeMap::new()),
|
||||
additional_properties: Some(true.into()),
|
||||
..Default::default()
|
||||
},
|
||||
)]),
|
||||
/*required*/ None,
|
||||
/*additional_properties*/ None
|
||||
@@ -250,16 +256,73 @@ fn parse_tool_input_schema_infers_string_from_enum_const_and_format_keywords() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_tool_input_schema_defaults_empty_schema_to_string() {
|
||||
fn parse_tool_input_schema_defaults_empty_schema_to_open_object() {
|
||||
// Example schema shape:
|
||||
// {}
|
||||
//
|
||||
// Expected normalization behavior:
|
||||
// - With no structural hints at all, the normalizer falls back to a
|
||||
// permissive string schema.
|
||||
// permissive object schema.
|
||||
let schema = parse_tool_input_schema(&serde_json::json!({})).expect("parse schema");
|
||||
|
||||
assert_eq!(schema, JsonSchema::string(/*description*/ None));
|
||||
assert_eq!(
|
||||
schema,
|
||||
JsonSchema::object(BTreeMap::new(), /*required*/ None, Some(true.into()))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_tool_input_schema_defaults_nested_empty_schema_to_open_object() {
|
||||
// Example schema shape:
|
||||
// {
|
||||
// "type": "object",
|
||||
// "properties": {
|
||||
// "metadata": {
|
||||
// "properties": {
|
||||
// "extra": {}
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Expected normalization behavior:
|
||||
// - The sanitizer recurses through nested object properties.
|
||||
// - The innermost `extra` field has no hints, so it falls back to an open
|
||||
// object.
|
||||
let schema = parse_tool_input_schema(&serde_json::json!({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"metadata": {
|
||||
"properties": {
|
||||
"extra": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}))
|
||||
.expect("parse schema");
|
||||
|
||||
assert_eq!(
|
||||
schema,
|
||||
JsonSchema::object(
|
||||
BTreeMap::from([(
|
||||
"metadata".to_string(),
|
||||
JsonSchema::object(
|
||||
BTreeMap::from([(
|
||||
"extra".to_string(),
|
||||
JsonSchema::object(
|
||||
BTreeMap::new(),
|
||||
/*required*/ None,
|
||||
Some(true.into()),
|
||||
),
|
||||
)]),
|
||||
/*required*/ None,
|
||||
/*additional_properties*/ None,
|
||||
)
|
||||
)]),
|
||||
/*required*/ None,
|
||||
/*additional_properties*/ None,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user