@devries-cameron20 / composio Mirror · read-only / commits / 8daa6a367
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 the `projects` commands into the directory shape (#4993)

This PR: - moves `dev projects list` from `projects/commands/projects.list.cmd.ts` to `projects/list/projects.list.{cmd,handler,format}.ts`; the command file only declares `--org-id` and `--limit`, passes `runProjectsList` to `Command.make`, and keeps `requireLogin` - moves `dev projects switch` to `projects/switch/projects.switch.{cmd,handler}.ts`; `projects/commands/` no longer exists - replaces the list handler's own "No user API key found" warning with `Effect.fromOption(ctx.data.apiKey, notLoggedIn)`, as #4972 did for `orgs list`. `requireLogin` on the command already rejects a missing key, so through the CLI the branch was unreachable and the logged-out exit is unchanged (`NotLoggedInError`, exit 1). The no-org fallback keeps its exact rule (an explicit `--org-id ""` does not fall back to the stored org) through `Option.orElse` + `Option.filter(String.isNonEmpty)` - moves both tests to mirrored paths and pins the full stdout and stderr: logged out, `--org-id`, current-org fallback with `--limit` clamping, no current org, no projects. Adds `projects.list.handler.test.ts` (org precedence, empty-org table, clamp table, empty list, missing key) and `projects.switch.handler.test.ts` over `Service.of` doubles and `layers/shadow-client.ts` - part of the CLI command-layout series (legacy-shape cleanup before U10); no user-visible change, so no CHANGELOG entry ## Context Verified: the new `.cmd.test.ts` suites pass unchanged against the `origin/next` (c37b41dd8) source before the move. On the branch tip: `pnpm --filter @composio/cli typecheck` passes; `pnpm --filter @composio/cli test` 189 files, 2057 passed, 1 skipped, `validate:command-tests` at 2 exemptions (unchanged), `root-help-consistency.test.ts` green; `lint:effect` 0 diagnostics; `oxlint` and prettier clean on touched files; root `pnpm typecheck` passes. Binary smoke (isolated `HOME`, developer mode on, telemetry off): 21 invocations covering root/`orgs`/`dev`/`dev projects` `--help`, logged-out `dev projects list` and `switch`, `--user-id`/`--project-name` rejections, and logged-in `dev projects list` (no org), `dev projects switch`, `orgs switch --org-id`. stdout, stderr, exit codes, and the resulting `user_data.json` and `config.json` are byte-identical to an `origin/next` binary, apart from minified function names in one stack trace for an expected connection failure.

Alberto Schiabel committed Oct 20, 2026 at 19:12 UTC 8daa6a367a6638c6ca7ee8ca79fe67d9d5049b2a
13 files changed +513 -154
ts/packages/cli/src/commands/projects/commands/projects.list.cmd.ts deleted
-83
@@ -1,83 +0,0 @@
1 -import { requireLogin } from 'src/effects/require-auth';
2 -import { Command, Flag } from 'effect/cli';
3 -import { Effect, Option } from 'effect';
4 -import { TerminalUI } from 'src/services/terminal-ui';
5 -import { listOrganizationProjects } from 'src/services/composio-account';
6 -import { ComposioUserContext } from 'src/services/user-context';
7 -import { clampLimit } from 'src/ui/clamp-limit';
8 -
9 -const orgId = Flag.String('org-id').pipe(
10 - Flag.optional,
11 - Flag.withDescription('Organization ID to list projects for (defaults to current global org)')
12 -);
13 -
14 -const limit = Flag.Int('limit').pipe(
15 - Flag.withDefault(50),
16 - Flag.withDescription('Max projects to fetch from API (default: 50)')
17 -);
18 -
19 -export const projectsCmd$List = Command.make('list', { orgId, limit }, ({ orgId, limit }) =>
20 - Effect.gen(function* () {
21 - const ui = yield* TerminalUI;
22 - const ctx = yield* ComposioUserContext;
23 - yield* ui.intro('composio dev projects list');
24 - const apiKey = Option.getOrUndefined(ctx.data.apiKey);
25 - if (!apiKey) {
26 - yield* ui.log.warn('No user API key found. Run `composio login` first.');
27 - return;
28 - }
29 -
30 - const resolvedOrgId = Option.getOrUndefined(Option.orElse(orgId, () => ctx.data.orgId));
31 - if (!resolvedOrgId) {
32 - yield* ui.log.warn('No current org is configured.');
33 - yield* ui.outro('Hint: run `composio orgs switch` first, or pass `--org-id`.');
34 - return;
35 - }
36 -
37 - const clampedLimit = clampLimit(limit);
38 - const projects = yield* ui.withSpinner(
39 - 'Loading projects...',
40 - listOrganizationProjects({
41 - apiKey,
42 - orgId: resolvedOrgId,
43 - limit: clampedLimit,
44 - }),
45 - {
46 - successMessage: result => `Loaded ${result.data.length} projects`,
47 - errorMessage: 'Failed to fetch projects',
48 - }
49 - );
50 -
51 - if (projects.data.length === 0) {
52 - yield* ui.log.warn('No projects found.');
53 - yield* ui.outro(
54 - 'Hint: run `composio dev init` in a directory to bind it to a developer project.'
55 - );
56 - return;
57 - }
58 -
59 - const lines = projects.data.map(project => {
60 - return ` ${project.name} (${project.id})`;
61 - });
62 - yield* ui.log.step(lines.join('\n'));
63 - yield* ui.outro(
64 - [
65 - 'Hint: run `composio dev init` in a directory to bind it to a developer project.',
66 - 'Run `composio orgs switch` to change your current org.',
67 - ].join('\n')
68 - );
69 -
70 - yield* ui.output(
71 - JSON.stringify(
72 - projects.data.map(project => ({
73 - id: project.id,
74 - name: project.name,
75 - is_selected_global_project: false,
76 - }))
77 - )
78 - );
79 - })
80 -).pipe(
81 - Command.withDescription('List developer projects for the current organization.'),
82 - requireLogin
83 -);
ts/packages/cli/src/commands/projects/commands/projects.switch.cmd.ts deleted
-15
@@ -1,15 +0,0 @@
1 -import { Command } from 'effect/cli';
2 -import { Effect } from 'effect';
3 -import { TerminalUI } from 'src/services/terminal-ui';
4 -
5 -export const projectsCmd$Switch = Command.make('switch', {}).pipe(
6 - Command.withDescription('Switch the developer project for this directory.'),
7 - Command.withHandler(() =>
8 - Effect.gen(function* () {
9 - const ui = yield* TerminalUI;
10 - yield* ui.log.info(
11 - 'Global developer project switching is no longer supported. Run `composio dev init` in a directory to bind it to a developer project.'
12 - );
13 - })
14 - )
15 -);
ts/packages/cli/src/commands/projects/list/projects.list.cmd.ts new
+18
@@ -0,0 +1,18 @@
1 +import { Command, Flag } from 'effect/cli';
2 +import { requireLogin } from 'src/effects/require-auth';
3 +import { runProjectsList } from './projects.list.handler';
4 +
5 +const orgId = Flag.String('org-id').pipe(
6 + Flag.optional,
7 + Flag.withDescription('Organization ID to list projects for (defaults to current global org)')
8 +);
9 +
10 +const limit = Flag.Int('limit').pipe(
11 + Flag.withDefault(50),
12 + Flag.withDescription('Max projects to fetch from API (default: 50)')
13 +);
14 +
15 +export const projectsCmd$List = Command.make('list', { orgId, limit }, runProjectsList).pipe(
16 + Command.withDescription('List developer projects for the current organization.'),
17 + requireLogin
18 +);
ts/packages/cli/src/commands/projects/list/projects.list.format.ts new
+39
@@ -0,0 +1,39 @@
1 +import type { OrganizationSummary } from 'src/services/composio-account';
2 +
3 +// --- stderr -----------------------------------------------------------------------------------
4 +
5 +export const PROJECTS_LIST_INTRO = 'composio dev projects list';
6 +export const NO_CURRENT_ORG_MESSAGE = 'No current org is configured.';
7 +export const NO_CURRENT_ORG_OUTRO = 'Hint: run `composio orgs switch` first, or pass `--org-id`.';
8 +export const LOADING_PROJECTS_MESSAGE = 'Loading projects...';
9 +export const FETCH_PROJECTS_FAILED_MESSAGE = 'Failed to fetch projects';
10 +export const NO_PROJECTS_MESSAGE = 'No projects found.';
11 +
12 +const INIT_HINT = 'Hint: run `composio dev init` in a directory to bind it to a developer project.';
13 +
14 +export const NO_PROJECTS_OUTRO = INIT_HINT;
15 +export const PROJECTS_LIST_OUTRO = [
16 + INIT_HINT,
17 + 'Run `composio orgs switch` to change your current org.',
18 +].join('\n');
19 +
20 +export const loadedProjectsMessage = (count: number) => `Loaded ${count} projects`;
21 +
22 +/** One indented line per project. */
23 +export const formatProjectLines = (projects: ReadonlyArray<OrganizationSummary>) =>
24 + projects.map(project => ` ${project.name} (${project.id})`).join('\n');
25 +
26 +// --- stdout -----------------------------------------------------------------------------------
27 +
28 +/**
29 + * The projects as JSON. No project is ever the selected global one, since the CLI binds
30 + * developer projects per directory.
31 + */
32 +export const formatProjectsJson = (projects: ReadonlyArray<OrganizationSummary>) =>
33 + JSON.stringify(
34 + projects.map(project => ({
35 + id: project.id,
36 + name: project.name,
37 + is_selected_global_project: false,
38 + }))
39 + );
ts/packages/cli/src/commands/projects/list/projects.list.handler.ts new
+74
@@ -0,0 +1,74 @@
1 +import { Array as Arr, Effect, Option, String as Str } from 'effect';
2 +import { notLoggedIn } from 'src/commands/errors';
3 +import { listOrganizationProjects } from 'src/services/composio-account';
4 +import { TerminalUI } from 'src/services/terminal-ui';
5 +import { ComposioUserContext } from 'src/services/user-context';
6 +import { clampLimit } from 'src/ui/clamp-limit';
7 +import {
8 + FETCH_PROJECTS_FAILED_MESSAGE,
9 + LOADING_PROJECTS_MESSAGE,
10 + NO_CURRENT_ORG_MESSAGE,
11 + NO_CURRENT_ORG_OUTRO,
12 + NO_PROJECTS_MESSAGE,
13 + NO_PROJECTS_OUTRO,
14 + PROJECTS_LIST_INTRO,
15 + PROJECTS_LIST_OUTRO,
16 + formatProjectLines,
17 + formatProjectsJson,
18 + loadedProjectsMessage,
19 +} from './projects.list.format';
20 +
21 +/** The flags of `composio dev projects list`. */
22 +export type ProjectsListParams = {
23 + readonly orgId: Option.Option<string>;
24 + readonly limit: number;
25 +};
26 +
27 +/** Lists the developer projects of `--org-id`, or of the current global org. */
28 +export const runProjectsList = ({ orgId, limit }: ProjectsListParams) =>
29 + Effect.gen(function* () {
30 + const ui = yield* TerminalUI;
31 + const ctx = yield* ComposioUserContext;
32 + // `requireLogin` on the command has already proven the key is there.
33 + const apiKey = yield* Effect.fromOption(ctx.data.apiKey, notLoggedIn);
34 +
35 + yield* ui.intro(PROJECTS_LIST_INTRO);
36 +
37 + // An explicit `--org-id ""` does not fall back to the current org.
38 + const resolvedOrgId = Option.orElse(orgId, () => ctx.data.orgId).pipe(
39 + Option.filter(Str.isNonEmpty)
40 + );
41 +
42 + yield* Option.match(resolvedOrgId, {
43 + onNone: () =>
44 + Effect.gen(function* () {
45 + yield* ui.log.warn(NO_CURRENT_ORG_MESSAGE);
46 + yield* ui.outro(NO_CURRENT_ORG_OUTRO);
47 + }),
48 + onSome: resolvedOrgId =>
49 + Effect.gen(function* () {
50 + const projects = yield* ui.withSpinner(
51 + LOADING_PROJECTS_MESSAGE,
52 + listOrganizationProjects({ apiKey, orgId: resolvedOrgId, limit: clampLimit(limit) }),
53 + {
54 + successMessage: result => loadedProjectsMessage(result.data.length),
55 + errorMessage: FETCH_PROJECTS_FAILED_MESSAGE,
56 + }
57 + );
58 +
59 + yield* Arr.match(projects.data, {
60 + onEmpty: () =>
61 + Effect.gen(function* () {
62 + yield* ui.log.warn(NO_PROJECTS_MESSAGE);
63 + yield* ui.outro(NO_PROJECTS_OUTRO);
64 + }),
65 + onNonEmpty: data =>
66 + Effect.gen(function* () {
67 + yield* ui.log.step(formatProjectLines(data));
68 + yield* ui.outro(PROJECTS_LIST_OUTRO);
69 + yield* ui.output(formatProjectsJson(data));
70 + }),
71 + });
72 + }),
73 + });
74 + });
ts/packages/cli/src/commands/projects/projects.cmd.ts
+2 -2
@@ -1,6 +1,6 @@
1 import { Command } from 'effect/cli';
2 -import { projectsCmd$List } from './commands/projects.list.cmd';
3 -import { projectsCmd$Switch } from './commands/projects.switch.cmd';
2 +import { projectsCmd$List } from './list/projects.list.cmd';
3 +import { projectsCmd$Switch } from './switch/projects.switch.cmd';
4
5 /**
6 * CLI entry point for project context commands.
ts/packages/cli/src/commands/projects/switch/projects.switch.cmd.ts new
+6
@@ -0,0 +1,6 @@
1 +import { Command } from 'effect/cli';
2 +import { runProjectsSwitch } from './projects.switch.handler';
3 +
4 +export const projectsCmd$Switch = Command.make('switch', {}, runProjectsSwitch).pipe(
5 + Command.withDescription('Switch the developer project for this directory.')
6 +);
ts/packages/cli/src/commands/projects/switch/projects.switch.handler.ts new
+15
@@ -0,0 +1,15 @@
1 +import { Effect } from 'effect';
2 +import { TerminalUI } from 'src/services/terminal-ui';
3 +
4 +export const PROJECTS_SWITCH_UNSUPPORTED_MESSAGE =
5 + 'Global developer project switching is no longer supported. Run `composio dev init` in a directory to bind it to a developer project.';
6 +
7 +/**
8 + * Points the user at `composio dev init`: developer projects are bound per directory, so there
9 + * is no global project to switch and nothing is written.
10 + */
11 +export const runProjectsSwitch = () =>
12 + Effect.gen(function* () {
13 + const ui = yield* TerminalUI;
14 + yield* ui.log.info(PROJECTS_SWITCH_UNSUPPORTED_MESSAGE);
15 + });
ts/packages/cli/test/src/commands/projects/list/projects.list.cmd.test.ts new
+155
@@ -0,0 +1,155 @@
1 +import { ConfigProvider, Effect } from 'effect';
2 +import { describe, expect, layer } from '@effect/vitest';
3 +import { cli, MockConsole, TestLive } from 'test/__utils__';
4 +import { makeOrgProject } from 'test/__utils__/models/account';
5 +import type { MockAccountRequest } from 'test/__utils__/services/test-layer';
6 +
7 +// The fixture stores a login whose current org is `org_1`.
8 +const LOGGED_IN_FIXTURE = 'user-config-with-global-context';
9 +
10 +const PROJECTS = [
11 + makeOrgProject({ id: 'project_1', name: 'Project One', orgId: 'org_1' }),
12 + makeOrgProject({ id: 'project_2', name: 'Project Two', orgId: 'org_1' }),
13 +];
14 +
15 +describe('CLI: composio dev projects list', () => {
16 + layer(TestLive())('[Given] no API key', it => {
17 + it.effect('[Then] fails with NotLoggedInError', () =>
18 + Effect.gen(function* () {
19 + const error = yield* cli(['dev', 'projects', 'list']).pipe(Effect.flip);
20 + expect(error).toMatchObject({ _tag: 'commands/NotLoggedInError' });
21 + })
22 + );
23 + });
24 +
25 + const requests: MockAccountRequest[] = [];
26 +
27 + layer(
28 + TestLive({
29 + fixture: LOGGED_IN_FIXTURE,
30 + accountData: {
31 + projects: PROJECTS,
32 + onRequest: request => requests.push(request),
33 + },
34 + })
35 + )(it => {
36 + it.effect('[Then] lists developer projects and shows init guidance', () =>
37 + Effect.gen(function* () {
38 + yield* cli(['dev', 'projects', 'list', '--org-id', 'org_1']);
39 +
40 + expect(requests).toEqual([
41 + expect.objectContaining({
42 + operation: 'org.project.list',
43 + params: { limit: 50 },
44 + scope: expect.objectContaining({ userApiKey: 'uak_test_key', orgId: 'org_1' }),
45 + }),
46 + ]);
47 + expect(requests[0]?.scope.projectId).toBeUndefined();
48 +
49 + const lines = yield* MockConsole.getLines({ stripAnsi: true });
50 + const output = lines.join('\n');
51 + expect(output).toContain('Loaded 2 projects');
52 + expect(output).toContain('Project One (project_1)');
53 + expect(output).toContain('Project Two (project_2)');
54 + expect(JSON.parse(String(lines.at(-1)))).toEqual([
55 + { id: 'project_1', name: 'Project One', is_selected_global_project: false },
56 + { id: 'project_2', name: 'Project Two', is_selected_global_project: false },
57 + ]);
58 + expect(output).toContain(
59 + 'Hint: run `composio dev init` in a directory to bind it to a developer project.'
60 + );
61 + expect(output).toContain('Run `composio orgs switch` to change your current org.');
62 + })
63 + );
64 + });
65 +
66 + const currentOrgRequests: MockAccountRequest[] = [];
67 +
68 + layer(
69 + TestLive({
70 + fixture: LOGGED_IN_FIXTURE,
71 + accountData: {
72 + projects: PROJECTS,
73 + onRequest: request => currentOrgRequests.push(request),
74 + },
75 + })
76 + )('[Given] no --org-id', it => {
77 + it.effect(
78 + '[Then] lists the projects of the current org, data on stdout and decoration on stderr',
79 + () =>
80 + Effect.gen(function* () {
81 + yield* cli(['dev', 'projects', 'list', '--limit', '5000']);
82 +
83 + expect(currentOrgRequests).toEqual([
84 + expect.objectContaining({
85 + operation: 'org.project.list',
86 + params: { limit: 1000 },
87 + scope: expect.objectContaining({ orgId: 'org_1' }),
88 + }),
89 + ]);
90 +
91 + const stdout = yield* MockConsole.getLines({ stream: 'stdout' });
92 + const stderr = yield* MockConsole.getLines({ stream: 'stderr', stripAnsi: true });
93 + expect(stdout).toEqual([
94 + JSON.stringify([
95 + { id: 'project_1', name: 'Project One', is_selected_global_project: false },
96 + { id: 'project_2', name: 'Project Two', is_selected_global_project: false },
97 + ]),
98 + ]);
99 + expect(stderr).toEqual([
100 + '-- composio dev projects list --',
101 + 'Loaded 2 projects',
102 + ' Project One (project_1)\n Project Two (project_2)',
103 + '-- Hint: run `composio dev init` in a directory to bind it to a developer project.\nRun `composio orgs switch` to change your current org. --',
104 + ]);
105 + })
106 + );
107 + });
108 +
109 + const noOrgRequests: MockAccountRequest[] = [];
110 +
111 + layer(
112 + TestLive({
113 + // Logged in through the environment, so no current org is stored.
114 + baseConfigProvider: ConfigProvider.fromEnvRecord({ COMPOSIO_USER_API_KEY: 'uak_no_org' }),
115 + accountData: { projects: PROJECTS, onRequest: request => noOrgRequests.push(request) },
116 + })
117 + )('[Given] no --org-id and no current org', it => {
118 + it.effect('[Then] warns with the `orgs switch` hint and sends no request', () =>
119 + Effect.gen(function* () {
120 + yield* cli(['dev', 'projects', 'list']);
121 +
122 + const stdout = yield* MockConsole.getLines({ stream: 'stdout' });
123 + const stderr = yield* MockConsole.getLines({ stream: 'stderr', stripAnsi: true });
124 + expect(noOrgRequests).toEqual([]);
125 + expect(stdout).toEqual([]);
126 + expect(stderr).toEqual([
127 + '-- composio dev projects list --',
128 + 'No current org is configured.',
129 + '-- Hint: run `composio orgs switch` first, or pass `--org-id`. --',
130 + ]);
131 + })
132 + );
133 + });
134 +
135 + layer(TestLive({ fixture: LOGGED_IN_FIXTURE, accountData: { projects: [] } }))(
136 + '[Given] an org without projects',
137 + it => {
138 + it.effect('[Then] warns, points at `dev init`, and prints no data', () =>
139 + Effect.gen(function* () {
140 + yield* cli(['dev', 'projects', 'list']);
141 +
142 + const stdout = yield* MockConsole.getLines({ stream: 'stdout' });
143 + const stderr = yield* MockConsole.getLines({ stream: 'stderr', stripAnsi: true });
144 + expect(stdout).toEqual([]);
145 + expect(stderr).toEqual([
146 + '-- composio dev projects list --',
147 + 'Loaded 0 projects',
148 + 'No projects found.',
149 + '-- Hint: run `composio dev init` in a directory to bind it to a developer project. --',
150 + ]);
151 + })
152 + );
153 + }
154 + );
155 +});
ts/packages/cli/test/src/commands/projects/list/projects.list.handler.test.ts new
+162
@@ -0,0 +1,162 @@
1 +import { describe, expect, it } from '@effect/vitest';
2 +import { Console, Effect, Layer, Option } from 'effect';
3 +import { runProjectsList } from 'src/commands/projects/list/projects.list.handler';
4 +import {
5 + NO_CURRENT_ORG_MESSAGE,
6 + NO_PROJECTS_MESSAGE,
7 +} from 'src/commands/projects/list/projects.list.format';
8 +import type { OrgProject } from 'src/services/composio-account';
9 +import { ComposioClientSingleton } from 'src/services/composio-clients';
10 +import { TerminalUI } from 'src/services/terminal-ui';
11 +import { ComposioUserContext } from 'src/services/user-context';
12 +import { MockConsole } from 'test/__utils__';
13 +import type { MockAccountRequest, MockRequestScope } from 'test/__utils__/layers/accounts';
14 +import { makeShadowClient } from 'test/__utils__/layers/shadow-client';
15 +import { makeOrgProject } from 'test/__utils__/models/account';
16 +import { terminalUITestImpl } from 'test/__utils__/services/terminal-ui-test';
17 +
18 +const PROJECTS: ReadonlyArray<OrgProject> = [
19 + makeOrgProject({ id: 'project_a', name: 'Project A', orgId: 'org_current' }),
20 + makeOrgProject({ id: 'project_b', name: 'Project B', orgId: 'org_current' }),
21 +];
22 +
23 +interface ProjectsListFixture {
24 + readonly apiKey?: Option.Option<string>;
25 + readonly orgId?: Option.Option<string>;
26 + readonly projects?: ReadonlyArray<OrgProject>;
27 +}
28 +
29 +/**
30 + * What `runProjectsList` reads: a user context, the account family of the mock client, and a
31 + * headless terminal whose stdout data lands in `outputs` and whose `org.project.list` requests
32 + * land in `requests`.
33 + */
34 +const projectsListTest = (fixture: ProjectsListFixture = {}) => {
35 + const outputs: Array<string> = [];
36 + const requests: Array<MockAccountRequest> = [];
37 + const apiKey = fixture.apiKey ?? Option.some('uak_projects_list');
38 + const accountData = {
39 + projects: fixture.projects ?? PROJECTS,
40 + onRequest: (request: MockAccountRequest) => {
41 + requests.push(request);
42 + },
43 + };
44 +
45 + const layer = Layer.mergeAll(
46 + Layer.effect(Console.Console, MockConsole.make),
47 + Layer.succeed(
48 + TerminalUI,
49 + TerminalUI.of({
50 + ...terminalUITestImpl,
51 + output: data =>
52 + Effect.sync(() => {
53 + outputs.push(data);
54 + }),
55 + })
56 + ),
57 + Layer.succeed(
58 + ComposioUserContext,
59 + ComposioUserContext.of({
60 + data: {
61 + apiKey,
62 + baseURL: 'https://mock.invalid',
63 + webURL: 'https://platform.mock.invalid/',
64 + orgId: fixture.orgId ?? Option.some('org_current'),
65 + projectId: Option.none(),
66 + testUserId: Option.none(),
67 + },
68 + isLoggedIn: () => Option.isSome(apiKey),
69 + logout: Effect.void,
70 + login: () => Effect.void,
71 + update: () => Effect.void,
72 + })
73 + ),
74 + Layer.succeed(
75 + ComposioClientSingleton,
76 + ComposioClientSingleton.of({
77 + get: () => Effect.succeed(makeShadowClient(accountData, {})),
78 + getFor: (scope: MockRequestScope) => Effect.succeed(makeShadowClient(accountData, scope)),
79 + getMetrics: () => Effect.succeed({ byteSize: 0, requests: 0 }),
80 + })
81 + )
82 + );
83 + return { layer, outputs, requests };
84 +};
85 +
86 +describe('runProjectsList', () => {
87 + it.effect('[Given] no --org-id [Then] lists the projects of the current org', () => {
88 + const { layer, outputs, requests } = projectsListTest();
89 + return Effect.gen(function* () {
90 + yield* runProjectsList({ orgId: Option.none(), limit: 50 });
91 +
92 + expect(requests.map(request => request.scope.orgId)).toEqual(['org_current']);
93 + expect(outputs.map(output => JSON.parse(output))).toEqual([
94 + [
95 + { id: 'project_a', name: 'Project A', is_selected_global_project: false },
96 + { id: 'project_b', name: 'Project B', is_selected_global_project: false },
97 + ],
98 + ]);
99 + }).pipe(Effect.provide(layer));
100 + });
101 +
102 + it.effect('[Given] --org-id [Then] it wins over the current org', () => {
103 + const { layer, requests } = projectsListTest();
104 + return Effect.gen(function* () {
105 + yield* runProjectsList({ orgId: Option.some('org_explicit'), limit: 50 });
106 +
107 + expect(requests.map(request => request.scope.orgId)).toEqual(['org_explicit']);
108 + }).pipe(Effect.provide(layer));
109 + });
110 +
111 + it.effect.each([
112 + { orgId: Option.none<string>(), current: Option.none<string>(), label: 'no org at all' },
113 + { orgId: Option.some(''), current: Option.some('org_current'), label: 'an empty --org-id' },
114 + { orgId: Option.none<string>(), current: Option.some(''), label: 'an empty current org' },
115 + ])('[Given] $label [Then] warns and sends no request', ({ orgId, current }) => {
116 + const { layer, outputs, requests } = projectsListTest({ orgId: current });
117 + return Effect.gen(function* () {
118 + yield* runProjectsList({ orgId, limit: 50 });
119 +
120 + expect(requests).toEqual([]);
121 + expect(outputs).toEqual([]);
122 + expect(yield* MockConsole.getLines({ stream: 'stderr' })).toContain(NO_CURRENT_ORG_MESSAGE);
123 + }).pipe(Effect.provide(layer));
124 + });
125 +
126 + it.effect.each([
127 + { limit: 50, expected: 50 },
128 + { limit: 0, expected: 1 },
129 + { limit: -3, expected: 1 },
130 + { limit: 1001, expected: 1000 },
131 + ])('[Given] limit $limit [Then] requests $expected projects', ({ limit, expected }) => {
132 + const { layer, requests } = projectsListTest();
133 + return Effect.gen(function* () {
134 + yield* runProjectsList({ orgId: Option.none(), limit });
135 +
136 + expect(requests.map(request => request.params)).toEqual([{ limit: expected }]);
137 + }).pipe(Effect.provide(layer));
138 + });
139 +
140 + it.effect('[Given] no projects [Then] warns and outputs nothing', () => {
141 + const { layer, outputs } = projectsListTest({ projects: [] });
142 + return Effect.gen(function* () {
143 + yield* runProjectsList({ orgId: Option.none(), limit: 50 });
144 +
145 + expect(outputs).toEqual([]);
146 + expect(yield* MockConsole.getLines({ stream: 'stderr' })).toEqual([NO_PROJECTS_MESSAGE]);
147 + }).pipe(Effect.provide(layer));
148 + });
149 +
150 + it.effect(
151 + '[Given] no stored API key [Then] fails with NotLoggedInError before any request',
152 + () => {
153 + const { layer, requests } = projectsListTest({ apiKey: Option.none() });
154 + return Effect.gen(function* () {
155 + const error = yield* Effect.flip(runProjectsList({ orgId: Option.none(), limit: 50 }));
156 +
157 + expect(error).toMatchObject({ _tag: 'commands/NotLoggedInError' });
158 + expect(requests).toEqual([]);
159 + }).pipe(Effect.provide(layer));
160 + }
161 + );
162 +});
ts/packages/cli/test/src/commands/projects/projects.list.cmd.test.ts deleted
-51
@@ -1,51 +0,0 @@
1 -import { Effect } from 'effect';
2 -import { describe, expect, layer } from '@effect/vitest';
3 -import { cli, MockConsole, TestLive } from 'test/__utils__';
4 -import { makeOrgProject } from 'test/__utils__/models/account';
5 -import type { MockAccountRequest } from 'test/__utils__/services/test-layer';
6 -
7 -describe('CLI: composio dev projects list', () => {
8 - const requests: MockAccountRequest[] = [];
9 -
10 - layer(
11 - TestLive({
12 - fixture: 'user-config-with-global-context',
13 - accountData: {
14 - projects: [
15 - makeOrgProject({ id: 'project_1', name: 'Project One', orgId: 'org_1' }),
16 - makeOrgProject({ id: 'project_2', name: 'Project Two', orgId: 'org_1' }),
17 - ],
18 - onRequest: request => requests.push(request),
19 - },
20 - })
21 - )(it => {
22 - it.effect('[Then] lists developer projects and shows init guidance', () =>
23 - Effect.gen(function* () {
24 - yield* cli(['dev', 'projects', 'list', '--org-id', 'org_1']);
25 -
26 - expect(requests).toEqual([
27 - expect.objectContaining({
28 - operation: 'org.project.list',
29 - params: { limit: 50 },
30 - scope: expect.objectContaining({ userApiKey: 'uak_test_key', orgId: 'org_1' }),
31 - }),
32 - ]);
33 - expect(requests[0]?.scope.projectId).toBeUndefined();
34 -
35 - const lines = yield* MockConsole.getLines({ stripAnsi: true });
36 - const output = lines.join('\n');
37 - expect(output).toContain('Loaded 2 projects');
38 - expect(output).toContain('Project One (project_1)');
39 - expect(output).toContain('Project Two (project_2)');
40 - expect(JSON.parse(String(lines.at(-1)))).toEqual([
41 - { id: 'project_1', name: 'Project One', is_selected_global_project: false },
42 - { id: 'project_2', name: 'Project Two', is_selected_global_project: false },
43 - ]);
44 - expect(output).toContain(
45 - 'Hint: run `composio dev init` in a directory to bind it to a developer project.'
46 - );
47 - expect(output).toContain('Run `composio orgs switch` to change your current org.');
48 - })
49 - );
50 - });
51 -});
ts/packages/cli/test/src/commands/projects/switch/projects.switch.cmd.test.ts renamed
+8 -3
@@ -6,9 +6,14 @@ describe('CLI: composio dev projects switch', () => {
6 layer(TestLive({ cliUserConfig: { developerDangerousCommandsEnabled: true } }))(it => {
7 it.effect('[Then] it reports global developer project switching is deprecated', () =>
8 Effect.gen(function* () {
9 - yield* cli(['dev', 'projects', 'switch']).pipe(Effect.catch(() => Effect.void));
10 - const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
11 - expect(output).toMatch(/composio dev init/);
9 + yield* cli(['dev', 'projects', 'switch']);
10 +
11 + const stdout = yield* MockConsole.getLines({ stream: 'stdout' });
12 + const stderr = yield* MockConsole.getLines({ stream: 'stderr', stripAnsi: true });
13 + expect(stdout).toEqual([]);
14 + expect(stderr).toEqual([
15 + 'Global developer project switching is no longer supported. Run `composio dev init` in a directory to bind it to a developer project.',
16 + ]);
17 })
18 );
19 });
ts/packages/cli/test/src/commands/projects/switch/projects.switch.handler.test.ts new
+34
@@ -0,0 +1,34 @@
1 +import { describe, expect, it } from '@effect/vitest';
2 +import { Console, Effect, Layer } from 'effect';
3 +import {
4 + PROJECTS_SWITCH_UNSUPPORTED_MESSAGE,
5 + runProjectsSwitch,
6 +} from 'src/commands/projects/switch/projects.switch.handler';
7 +import { TerminalUI } from 'src/services/terminal-ui';
8 +import { MockConsole } from 'test/__utils__';
9 +import { terminalUITestImpl } from 'test/__utils__/services/terminal-ui-test';
10 +
11 +describe('runProjectsSwitch', () => {
12 + it.effect('[Then] logs the `composio dev init` pointer and outputs no data', () => {
13 + const outputs: Array<string> = [];
14 + const layer = Layer.mergeAll(
15 + Layer.effect(Console.Console, MockConsole.make),
16 + Layer.succeed(
17 + TerminalUI,
18 + TerminalUI.of({
19 + ...terminalUITestImpl,
20 + output: data =>
21 + Effect.sync(() => {
22 + outputs.push(data);
23 + }),
24 + })
25 + )
26 + );
27 + return Effect.gen(function* () {
28 + yield* runProjectsSwitch();
29 +
30 + expect(outputs).toEqual([]);
31 + expect(yield* MockConsole.getLines()).toEqual([PROJECTS_SWITCH_UNSUPPORTED_MESSAGE]);
32 + }).pipe(Effect.provide(layer));
33 + });
34 +});