@devries-cameron20 / composio-1 / commits / a7c2d16bf
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

test(connected-accounts): cover REVOKED rollout and forward-compat

Adds the test coverage flagged in PR #3344 review item P1#5: TS (`ts/packages/core/test/connectedAccounts/connectedAccountAuthStates.test.ts`): - `Oauth2RevokedConnectionDataSchema` parses with and without optional `revoked_at` - `ConnectionDataSchema` discriminated union accepts REVOKED for both OAUTH2 and S2S_OAUTH2 (the preempted Apollo arm from P1#1) - `transformConnectedAccountResponse` does not silently drop `state` for REVOKED on either auth scheme - Closure test on the `ConnectionStatuses` enum so a future Apollo addition trips a CI failure on purpose TS CLI (`connected-accounts.list.cmd.test.ts`): - Server returning an unrecognized status no longer crashes the command — the `catchTag('ParseError')` fallback warns the user to run `composio upgrade` and renders the row anyway Python (`tests/test_connected_accounts.py`): - `wait_for_connection` fails fast on FAILED / EXPIRED / REVOKED (parameterized) — the contract added by this PR - `wait_for_connection` does NOT treat INACTIVE as terminal, so a connection briefly transiting through INACTIVE still recovers to ACTIVE — guards against the regression called out in P1#2

