@devries-cameron20 / composio-1 / commits / 17f2ee889
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): exit 1 on bad input to auth-configs, tools info, triggers (#4998)

This PR: - breaking: these commands now fail with `CommandInputError` (exit 1, message on stderr, nothing on stdout, no request sent) instead of warning and exiting 0: - `dev auth-configs info` without `<id>` - `dev auth-configs create` with `--custom-credentials` that is not a JSON object - `tools info` without `<slug>` - `dev triggers create` without `<trigger-name>`, or with `--trigger-config` that is invalid JSON or not a JSON object - `dev triggers enable` without `<id>` - keeps each message and its example text; the example moves into the error message after a newline, since `cli-main.ts` prints a `CommandInputError` as plain stderr text rather than as a clack warning plus step (the `composio run` usage error already does this) - rewrites the handler and command tests that asserted the warning and exit 0: each now asserts the `commands/CommandInputError` tag, `command`, `option` and message, `isUsageFailure` (the `cli-main.ts` exit-1 path), empty output, and a repository whose every method dies; every new case fails without its fix - adds an entry under `## Unreleased` in `ts/packages/cli/CHANGELOG.md` ## Context A missing argument or malformed JSON flag is a usage error, but these five handlers returned normally, so scripts and agents that check `$?` could not tell a typo from success. When stderr is not a TTY it was worse: the old warning was clack decoration, so a piped run printed nothing at all and exited 0. The fix uses `CommandInputError` from `src/commands/errors.ts`, the error every other handler-level usage mistake already raises. `dev triggers disable` has the same missing-`<id>` path, behind its two gates; it is left for a follow-up along with the other cases below, to keep this PR to the five agreed commands. Verified on the merged head: CLI `pnpm run typecheck`, `lint:effect` (0 diagnostics), `pnpm run test` (192 files, 2071 passed; `validate:command-tests` still at 2 exemptions), `oxlint` (no findings in changed files), prettier, and root `pnpm typecheck`. Binary smoke test (`build:binary`, isolated `HOME`, fake `COMPOSIO_USER_API_KEY`, `COMPOSIO_BASE_URL=http://127.0.0.1:9`), comparing a binary built from the base with these handlers reverted against this branch: | Invocation | Before | After | | --- | --- | --- | | `dev auth-configs info` | exit 0, stderr empty when piped | exit 1, `Missing required argument: <id>` + example | | `dev auth-configs create … --custom-credentials '{bad'` / `'["x"]'` | exit 0 | exit 1, `Invalid JSON in --custom-credentials. …` + example | | `tools info` | exit 0 | exit 1, `Missing required argument: <slug>` + example | | `dev triggers create` | exit 0 | exit 1, `Missing required argument: <trigger-name>` + example | | `dev triggers create X --trigger-config '{'` / `'[1]'` | exit 0 | exit 1, `Invalid JSON in --trigger-config. …` / `--trigger-config must be a JSON object …` | | `dev triggers enable` | exit 0 | exit 1, `Missing required argument: <id>` + example | stdout was 0 bytes in every failing case. The valid invocations (`auth-configs info ac_123`, `auth-configs create` with valid JSON, `tools info GMAIL_SEND_EMAIL`, `triggers create` with a JSON object, `triggers enable trg_123`) produce byte-identical stderr and exit codes before and after (they reach the unreachable API and report it with the usual hint). Other handlers that still warn and exit 0 on invalid input, not changed here: `dev triggers disable` (no `<id>`), `dev triggers info` and `toolkits info` (no `<slug>`), `dev connected-accounts info` and `whoami` (no `<id>`), `connections remove` (selector that matches no account; #4817 owns that file), and the missing-login or missing-org checks in `orgs switch`, `dev projects list` and `init`.

Alberto Schiabel committed Oct 20, 2026 at 20:03 UTC 17f2ee889d82156e1b0f783ea802dcc5f13fd228
14 files changed +211 -150
ts/packages/cli/CHANGELOG.md
+10
@@ -27,6 +27,16 @@
27 `COMPOSIO_DISABLE_TELEMETRY`, or `CI`): when telemetry is off, or no install
28 ID is stored, the header is not sent. It is never sent to the backend API.
29
30 +- These commands now exit 1 instead of 0 when their input is missing or
31 + invalid, printing the same message and example on stderr and nothing on
32 + stdout. No request is sent.
33 + - `composio dev auth-configs info` without an `<id>`
34 + - `composio dev auth-configs create` with `--custom-credentials` that is not
35 + a JSON object
36 + - `composio tools info` without a `<slug>`
37 + - `composio dev triggers create` without a `<trigger-name>`, or with
38 + `--trigger-config` that is not a JSON object
39 + - `composio dev triggers enable` without an `<id>`
40 - `composio link` and `composio dev connected-accounts link` reword their usage
41 and status messages on stderr: the rejected `--auth-config` on the root
42 command, a toolkit passed together with `--auth-config`, a missing toolkit,
ts/packages/cli/src/commands/auth-configs/create/auth-configs.create.handler.ts
+8 -6
@@ -1,5 +1,6 @@
1 import type { AuthConfigCreateParams as AuthConfigCreateRequest } from '@composio/client/resources/auth-configs';
2 import { Effect, Option, Result } from 'effect';
3 +import { commandInputError } from 'src/commands/errors';
4 import { handleClientApiError } from 'src/effects/handle-http-error';
5 import { ComposioToolkitsRepository } from 'src/services/composio-clients';
6 import { CLIENT_API_ERROR_TAGS } from 'src/services/composio-errors';
@@ -73,10 +74,12 @@ export const buildAuthConfigCreateRequest = (input: {
74 }),
75 });
76
77 +const invalidInput = commandInputError('dev auth-configs create');
78 +
79 /**
80 * Create an auth config: the summary on stderr, the API response as JSON on stdout. Invalid
78 - * `--custom-credentials` JSON is reported before any request and exits 0; an API failure is
79 - * reported with a hint and exits 1.
81 + * `--custom-credentials` JSON fails with a `CommandInputError` before any request; an API
82 + * failure is reported with a hint and exits 1.
83 */
84 export const runAuthConfigsCreate = ({
85 name,
@@ -91,11 +94,10 @@ export const runAuthConfigsCreate = ({
94
95 const parsedCustomCredentials = parseCustomCredentials(customCredentials);
96 if (Result.isFailure(parsedCustomCredentials)) {
94 - yield* ui.log.error('Invalid JSON in --custom-credentials. Please provide valid JSON.');
95 - yield* ui.log.step(
96 - 'Example:\n> composio dev auth-configs create "name" --toolkit "gmail" --custom-credentials \'{"client_id":"...","client_secret":"..."}\''
97 + return yield* invalidInput(
98 + 'Invalid JSON in --custom-credentials. Please provide valid JSON.\nExample:\n> composio dev auth-configs create "name" --toolkit "gmail" --custom-credentials \'{"client_id":"...","client_secret":"..."}\'',
99 + '--custom-credentials'
100 );
98 - return;
101 }
102
103 const request = buildAuthConfigCreateRequest({
ts/packages/cli/src/commands/auth-configs/info/auth-configs.info.handler.ts
+8 -6
@@ -1,4 +1,5 @@
1 import { Effect, Option } from 'effect';
2 +import { commandInputError } from 'src/commands/errors';
3 import { handleClientApiError } from 'src/effects/handle-http-error';
4 import { ComposioToolkitsRepository } from 'src/services/composio-clients';
5 import { CLIENT_API_ERROR_TAGS } from 'src/services/composio-errors';
@@ -9,9 +10,11 @@ export type AuthConfigsInfoParams = {
10 readonly id: Option.Option<string>;
11 };
12
13 +const invalidInput = commandInputError('dev auth-configs info');
14 +
15 /**
13 - * Show one auth config: the details on stderr, the JSON on stdout. A missing `<id>` warns and
14 - * exits 0; an API failure is reported with a hint and exits 1.
16 + * Show one auth config: the details on stderr, the JSON on stdout. A missing `<id>` fails with a
17 + * `CommandInputError` before any request; an API failure is reported with a hint and exits 1.
18 */
19 export const runAuthConfigsInfo = ({ id }: AuthConfigsInfoParams) =>
20 Effect.gen(function* () {
@@ -19,11 +22,10 @@ export const runAuthConfigsInfo = ({ id }: AuthConfigsInfoParams) =>
22 const repo = yield* ComposioToolkitsRepository;
23
24 if (Option.isNone(id)) {
22 - yield* ui.log.warn('Missing required argument: <id>');
23 - yield* ui.log.step(
24 - 'Try specifying an auth config ID, e.g.:\n> composio dev auth-configs info "ac_1232323"\n\nTo find auth config IDs:\n> composio dev auth-configs list'
25 + return yield* invalidInput(
26 + 'Missing required argument: <id>\nTry specifying an auth config ID, e.g.:\n> composio dev auth-configs info "ac_1232323"\n\nTo find auth config IDs:\n> composio dev auth-configs list',
27 + '<id>'
28 );
26 - return;
29 }
30
31 const idValue = id.value;
ts/packages/cli/src/commands/tools/info/tools.info.handler.ts
+6 -7
@@ -1,5 +1,6 @@
1 import type { ToolRetrieveResponse } from '@composio/client/resources/tools';
2 import { Effect, Option } from 'effect';
3 +import { commandInputError } from 'src/commands/errors';
4 import { handleClientApiError } from 'src/effects/handle-http-error';
5 import { commandHintStep } from 'src/services/command-hints';
6 import { ComposioToolkitsRepository } from 'src/services/composio-clients';
@@ -25,12 +26,10 @@ export type ToolsInfoParams = {
26 readonly slug: Option.Option<string>;
27 };
28
28 -/** A missing slug is reported as a warning with an example; the command still exits 0. */
29 -const warnMissingSlug = Effect.gen(function* () {
30 - const ui = yield* TerminalUI;
31 - yield* ui.log.warn(MISSING_SLUG_MESSAGE);
32 - yield* ui.log.step(MISSING_SLUG_HINT);
33 -});
29 +const invalidInput = commandInputError('tools info');
30 +
31 +/** A missing slug fails with a usage error that carries an example, before any request. */
32 +const missingSlug = () => invalidInput(`${MISSING_SLUG_MESSAGE}\n${MISSING_SLUG_HINT}`, '<slug>');
33
34 /**
35 * Fetches the tool, or reports the API failure with "did you mean" suggestions, sets exit
@@ -84,7 +83,7 @@ const showTool = (slug: string, tool: ToolRetrieveResponse) =>
83 export const runToolsInfo = ({ slug }: ToolsInfoParams) =>
84 Effect.gen(function* () {
85 return yield* Option.match(slug, {
87 - onNone: () => warnMissingSlug,
86 + onNone: () => Effect.fail(missingSlug()),
87 onSome: slugValue =>
88 fetchTool(slugValue).pipe(
89 Effect.flatMap(
ts/packages/cli/src/commands/triggers/create/triggers.create.handler.ts
+25 -20
@@ -1,4 +1,5 @@
1 import { Effect, Match, Option, Result } from 'effect';
2 +import { commandInputError } from 'src/commands/errors';
3 import { handleClientApiError } from 'src/effects/handle-http-error';
4 import { ComposioToolkitsRepository } from 'src/services/composio-clients';
5 import { CLIENT_API_ERROR_TAGS } from 'src/services/composio-errors';
@@ -18,24 +19,30 @@ const parseTriggerConfig = (triggerConfig: Option.Option<string>) =>
19 onSome: parseJsonRecord,
20 });
21
21 -const reportInvalidTriggerConfig = (ui: TerminalUI, error: JsonParsingError) =>
22 - Match.value(error.reason).pipe(
23 - Match.when('not-a-record', () =>
24 - ui.log.error('--trigger-config must be a JSON object (e.g. \'{"key":"value"}\').')
25 - ),
26 - Match.when('syntax', () =>
27 - Effect.andThen(
28 - ui.log.error('Invalid JSON in --trigger-config. Please provide valid JSON.'),
29 - ui.log.step(
30 - 'Example:\n> composio dev triggers create "GMAIL_NEW_GMAIL_MESSAGE" --trigger-config \'{"label":"inbox"}\''
31 - )
32 - )
22 +const invalidInput = commandInputError('dev triggers create');
23 +
24 +/** The usage error for a `--trigger-config` that is not valid JSON or not a JSON object. */
25 +const invalidTriggerConfig = (error: JsonParsingError) =>
26 + invalidInput(
27 + Match.value(error.reason).pipe(
28 + Match.when(
29 + 'not-a-record',
30 + () => '--trigger-config must be a JSON object (e.g. \'{"key":"value"}\').'
31 + ),
32 + Match.when(
33 + 'syntax',
34 + () =>
35 + 'Invalid JSON in --trigger-config. Please provide valid JSON.\nExample:\n> composio dev triggers create "GMAIL_NEW_GMAIL_MESSAGE" --trigger-config \'{"label":"inbox"}\''
36 + ),
37 + Match.exhaustive
38 ),
34 - Match.exhaustive
39 + '--trigger-config'
40 );
41
42 /**
38 - * Create a trigger instance.
43 + * Create a trigger instance. A missing `<trigger-name>` or an invalid `--trigger-config` fails
44 + * with a `CommandInputError` before any request; an API failure is reported with a hint and
45 + * exits 1.
46 *
47 * @example
48 * ```bash
@@ -52,17 +59,15 @@ export const runTriggersCreate = ({
59 const repo = yield* ComposioToolkitsRepository;
60
61 if (Option.isNone(triggerName)) {
55 - yield* ui.log.warn('Missing required argument: <trigger-name>');
56 - yield* ui.log.step(
57 - 'Try specifying a trigger slug, e.g.:\n> composio dev triggers create "GMAIL_NEW_GMAIL_MESSAGE" --connected-account-id "con_123"'
62 + return yield* invalidInput(
63 + 'Missing required argument: <trigger-name>\nTry specifying a trigger slug, e.g.:\n> composio dev triggers create "GMAIL_NEW_GMAIL_MESSAGE" --connected-account-id "con_123"',
64 + '<trigger-name>'
65 );
59 - return;
66 }
67
68 const parsedTriggerConfig = parseTriggerConfig(triggerConfig);
69 if (Result.isFailure(parsedTriggerConfig)) {
64 - yield* reportInvalidTriggerConfig(ui, parsedTriggerConfig.failure);
65 - return;
70 + return yield* invalidTriggerConfig(parsedTriggerConfig.failure);
71 }
72
73 const createdOpt = yield* ui
ts/packages/cli/src/commands/triggers/enable/triggers.enable.handler.ts
+8 -5
@@ -1,4 +1,5 @@
1 import { Effect, Option } from 'effect';
2 +import { commandInputError } from 'src/commands/errors';
3 import { handleClientApiError } from 'src/effects/handle-http-error';
4 import { ComposioToolkitsRepository } from 'src/services/composio-clients';
5 import { CLIENT_API_ERROR_TAGS } from 'src/services/composio-errors';
@@ -8,8 +9,11 @@ export type TriggersEnableParams = {
9 readonly id: Option.Option<string>;
10 };
11
12 +const invalidInput = commandInputError('dev triggers enable');
13 +
14 /**
12 - * Enable an existing trigger instance.
15 + * Enable an existing trigger instance. A missing `<id>` fails with a `CommandInputError` before
16 + * any request; an API failure is reported with a hint and exits 1.
17 *
18 * @example
19 * ```bash
@@ -22,11 +26,10 @@ export const runTriggersEnable = ({ id }: TriggersEnableParams) =>
26 const repo = yield* ComposioToolkitsRepository;
27
28 if (Option.isNone(id)) {
25 - yield* ui.log.warn('Missing required argument: <id>');
26 - yield* ui.log.step(
27 - 'Try specifying a trigger ID, e.g.:\n> composio dev triggers enable "trg_123"\n\nTo find trigger IDs:\n> composio dev triggers status --show-disabled'
29 + return yield* invalidInput(
30 + 'Missing required argument: <id>\nTry specifying a trigger ID, e.g.:\n> composio dev triggers enable "trg_123"\n\nTo find trigger IDs:\n> composio dev triggers status --show-disabled',
31 + '<id>'
32 );
29 - return;
33 }
34
35 const idValue = id.value;
ts/packages/cli/test/src/commands/auth-configs/create/auth-configs.create.cmd.test.ts
+10 -7
@@ -97,11 +97,11 @@ describe('CLI: composio dev auth-configs create', () => {
97 });
98
99 layer(TestLive({ baseConfigProvider: testConfigProvider, ...dangerousDevConfig }))(
100 - '[Given] invalid JSON in --custom-credentials [Then] shows error',
100 + '[Given] invalid JSON in --custom-credentials [Then] fails with a usage error',
101 it => {
102 - it.effect('shows JSON parse error', () =>
102 + it.effect('raises a CommandInputError naming --custom-credentials', () =>
103 Effect.gen(function* () {
104 - yield* cli([
104 + const failure = yield* cli([
105 'dev',
106 'auth-configs',
107 'create',
@@ -111,11 +111,14 @@ describe('CLI: composio dev auth-configs create', () => {
111 'OAUTH2',
112 '--custom-credentials',
113 '{invalid json}',
114 - ]);
115 - const lines = yield* MockConsole.getLines({ stripAnsi: true });
116 - const output = lines.join('\n');
114 + ]).pipe(Effect.flip);
115
118 - expect(output).toContain('Invalid JSON');
116 + expect(failure).toMatchObject({
117 + _tag: 'commands/CommandInputError',
118 + option: '--custom-credentials',
119 + message: expect.stringContaining('Invalid JSON in --custom-credentials'),
120 + });
121 + expect(yield* MockConsole.getLines()).toEqual([]);
122 })
123 );
124 }
ts/packages/cli/test/src/commands/auth-configs/create/auth-configs.create.handler.test.ts
+15 -6
@@ -6,6 +6,7 @@ import {
6 runAuthConfigsCreate,
7 type AuthConfigsCreateParams,
8 } from 'src/commands/auth-configs/create/auth-configs.create.handler';
9 +import { isUsageFailure } from 'src/commands/errors';
10 import { MockConsole } from 'test/__utils__';
11 import { AuthConfigsHandlerTest } from 'test/__utils__/layers/auth-configs';
12 import { notFoundError } from 'test/__utils__/layers/not-found';
@@ -125,21 +126,29 @@ describe('runAuthConfigsCreate', () => {
126 { name: 'malformed JSON', customCredentials: '{invalid json}' },
127 { name: 'a JSON array', customCredentials: '["client_id"]' },
128 ])(
128 - '[Given] $name in --custom-credentials [Then] reports it, sends no request, and exits 0',
129 + '[Given] $name in --custom-credentials [Then] fails with a usage error before any request',
130 ({ customCredentials }) => {
131 const { layer, outputs, exitCode } = AuthConfigsHandlerTest({
132 repository: { createAuthConfig: () => Effect.die('createAuthConfig must not be called') },
133 });
134 return Effect.gen(function* () {
134 - yield* runAuthConfigsCreate({
135 + const failure = yield* runAuthConfigsCreate({
136 ...params,
137 authScheme: Option.some('OAUTH2'),
138 customCredentials: Option.some(customCredentials),
138 - });
139 + }).pipe(Effect.flip);
140
140 - expect(yield* MockConsole.getLines({ stream: 'stderr' })).toEqual([
141 - 'Invalid JSON in --custom-credentials. Please provide valid JSON.',
142 - ]);
141 + expect(failure).toMatchObject({
142 + _tag: 'commands/CommandInputError',
143 + command: 'dev auth-configs create',
144 + option: '--custom-credentials',
145 + message: expect.stringMatching(
146 + /^Invalid JSON in --custom-credentials\. Please provide valid JSON\.\nExample:\n> composio dev auth-configs create /
147 + ),
148 + });
149 + // `cli-main.ts` prints a usage failure on stderr and exits 1.
150 + expect(isUsageFailure(failure)).toBe(true);
151 + expect(yield* MockConsole.getLines()).toEqual([]);
152 expect(outputs).toEqual([]);
153 expect(exitCode()).toBeUndefined();
154 }).pipe(Effect.provide(layer));
ts/packages/cli/test/src/commands/auth-configs/info/auth-configs.info.cmd.test.ts
+9 -6
@@ -50,15 +50,18 @@ describe('CLI: composio dev auth-configs info', () => {
50 );
51
52 layer(TestLive({ baseConfigProvider: testConfigProvider, authConfigsData }))(
53 - '[Given] no ID [Then] warns missing argument',
53 + '[Given] no ID [Then] fails with a usage error',
54 it => {
55 - it.effect('shows missing argument warning', () =>
55 + it.effect('raises a CommandInputError naming <id>', () =>
56 Effect.gen(function* () {
57 - yield* cli(['dev', 'auth-configs', 'info']);
58 - const lines = yield* MockConsole.getLines({ stripAnsi: true });
59 - const output = lines.join('\n');
57 + const failure = yield* cli(['dev', 'auth-configs', 'info']).pipe(Effect.flip);
58
61 - expect(output).toContain('Missing required argument');
59 + expect(failure).toMatchObject({
60 + _tag: 'commands/CommandInputError',
61 + option: '<id>',
62 + message: expect.stringContaining('Missing required argument: <id>'),
63 + });
64 + expect(yield* MockConsole.getLines()).toEqual([]);
65 })
66 );
67 }
ts/packages/cli/test/src/commands/auth-configs/info/auth-configs.info.handler.test.ts
+14 -5
@@ -1,6 +1,7 @@
1 import { describe, expect, it } from '@effect/vitest';
2 import { Effect, Option } from 'effect';
3 import { runAuthConfigsInfo } from 'src/commands/auth-configs/info/auth-configs.info.handler';
4 +import { isUsageFailure } from 'src/commands/errors';
5 import { MockConsole } from 'test/__utils__';
6 import { AuthConfigsHandlerTest } from 'test/__utils__/layers/auth-configs';
7 import { makeAuthConfigItem } from 'test/__utils__/models/auth-configs';
@@ -23,17 +24,25 @@ describe('runAuthConfigsInfo', () => {
24 }).pipe(Effect.provide(layer));
25 });
26
26 - it.effect('[Given] no ID [Then] warns, sends no request, and exits 0', () => {
27 + it.effect('[Given] no ID [Then] fails with a usage error before any request', () => {
28 // The stub repository dies on any call, so reaching the API fails the test.
29 const { layer, outputs, exitCode } = AuthConfigsHandlerTest({
30 repository: { getAuthConfig: () => Effect.die('getAuthConfig must not be called') },
31 });
32 return Effect.gen(function* () {
32 - yield* runAuthConfigsInfo({ id: Option.none() });
33 + const failure = yield* runAuthConfigsInfo({ id: Option.none() }).pipe(Effect.flip);
34
34 - expect(yield* MockConsole.getLines({ stream: 'stderr' })).toEqual([
35 - 'Missing required argument: <id>',
36 - ]);
35 + expect(failure).toMatchObject({
36 + _tag: 'commands/CommandInputError',
37 + command: 'dev auth-configs info',
38 + option: '<id>',
39 + message: expect.stringMatching(
40 + /^Missing required argument: <id>\n[\s\S]*> composio dev auth-configs list$/
41 + ),
42 + });
43 + // `cli-main.ts` prints a usage failure on stderr and exits 1.
44 + expect(isUsageFailure(failure)).toBe(true);
45 + expect(yield* MockConsole.getLines()).toEqual([]);
46 expect(outputs).toEqual([]);
47 expect(exitCode()).toBeUndefined();
48 }).pipe(Effect.provide(layer));
ts/packages/cli/test/src/commands/tools/info/tools.info.cmd.test.ts
+9 -6
@@ -132,15 +132,18 @@ describe('CLI: composio tools info', () => {
132 );
133
134 layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))(
135 - '[Given] no slug [Then] warns missing argument',
135 + '[Given] no slug [Then] fails with a usage error',
136 it => {
137 - it.effect('shows missing argument warning', () =>
137 + it.effect('raises a CommandInputError naming <slug>', () =>
138 Effect.gen(function* () {
139 - yield* cli(['tools', 'info']);
140 - const lines = yield* MockConsole.getLines({ stripAnsi: true });
141 - const output = lines.join('\n');
139 + const failure = yield* cli(['tools', 'info']).pipe(Effect.flip);
140
143 - expect(output).toContain('Missing required argument');
141 + expect(failure).toMatchObject({
142 + _tag: 'commands/CommandInputError',
143 + option: '<slug>',
144 + message: expect.stringContaining('Missing required argument: <slug>'),
145 + });
146 + expect(yield* MockConsole.getLines()).toEqual([]);
147 })
148 );
149 }
ts/packages/cli/test/src/commands/tools/info/tools.info.handler.test.ts
+19 -4
@@ -1,5 +1,6 @@
1 import { afterEach, describe, expect, it } from '@effect/vitest';
2 -import { ConfigProvider, Effect, Option } from 'effect';
2 +import { ConfigProvider, Effect, Layer, Option } from 'effect';
3 +import { isUsageFailure } from 'src/commands/errors';
4 import { runToolsInfo } from 'src/commands/tools/info/tools.info.handler';
5 import {
6 MISSING_SLUG_HINT,
@@ -7,9 +8,11 @@ import {
8 toolNotFoundMessage,
9 } from 'src/commands/tools/info/tools.info.format';
10 import type { Tools } from 'src/models/tools';
11 +import { ComposioToolkitsRepository } from 'src/services/composio-clients';
12 import { TerminalUI } from 'src/services/terminal-ui';
13 import { MockConsole, TestLive } from 'test/__utils__';
14 import { terminalUITestImpl } from 'test/__utils__/services/terminal-ui-test';
15 +import { makeToolkitsRepositoryStub } from 'test/__utils__/services/toolkits-repository-stub';
16
17 const TOOLS: Tools = [
18 {
@@ -54,12 +57,24 @@ describe('runToolsInfo', () => {
57 process.exitCode = undefined;
58 });
59
57 - it.effect('[Given] no slug [Then] warns with an example and keeps exit code 0', () => {
60 + it.effect('[Given] no slug [Then] fails with a usage error before any request', () => {
61 const { layer, outputs } = toolsInfoTest();
62 return Effect.gen(function* () {
60 - yield* runToolsInfo({ slug: Option.none() });
63 + const failure = yield* runToolsInfo({ slug: Option.none() }).pipe(
64 + // Every repository method dies, so reaching the API fails the test.
65 + Effect.provide(Layer.succeed(ComposioToolkitsRepository, makeToolkitsRepositoryStub({}))),
66 + Effect.flip
67 + );
68
62 - expect(yield* MockConsole.getLines()).toEqual([MISSING_SLUG_MESSAGE, MISSING_SLUG_HINT]);
69 + expect(failure).toMatchObject({
70 + _tag: 'commands/CommandInputError',
71 + command: 'tools info',
72 + option: '<slug>',
73 + message: `${MISSING_SLUG_MESSAGE}\n${MISSING_SLUG_HINT}`,
74 + });
75 + // `cli-main.ts` prints a usage failure on stderr and exits 1.
76 + expect(isUsageFailure(failure)).toBe(true);
77 + expect(yield* MockConsole.getLines()).toEqual([]);
78 expect(outputs).toEqual([]);
79 expect(process.exitCode).toBeUndefined();
80 }).pipe(Effect.provide(layer));
ts/packages/cli/test/src/commands/triggers/create/triggers.create.cmd.test.ts
+46 -66
@@ -1,6 +1,7 @@
1 import { describe, expect, layer } from '@effect/vitest';
2 import { ConfigProvider, Effect, Layer } from 'effect';
3 import type { TriggerInstanceUpsertParams } from '@composio/client/resources/trigger-instances';
4 +import { isUsageFailure } from 'src/commands/errors';
5 import { ComposioToolkitsRepository } from 'src/services/composio-clients';
6 import { cli, MockConsole, TestLive } from 'test/__utils__';
7 import { notFoundError } from 'test/__utils__/layers/not-found';
@@ -82,75 +83,54 @@ describe('CLI: composio dev triggers create', () => {
83 );
84
85 layer(TestLive(dangerousDevConfig))(
85 - '[Given] create with invalid JSON config [Then] shows JSON validation error',
86 + '[Given] invalid input [Then] fails with a usage error before any request',
87 it => {
87 - it.effect('rejects invalid trigger config JSON', () =>
88 + it.effect.each([
89 + {
90 + name: 'no trigger name',
91 + args: [],
92 + option: '<trigger-name>',
93 + message: /^Missing required argument: <trigger-name>\nTry specifying a trigger slug/,
94 + },
95 + {
96 + name: 'invalid JSON in --trigger-config',
97 + args: ['GMAIL_NEW_GMAIL_MESSAGE', '--trigger-config', '{'],
98 + option: '--trigger-config',
99 + message: /^Invalid JSON in --trigger-config\. Please provide valid JSON\.\nExample:\n/,
100 + },
101 + {
102 + name: 'a JSON array in --trigger-config',
103 + args: ['GMAIL_NEW_GMAIL_MESSAGE', '--trigger-config', '[1,2,3]'],
104 + option: '--trigger-config',
105 + message: /^--trigger-config must be a JSON object/,
106 + },
107 + {
108 + name: 'a JSON number in --trigger-config',
109 + args: ['GMAIL_NEW_GMAIL_MESSAGE', '--trigger-config', '42'],
110 + option: '--trigger-config',
111 + message: /^--trigger-config must be a JSON object/,
112 + },
113 + ])('[Given] $name [Then] raises a CommandInputError', ({ args, option, message }) =>
114 Effect.gen(function* () {
89 - yield* cli([
90 - 'dev',
91 - 'triggers',
92 - 'create',
93 - 'GMAIL_NEW_GMAIL_MESSAGE',
94 - '--trigger-config',
95 - '{',
96 - ]);
97 - const lines = yield* MockConsole.getLines({ stripAnsi: true });
98 - const output = lines.join('\n');
99 -
100 - expect(output).toContain('Invalid JSON in --trigger-config');
101 - })
102 - );
103 - }
104 - );
105 -
106 - layer(TestLive(dangerousDevConfig))(
107 - '[Given] create with non-object JSON config [Then] shows type validation error',
108 - it => {
109 - it.effect('rejects array JSON in --trigger-config', () =>
110 - Effect.gen(function* () {
111 - yield* cli([
112 - 'dev',
113 - 'triggers',
114 - 'create',
115 - 'GMAIL_NEW_GMAIL_MESSAGE',
116 - '--trigger-config',
117 - '[1,2,3]',
118 - ]);
119 - const lines = yield* MockConsole.getLines({ stripAnsi: true });
120 - const output = lines.join('\n');
121 -
122 - expect(output).toContain('--trigger-config must be a JSON object');
123 - })
124 - );
125 -
126 - it.effect('rejects number JSON in --trigger-config', () =>
127 - Effect.gen(function* () {
128 - yield* cli([
129 - 'dev',
130 - 'triggers',
131 - 'create',
132 - 'GMAIL_NEW_GMAIL_MESSAGE',
133 - '--trigger-config',
134 - '42',
135 - ]);
136 - const lines = yield* MockConsole.getLines({ stripAnsi: true });
137 - const output = lines.join('\n');
138 -
139 - expect(output).toContain('--trigger-config must be a JSON object');
140 - })
141 - );
142 - }
143 - );
115 + // Every repository method dies, so reaching the API fails the test.
116 + const repository = Layer.succeed(
117 + ComposioToolkitsRepository,
118 + makeToolkitsRepositoryStub({})
119 + );
120 + const failure = yield* cli(['dev', 'triggers', 'create', ...args]).pipe(
121 + Effect.provide(repository),
122 + Effect.flip
123 + );
124
145 - layer(TestLive(dangerousDevConfig))(
146 - '[Given] create without a trigger name [Then] warns about missing argument',
147 - it => {
148 - it.effect('shows missing trigger-name warning', () =>
149 - Effect.gen(function* () {
150 - yield* cli(['dev', 'triggers', 'create']);
151 - const lines = yield* MockConsole.getLines({ stripAnsi: true });
152 - const output = lines.join('\n');
153 - expect(output).toContain('Missing required argument: <trigger-name>');
125 + expect(failure).toMatchObject({
126 + _tag: 'commands/CommandInputError',
127 + command: 'dev triggers create',
128 + option,
129 + message: expect.stringMatching(message),
130 + });
131 + // `cli-main.ts` prints a usage failure on stderr and exits 1.
132 + expect(isUsageFailure(failure)).toBe(true);
133 + expect(yield* MockConsole.getLines()).toEqual([]);
134 })
135 );
136 }
ts/packages/cli/test/src/commands/triggers/enable/triggers.enable.cmd.test.ts
+24 -6
@@ -1,5 +1,6 @@
1 import { describe, expect, layer } from '@effect/vitest';
2 import { ConfigProvider, Effect, Layer } from 'effect';
3 +import { isUsageFailure } from 'src/commands/errors';
4 import { ComposioToolkitsRepository } from 'src/services/composio-clients';
5 import { cli, MockConsole, TestLive } from 'test/__utils__';
6 import { notFoundError } from 'test/__utils__/layers/not-found';
@@ -28,14 +29,31 @@ describe('CLI: composio dev triggers enable', () => {
29 });
30
31 layer(TestLive(dangerousDevConfig))(
31 - '[Given] missing ID for enable [Then] warns about missing argument',
32 + '[Given] missing ID for enable [Then] fails with a usage error before any request',
33 it => {
33 - it.effect('shows missing id warning', () =>
34 + it.effect('raises a CommandInputError naming <id>', () =>
35 Effect.gen(function* () {
35 - yield* cli(['dev', 'triggers', 'enable']);
36 - const lines = yield* MockConsole.getLines({ stripAnsi: true });
37 - const output = lines.join('\n');
38 - expect(output).toContain('Missing required argument');
36 + // Every repository method dies, so reaching the API fails the test.
37 + const repository = Layer.succeed(
38 + ComposioToolkitsRepository,
39 + makeToolkitsRepositoryStub({})
40 + );
41 + const failure = yield* cli(['dev', 'triggers', 'enable']).pipe(
42 + Effect.provide(repository),
43 + Effect.flip
44 + );
45 +
46 + expect(failure).toMatchObject({
47 + _tag: 'commands/CommandInputError',
48 + command: 'dev triggers enable',
49 + option: '<id>',
50 + message: expect.stringMatching(
51 + /^Missing required argument: <id>\n[\s\S]*> composio dev triggers status --show-disabled$/
52 + ),
53 + });
54 + // `cli-main.ts` prints a usage failure on stderr and exits 1.
55 + expect(isUsageFailure(failure)).toBe(true);
56 + expect(yield* MockConsole.getLines()).toEqual([]);
57 })
58 );
59 }