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

test(cli): isolate help page output and assert exit codes

Check each curated page against its own output, cover experimental commands in the registry check, and assert exit status and stderr for unknown help targets.

jkomyno committed Sep 16, 2026 at 15:30 UTC b320526d118f62126cafb6ef4202d66274ad3f5a
1 file changed +50 -26
ts/packages/cli/test/src/commands/root-help-consistency.test.ts
+50 -26
@@ -1,5 +1,6 @@
1 import { layer } from '@effect/vitest';
2 import { Effect } from 'effect';
3 +import { teardown } from 'src/cli-main';
4 import { afterEach, describe, expect, it } from 'vitest';
5 import { buildRootCommand } from 'src/commands';
6 import {
@@ -14,19 +15,39 @@ const stableVisibility = {
15 isExperimentalFeatureEnabled: () => false,
16 };
17
17 -const getVisibleRootCommandNames = () =>
18 - buildRootCommand(stableVisibility).subcommands.flatMap(group =>
19 - group.commands.map(cmd => cmd.name)
20 - );
18 +// Beta builds expose experimental commands, so the registry check covers that surface too.
19 +const allFeaturesVisibility = {
20 + isDevModeEnabled: true,
21 + isExperimentalFeatureEnabled: () => true,
22 +};
23 +
24 +const getVisibleRootCommandNames = (visibility: typeof stableVisibility) =>
25 + buildRootCommand(visibility).subcommands.flatMap(group => group.commands.map(cmd => cmd.name));
26 +
27 +/** Runs the CLI and returns the exit code `cli-main` would hand the process, plus split streams. */
28 +const runCapturingExit = (args: ReadonlyArray<string>) =>
29 + Effect.gen(function* () {
30 + const exit = yield* Effect.exit(cli(args));
31 + let exitCode = 0;
32 + teardown(exit, code => {
33 + exitCode = code;
34 + });
35 + const stdout = (yield* MockConsole.getLines({ stripAnsi: true, stream: 'stdout' })).join('\n');
36 + const stderr = (yield* MockConsole.getLines({ stripAnsi: true, stream: 'stderr' })).join('\n');
37 + return { exitCode, stdout, stderr };
38 + });
39
40 describe('subcommand help registry consistency', () => {
41 afterEach(() => {
42 process.exitCode = undefined;
43 });
44
27 - it('has a curated help entry for every visible root command', () => {
28 - for (const name of getVisibleRootCommandNames()) {
29 - const matched = matchSubcommandHelp(['bun', 'composio', name, '--help'], stableVisibility);
45 + it.each([
46 + ['stable', stableVisibility],
47 + ['all experimental features', allFeaturesVisibility],
48 + ])('has a curated help entry for every visible root command (%s)', (_, visibility) => {
49 + for (const name of getVisibleRootCommandNames(visibility)) {
50 + const matched = matchSubcommandHelp(['bun', 'composio', name, '--help'], visibility);
51 expect(matched, `missing curated help for \`composio ${name}\``).toBe(name);
52 }
53 });
@@ -83,9 +104,14 @@ describe('subcommand help registry consistency', () => {
104 it.effect('renders curated pages for formerly raw-fallback groups', () =>
105 Effect.gen(function* () {
106 for (const cmd of ['connections', 'triggers', 'tools', 'artifacts', 'install']) {
107 + // MockConsole accumulates across renders; inspect only this page's lines.
108 + const before = (yield* MockConsole.getLines()).length;
109 yield* printSubcommandHelp(cmd, stableVisibility);
87 - const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
110 + const output = (yield* MockConsole.getLines({ stripAnsi: true }))
111 + .slice(before)
112 + .join('\n');
113 expect(output, `\`composio ${cmd}\` help page`).toContain('USAGE');
114 + expect(output, `\`composio ${cmd}\` help page`).toContain(`composio ${cmd}`);
115 }
116 })
117 );
@@ -203,20 +229,16 @@ describe('subcommand help registry consistency', () => {
229 layer(TestLive())(it => {
230 it.effect('`composio help <unknown>` fails like any unknown command', () =>
231 Effect.gen(function* () {
206 - yield* cli(['help', 'frobnicate']).pipe(Effect.catch(() => Effect.void));
207 - const stdout = (yield* MockConsole.getLines({ stripAnsi: true, stream: 'stdout' })).join(
208 - '\n'
209 - );
210 - const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
232 + const { exitCode, stdout, stderr } = yield* runCapturingExit(['help', 'frobnicate']);
233
234 // The framework renders its unknown-subcommand failure (stderr channel,
235 // "Did you mean?", exit 1 via CliError.ShowHelp) instead of an exit-0
236 // "Unknown command" line on the stdout data channel.
215 - expect(stdout).not.toContain('Unknown command');
216 - expect(output).not.toContain('Unknown command');
217 - expect(output).toContain('generate');
218 - expect(output).toContain('Unknown subcommand "frobnicate"');
219 - expect(output).not.toContain('Unknown subcommand "help"');
237 + expect(exitCode).toBe(1);
238 + expect(stdout).toBe('');
239 + expect(stderr).toContain('generate');
240 + expect(stderr).toContain('Unknown subcommand "frobnicate"');
241 + expect(stderr).not.toContain('Unknown subcommand "help"');
242 })
243 );
244 });
@@ -224,11 +246,12 @@ describe('subcommand help registry consistency', () => {
246 layer(TestLive())(it => {
247 it.effect('`composio help <typo>` suggests the closest command', () =>
248 Effect.gen(function* () {
227 - yield* cli(['help', 'orgz']).pipe(Effect.catch(() => Effect.void));
228 - const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
249 + const { exitCode, stdout, stderr } = yield* runCapturingExit(['help', 'orgz']);
250
230 - expect(output).toContain('Unknown subcommand "orgz"');
231 - expect(output).toContain('Did you mean this?');
251 + expect(exitCode).toBe(1);
252 + expect(stdout).toBe('');
253 + expect(stderr).toContain('Unknown subcommand "orgz"');
254 + expect(stderr).toContain('Did you mean this?');
255 })
256 );
257 });
@@ -236,11 +259,12 @@ describe('subcommand help registry consistency', () => {
259 layer(TestLive())(it => {
260 it.effect('`composio help --help` renders the curated root help', () =>
261 Effect.gen(function* () {
239 - yield* cli(['help', '--help']);
240 - const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
262 + const { exitCode, stdout, stderr } = yield* runCapturingExit(['help', '--help']);
263
242 - expect(output).not.toContain('--log-level');
243 - expect(output).not.toContain('Unknown subcommand');
264 + expect(exitCode).toBe(0);
265 + expect(stdout).toContain('LEARN MORE');
266 + expect(stdout).not.toContain('--log-level');
267 + expect(stderr).not.toContain('Unknown subcommand');
268 })
269 );
270 });