1
import { layer } from '@effect/vitest';
2
import { Effect } from 'effect';
3
-import { describe, expect, it } from 'vitest';
3
+import { afterEach, describe, expect, it } from 'vitest';
4
import { buildRootCommand } from 'src/commands';
5
import {
6
getCommandHelpText,
7
matchSubcommandHelp,
8
printSubcommandHelp,
9
} from 'src/commands/root-help';
10
-import { MockConsole, TestLive } from 'test/__utils__';
10
+import { cli, MockConsole, TestLive } from 'test/__utils__';
11
12
const stableVisibility = {
13
isDevModeEnabled: true,
20
);
21
22
describe('subcommand help registry consistency', () => {
23
+ afterEach(() => {
24
+ process.exitCode = undefined;
25
+ });
26
+
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);
46
).toBe('orgs');
47
});
48
45
- it('renders the curated orgs page', () =>
46
- Effect.gen(function* () {
47
- yield* printSubcommandHelp('orgs', stableVisibility);
48
- const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
49
-
50
- expect(output).toContain('USAGE');
51
- expect(output).toContain('composio orgs <subcommand>');
52
- expect(output).toContain('SEE ALSO');
53
- expect(output).toContain('composio orgs list');
54
- expect(output).toContain('composio orgs switch');
55
- }));
56
-
57
- it('renders curated pages for formerly raw-fallback groups', () =>
58
- Effect.gen(function* () {
59
- for (const cmd of ['connections', 'triggers', 'tools', 'artifacts', 'install']) {
60
- yield* printSubcommandHelp(cmd, stableVisibility);
61
- const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
62
- expect(output, `\`composio ${cmd}\` help page`).toContain('USAGE');
63
- }
64
- }));
49
+ it('matches every agent family invocation', () => {
50
+ expect(matchSubcommandHelp(['bun', 'composio', 'agent', '--help'], stableVisibility)).toBe(
51
+ 'agent'
52
+ );
53
+ for (const child of ['signup', 'login', 'whoami', 'inbox', 'claim']) {
54
+ expect(
55
+ matchSubcommandHelp(['bun', 'composio', 'agent', child, '--help'], stableVisibility),
56
+ `missing curated help for \`composio agent ${child}\``
57
+ ).toBe(`agent ${child}`);
58
+ }
59
+ });
60
61
it('uses the current orgs description in contextual help', () => {
62
expect(getCommandHelpText('orgs', stableVisibility)).toContain(
63
'Manage default global organization/project context.'
64
);
65
});
66
+
67
+ layer(TestLive())(it => {
68
+ it.effect('renders the curated orgs page', () =>
69
+ Effect.gen(function* () {
70
+ yield* printSubcommandHelp('orgs', stableVisibility);
71
+ const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
72
+
73
+ expect(output).toContain('USAGE');
74
+ expect(output).toContain('composio orgs <subcommand>');
75
+ expect(output).toContain('SEE ALSO');
76
+ expect(output).toContain('composio orgs list');
77
+ expect(output).toContain('composio orgs switch');
78
+ })
79
+ );
80
+ });
81
+
82
+ layer(TestLive())(it => {
83
+ it.effect('renders curated pages for formerly raw-fallback groups', () =>
84
+ Effect.gen(function* () {
85
+ for (const cmd of ['connections', 'triggers', 'tools', 'artifacts', 'install']) {
86
+ yield* printSubcommandHelp(cmd, stableVisibility);
87
+ const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
88
+ expect(output, `\`composio ${cmd}\` help page`).toContain('USAGE');
89
+ }
90
+ })
91
+ );
92
+ });
93
+
94
+ layer(TestLive())(it => {
95
+ it.effect('renders the curated agent signup page', () =>
96
+ Effect.gen(function* () {
97
+ yield* printSubcommandHelp('agent signup', stableVisibility);
98
+ const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
99
+
100
+ expect(output).toContain('USAGE');
101
+ expect(output).toContain('composio agent signup');
102
+ expect(output).toContain('--no-wait');
103
+ expect(output).toContain('Sign up and optionally log in as a Composio agent.');
104
+ })
105
+ );
106
+ });
107
+
108
+ describe('composio help routing', () => {
109
+ layer(TestLive())(it => {
110
+ it.effect('bare `composio help` prints the root help page', () =>
111
+ Effect.gen(function* () {
112
+ yield* cli(['help']);
113
+ const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
114
+
115
+ expect(output).toContain('USAGE');
116
+ expect(output).toContain('LEARN MORE');
117
+ })
118
+ );
119
+ });
120
+
121
+ layer(TestLive())(it => {
122
+ it.effect('`composio help orgs` matches `composio orgs --help`', () =>
123
+ Effect.gen(function* () {
124
+ yield* cli(['help', 'orgs']);
125
+ const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
126
+
127
+ expect(output).toContain('USAGE');
128
+ expect(output).toContain('composio orgs <subcommand>');
129
+ expect(output).toContain('composio orgs list');
130
+ })
131
+ );
132
+ });
133
+
134
+ layer(TestLive())(it => {
135
+ it.effect('`composio help orgs list` prints the orgs list page', () =>
136
+ Effect.gen(function* () {
137
+ yield* cli(['help', 'orgs', 'list']);
138
+ const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
139
+
140
+ expect(output).toContain('composio orgs list [--limit integer]');
141
+ })
142
+ );
143
+ });
144
+
145
+ layer(TestLive())(it => {
146
+ it.effect('`composio help agent signup` prints the agent signup page', () =>
147
+ Effect.gen(function* () {
148
+ yield* cli(['help', 'agent', 'signup']);
149
+ const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
150
+
151
+ expect(output).toContain('composio agent signup');
152
+ expect(output).toContain('--no-wait');
153
+ })
154
+ );
155
+ });
156
+
157
+ layer(TestLive())(it => {
158
+ it.effect('`composio help orgs simple` applies the simple level', () =>
159
+ Effect.gen(function* () {
160
+ yield* cli(['help', 'orgs', 'simple']);
161
+ const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
162
+
163
+ expect(output).toContain('USAGE');
164
+ expect(output).not.toContain('SEE ALSO');
165
+ })
166
+ );
167
+ });
168
+
169
+ layer(TestLive())(it => {
170
+ it.effect('`composio help orgs full` applies the full level', () =>
171
+ Effect.gen(function* () {
172
+ yield* cli(['help', 'orgs', 'full']);
173
+ const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
174
+
175
+ expect(output).toContain('composio orgs <subcommand>');
176
+ expect(output).toContain('SEE ALSO');
177
+ })
178
+ );
179
+ });
180
+
181
+ layer(TestLive())(it => {
182
+ it.effect('`composio help orgs --help` tolerates a trailing help flag', () =>
183
+ Effect.gen(function* () {
184
+ yield* cli(['help', 'orgs', '--help']);
185
+ const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
186
+
187
+ expect(output).toContain('composio orgs <subcommand>');
188
+ })
189
+ );
190
+ });
191
+
192
+ layer(TestLive())(it => {
193
+ it.effect('`composio help dev toolkits` falls back to the curated dev page', () =>
194
+ Effect.gen(function* () {
195
+ yield* cli(['help', 'dev', 'toolkits']);
196
+ const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
197
+
198
+ expect(output).toContain('GUARDED');
199
+ })
200
+ );
201
+ });
202
+
203
+ layer(TestLive())(it => {
204
+ it.effect('`composio help <unknown>` fails like any unknown command', () =>
205
+ 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');
211
+
212
+ // The framework renders its unknown-subcommand failure (stderr channel,
213
+ // "Did you mean?", exit 1 via CliError.ShowHelp) instead of an exit-0
214
+ // "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
+ })
219
+ );
220
+ });
221
+ });
222
});