@devries-cameron20 / composio-1 / commits / 9ebaac589
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.

fix(cli): fallback to global test user id for action commands (#2781)

Musthaq Ahamad committed Feb 26, 2026 at 15:14 UTC 9ebaac589d10a8d6df0a58de9b3eb5c1776085f1
6 files changed +77 -2
.changeset/short-singers-fix.md new
+5
@@ -0,0 +1,5 @@
1 +---
2 +'@composio/cli': patch
3 +---
4 +
5 +Fallback to gloabl user_id if project user_id is not present
ts/packages/cli/src/commands/connected-accounts/commands/connected-accounts.link.cmd.ts
+6 -1
@@ -2,6 +2,7 @@ import { Args, Command, Options } from '@effect/cli';
2 import { Effect, Option, Schedule } from 'effect';
3 import open from 'open';
4 import { ComposioToolkitsRepository } from 'src/services/composio-clients';
5 +import { ComposioUserContext } from 'src/services/user-context';
6 import { TerminalUI } from 'src/services/terminal-ui';
7 import { requireAuth } from 'src/effects/require-auth';
8 import { handleHttpServerError } from 'src/effects/handle-http-error';
@@ -127,11 +128,13 @@ export const connectedAccountsCmd$Link = Command.make(
128 const ui = yield* TerminalUI;
129 const repo = yield* ComposioToolkitsRepository;
130 const projectContext = yield* ProjectContext;
131 + const userContext = yield* ComposioUserContext;
132 const resolvedProjectContext = yield* projectContext.resolve;
133 const testUserId = Option.flatMap(resolvedProjectContext, keys => keys.testUserId);
134 + const globalTestUserId = userContext.data.testUserId;
135 const resolvedUserId = Option.match(userId, {
136 onSome: value => Option.some(value),
134 - onNone: () => testUserId,
137 + onNone: () => Option.orElse(testUserId, () => globalTestUserId),
138 });
139 if (Option.isNone(resolvedUserId)) {
140 return yield* Effect.fail(
@@ -140,6 +143,8 @@ export const connectedAccountsCmd$Link = Command.make(
143 }
144 if (Option.isNone(userId) && Option.isSome(testUserId)) {
145 yield* ui.log.warn(`Using test user id "${testUserId.value}"`);
146 + } else if (Option.isNone(userId) && Option.isSome(globalTestUserId)) {
147 + yield* ui.log.warn(`Using global test user id "${globalTestUserId.value}"`);
148 }
149
150 // Validate: exactly one of <toolkit> or --auth-config must be provided
ts/packages/cli/src/commands/tools/commands/tools.execute.cmd.ts
+6 -1
@@ -14,6 +14,7 @@ import {
14 import type { ToolExecuteParams } from 'src/services/tools-executor';
15 import { ProjectContext } from 'src/services/project-context';
16 import { ComposioToolkitsRepository } from 'src/services/composio-clients';
17 +import { ComposioUserContext } from 'src/services/user-context';
18 import {
19 extractApiErrorDetails,
20 extractMessage,
@@ -294,11 +295,13 @@ export const toolsCmd$Execute = Command.make(
295 const ui = yield* TerminalUI;
296 const executor = yield* ToolsExecutor;
297 const projectContext = yield* ProjectContext;
298 + const userContext = yield* ComposioUserContext;
299 const resolvedProjectContext = yield* projectContext.resolve;
300 const testUserId = Option.flatMap(resolvedProjectContext, keys => keys.testUserId);
301 + const globalTestUserId = userContext.data.testUserId;
302 const resolvedUserId = Option.match(userId, {
303 onSome: value => Option.some(value),
301 - onNone: () => testUserId,
304 + onNone: () => Option.orElse(testUserId, () => globalTestUserId),
305 });
306 if (Option.isNone(resolvedUserId)) {
307 return yield* Effect.fail(
@@ -307,6 +310,8 @@ export const toolsCmd$Execute = Command.make(
310 }
311 if (Option.isNone(userId) && Option.isSome(testUserId)) {
312 yield* ui.log.warn(`Using test user id "${testUserId.value}"`);
313 + } else if (Option.isNone(userId) && Option.isSome(globalTestUserId)) {
314 + yield* ui.log.warn(`Using global test user id "${globalTestUserId.value}"`);
315 }
316
317 const input = yield* resolveInput(data);
ts/packages/cli/test/__fixtures__/global-test-user-id/.composio/user_data.json new
+8
@@ -0,0 +1,8 @@
1 +{
2 + "api_key": "test_api_key",
3 + "base_url": "https://backend.composio.dev",
4 + "web_url": "https://platform.composio.dev",
5 + "org_id": null,
6 + "project_id": null,
7 + "test_user_id": "global-default"
8 +}
ts/packages/cli/test/src/commands/connected-accounts/connected-accounts.link.cmd.test.ts
+28
@@ -81,6 +81,34 @@ describe('CLI: composio connected-accounts link', () => {
81 }
82 );
83
84 + layer(
85 + TestLive({
86 + baseConfigProvider: testConfigProvider,
87 + connectedAccountsData,
88 + fixture: 'global-test-user-id',
89 + })
90 + )(
91 + '[Given] no --user-id and no project test_user_id [Then] falls back to global test_user_id',
92 + it => {
93 + it.scoped('uses global test user id from user_data.json', () =>
94 + Effect.gen(function* () {
95 + yield* cli([
96 + 'connected-accounts',
97 + 'link',
98 + '--auth-config',
99 + 'ac_gmail_oauth',
100 + '--no-browser',
101 + ]);
102 + const lines = yield* MockConsole.getLines({ stripAnsi: true });
103 + const output = lines.join('\n');
104 +
105 + expect(output).toContain('Using global test user id "global-default"');
106 + expect(output).toContain('https://app.composio.dev/link?token=lt_test_token');
107 + })
108 + );
109 + }
110 + );
111 +
112 layer(TestLive())('[Given] no API key [Then] warns user to login', it => {
113 it.scoped('warns user to login', () =>
114 Effect.gen(function* () {
ts/packages/cli/test/src/commands/tools/tools.execute.cmd.test.ts
+24
@@ -71,6 +71,30 @@ describe('CLI: composio tools execute', () => {
71 );
72 });
73
74 + layer(
75 + TestLive({
76 + baseConfigProvider: testConfigProvider,
77 + fixture: 'global-test-user-id',
78 + stdin: { isTTY: true, data: '' },
79 + })
80 + )(
81 + '[Given] no --user-id and no project test_user_id [Then] falls back to global test_user_id',
82 + it => {
83 + it.scoped('uses global test user id from user_data.json', () =>
84 + Effect.gen(function* () {
85 + yield* cli(['tools', 'execute', 'GMAIL_SEND_EMAIL', '-d', '{"recipient":"a"}']);
86 + const lines = yield* MockConsole.getLines({ stripAnsi: true });
87 + const output = parseLastJson(lines);
88 + const text = lines.join('\n');
89 +
90 + expect(output.successful).toBe(true);
91 + expect(output.data.tool_slug).toBe('GMAIL_SEND_EMAIL');
92 + expect(text).toContain('Using global test user id "global-default"');
93 + })
94 + );
95 + }
96 + );
97 +
98 layer(
99 TestLive({
100 baseConfigProvider: testConfigProvider,