Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
test(connected-accounts): cover REVOKED rollout and forward-compat
jkomynoa7c2d16bf307
diff --git a/python/tests/test_connected_accounts.py b/python/tests/test_connected_accounts.pyindex 9a9e9ff98..4092ad7fa 100644--- a/python/tests/test_connected_accounts.py+++ b/python/tests/test_connected_accounts.py@@ -175,6 +175,69 @@ class TestConnectionRequest:assert "Timeout while waiting for connection conn-timeout" in str(excinfo.value)+ @pytest.mark.parametrize("terminal_status", ["FAILED", "EXPIRED", "REVOKED"])+ def test_wait_for_connection_fails_fast_on_terminal_status(+ self, monkeypatch, terminal_status+ ):+ # Mirrors the TS contract (`ConnectionRequest.ts` `terminalErrorStates`):+ # FAILED / EXPIRED / REVOKED are credentials-gone states and should+ # raise immediately rather than poll until timeout.+ mock_client = Mock()+ terminal = Mock()+ terminal.status = terminal_status+ mock_client.connected_accounts.retrieve.return_value = terminal++ req = ConnectionRequest(+ id="conn-terminal",+ status="PENDING",+ redirect_url=None,+ client=mock_client,+ )++ monkeypatch.setattr(time, "sleep", lambda *_args, **_kwargs: None)++ with pytest.raises(exceptions.SDKError) as excinfo:+ req.wait_for_connection(timeout=10.0)++ assert "conn-terminal" in str(excinfo.value)+ assert terminal_status in str(excinfo.value)+ # One retrieve call only — no polling once we hit a terminal state.+ assert mock_client.connected_accounts.retrieve.call_count == 1++ def test_wait_for_connection_does_not_treat_inactive_as_terminal(self, monkeypatch):+ # INACTIVE means "user disabled, can be reactivated" — a connection can+ # briefly transit through it before settling on ACTIVE. Failing fast+ # there would regress callers that previously recovered.+ mock_client = Mock()+ inactive = Mock()+ inactive.status = "INACTIVE"+ active = Mock()+ active.status = "ACTIVE"+ mock_client.connected_accounts.retrieve.side_effect = [inactive, active]++ req = ConnectionRequest(+ id="conn-inactive-recover",+ status="PENDING",+ redirect_url=None,+ client=mock_client,+ )++ current_time = {"value": 0.0}++ def fake_time():+ value = current_time["value"]+ current_time["value"] += 0.1+ return value++ monkeypatch.setattr(time, "time", fake_time)+ monkeypatch.setattr(time, "sleep", lambda *_args, **_kwargs: None)++ result = req.wait_for_connection(timeout=1.0)++ assert result is active+ assert req.status == "ACTIVE"+ assert mock_client.connected_accounts.retrieve.call_count == 2+def test_from_id_uses_client_retrieve(self):mock_client = Mock()retrieved = Mock()diff --git a/ts/packages/cli/test/src/commands/connected-accounts/connected-accounts.list.cmd.test.ts b/ts/packages/cli/test/src/commands/connected-accounts/connected-accounts.list.cmd.test.tsindex b4d097bdb..d69e5e063 100644--- a/ts/packages/cli/test/src/commands/connected-accounts/connected-accounts.list.cmd.test.ts+++ b/ts/packages/cli/test/src/commands/connected-accounts/connected-accounts.list.cmd.test.ts@@ -231,4 +231,40 @@ describe('CLI: composio dev connected-accounts list', () => {);});++ // Forward-compat: simulate the server returning a status the CLI does not+ // know about (e.g. a freshly-added Apollo enum value). The decode now uses+ // `catchTag('ParseError')` to warn and degrade rather than crashing the+ // entire command — even users filtering on `--status ACTIVE` would+ // otherwise be blocked.+ const unknownStatusAccounts = [+ {+ ...testConnectedAccounts[0],+ id: 'con_future_status',+ // Cast to bypass the closed `ConnectedAccountItem['status']` literal —+ // the whole point of this test is what happens when the server hands+ // us a value the schema rejects.+ status: 'FUTURE_NOT_YET_KNOWN' as ConnectedAccountItem['status'],+ },+ ];++ layer(+ TestLive({+ baseConfigProvider: testDevConfigProvider,+ connectedAccountsData: { items: unknownStatusAccounts },+ })+ )('[Given] server returns unknown status [Then] warns and degrades instead of crashing', it => {+ it.scoped('does not crash on unknown status', () =>+ Effect.gen(function* () {+ const userContext = yield* ComposioUserContext;+ yield* userContext.login('test_api_key', 'org_test');+ yield* cli(['dev', 'connected-accounts', 'list']);+ const lines = yield* MockConsole.getLines({ stripAnsi: true });+ const output = lines.join('\n');++ expect(output).toContain('composio upgrade');+ expect(output).toContain('con_future_status');+ })+ );+ });});diff --git a/ts/packages/core/test/connectedAccounts/connectedAccountAuthStates.test.ts b/ts/packages/core/test/connectedAccounts/connectedAccountAuthStates.test.tsnew file mode 100644index 000000000..2ae7575cd--- /dev/null+++ b/ts/packages/core/test/connectedAccounts/connectedAccountAuthStates.test.ts@@ -0,0 +1,141 @@+import { describe, it, expect } from 'vitest';+import {+ ConnectionDataSchema,+ ConnectionStatuses,+ Oauth2RevokedConnectionDataSchema,+} from '../../src/types/connectedAccountAuthStates.types';+import { transformConnectedAccountResponse } from '../../src/utils/transformers/connectedAccounts';+import { AuthSchemeTypes } from '../../src/types/authConfigs.types';++describe('connectedAccountAuthStates — REVOKED arms', () => {+ describe('Oauth2RevokedConnectionDataSchema', () => {+ it('parses a payload with only the status discriminator', () => {+ const parsed = Oauth2RevokedConnectionDataSchema.parse({+ status: ConnectionStatuses.REVOKED,+ });++ expect(parsed.status).toBe(ConnectionStatuses.REVOKED);+ expect(parsed.revoked_at).toBeUndefined();+ });++ it('parses a payload with optional revoked_at', () => {+ const parsed = Oauth2RevokedConnectionDataSchema.parse({+ status: ConnectionStatuses.REVOKED,+ revoked_at: '2026-05-01T12:34:56Z',+ });++ expect(parsed.revoked_at).toBe('2026-05-01T12:34:56Z');+ });++ it('rejects when status is not REVOKED', () => {+ expect(() =>+ Oauth2RevokedConnectionDataSchema.parse({+ status: ConnectionStatuses.ACTIVE,+ })+ ).toThrow();+ });+ });++ describe('ConnectionDataSchema discriminated union', () => {+ it('accepts REVOKED for OAUTH2 and preserves auth-scheme metadata', () => {+ const parsed = ConnectionDataSchema.parse({+ authScheme: AuthSchemeTypes.OAUTH2,+ val: {+ status: ConnectionStatuses.REVOKED,+ revoked_at: '2026-05-01T00:00:00Z',+ },+ });++ expect(parsed.authScheme).toBe(AuthSchemeTypes.OAUTH2);+ expect(parsed.val.status).toBe(ConnectionStatuses.REVOKED);+ });++ it('accepts REVOKED for S2S_OAUTH2 (preempts the queued Apollo rollout)', () => {+ // Today the server only emits REVOKED for OAUTH2, but S2S_OAUTH2 is on+ // Apollo's near-term roadmap. Without the matching arm, the entire+ // `state` would silently fail discriminated-union parsing in the+ // top-level transformer.+ const parsed = ConnectionDataSchema.parse({+ authScheme: AuthSchemeTypes.S2S_OAUTH2,+ val: {+ status: ConnectionStatuses.REVOKED,+ revoked_at: '2026-05-01T00:00:00Z',+ },+ });++ expect(parsed.authScheme).toBe(AuthSchemeTypes.S2S_OAUTH2);+ expect(parsed.val.status).toBe(ConnectionStatuses.REVOKED);+ });+ });++ describe('transformConnectedAccountResponse — REVOKED preserves state', () => {+ const baseResponse = {+ id: 'conn_123',+ auth_config: {+ id: 'auth_123',+ auth_scheme: 'OAUTH2',+ is_composio_managed: true,+ is_disabled: false,+ },+ user_id: 'user_123',+ data: {},+ params: {},+ is_disabled: false,+ created_at: '2023-01-01T00:00:00Z',+ updated_at: '2023-01-01T00:00:00Z',+ status_reason: 'token revoked at provider',+ toolkit: { slug: 'gmail' },+ test_request_endpoint: '',+ } as const;++ it('does not drop state for an OAUTH2 REVOKED payload', () => {+ const transformed = transformConnectedAccountResponse({+ ...baseResponse,+ status: ConnectionStatuses.REVOKED,+ state: {+ authScheme: AuthSchemeTypes.OAUTH2,+ val: {+ status: ConnectionStatuses.REVOKED,+ revoked_at: '2026-05-01T00:00:00Z',+ },+ },+ // eslint-disable-next-line @typescript-eslint/no-explicit-any+ } as any);++ expect(transformed.status).toBe(ConnectionStatuses.REVOKED);+ expect(transformed.state).toBeDefined();+ expect(transformed.state?.authScheme).toBe(AuthSchemeTypes.OAUTH2);+ expect(transformed.state?.val.status).toBe(ConnectionStatuses.REVOKED);+ });++ it('does not drop state for an S2S_OAUTH2 REVOKED payload', () => {+ const transformed = transformConnectedAccountResponse({+ ...baseResponse,+ auth_config: { ...baseResponse.auth_config, auth_scheme: 'S2S_OAUTH2' },+ status: ConnectionStatuses.REVOKED,+ state: {+ authScheme: AuthSchemeTypes.S2S_OAUTH2,+ val: {+ status: ConnectionStatuses.REVOKED,+ revoked_at: '2026-05-01T00:00:00Z',+ },+ },+ // eslint-disable-next-line @typescript-eslint/no-explicit-any+ } as any);++ expect(transformed.state).toBeDefined();+ expect(transformed.state?.authScheme).toBe(AuthSchemeTypes.S2S_OAUTH2);+ });+ });++ describe('ConnectionStatuses enum closure', () => {+ it('enumerates exactly the values this PR contracts for', () => {+ // Closure test — if Apollo adds a new status, the SDK should mirror it+ // here on purpose, not by accident. Compare the enum object's value set+ // to the set this PR ships.+ expect(new Set(Object.values(ConnectionStatuses))).toEqual(+ new Set(['INITIALIZING', 'INITIATED', 'ACTIVE', 'FAILED', 'EXPIRED', 'INACTIVE', 'REVOKED'])+ );+ });+ });+});diff --git a/uv.lock b/uv.lockindex 2e7996b70..8cf697707 100644--- a/uv.lock+++ b/uv.lock@@ -1,5 +1,5 @@version = 1-revision = 3+revision = 2requires-python = ">=3.10, <4"resolution-markers = ["python_full_version >= '3.13'",@@ -22,7 +22,7 @@ members = [][manifest.dependency-groups]-dev = [{ name = "composio", editable = "python" }]+dev = [{ name = "composio", virtual = "python" }][[package]]name = "aiohappyeyeballs"@@ -592,7 +592,7 @@ wheels = [[[package]]name = "composio"version = "0.12.0"-source = { editable = "python" }+source = { virtual = "python" }dependencies = [{ name = "composio-client" },{ name = "json-schema-to-pydantic" },@@ -621,7 +621,7 @@ dev = [[package.metadata]requires-dist = [- { name = "composio-client", specifier = "==1.36.0" },+ { name = "composio-client", specifier = "==1.37.0" },{ name = "json-schema-to-pydantic", specifier = ">=0.4.8" },{ name = "openai" },{ name = "pydantic", specifier = ">=2.6.4" },@@ -632,7 +632,7 @@ requires-dist = [[package.metadata.requires-dev]dev = [{ name = "click", specifier = ">=8.2.1" },- { name = "composio", editable = "python" },+ { name = "composio", virtual = "python" },{ name = "fastapi", specifier = ">=0.115.9" },{ name = "langchain-openai", specifier = "==1.1.0" },{ name = "nox", specifier = ">=2025.5.1" },@@ -649,7 +649,7 @@ dev = [[[package]]name = "composio-anthropic"version = "0.12.0"-source = { editable = "python/providers/anthropic" }+source = { virtual = "python/providers/anthropic" }dependencies = [{ name = "anthropic" },{ name = "composio" },@@ -663,7 +663,7 @@ requires-dist = [[[package]]name = "composio-client"-version = "1.36.0"+version = "1.37.0"source = { registry = "https://pypi.org/simple" }dependencies = [{ name = "anyio" },@@ -673,15 +673,15 @@ dependencies = [{ name = "sniffio" },{ name = "typing-extensions" },]-sdist = { url = "https://files.pythonhosted.org/packages/3b/1c/ad526e950c1fb51ba2dc67e0467c58a8d8fd66991284c6fc8e8f08868aa9/composio_client-1.36.0.tar.gz", hash = "sha256:924e97c8e1069fb6815a382a724d9ab5992f4f393881146416eec68b66189885", size = 241263, upload-time = "2026-05-05T08:40:16.697Z" }+sdist = { url = "https://files.pythonhosted.org/packages/75/14/d0a1cb2fb202357e4e49bdbd017d96131f0e821d136943074e9f9933436c/composio_client-1.37.0.tar.gz", hash = "sha256:b9f5c4b97863f98714634b88f61139aceef11274ee74a6fda59afc4095c5d094", size = 242029, upload-time = "2026-05-07T03:09:36.419Z" }wheels = [- { url = "https://files.pythonhosted.org/packages/ce/bc/f5bb734d1e6abf246130f4549de745b87ced2957839a315479cacc6d31bb/composio_client-1.36.0-py3-none-any.whl", hash = "sha256:820961ec9001b1967273970e406f8469386c71fa378a0f4dd1c36864eff8819b", size = 277167, upload-time = "2026-05-05T08:40:15.344Z" },+ { url = "https://files.pythonhosted.org/packages/49/98/cfc8d6c6208e00e015db59278855831d77b73730cb4e574c330fcfd53d4a/composio_client-1.37.0-py3-none-any.whl", hash = "sha256:bb228899c294c348cd982bcea9a33773bd65185108e863d41465e51890872bc5", size = 278188, upload-time = "2026-05-07T03:09:34.69Z" },][[package]]name = "composio-crewai"version = "0.12.0"-source = { editable = "python/providers/crewai" }+source = { virtual = "python/providers/crewai" }dependencies = [{ name = "composio" },{ name = "crewai" },@@ -711,7 +711,7 @@ requires-dist = [[[package]]name = "composio-google"version = "0.12.0"-source = { editable = "python/providers/google" }+source = { virtual = "python/providers/google" }dependencies = [{ name = "composio" },{ name = "google-cloud-aiplatform" },@@ -726,7 +726,7 @@ requires-dist = [[[package]]name = "composio-google-adk"version = "0.12.0"-source = { editable = "python/providers/google_adk" }+source = { virtual = "python/providers/google_adk" }dependencies = [{ name = "composio" },{ name = "google-adk" },@@ -741,7 +741,7 @@ requires-dist = [[[package]]name = "composio-langchain"version = "0.12.0"-source = { editable = "python/providers/langchain" }+source = { virtual = "python/providers/langchain" }dependencies = [{ name = "composio" },{ name = "langchain" },@@ -756,7 +756,7 @@ requires-dist = [[[package]]name = "composio-openai"version = "0.12.0"-source = { editable = "python/providers/openai" }+source = { virtual = "python/providers/openai" }dependencies = [{ name = "composio" },{ name = "openai" },@@ -771,7 +771,7 @@ requires-dist = [[[package]]name = "composio-openai-agents"version = "0.12.0"-source = { editable = "python/providers/openai_agents" }+source = { virtual = "python/providers/openai_agents" }dependencies = [{ name = "composio" },{ name = "openai-agents" },