Files
ai-agent-book/chapter9/self-evolving-tools/test_normalize_schema_bare_object.py
liqiang b119135836
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
2026-08-20 13:12:50 +00:00

59 lines
1.6 KiB
Python

"""normalize_schema must keep bare {"type":"object"} as an empty-object schema while preserving extra metadata."""
from tool_manager import normalize_schema
def test_bare_object_type_stays_empty_properties():
assert normalize_schema({"type": "object"}) == {
"type": "object",
"properties": {},
}
def test_object_with_required_keeps_required_not_as_property():
assert normalize_schema({"type": "object", "required": []}) == {
"type": "object",
"properties": {},
"required": [],
}
def test_object_with_properties_unchanged():
schema = {
"type": "object",
"properties": {"x": {"type": "string"}},
"required": ["x"],
}
assert normalize_schema(schema) == schema
def test_properties_only_still_gets_object_type():
assert normalize_schema({"properties": {"y": {"type": "number"}}}) == {
"type": "object",
"properties": {"y": {"type": "number"}},
}
def test_plain_property_map_still_wrapped():
assert normalize_schema({"z": {"type": "boolean"}}) == {
"type": "object",
"properties": {"z": {"type": "boolean"}},
}
def test_object_retains_extra_metadata():
schema = {
"type": "object",
"description": "Tool parameters",
"additionalProperties": False,
"$defs": {"Item": {"type": "string"}},
}
expected = {
"type": "object",
"properties": {},
"description": "Tool parameters",
"additionalProperties": False,
"$defs": {"Item": {"type": "string"}},
}
assert normalize_schema(schema) == expected