1
import { describe, expect, layer } from '@effect/vitest';
2
-import { Cause, Effect, Exit, Fiber, Latch } from 'effect';
2
+import { Effect, Exit, Fiber, Latch } from 'effect';
3
import { TestClock } from 'effect/testing';
4
import { ChildProcess, ChildProcessSpawner } from 'effect/process';
5
import { afterEach, vi } from 'vitest';
336
);
337
});
338
339
- for (const host of ['claude', 'codex'] as const) {
339
+ describe.each([
340
+ {
341
+ host: 'claude',
342
+ repairCommand: ['claude', 'plugin', 'enable', 'composio@composio', '--scope', 'user'],
343
+ },
344
+ {
345
+ host: 'codex',
346
+ repairCommand: ['codex', 'plugin', 'add', 'composio@composio', '--json'],
347
+ },
348
+ ] as const)('disabled $host plugin', ({ host, repairCommand }) => {
349
const disabled = makeFakeHosts({
350
[host]: { available: true, marketplace: 'canonical', plugin: 'disabled' },
351
});
354
commandRunner: disabled.runner,
355
setupSkillInstaller: makeSkillInstaller(true),
356
})
348
- )(`disabled ${host} plugin`, it => {
357
+ )(it => {
358
it.effect('repairs the plugin through the native path', () =>
359
Effect.gen(function* () {
360
yield* cli(['setup', '--target', host, '--yes']);
361
362
expect(disabled.state[host].plugin).toBe('enabled');
354
- if (host === 'claude') {
355
- expect(disabled.commands).toContainEqual([
356
- 'claude',
357
- 'plugin',
358
- 'enable',
359
- 'composio@composio',
360
- '--scope',
361
- 'user',
362
- ]);
363
- }
363
+ expect(disabled.commands).toContainEqual(repairCommand);
364
})
365
);
366
});
367
- }
367
+ });
368
369
const freshCodex = makeFakeHosts({ codex: { available: true } });
370
layer(TestLive({ commandRunner: freshCodex.runner }))('fresh Codex install', it => {
892
893
it.effect('does not skip an explicitly requested missing host', () =>
894
Effect.gen(function* () {
895
- const exit = yield* Effect.exit(
896
- cli(['setup', '--target', 'claude', '--yes', '--if-present'])
895
+ const failure = yield* cli(['setup', '--target', 'claude', '--yes', '--if-present']).pipe(
896
+ Effect.flip
897
);
898
- expect(Exit.isFailure(exit)).toBe(true);
899
- if (Exit.isFailure(exit)) {
900
- expect(Cause.pretty(exit.cause)).toContain(
901
- 'claude is not installed or not available on PATH'
902
- );
903
- }
898
+ expect(failure).toMatchObject({
899
+ message: expect.stringContaining('claude is not installed or not available on PATH'),
900
+ });
901
})
902
);
903
});
915
);
916
});
917
921
- for (const unsafeSource of [
918
+ describe.each([
919
'http://github.com/ComposioHQ/composio-plugin-cc.git',
920
'https://token@github.com/ComposioHQ/composio-plugin-cc.git',
921
'https://github.com/ComposioHQ/composio-plugin-cc.git?token=secret',
925
- ]) {
922
+ ])('unsafe marketplace source: %s', unsafeSource => {
923
const unsafeMarketplace = makeFakeHosts(
924
{ claude: { available: true, marketplace: 'canonical' } },
925
{ marketplaceSource: { claude: unsafeSource } }
926
);
930
- layer(TestLive({ commandRunner: unsafeMarketplace.runner }))(
931
- `unsafe marketplace source: ${unsafeSource}`,
932
- it => {
933
- it.effect('rejects a non-canonical GitHub URL', () =>
934
- Effect.gen(function* () {
935
- const exit = yield* Effect.exit(cli(['setup', '--target', 'claude', '--yes']));
936
-
937
- expect(Exit.isFailure(exit)).toBe(true);
938
- expect(
939
- unsafeMarketplace.commands.some(parts =>
940
- ['add', 'install', 'enable'].some(operation => parts.includes(operation))
941
- )
942
- ).toBe(false);
943
- })
944
- );
945
- }
946
- );
947
- }
927
+ layer(TestLive({ commandRunner: unsafeMarketplace.runner }))(it => {
928
+ it.effect('rejects a non-canonical GitHub URL', () =>
929
+ Effect.gen(function* () {
930
+ const exit = yield* Effect.exit(cli(['setup', '--target', 'claude', '--yes']));
931
+
932
+ expect(Exit.isFailure(exit)).toBe(true);
933
+ expect(
934
+ unsafeMarketplace.commands.some(parts =>
935
+ ['add', 'install', 'enable'].some(operation => parts.includes(operation))
936
+ )
937
+ ).toBe(false);
938
+ })
939
+ );
940
+ });
941
+ });
942
943
const failedInspection = makeFakeHosts(
944
{ claude: { available: true } },
978
it => {
979
it.effect('fails automatic setup with actionable update instructions', () =>
980
Effect.gen(function* () {
987
- const exit = yield* Effect.exit(cli(['setup', '--target', 'auto', '--yes']));
981
+ const failure = yield* cli(['setup', '--target', 'auto', '--yes']).pipe(Effect.flip);
982
989
- expect(Exit.isFailure(exit)).toBe(true);
990
- if (Exit.isFailure(exit)) {
991
- const renderedCause = Cause.pretty(exit.cause);
992
- expect(renderedCause).toContain('requires JSON plugin inspection');
993
- expect(renderedCause).toContain('claude update');
994
- }
983
+ expect(failure).toMatchObject({
984
+ message: expect.stringContaining('requires JSON plugin inspection'),
985
+ });
986
+ expect(failure).toMatchObject({ message: expect.stringContaining('claude update') });
987
expect(legacyClaude.commands.some(parts => parts.includes('--json'))).toBe(false);
988
expect(
989
legacyClaude.commands.some(parts =>
999
it => {
1000
it.effect('fails automatic setup when no supported host remains', () =>
1001
Effect.gen(function* () {
1010
- const exit = yield* Effect.exit(cli(['setup', '--target', 'auto', '--yes']));
1002
+ const failure = yield* cli(['setup', '--target', 'auto', '--yes']).pipe(Effect.flip);
1003
1012
- expect(Exit.isFailure(exit)).toBe(true);
1013
- if (Exit.isFailure(exit)) {
1014
- expect(Cause.pretty(exit.cause)).toContain('requires Codex 0.139.0 or newer');
1015
- }
1004
+ expect(failure).toMatchObject({
1005
+ message: expect.stringContaining('requires Codex 0.139.0 or newer'),
1006
+ });
1007
})
1008
);
1009
1023
1024
it.effect('fails with an actionable upgrade message before running setup mutations', () =>
1025
Effect.gen(function* () {
1035
- const exit = yield* Effect.exit(cli(['setup', '--target', 'codex', '--yes']));
1026
+ const failure = yield* cli(['setup', '--target', 'codex', '--yes']).pipe(Effect.flip);
1027
1037
- expect(Exit.isFailure(exit)).toBe(true);
1038
- if (Exit.isFailure(exit)) {
1039
- const renderedCause = Cause.pretty(exit.cause);
1040
- expect(renderedCause).toContain('requires Codex 0.139.0 or newer');
1041
- expect(renderedCause).toContain('codex update');
1042
- expect(renderedCause).not.toContain("unexpected argument '--json'");
1043
- }
1028
+ expect(failure).toMatchObject({
1029
+ message: expect.stringContaining('requires Codex 0.139.0 or newer'),
1030
+ });
1031
+ expect(failure).toMatchObject({ message: expect.stringContaining('codex update') });
1032
+ expect(failure).not.toMatchObject({
1033
+ message: expect.stringContaining("unexpected argument '--json'"),
1034
+ });
1035
expect(legacyCodex.commands.some(parts => parts.includes('--json'))).toBe(false);
1036
expect(
1037
legacyCodex.commands.some(parts =>
1094
)('multi-host mutation failure', it => {
1095
it.effect('reports hosts completed before a later target fails', () =>
1096
Effect.gen(function* () {
1106
- const exit = yield* Effect.exit(cli(['setup', '--target', 'all', '--yes']));
1097
+ const failure = yield* cli(['setup', '--target', 'all', '--yes']).pipe(Effect.flip);
1098
1108
- expect(Exit.isFailure(exit)).toBe(true);
1109
- if (Exit.isFailure(exit)) {
1110
- expect(Cause.pretty(exit.cause)).toContain(
1099
+ expect(failure).toMatchObject({
1100
+ message: expect.stringContaining(
1101
'Setup completed for claude before a later target failed'
1112
- );
1113
- }
1102
+ ),
1103
+ });
1104
expect(laterMutationFailure.state.claude).toMatchObject({
1105
marketplace: 'canonical',
1106
plugin: 'enabled',
1141
it.effect('times out instead of blocking setup forever', () =>
1142
Effect.gen(function* () {
1143
const fiber = yield* cli(['setup', '--target', 'claude', '--yes']).pipe(
1154
- Effect.exit,
1144
+ Effect.flip,
1145
Effect.forkChild
1146
);
1147
yield* hostCommandReached.await;
1148
yield* Effect.yieldNow;
1149
yield* TestClock.adjust('2 minutes');
1160
- const exit = yield* Fiber.join(fiber);
1150
+ const failure = yield* Fiber.join(fiber);
1151
1162
- expect(Exit.isFailure(exit)).toBe(true);
1163
- if (Exit.isFailure(exit)) {
1164
- const renderedCause = Cause.pretty(exit.cause);
1165
- expect(renderedCause).toContain(
1152
+ expect(failure).toMatchObject({
1153
+ message: expect.stringContaining(
1154
'The `claude --version` command timed out after 2 minutes'
1167
- );
1168
- expect(renderedCause).not.toContain('not installed or not available on PATH');
1169
- }
1155
+ ),
1156
+ });
1157
+ expect(failure).not.toMatchObject({
1158
+ message: expect.stringContaining('not installed or not available on PATH'),
1159
+ });
1160
})
1161
);
1162
});
1181
layer(TestLive({ commandRunner: failedInstall.runner }))('native install failure', it => {
1182
it.effect('preserves the structured setup process failure as the command cause', () =>
1183
Effect.gen(function* () {
1194
- const exit = yield* Effect.exit(cli(['setup', '--target', 'claude', '--yes']));
1195
- expect(Exit.isFailure(exit)).toBe(true);
1196
- if (Exit.isFailure(exit)) {
1197
- const failure = Cause.squash(exit.cause);
1198
- expect(failure).toBeInstanceOf(SetupCommandError);
1199
- if (failure instanceof SetupCommandError) {
1200
- expect(failure.operation).toBe('setup');
1201
- expect(failure.cause).toBeInstanceOf(SetupProcessError);
1202
- if (failure.cause instanceof SetupProcessError) {
1203
- expect(failure.cause).toMatchObject({ target: 'claude', stage: 'mutate' });
1204
- }
1205
- }
1206
- }
1184
+ const failure = yield* cli(['setup', '--target', 'claude', '--yes']).pipe(Effect.flip);
1185
+
1186
+ expect(failure).toBeInstanceOf(SetupCommandError);
1187
+ expect(failure).toMatchObject({ operation: 'setup', cause: expect.any(SetupProcessError) });
1188
+ expect(failure).toMatchObject({ cause: { target: 'claude', stage: 'mutate' } });
1189
})
1190
);
1191
});
1208
});
1209
});
1210
1229
-const reasonCodeOf = (exit: Exit.Exit<unknown, unknown>): string | undefined => {
1230
- if (!Exit.isFailure(exit)) return undefined;
1231
- const failure = Cause.squash(exit.cause);
1232
- if (failure instanceof SetupCommandError) return failure.reasonCode;
1233
- return undefined;
1234
-};
1235
-
1211
const REASON_CODE_FIXTURES = {
1212
'only Claude Code installed': () => makeFakeHosts({ claude: { available: true } }),
1213
'no host installed': () => makeFakeHosts({}),
1221
1222
const REASON_CODE_CASES: ReadonlyArray<{
1223
readonly hosts: keyof typeof REASON_CODE_FIXTURES;
1249
- readonly argv: ReadonlyArray<string>;
1250
- readonly expected: string;
1224
+ readonly cases: ReadonlyArray<{ readonly args: string; readonly expected: string }>;
1225
}> = [
1226
{
1227
hosts: 'only Claude Code installed',
1254
- argv: ['--target', 'all', '--yes'],
1255
- expected: 'all_requires_both_hosts',
1256
- },
1257
- {
1258
- hosts: 'only Claude Code installed',
1259
- argv: ['--target', 'codex', '--yes'],
1260
- expected: 'target_not_installed',
1261
- },
1262
- {
1263
- hosts: 'only Claude Code installed',
1264
- argv: ['--target', 'claude'],
1265
- expected: 'non_interactive_requires_yes',
1228
+ cases: [
1229
+ { args: '--target all --yes', expected: 'all_requires_both_hosts' },
1230
+ { args: '--target codex --yes', expected: 'target_not_installed' },
1231
+ { args: '--target claude', expected: 'non_interactive_requires_yes' },
1232
+ ],
1233
},
1267
- { hosts: 'no host installed', argv: ['--yes'], expected: 'no_host_detected' },
1234
+ { hosts: 'no host installed', cases: [{ args: '--yes', expected: 'no_host_detected' }] },
1235
{
1236
hosts: 'unsupported Codex only',
1270
- argv: ['--target', 'codex', '--yes'],
1271
- expected: 'unsupported_host',
1237
+ cases: [
1238
+ { args: '--target codex --yes', expected: 'unsupported_host' },
1239
+ { args: '--yes', expected: 'unsupported_host' },
1240
+ ],
1241
},
1273
- { hosts: 'unsupported Codex only', argv: ['--yes'], expected: 'unsupported_host' },
1242
{
1243
hosts: 'marketplace conflict',
1276
- argv: ['--target', 'claude', '--yes'],
1277
- expected: 'marketplace_conflict',
1244
+ cases: [{ args: '--target claude --yes', expected: 'marketplace_conflict' }],
1245
+ },
1246
+ {
1247
+ hosts: 'native install failure',
1248
+ cases: [{ args: '--target claude --yes', expected: 'unknown' }],
1249
},
1279
- { hosts: 'native install failure', argv: ['--target', 'claude', '--yes'], expected: 'unknown' },
1250
];
1251
1252
describe('CLI: composio setup failure reason codes', () => {
1254
process.exitCode = undefined;
1255
});
1256
1287
- for (const [hosts, makeHosts] of Object.entries(REASON_CODE_FIXTURES)) {
1288
- const fake = makeHosts();
1289
- layer(TestLive({ commandRunner: fake.runner }))(hosts, it => {
1290
- for (const { argv, expected } of REASON_CODE_CASES.filter(c => c.hosts === hosts)) {
1291
- it.effect(`codes \`setup ${argv.join(' ')}\` as ${expected}`, () =>
1292
- Effect.gen(function* () {
1293
- const exit = yield* Effect.exit(cli(['setup', ...argv]));
1294
- expect(reasonCodeOf(exit)).toBe(expected);
1295
- })
1296
- );
1297
- }
1257
+ describe.each(REASON_CODE_CASES)('$hosts', ({ hosts, cases }) => {
1258
+ layer(TestLive({ commandRunner: REASON_CODE_FIXTURES[hosts]().runner }))(it => {
1259
+ it.effect.each(cases)('codes `setup $args` as $expected', ({ args, expected }) =>
1260
+ Effect.gen(function* () {
1261
+ const failure = yield* cli(['setup', ...args.split(' ')]).pipe(Effect.flip);
1262
+
1263
+ expect(failure).toBeInstanceOf(SetupCommandError);
1264
+ expect(failure).toMatchObject({ reasonCode: expected });
1265
+ })
1266
+ );
1267
});
1299
- }
1268
+ });
1269
});
1270
1271
describe('CLI: composio setup rerun hints stay non-interactive safe', () => {
1273
process.exitCode = undefined;
1274
});
1275
1307
- const messageOf = (exit: Exit.Exit<unknown, unknown>): string | undefined => {
1308
- if (!Exit.isFailure(exit)) return undefined;
1309
- const failure = Cause.squash(exit.cause);
1310
- return failure instanceof Error ? failure.message : String(failure);
1311
- };
1312
-
1276
layer(TestLive({ commandRunner: REASON_CODE_FIXTURES['only Claude Code installed']().runner }))(
1277
'targeted host missing',
1278
it => {
1279
it.effect('target_not_installed rerun carries --yes', () =>
1280
Effect.gen(function* () {
1318
- const exit = yield* Effect.exit(cli(['setup', '--target', 'codex', '--yes']));
1319
- expect(messageOf(exit)).toContain('rerun `composio setup --yes --target codex`');
1281
+ const failure = yield* cli(['setup', '--target', 'codex', '--yes']).pipe(Effect.flip);
1282
+ expect(failure).toMatchObject({
1283
+ message: expect.stringContaining('rerun `composio setup --yes --target codex`'),
1284
+ });
1285
})
1286
);
1287
}
1292
it => {
1293
it.effect('no_host_detected rerun carries --yes', () =>
1294
Effect.gen(function* () {
1330
- const exit = yield* Effect.exit(cli(['setup', '--yes']));
1331
- expect(messageOf(exit)).toContain('rerun `composio setup --yes`');
1295
+ const failure = yield* cli(['setup', '--yes']).pipe(Effect.flip);
1296
+ expect(failure).toMatchObject({
1297
+ message: expect.stringContaining('rerun `composio setup --yes`'),
1298
+ });
1299
})
1300
);
1301
}
1306
it => {
1307
it.effect('marketplace_conflict rerun carries --yes', () =>
1308
Effect.gen(function* () {
1342
- const exit = yield* Effect.exit(cli(['setup', '--target', 'claude', '--yes']));
1343
- expect(messageOf(exit)).toContain('rerun `composio setup --yes --target claude`');
1309
+ const failure = yield* cli(['setup', '--target', 'claude', '--yes']).pipe(Effect.flip);
1310
+ expect(failure).toMatchObject({
1311
+ message: expect.stringContaining('rerun `composio setup --yes --target claude`'),
1312
+ });
1313
})
1314
);
1315
}