10
"""
11
12
import inspect
13
-import typing as t
13
from unittest.mock import MagicMock, Mock
14
15
import pytest
193
result = provider.wrap_tool(tool, create_mock_execute_tool())
194
parameter = inspect.signature(result).parameters["payload"]
195
197
- assert parameter.annotation == t.Dict[str, t.Any] # noqa: UP006
198
- assert result.__annotations__["payload"] == t.Dict[str, t.Any] # noqa: UP006
196
+ # Plain `dict`: AFC calls `isinstance` with each value's annotation, and
197
+ # `Dict[str, Any]` makes that raise for every nested value.
198
+ assert parameter.annotation is dict
199
+ assert result.__annotations__["payload"] is dict
200
201
def test_callable_has_annotations(self):
202
from composio_gemini import GeminiProvider
586
function_map[func.__name__] = func
587
assert "GITHUB_STAR_REPO" in function_map
588
589
+ @pytest.mark.parametrize(
590
+ ("properties", "required", "arguments"),
591
+ [
592
+ (
593
+ {"query": {"type": "string"}, "max_results": {"type": "integer"}},
594
+ ["query"],
595
+ {"query": "is:unread"},
596
+ ),
597
+ (
598
+ {"order": {"type": "string", "enum": ["asc", "desc"]}},
599
+ ["order"],
600
+ {"order": "asc"},
601
+ ),
602
+ (
603
+ {"slug": {"type": "string", "pattern": "^[a-z_]+$"}},
604
+ ["slug"],
605
+ {"slug": "a_b"},
606
+ ),
607
+ ({"n": {"type": "integer", "minimum": 1}}, ["n"], {"n": 3}),
608
+ (
609
+ {"v": {"anyOf": [{"type": "integer"}, {"type": "string"}]}},
610
+ ["v"],
611
+ {"v": "x"},
612
+ ),
613
+ ({"meta": {"type": "object"}}, ["meta"], {"meta": {"x": {"y": 1}}}),
614
+ ({"c": {"const": "fixed"}}, ["c"], {"c": "fixed"}),
615
+ (
616
+ {
617
+ "body": {
618
+ "type": "object",
619
+ "properties": {
620
+ "a": {"type": "string"},
621
+ "b": {"type": "integer"},
622
+ },
623
+ "required": ["a"],
624
+ }
625
+ },
626
+ ["body"],
627
+ {"body": {"a": "x"}},
628
+ ),
629
+ (
630
+ {
631
+ "items": {
632
+ "type": "array",
633
+ "items": {
634
+ "type": "object",
635
+ "properties": {
636
+ "k": {"type": "string"},
637
+ "v": {"type": "string"},
638
+ },
639
+ "required": ["k"],
640
+ },
641
+ }
642
+ },
643
+ ["items"],
644
+ {"items": [{"k": "a"}, {"k": "b", "v": "c"}]},
645
+ ),
646
+ ],
647
+ ids=[
648
+ "omitted-optional",
649
+ "enum",
650
+ "pattern",
651
+ "minimum",
652
+ "any-of",
653
+ "free-form-object",
654
+ "const",
655
+ "nested-omitted-optional",
656
+ "array-of-objects",
657
+ ],
658
+ )
659
+ def test_afc_executes_arguments_as_returned(self, properties, required, arguments):
660
+ """AFC converts each argument with its annotation before calling the tool."""
661
+ from composio_gemini import GeminiProvider
662
+ from google import genai
663
+ from google.genai import _extra_utils
664
+
665
+ provider = GeminiProvider()
666
+ tool = create_mock_tool(
667
+ "AFC_TOOL",
668
+ "test",
669
+ input_parameters={
670
+ "type": "object",
671
+ "properties": properties,
672
+ "required": required,
673
+ },
674
+ )
675
+ execute_tool = create_mock_execute_tool()
676
+ func = provider.wrap_tool(tool, execute_tool)
677
+
678
+ client = genai.Client(api_key="test")
679
+ genai_types.FunctionDeclaration.from_callable(
680
+ client=client._api_client, callable=func
681
+ )
682
+ _extra_utils.invoke_function_from_dict_args(arguments, func)
683
+
684
+ execute_tool.assert_called_once_with("AFC_TOOL", arguments)
685
+
686
+ def test_afc_still_validates_the_source_schema(self):
687
+ from composio_gemini import GeminiProvider
688
+ from google.genai import _extra_utils, errors
689
+
690
+ provider = GeminiProvider()
691
+ tool = create_mock_tool(
692
+ "AFC_TOOL",
693
+ "test",
694
+ input_parameters={
695
+ "type": "object",
696
+ "properties": {"slug": {"type": "string", "pattern": "^[a-z_]+$"}},
697
+ "required": ["slug"],
698
+ },
699
+ )
700
+ execute_tool = create_mock_execute_tool()
701
+ func = provider.wrap_tool(tool, execute_tool)
702
+
703
+ with pytest.raises(errors.FunctionInvocationError):
704
+ _extra_utils.invoke_function_from_dict_args({"slug": "Not Valid"}, func)
705
+ execute_tool.assert_not_called()
706
+
707
def test_callables_in_generate_content_config(self):
708
"""Wrapped callables can be passed to GenerateContentConfig without error."""
709
from composio_gemini import GeminiProvider