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 | """ |
| 2 | Live test for the ``proxy_execute`` session option. |
| 3 | |
| 4 | Unit tests mock the transport, so they cannot tell whether the API accepts |
| 5 | the ``proxy_execute`` block, stores it, or lists the ``COMPOSIO_PROXY_EXECUTE`` |
| 6 | meta tool. This test sends the real requests. |
| 7 | """ |
| 8 | |
| 9 | import time |
| 10 | |
| 11 | import pytest |
| 12 | |
| 13 | META_TOOL = "COMPOSIO_PROXY_EXECUTE" |
| 14 | |
| 15 | |
| 16 | def _enable_of(config): |
| 17 | block = getattr(config, "proxy_execute", None) |
| 18 | return None if block is None else block.enable |
| 19 | |
| 20 | |
| 21 | def _lists_meta_tool(session) -> bool: |
| 22 | return META_TOOL in {tool["function"]["name"] for tool in session.tools()} |
| 23 | |
| 24 | |
| 25 | @pytest.mark.integration |
| 26 | def test_proxy_execute_option_round_trip(composio_client): |
| 27 | user_id = f"pytest-session-proxy-execute-{int(time.time())}" |
| 28 | sessions = [] |
| 29 | try: |
| 30 | on = composio_client.sessions.create( |
| 31 | user_id=user_id, toolkits=["github"], proxy_execute=True |
| 32 | ) |
| 33 | sessions.append(on) |
| 34 | assert _enable_of(on.config) is True |
| 35 | assert _lists_meta_tool(on) |
| 36 | |
| 37 | assert _enable_of(on.update(proxy_execute=False)) is False |
| 38 | assert not _lists_meta_tool(on) |
| 39 | |
| 40 | assert _enable_of(on.update(proxy_execute={"enable": True})) is True |
| 41 | assert _enable_of(on.update(proxy_execute=None)) is None |
| 42 | reread = composio_client.sessions.use(session_id=on.session_id) |
| 43 | assert _enable_of(reread.config) is None |
| 44 | |
| 45 | off = composio_client.sessions.create(user_id=user_id, toolkits=["github"]) |
| 46 | sessions.append(off) |
| 47 | assert _enable_of(off.config) is None |
| 48 | assert not _lists_meta_tool(off) |
| 49 | finally: |
| 50 | for session in sessions: |
| 51 | composio_client.sessions.delete(session.session_id) |
| 52 | |
| 53 | |
| 54 | @pytest.mark.integration |
| 55 | def test_proxy_execute_false_conflicts_with_sandbox_helper(composio_client): |
| 56 | user_id = f"pytest-session-proxy-execute-conflict-{int(time.time())}" |
| 57 | with pytest.raises(Exception): # noqa: B017 - the API returns a 400 |
| 58 | session = composio_client.sessions.create( |
| 59 | user_id=user_id, |
| 60 | toolkits=["github"], |
| 61 | proxy_execute=False, |
| 62 | sandbox={"enable_proxy_execution": True}, |
| 63 | ) |
| 64 | composio_client.sessions.delete(session.session_id) |