Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 22, 05:45 UTC
fix(cli): preserve test user id fallback on login (#2775)
Musthaq Ahamad committed
Feb 25, 2026 at 23:57 UTC
501521063e80829ecfde49bddea56ce53a80bc0f
7 files changed
+43
-4
.changeset/salty-olives-guess.md
new
+5
@@ -0,0 +1,5 @@
1
+---
2
+'@composio/cli': patch
3
+---
4
+
5
+Fallback to global context if project apikeys not found
ts/packages/cli/src/commands/login.cmd.ts
+5
-1
@@ -95,6 +95,10 @@ const storeCredentials = (params: {
95
// identifiers rather than the actual org/project IDs).
96
const orgId = sessionInfo?.project.org.id ?? initialOrgId;
97
const projectId = sessionInfo?.project.nano_id ?? initialProjectId;
98
+ const sessionUserId = sessionInfo?.org_member.user_id ?? sessionInfo?.org_member.id;
99
+ const testUserId = sessionUserId
100
+ ? `pg-test-${sessionUserId}`
101
+ : Option.getOrUndefined(ctx.data.testUserId);
102
103
if (sessionInfo) {
104
if (initialOrgId !== orgId) {
@@ -108,7 +112,7 @@ const storeCredentials = (params: {
112
}
113
114
// Store UAK + org/project IDs in user_data.json
111
- yield* ctx.login(uakApiKey, orgId, projectId);
115
+ yield* ctx.login(uakApiKey, orgId, projectId, testUserId);
116
117
const email = sessionInfo?.org_member.email || fallbackEmail || undefined;
118
yield* ui.log.success(email ? `Logged in as ${email}` : 'Logged in successfully');
ts/packages/cli/src/models/user-data.ts
+7
@@ -37,6 +37,13 @@ export const UserData = Schema.Struct({
37
projectId: Schema.propertySignature(OptionFromNullishOr(Schema.String, null)).pipe(
38
Schema.fromKey('project_id')
39
),
40
+
41
+ /**
42
+ * Optional global test user identifier used by CLI/e2e flows.
43
+ */
44
+ testUserId: Schema.propertySignature(OptionFromNullishOr(Schema.String, null)).pipe(
45
+ Schema.fromKey('test_user_id')
46
+ ),
47
}).annotations({
48
identifier: 'UserData',
49
description: 'User data storage for the Composio CLI',
ts/packages/cli/src/services/composio-clients.ts
+9
-1
@@ -1103,13 +1103,21 @@ export class ComposioClientSingleton extends Effect.Service<ComposioClientSingle
1103
const apiKey =
1104
typeof rawApiKey === 'string' && rawApiKey.trim().length > 0 ? rawApiKey : undefined;
1105
const baseURL = ctx.data.baseURL;
1106
+ const globalOrgId = Option.getOrUndefined(ctx.data.orgId);
1107
+ const globalProjectId = Option.getOrUndefined(ctx.data.projectId);
1108
const resolvedProjectContext = yield* Option.match(projectContextOpt, {
1109
onNone: () => Effect.succeed(Option.none()),
1110
onSome: projectContext =>
1111
projectContext.resolve.pipe(Effect.catchAll(() => Effect.succeed(Option.none()))),
1112
});
1113
const defaultHeaders = Option.match(resolvedProjectContext, {
1112
- onNone: () => undefined,
1114
+ onNone: () =>
1115
+ globalOrgId && globalProjectId
1116
+ ? ({
1117
+ 'x-org-id': globalOrgId,
1118
+ 'x-project-id': globalProjectId,
1119
+ } satisfies Record<string, string>)
1120
+ : undefined,
1121
onSome: keys =>
1122
({
1123
'x-org-id': keys.orgId,
ts/packages/cli/src/services/user-context.ts
+8
-2
@@ -34,7 +34,8 @@ export class ComposioUserContext extends Context.Tag('ComposioUserData')<
34
login: (
35
apiKey: string,
36
orgId?: string,
37
- projectId?: string
37
+ projectId?: string,
38
+ testUserId?: string
39
) => Effect.Effect<void, ParseError | PlatformError, never>;
40
41
/**
@@ -64,6 +65,7 @@ export const ComposioUserContextLive = Layer.effect(
65
webURL: Option.some(webURL),
66
orgId: Option.none(),
67
projectId: Option.none(),
68
+ testUserId: Option.none(),
69
});
70
71
const logout = Effect.gen(function* () {
@@ -73,10 +75,11 @@ export const ComposioUserContextLive = Layer.effect(
75
webURL: Option.some(webURL),
76
orgId: Option.none(),
77
projectId: Option.none(),
78
+ testUserId: Option.none(),
79
});
80
});
81
79
- const login = (apiKey: string, orgId?: string, projectId?: string) =>
82
+ const login = (apiKey: string, orgId?: string, projectId?: string, testUserId?: string) =>
83
Effect.gen(function* () {
84
yield* update({
85
apiKey: Option.some(apiKey),
@@ -84,6 +87,7 @@ export const ComposioUserContextLive = Layer.effect(
87
webURL: Option.some(webURL),
88
orgId: Option.fromNullable(orgId),
89
projectId: Option.fromNullable(projectId),
90
+ testUserId: Option.fromNullable(testUserId),
91
});
92
});
93
@@ -117,6 +121,7 @@ export const ComposioUserContextLive = Layer.effect(
121
webURL: Option.some(webURL),
122
orgId: parsedUserData.orgId,
123
projectId: parsedUserData.projectId,
124
+ testUserId: parsedUserData.testUserId,
125
} satisfies UserData;
126
127
yield* Effect.logDebug('User data (overridden from env vars):', overriddenUserData);
@@ -151,6 +156,7 @@ export const ComposioUserContextLive = Layer.effect(
156
webURL: Option.getOrElse(userData.webURL, () => webURL),
157
orgId: userData.orgId,
158
projectId: userData.projectId,
159
+ testUserId: userData.testUserId,
160
};
161
162
return ComposioUserContext.of({
ts/packages/cli/test/src/commands/logout.cmd.test.ts
+2
@@ -19,6 +19,7 @@ describe('CLI: composio logout', () => {
19
webURL: 'https://platform.composio.dev',
20
orgId: Option.none(),
21
projectId: Option.none(),
22
+ testUserId: Option.none(),
23
});
24
25
expect(ctx.data).toMatchObject(expectedUserData);
@@ -55,6 +56,7 @@ describe('CLI: composio logout', () => {
56
webURL: 'https://platform.composio.dev',
57
orgId: Option.none(),
58
projectId: Option.none(),
59
+ testUserId: Option.none(),
60
})
61
);
62
ts/packages/cli/test/src/services/user-context.test.ts
+7
@@ -35,6 +35,7 @@ describe('ComposioUserContext', () => {
35
webURL: 'https://platform.composio.dev',
36
orgId: Option.none(),
37
projectId: Option.none(),
38
+ testUserId: Option.none(),
39
});
40
assertEquals(Data.struct(ctx.data), Data.struct(expectedUserData));
41
assertEquals(ctx.isLoggedIn(), false);
@@ -65,6 +66,7 @@ describe('ComposioUserContext', () => {
66
webURL: 'https://platform.composio.dev',
67
orgId: Option.none(),
68
projectId: Option.none(),
69
+ testUserId: Option.none(),
70
});
71
assertEquals(Data.struct(ctx.data), Data.struct(expectedUserData));
72
assertEquals(ctx.isLoggedIn(), true);
@@ -93,6 +95,7 @@ describe('ComposioUserContext', () => {
95
webURL: Option.some('https://platform.composio.dev'),
96
orgId: Option.none(),
97
projectId: Option.none(),
98
+ testUserId: Option.none(),
99
});
100
const userDataAsJson = yield* userDataToJSON(expectedUserData);
101
@@ -132,6 +135,7 @@ describe('ComposioUserContext', () => {
135
webURL: Option.some('https://platform.composio.dev'),
136
orgId: Option.none(),
137
projectId: Option.none(),
138
+ testUserId: Option.none(),
139
});
140
const userDataAsJson = yield* userDataToJSON(expectedUserData);
141
@@ -180,6 +184,7 @@ describe('ComposioUserContext', () => {
184
webURL: 'https://platform.composio.dev',
185
orgId: Option.none(),
186
projectId: Option.none(),
187
+ testUserId: Option.none(),
188
});
189
assertEquals(Data.struct(ctx.data), Data.struct(expectedUserData));
190
assertEquals(ctx.isLoggedIn(), false);
@@ -224,6 +229,7 @@ describe('ComposioUserContext', () => {
229
webURL: 'https://platform.composio.dev',
230
orgId: Option.none(),
231
projectId: Option.none(),
232
+ testUserId: Option.none(),
233
});
234
assertEquals(Data.struct(ctx.data), Data.struct(expectedUserData));
235
assertEquals(ctx.isLoggedIn(), false);
@@ -260,6 +266,7 @@ describe('ComposioUserContext', () => {
266
webURL: 'https://platform.composio.dev',
267
orgId: Option.none(),
268
projectId: Option.none(),
269
+ testUserId: Option.none(),
270
});
271
assertEquals(Data.struct(ctx.data), Data.struct(expectedUserData));
272
assertEquals(ctx.isLoggedIn(), false);