jkomyno committed May 7, 2026 at 10:29 UTC a7c2d16bf307fe07791a973aeed12539d1132b07
4 files changed +255 -15
python/tests/test_connected_accounts.py
+63
@@ -175,6 +175,69 @@ class TestConnectionRequest:
175
176 assert "Timeout while waiting for connection conn-timeout" in str(excinfo.value)
177
178 + @pytest.mark.parametrize("terminal_status", ["FAILED", "EXPIRED", "REVOKED"])
179 + def test_wait_for_connection_fails_fast_on_terminal_status(
180 + self, monkeypatch, terminal_status
181 + ):
182 + # Mirrors the TS contract (`ConnectionRequest.ts` `terminalErrorStates`):
183 + # FAILED / EXPIRED / REVOKED are credentials-gone states and should
184 + # raise immediately rather than poll until timeout.
185 + mock_client = Mock()
186 + terminal = Mock()
187 + terminal.status = terminal_status
188 + mock_client.connected_accounts.retrieve.return_value = terminal
189 +
190 + req = ConnectionRequest(
191 + id="conn-terminal",
192 + status="PENDING",
193 + redirect_url=None,
194 + client=mock_client,
195 + )
196 +
197 + monkeypatch.setattr(time, "sleep", lambda *_args, **_kwargs: None)
198 +
199 + with pytest.raises(exceptions.SDKError) as excinfo:
200 + req.wait_for_connection(timeout=10.0)
201 +
202 + assert "conn-terminal" in str(excinfo.value)
203 + assert terminal_status in str(excinfo.value)
204 + # One retrieve call only — no polling once we hit a terminal state.
205 + assert mock_client.connected_accounts.retrieve.call_count == 1
206 +
207 + def test_wait_for_connection_does_not_treat_inactive_as_terminal(self, monkeypatch):
208 + # INACTIVE means "user disabled, can be reactivated" — a connection can
209 + # briefly transit through it before settling on ACTIVE. Failing fast
210 + # there would regress callers that previously recovered.
211 + mock_client = Mock()
212 + inactive = Mock()
213 + inactive.status = "INACTIVE"
214 + active = Mock()
215 + active.status = "ACTIVE"
216 + mock_client.connected_accounts.retrieve.side_effect = [inactive, active]
217 +
218 + req = ConnectionRequest(
219 + id="conn-inactive-recover",
220 + status="PENDING",
221 + redirect_url=None,
222 + client=mock_client,
223 + )
224 +
225 + current_time = {"value": 0.0}
226 +
227 + def fake_time():
228 + value = current_time["value"]
229 + current_time["value"] += 0.1
230 + return value
231 +
232 + monkeypatch.setattr(time, "time", fake_time)
233 + monkeypatch.setattr(time, "sleep", lambda *_args, **_kwargs: None)
234 +
235 + result = req.wait_for_connection(timeout=1.0)
236 +
237 + assert result is active
238 + assert req.status == "ACTIVE"
239 + assert mock_client.connected_accounts.retrieve.call_count == 2
240 +
241 def test_from_id_uses_client_retrieve(self):
242 mock_client = Mock()
243 retrieved = Mock()
ts/packages/cli/test/src/commands/connected-accounts/connected-accounts.list.cmd.test.ts
+36
@@ -231,4 +231,40 @@ describe('CLI: composio dev connected-accounts list', () => {
231 );
232 }
233 );
234 +
235 + // Forward-compat: simulate the server returning a status the CLI does not
236 + // know about (e.g. a freshly-added Apollo enum value). The decode now uses
237 + // `catchTag('ParseError')` to warn and degrade rather than crashing the
238 + // entire command — even users filtering on `--status ACTIVE` would
239 + // otherwise be blocked.
240 + const unknownStatusAccounts = [
241 + {
242 + ...testConnectedAccounts[0],
243 + id: 'con_future_status',
244 + // Cast to bypass the closed `ConnectedAccountItem['status']` literal —
245 + // the whole point of this test is what happens when the server hands
246 + // us a value the schema rejects.
247 + status: 'FUTURE_NOT_YET_KNOWN' as ConnectedAccountItem['status'],
248 + },
249 + ];
250 +
251 + layer(
252 + TestLive({
253 + baseConfigProvider: testDevConfigProvider,
254 + connectedAccountsData: { items: unknownStatusAccounts },
255 + })
256 + )('[Given] server returns unknown status [Then] warns and degrades instead of crashing', it => {
257 + it.scoped('does not crash on unknown status', () =>
258 + Effect.gen(function* () {
259 + const userContext = yield* ComposioUserContext;
260 + yield* userContext.login('test_api_key', 'org_test');
261 + yield* cli(['dev', 'connected-accounts', 'list']);
262 + const lines = yield* MockConsole.getLines({ stripAnsi: true });
263 + const output = lines.join('\n');
264 +
265 + expect(output).toContain('composio upgrade');
266 + expect(output).toContain('con_future_status');
267 + })
268 + );
269 + });
270 });
ts/packages/core/test/connectedAccounts/connectedAccountAuthStates.test.ts new
+141
@@ -0,0 +1,141 @@
1 +import { describe, it, expect } from 'vitest';
2 +import {
3 + ConnectionDataSchema,
4 + ConnectionStatuses,
5 + Oauth2RevokedConnectionDataSchema,
6 +} from '../../src/types/connectedAccountAuthStates.types';
7 +import { transformConnectedAccountResponse } from '../../src/utils/transformers/connectedAccounts';
8 +import { AuthSchemeTypes } from '../../src/types/authConfigs.types';
9 +
10 +describe('connectedAccountAuthStates — REVOKED arms', () => {
11 + describe('Oauth2RevokedConnectionDataSchema', () => {
12 + it('parses a payload with only the status discriminator', () => {
13 + const parsed = Oauth2RevokedConnectionDataSchema.parse({
14 + status: ConnectionStatuses.REVOKED,
15 + });
16 +
17 + expect(parsed.status).toBe(ConnectionStatuses.REVOKED);
18 + expect(parsed.revoked_at).toBeUndefined();
19 + });
20 +
21 + it('parses a payload with optional revoked_at', () => {
22 + const parsed = Oauth2RevokedConnectionDataSchema.parse({
23 + status: ConnectionStatuses.REVOKED,
24 + revoked_at: '2026-05-01T12:34:56Z',
25 + });
26 +
27 + expect(parsed.revoked_at).toBe('2026-05-01T12:34:56Z');
28 + });
29 +
30 + it('rejects when status is not REVOKED', () => {
31 + expect(() =>
32 + Oauth2RevokedConnectionDataSchema.parse({
33 + status: ConnectionStatuses.ACTIVE,
34 + })
35 + ).toThrow();
36 + });
37 + });
38 +
39 + describe('ConnectionDataSchema discriminated union', () => {
40 + it('accepts REVOKED for OAUTH2 and preserves auth-scheme metadata', () => {
41 + const parsed = ConnectionDataSchema.parse({
42 + authScheme: AuthSchemeTypes.OAUTH2,
43 + val: {
44 + status: ConnectionStatuses.REVOKED,
45 + revoked_at: '2026-05-01T00:00:00Z',
46 + },
47 + });
48 +
49 + expect(parsed.authScheme).toBe(AuthSchemeTypes.OAUTH2);
50 + expect(parsed.val.status).toBe(ConnectionStatuses.REVOKED);
51 + });
52 +
53 + it('accepts REVOKED for S2S_OAUTH2 (preempts the queued Apollo rollout)', () => {
54 + // Today the server only emits REVOKED for OAUTH2, but S2S_OAUTH2 is on
55 + // Apollo's near-term roadmap. Without the matching arm, the entire
56 + // `state` would silently fail discriminated-union parsing in the
57 + // top-level transformer.
58 + const parsed = ConnectionDataSchema.parse({
59 + authScheme: AuthSchemeTypes.S2S_OAUTH2,
60 + val: {
61 + status: ConnectionStatuses.REVOKED,
62 + revoked_at: '2026-05-01T00:00:00Z',
63 + },
64 + });
65 +
66 + expect(parsed.authScheme).toBe(AuthSchemeTypes.S2S_OAUTH2);
67 + expect(parsed.val.status).toBe(ConnectionStatuses.REVOKED);
68 + });
69 + });
70 +
71 + describe('transformConnectedAccountResponse — REVOKED preserves state', () => {
72 + const baseResponse = {
73 + id: 'conn_123',
74 + auth_config: {
75 + id: 'auth_123',
76 + auth_scheme: 'OAUTH2',
77 + is_composio_managed: true,
78 + is_disabled: false,
79 + },
80 + user_id: 'user_123',
81 + data: {},
82 + params: {},
83 + is_disabled: false,
84 + created_at: '2023-01-01T00:00:00Z',
85 + updated_at: '2023-01-01T00:00:00Z',
86 + status_reason: 'token revoked at provider',
87 + toolkit: { slug: 'gmail' },
88 + test_request_endpoint: '',
89 + } as const;
90 +
91 + it('does not drop state for an OAUTH2 REVOKED payload', () => {
92 + const transformed = transformConnectedAccountResponse({
93 + ...baseResponse,
94 + status: ConnectionStatuses.REVOKED,
95 + state: {
96 + authScheme: AuthSchemeTypes.OAUTH2,
97 + val: {
98 + status: ConnectionStatuses.REVOKED,
99 + revoked_at: '2026-05-01T00:00:00Z',
100 + },
101 + },
102 + // eslint-disable-next-line @typescript-eslint/no-explicit-any
103 + } as any);
104 +
105 + expect(transformed.status).toBe(ConnectionStatuses.REVOKED);
106 + expect(transformed.state).toBeDefined();
107 + expect(transformed.state?.authScheme).toBe(AuthSchemeTypes.OAUTH2);
108 + expect(transformed.state?.val.status).toBe(ConnectionStatuses.REVOKED);
109 + });
110 +
111 + it('does not drop state for an S2S_OAUTH2 REVOKED payload', () => {
112 + const transformed = transformConnectedAccountResponse({
113 + ...baseResponse,
114 + auth_config: { ...baseResponse.auth_config, auth_scheme: 'S2S_OAUTH2' },
115 + status: ConnectionStatuses.REVOKED,
116 + state: {
117 + authScheme: AuthSchemeTypes.S2S_OAUTH2,
118 + val: {
119 + status: ConnectionStatuses.REVOKED,
120 + revoked_at: '2026-05-01T00:00:00Z',
121 + },
122 + },
123 + // eslint-disable-next-line @typescript-eslint/no-explicit-any
124 + } as any);
125 +
126 + expect(transformed.state).toBeDefined();
127 + expect(transformed.state?.authScheme).toBe(AuthSchemeTypes.S2S_OAUTH2);
128 + });
129 + });
130 +
131 + describe('ConnectionStatuses enum closure', () => {
132 + it('enumerates exactly the values this PR contracts for', () => {
133 + // Closure test — if Apollo adds a new status, the SDK should mirror it
134 + // here on purpose, not by accident. Compare the enum object's value set
135 + // to the set this PR ships.
136 + expect(new Set(Object.values(ConnectionStatuses))).toEqual(
137 + new Set(['INITIALIZING', 'INITIATED', 'ACTIVE', 'FAILED', 'EXPIRED', 'INACTIVE', 'REVOKED'])
138 + );
139 + });
140 + });
141 +});
uv.lock
+15 -15
@@ -1,5 +1,5 @@
1 version = 1
2 -revision = 3
2 +revision = 2
3 requires-python = ">=3.10, <4"
4 resolution-markers = [
5 "python_full_version >= '3.13'",
@@ -22,7 +22,7 @@ members = [
22 ]
23
24 [manifest.dependency-groups]
25 -dev = [{ name = "composio", editable = "python" }]
25 +dev = [{ name = "composio", virtual = "python" }]
26
27 [[package]]
28 name = "aiohappyeyeballs"
@@ -592,7 +592,7 @@ wheels = [
592 [[package]]
593 name = "composio"
594 version = "0.12.0"
595 -source = { editable = "python" }
595 +source = { virtual = "python" }
596 dependencies = [
597 { name = "composio-client" },
598 { name = "json-schema-to-pydantic" },
@@ -621,7 +621,7 @@ dev = [
621
622 [package.metadata]
623 requires-dist = [
624 - { name = "composio-client", specifier = "==1.36.0" },
624 + { name = "composio-client", specifier = "==1.37.0" },
625 { name = "json-schema-to-pydantic", specifier = ">=0.4.8" },
626 { name = "openai" },
627 { name = "pydantic", specifier = ">=2.6.4" },
@@ -632,7 +632,7 @@ requires-dist = [
632 [package.metadata.requires-dev]
633 dev = [
634 { name = "click", specifier = ">=8.2.1" },
635 - { name = "composio", editable = "python" },
635 + { name = "composio", virtual = "python" },
636 { name = "fastapi", specifier = ">=0.115.9" },
637 { name = "langchain-openai", specifier = "==1.1.0" },
638 { name = "nox", specifier = ">=2025.5.1" },
@@ -649,7 +649,7 @@ dev = [
649 [[package]]
650 name = "composio-anthropic"
651 version = "0.12.0"
652 -source = { editable = "python/providers/anthropic" }
652 +source = { virtual = "python/providers/anthropic" }
653 dependencies = [
654 { name = "anthropic" },
655 { name = "composio" },
@@ -663,7 +663,7 @@ requires-dist = [
663
664 [[package]]
665 name = "composio-client"
666 -version = "1.36.0"
666 +version = "1.37.0"
667 source = { registry = "https://pypi.org/simple" }
668 dependencies = [
669 { name = "anyio" },
@@ -673,15 +673,15 @@ dependencies = [
673 { name = "sniffio" },
674 { name = "typing-extensions" },
675 ]
676 -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" }
676 +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" }
677 wheels = [
678 - { 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" },
678 + { 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" },
679 ]
680
681 [[package]]
682 name = "composio-crewai"
683 version = "0.12.0"
684 -source = { editable = "python/providers/crewai" }
684 +source = { virtual = "python/providers/crewai" }
685 dependencies = [
686 { name = "composio" },
687 { name = "crewai" },
@@ -711,7 +711,7 @@ requires-dist = [
711 [[package]]
712 name = "composio-google"
713 version = "0.12.0"
714 -source = { editable = "python/providers/google" }
714 +source = { virtual = "python/providers/google" }
715 dependencies = [
716 { name = "composio" },
717 { name = "google-cloud-aiplatform" },
@@ -726,7 +726,7 @@ requires-dist = [
726 [[package]]
727 name = "composio-google-adk"
728 version = "0.12.0"
729 -source = { editable = "python/providers/google_adk" }
729 +source = { virtual = "python/providers/google_adk" }
730 dependencies = [
731 { name = "composio" },
732 { name = "google-adk" },
@@ -741,7 +741,7 @@ requires-dist = [
741 [[package]]
742 name = "composio-langchain"
743 version = "0.12.0"
744 -source = { editable = "python/providers/langchain" }
744 +source = { virtual = "python/providers/langchain" }
745 dependencies = [
746 { name = "composio" },
747 { name = "langchain" },
@@ -756,7 +756,7 @@ requires-dist = [
756 [[package]]
757 name = "composio-openai"
758 version = "0.12.0"
759 -source = { editable = "python/providers/openai" }
759 +source = { virtual = "python/providers/openai" }
760 dependencies = [
761 { name = "composio" },
762 { name = "openai" },
@@ -771,7 +771,7 @@ requires-dist = [
771 [[package]]
772 name = "composio-openai-agents"
773 version = "0.12.0"
774 -source = { editable = "python/providers/openai_agents" }
774 +source = { virtual = "python/providers/openai_agents" }
775 dependencies = [
776 { name = "composio" },
777 { name = "openai-agents" },