Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | """Cross-entry-point checks for composed JSON Schema conversion.""" |
| 2 | |
| 3 | import pytest |
| 4 | from pydantic import TypeAdapter, ValidationError |
| 5 | |
| 6 | from composio.utils.shared import pydantic_model_from_param_schema |
| 7 | from tests.fixtures.json_schema_conversion_corpus import find_case |
| 8 | |
| 9 | COMPOSITION_CASE_IDS = ( |
| 10 | "composition-fixed-tuple-items", |
| 11 | "composition-open-tuple-items", |
| 12 | "composition-false-tuple-position", |
| 13 | "composition-allof-object-intersection", |
| 14 | "composition-scalar-allof", |
| 15 | "composition-oneof-exclusive-match", |
| 16 | ) |
| 17 | |
| 18 | |
| 19 | @pytest.mark.parametrize("case_id", COMPOSITION_CASE_IDS) |
| 20 | def test_legacy_model_entry_point_matches_shared_composition_corpus( |
| 21 | case_id: str, |
| 22 | ) -> None: |
| 23 | case = find_case(case_id) |
| 24 | model = pydantic_model_from_param_schema( |
| 25 | {**case.schema_, "title": f"Composition_{case_id}"} |
| 26 | ) |
| 27 | |
| 28 | for instance in case.instances: |
| 29 | if instance.accepted_for("python"): |
| 30 | model.model_validate(instance.input) |
| 31 | else: |
| 32 | with pytest.raises(ValidationError): |
| 33 | model.model_validate(instance.input) |
| 34 | |
| 35 | |
| 36 | def test_standalone_draft7_tuple_preserves_positional_validation() -> None: |
| 37 | adapter = TypeAdapter( |
| 38 | pydantic_model_from_param_schema( |
| 39 | { |
| 40 | "title": "StandaloneTuple", |
| 41 | "type": "array", |
| 42 | "items": [{"type": "string"}, {"type": "integer"}], |
| 43 | "additionalItems": False, |
| 44 | } |
| 45 | ) |
| 46 | ) |
| 47 | |
| 48 | assert adapter.validate_python([]) == [] |
| 49 | assert adapter.validate_python(["ready"]) == ["ready"] |
| 50 | assert adapter.validate_python(["ready", 2]) == ["ready", 2] |
| 51 | for value in ([2, "ready"], ["ready", 2, True]): |
| 52 | with pytest.raises(ValidationError): |
| 53 | adapter.validate_python(value) |