@devries-cameron20 / composio Mirror · read-only / commits / fc33028fa
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.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 08:30 UTC

refactor(cli): move `signup` into the directory shape (#4975)

This PR: - moves the signup flow `composio signup` and `composio agent signup` share from `signup.cmd.ts` to `src/effects/agent-signup.ts` (`runAgentSignupFlow`), so `agent signup` no longer imports from another command's file. This first commit is the same change as the one on the `agent` U9 branch (`refactor/cli-agent-layout`), cherry-picked so both PRs merge in either order - moves `signup.cmd.ts` to `signup/signup.{cmd,handler}.ts`; `runSignup` runs the shared flow under the `composio signup` label - adds `signup.cmd.test.ts` (default flow logs in and stores the user config, `--no-wait -f`, `--no-login`, human login warns and exits 1) and `signup.handler.test.ts` (exact stderr lines and the stdout summary, written without `force`) - removes `signup.cmd.ts` from `COMMAND_TEST_EXEMPTIONS` (15 to 14) Part of U9 of the CLI command-layout series. No user-visible change, so no CHANGELOG entry. Verified locally on the branch tip: | Check | Result | | --- | --- | | `pnpm --filter @composio/cli typecheck` | passes | | `pnpm --filter @composio/cli test` (skills, boundaries, command tests, Vitest) | 162 files, 1903 passed, 1 skipped | | `validate:command-tests` | 14 exemptions (was 15) | | `lint:effect` | 0 diagnostics | | `oxlint`, prettier on touched files | clean | | Binary smoke | `signup --help`, `agent signup --help`, root `--help`: identical to an `origin/next` (231122de1) binary | `agent.cmd.test.ts` keeps its top-level `signup` case so this PR does not touch the file the `agent` PR rewrites; whichever merges second can drop it.

Alberto Schiabel committed Oct 20, 2026 at 16:33 UTC fc33028fa85f0c66c95ff70f45557725ab1ae4e2
7 files changed +247 -29
ts/packages/cli/scripts/command-tests.ts
-1
@@ -19,7 +19,6 @@ const TEST_SUFFIX = '.cmd.test.ts';
19 // test/src/commands/. Both use forward slashes.
20 export const COMMAND_TEST_EXEMPTIONS: readonly CommandTestExemption[] = [
21 { command: 'connections/commands/connections.remove.cmd.ts', reason: 'no test yet' },
22 - { command: 'signup.cmd.ts', reason: 'no test yet' },
22 { command: 'triggers/commands/triggers.listen.cmd.ts', reason: 'no test yet' },
23 { command: 'upgrade.cmd.ts', reason: 'no test yet' },
24 ];
ts/packages/cli/src/commands/index.ts
+1 -1
@@ -6,7 +6,7 @@ import { versionCmd } from './version.cmd';
6 import { upgradeCmd } from './upgrade.cmd';
7 import { whoamiCmd } from './whoami.cmd';
8 import { loginCmd } from './login/login.cmd';
9 -import { signupCmd } from './signup.cmd';
9 +import { signupCmd } from './signup/signup.cmd';
10 import { setupCmd } from './setup.cmd';
11 import { listenCmd } from './listen.cmd';
12 import { logoutCmd } from './logout.cmd';
ts/packages/cli/src/commands/signup/signup.cmd.ts renamed
+4 -6
@@ -1,5 +1,5 @@
1 import { Command, Flag } from 'effect/cli';
2 -import { runAgentSignupFlow } from 'src/effects/agent-signup';
2 +import { runSignup } from './signup.handler';
3
4 const noWait = Flag.Boolean('no-wait').pipe(
5 Flag.withDefault(false),
@@ -17,8 +17,6 @@ const force = Flag.Boolean('force').pipe(
17 Flag.withDescription('Create a new agent identity even if ~/.composio/agent.json already exists')
18 );
19
20 -export const signupCmd = Command.make(
21 - 'signup',
22 - { noWait, noLogin, force },
23 - ({ noWait, noLogin, force }) => runAgentSignupFlow({ noWait, noLogin, force })
24 -).pipe(Command.withDescription('Sign up and optionally log in as a Composio agent.'));
20 +export const signupCmd = Command.make('signup', { noWait, noLogin, force }, runSignup).pipe(
21 + Command.withDescription('Sign up and optionally log in as a Composio agent.')
22 +);
ts/packages/cli/src/commands/signup/signup.handler.ts new
+12
@@ -0,0 +1,12 @@
1 +import { runAgentSignupFlow } from 'src/effects/agent-signup';
2 +
3 +/** The flags of `composio signup`. */
4 +export type SignupParams = {
5 + readonly noWait: boolean;
6 + readonly noLogin: boolean;
7 + readonly force: boolean;
8 +};
9 +
10 +/** Runs the agent signup flow `composio agent signup` shares, under this command's name. */
11 +export const runSignup = (params: SignupParams) =>
12 + runAgentSignupFlow({ ...params, commandLabel: 'composio signup' });
ts/packages/cli/test/src/commands/agent/agent.cmd.test.ts
+1 -21
@@ -6,7 +6,7 @@ import { afterEach, vi } from 'vitest';
6 import { setupCacheDir } from 'src/effects/setup-cache-dir';
7 import { readStoredAgentIdentity } from 'src/services/agents';
8 import { cli, MockConsole, TestLive } from 'test/__utils__';
9 -import { agentsJsonResponse, makeAgentIdentity } from 'test/__utils__/models/agent';
9 +import { makeAgentIdentity } from 'test/__utils__/models/agent';
10
11 describe('CLI: composio agent', () => {
12 afterEach(() => {
@@ -45,24 +45,4 @@ describe('CLI: composio agent', () => {
45 })
46 );
47 });
48 -
49 - layer(TestLive())(it => {
50 - it.effect('top-level signup makes clear it signs up an agent', () =>
51 - Effect.gen(function* () {
52 - const fetchSpy = vi
53 - .spyOn(globalThis, 'fetch')
54 - .mockImplementation(async () => agentsJsonResponse(makeAgentIdentity()));
55 -
56 - yield* cli(['signup']);
57 - const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
58 -
59 - expect(fetchSpy).toHaveBeenCalledExactlyOnceWith(
60 - expect.stringContaining('/api/signup'),
61 - expect.objectContaining({ method: 'POST' })
62 - );
63 -
64 - expect(output).toContain('composio signup signs you up as a Composio agent');
65 - })
66 - );
67 - });
48 });
ts/packages/cli/test/src/commands/signup/signup.cmd.test.ts new
+137
@@ -0,0 +1,137 @@
1 +import { describe, expect, layer } from '@effect/vitest';
2 +import * as FileSystem from 'effect/FileSystem';
3 +import { Effect, Option } from 'effect';
4 +import path from 'node:path';
5 +import { afterEach, vi } from 'vitest';
6 +import * as constants from 'src/constants';
7 +import { setupCacheDir } from 'src/effects/setup-cache-dir';
8 +import type { AgentIdentity } from 'src/services/agents';
9 +import { ComposioUserContext } from 'src/services/user-context';
10 +import { cli, MockConsole, TestLive } from 'test/__utils__';
11 +
12 +const readyIdentity: AgentIdentity = {
13 + status: 'READY',
14 + slug: 'test-agent',
15 + email: 'test-agent@agent.composio.ai',
16 + composio_agent_key: 'cak_test_agent',
17 + composio: {
18 + member_id: 'mem_agent',
19 + org_id: 'org_agent',
20 + project_id: 'proj_agent',
21 + user_api_key: 'uak_agent',
22 + },
23 +};
24 +
25 +const pendingIdentity: AgentIdentity = {
26 + ...readyIdentity,
27 + status: 'PENDING',
28 + composio: undefined,
29 +};
30 +
31 +/** Answers every agents API request with `body`. */
32 +const stubAgentsApi = (body: AgentIdentity) =>
33 + vi.spyOn(globalThis, 'fetch').mockImplementation(
34 + async () =>
35 + new Response(JSON.stringify(body), {
36 + status: 200,
37 + headers: { 'Content-Type': 'application/json' },
38 + })
39 + );
40 +
41 +describe('CLI: composio signup', () => {
42 + afterEach(() => {
43 + vi.restoreAllMocks();
44 + process.exitCode = undefined;
45 + });
46 +
47 + layer(TestLive())('[Given] no login', it => {
48 + it.effect('[Then] signs up an agent, waits for it, and logs the CLI in', () =>
49 + Effect.gen(function* () {
50 + const fetchSpy = stubAgentsApi(readyIdentity);
51 +
52 + yield* cli(['signup']);
53 +
54 + expect(fetchSpy).toHaveBeenCalledExactlyOnceWith(
55 + expect.stringMatching(/\/api\/signup$/),
56 + expect.objectContaining({ method: 'POST' })
57 + );
58 + const stderr = yield* MockConsole.getLines({ stream: 'stderr', stripAnsi: true });
59 + expect(stderr).toContain('-- composio signup --');
60 + expect(stderr).toContain(
61 + 'composio signup signs you up as a Composio agent. This flow is fully non-interactive and does not open a browser.'
62 + );
63 + const stdout = yield* MockConsole.getLines({ stream: 'stdout' });
64 + expect(JSON.parse(stdout.at(-1) ?? '')).toMatchObject({
65 + status: 'READY',
66 + org_id: 'org_agent',
67 + logged_in: true,
68 + });
69 +
70 + const ctx = yield* ComposioUserContext;
71 + expect(Option.getOrUndefined(ctx.data.apiKey)).toBe('uak_agent');
72 + const fs = yield* FileSystem.FileSystem;
73 + const cacheDir = yield* setupCacheDir;
74 + const userConfig = yield* fs.readFileString(
75 + path.join(cacheDir, constants.USER_CONFIG_FILE_NAME),
76 + 'utf8'
77 + );
78 + expect(JSON.parse(userConfig)).toMatchObject({ api_key: 'uak_agent', org_id: 'org_agent' });
79 + })
80 + );
81 + });
82 +
83 + layer(TestLive())('[Given] --no-wait -f', it => {
84 + it.effect('[Then] starts a fresh signup without waiting and stays logged out', () =>
85 + Effect.gen(function* () {
86 + const fetchSpy = stubAgentsApi(pendingIdentity);
87 +
88 + yield* cli(['signup', '--no-wait', '-f']);
89 +
90 + expect(fetchSpy).toHaveBeenCalledExactlyOnceWith(
91 + expect.stringMatching(/\/api\/signup\?wait=0$/),
92 + expect.objectContaining({ method: 'POST' })
93 + );
94 + const stdout = yield* MockConsole.getLines({ stream: 'stdout' });
95 + expect(JSON.parse(stdout.at(-1) ?? '')).toMatchObject({
96 + status: 'PENDING',
97 + logged_in: false,
98 + });
99 + const ctx = yield* ComposioUserContext;
100 + expect(Option.isNone(ctx.data.apiKey)).toBe(true);
101 + })
102 + );
103 + });
104 +
105 + layer(TestLive())('[Given] --no-login', it => {
106 + it.effect('[Then] signs up a ready agent but leaves the CLI logged out', () =>
107 + Effect.gen(function* () {
108 + stubAgentsApi(readyIdentity);
109 +
110 + yield* cli(['signup', '--no-login']);
111 +
112 + const stdout = yield* MockConsole.getLines({ stream: 'stdout' });
113 + expect(JSON.parse(stdout.at(-1) ?? '')).toMatchObject({
114 + status: 'READY',
115 + logged_in: false,
116 + });
117 + const ctx = yield* ComposioUserContext;
118 + expect(Option.isNone(ctx.data.apiKey)).toBe(true);
119 + })
120 + );
121 + });
122 +
123 + layer(TestLive({ fixture: 'user-config-example' }))('[Given] a human login', it => {
124 + it.effect('[Then] warns, exits 1, and signs nothing up', () =>
125 + Effect.gen(function* () {
126 + const fetchSpy = vi.spyOn(globalThis, 'fetch');
127 +
128 + yield* cli(['signup']);
129 +
130 + const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
131 + expect(output).toContain('currently signed in to Composio as a regular user');
132 + expect(process.exitCode).toBe(1);
133 + expect(fetchSpy).not.toHaveBeenCalled();
134 + })
135 + );
136 + });
137 +});
ts/packages/cli/test/src/commands/signup/signup.handler.test.ts new
+92
@@ -0,0 +1,92 @@
1 +import { describe, expect, layer } from '@effect/vitest';
2 +import { Effect } from 'effect';
3 +import { afterEach, vi } from 'vitest';
4 +import { runSignup } from 'src/commands/signup/signup.handler';
5 +import type { AgentIdentity } from 'src/services/agents';
6 +import { TerminalUI } from 'src/services/terminal-ui';
7 +import { MockConsole, TestLive } from 'test/__utils__';
8 +import { terminalUITestImpl } from 'test/__utils__/services/terminal-ui-test';
9 +
10 +const readyIdentity: AgentIdentity = {
11 + status: 'READY',
12 + slug: 'test-agent',
13 + email: 'test-agent@agent.composio.ai',
14 + composio_agent_key: 'cak_test_agent',
15 + composio: {
16 + member_id: 'mem_agent',
17 + org_id: 'org_agent',
18 + project_id: 'proj_agent',
19 + user_api_key: 'uak_agent',
20 + },
21 +};
22 +
23 +/** A headless terminal whose stdout payloads land in `outputs`. */
24 +const capturingTest = () => {
25 + const outputs: Array<{ readonly data: string; readonly force: boolean }> = [];
26 + const terminalUI = TerminalUI.of({
27 + ...terminalUITestImpl,
28 + output: (data, options) =>
29 + Effect.sync(() => {
30 + outputs.push({ data, force: options?.force ?? false });
31 + }),
32 + });
33 + return { outputs, layer: TestLive({ terminalUI }) };
34 +};
35 +
36 +const noLogin = capturingTest();
37 +
38 +describe('runSignup', () => {
39 + afterEach(() => {
40 + vi.restoreAllMocks();
41 + });
42 +
43 + layer(noLogin.layer)(it => {
44 + it.effect(
45 + '[Given] --no-login [Then] names `composio signup` and prints the summary as data',
46 + () =>
47 + Effect.gen(function* () {
48 + vi.spyOn(globalThis, 'fetch').mockImplementation(
49 + async () =>
50 + new Response(JSON.stringify(readyIdentity), {
51 + status: 200,
52 + headers: { 'Content-Type': 'application/json' },
53 + })
54 + );
55 +
56 + yield* runSignup({ noWait: false, noLogin: true, force: false });
57 +
58 + expect(yield* MockConsole.getLines({ stripAnsi: true })).toEqual([
59 + '-- composio signup --',
60 + 'composio signup signs you up as a Composio agent. This flow is fully non-interactive and does not open a browser.',
61 + [
62 + '[Composio Agent] Type: agent',
63 + 'Status: READY',
64 + 'Email: test-agent@agent.composio.ai',
65 + 'Slug: test-agent',
66 + 'Current Org ID: org_agent',
67 + 'Project ID: proj_agent',
68 + 'Agent key: stored in ~/.composio/agent.json',
69 + ].join('\n'),
70 + '-- Agent setup complete. --',
71 + ]);
72 + expect(noLogin.outputs).toEqual([
73 + {
74 + data: JSON.stringify({
75 + account_type: 'agent',
76 + status: 'READY',
77 + slug: 'test-agent',
78 + email: 'test-agent@agent.composio.ai',
79 + org_id: 'org_agent',
80 + project_id: 'proj_agent',
81 + member_id: 'mem_agent',
82 + claimed_by: null,
83 + claimed_at: null,
84 + logged_in: false,
85 + }),
86 + force: false,
87 + },
88 + ]);
89 + })
90 + );
91 + });
92 +});