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

refactor(cli): extract the setup and command runner doubles from the test layer (#4927)

This PR: - moves the `CommandRunner` double out of `test/__utils__/services/test-layer.ts` into `test/__utils__/layers/command-runner.ts`: `CommandRunnerTest(runner?)` answers with the runner the test passes, or exits 0 with empty output (`run` and `capture`) without spawning - moves the `SetupSkillInstaller` double into `test/__utils__/layers/setup.ts`: `SetupSkillInstallerTest(installer?)` answers with the installer the test passes, or the no-op one whose four effects answer `false` however often they run - adds `SetupTest({ commandRunner?, setupSkillInstaller? })` in the same file, the two layers merged, for handler tests of `setup` (U7) that need nothing else from `TestLive` - keeps `TestLive(input)` unchanged: `TestLiveInput`'s `commandRunner` and `setupSkillInstaller` keep their types and docs, and `TestLive` composes `CommandRunnerTest(input?.commandRunner)` and `SetupSkillInstallerTest(input?.setupSkillInstaller)` where the two inline layers were - exports `CommandRunnerTest` and `SetupTest` from `test/__utils__` - extends `test/src/services/test-layer.test.ts` with eight cases: the standalone layer and `TestLive` give the same default and override answers for the runner and the installer, and the runner doubles never reach a `ChildProcessSpawner` that dies on use ## Context Unit U3 of the command-layout series (KTD5), third family: setup and the command runner, which `setup` and `install` (U7) rely on. The moved bodies are unchanged; the two defaults are module constants now instead of being rebuilt per `TestLive` call, which changes nothing because they hold only `Effect.succeed` values. No suite under `test/src/commands/` changes. `test-layer.ts` goes from 1167 to 1139 lines. The runner gets its own file because `generate` and `run` also use `CommandRunner`, so it is not part of the setup family alone. `install` needs neither service: it reads `NodeOs`, `NodeProcess`, `FileSystem`, `Path`, `TerminalUI`, and `ComposioCliUserConfig`. The `NodeOs`/`NodeProcess` doubles depend on the per-test home directory and fixture copy that `TestLive` builds, so they stay in place until a host family moves them. U7's planned `src/services/shell-config.ts` does not exist yet, so there is no shell double to extract. `SetupSkillInstallerShape` is derived from the real installer (`Effect.Success<typeof makeSetupSkillInstaller>`), so its effects still name `FileSystem`, `Path`, `HttpClient`, `NodeOs`, and `TerminalUI` as requirements even when a double reads none of them. A test that provides `SetupTest` alone has to provide those too (the new cases do). Narrowing the shape would change `src/`, so this PR leaves it alone. ## Verification On the branch tip (`894b93535`): - `pnpm typecheck`: 14/14 tasks, `@composio/cli:typecheck` a cache miss (src and test configs) - `pnpm --filter @composio/cli test`: 156 files, 1862 passed, 1 skipped (the eight new cases included); `validate:command-tests` at 16 exemptions, unchanged - `pnpm --filter @composio/cli run lint:effect`: 0 errors, 0 warnings - `oxlint` and `prettier --check` clean on every touched file

Alberto Schiabel committed Oct 16, 2026 at 13:01 UTC 32917664b786aea0a603f4139fa1fc49aaa5a9a3
5 files changed +185 -36
ts/packages/cli/test/__utils__/index.ts
+2
@@ -5,6 +5,8 @@ export * as MockTerminal from './services/mock-terminal';
5 export { TestLayer as TestLive } from './services/test-layer';
6 export { ToolkitsTest } from './layers/toolkits';
7 export { ConnectedAccountsTest } from './layers/connected-accounts';
8 +export { CommandRunnerTest } from './layers/command-runner';
9 +export { SetupTest } from './layers/setup';
10 export { cli } from './cli';
11 export { pkg };
12 export { withHttpServer } from './http-server';
ts/packages/cli/test/__utils__/layers/command-runner.ts new
+23
@@ -0,0 +1,23 @@
1 +import { Effect, Layer } from 'effect';
2 +import { CommandRunner, type CommandRunnerShape } from 'src/services/command-runner';
3 +
4 +/**
5 + * A runner that never spawns: every command exits 0 with empty output.
6 + */
7 +const exitZeroCommandRunner = CommandRunner.of({
8 + run: () => Effect.succeed(0),
9 + capture: () =>
10 + Effect.succeed({
11 + exitCode: 0,
12 + stdout: '',
13 + stderr: '',
14 + }),
15 +});
16 +
17 +/**
18 + * A `CommandRunner` that answers with `runner`, or exits 0 with empty output
19 + * when the test leaves it out. It never spawns a process, but its methods
20 + * still require the `ChildProcessSpawner` their shape names.
21 + */
22 +export const CommandRunnerTest = (runner?: CommandRunnerShape) =>
23 + Layer.succeed(CommandRunner, runner ?? exitZeroCommandRunner);
ts/packages/cli/test/__utils__/layers/setup.ts new
+38
@@ -0,0 +1,38 @@
1 +import { Effect, Layer } from 'effect';
2 +import type { CommandRunnerShape } from 'src/services/command-runner';
3 +import {
4 + SetupSkillInstaller,
5 + type SetupSkillInstallerShape,
6 +} from 'src/services/setup-skill-installer';
7 +import { CommandRunnerTest } from './command-runner';
8 +
9 +/**
10 + * An installer with no Claude skill that changes nothing: every check and
11 + * every install or removal answers `false`, however often it runs.
12 + */
13 +const noOpSetupSkillInstaller = SetupSkillInstaller.of({
14 + isClaudeSkillReady: Effect.succeed(false),
15 + hasManagedClaudeSkill: Effect.succeed(false),
16 + ensureClaudeSkill: Effect.succeed(false),
17 + removeClaudeSkill: Effect.succeed(false),
18 +});
19 +
20 +/**
21 + * A `SetupSkillInstaller` that answers with `installer`, or the no-op one
22 + * when the test leaves it out.
23 + */
24 +export const SetupSkillInstallerTest = (installer?: SetupSkillInstallerShape) =>
25 + Layer.succeed(SetupSkillInstaller, installer ?? noOpSetupSkillInstaller);
26 +
27 +/**
28 + * The host commands `setup` runs and the Claude skill it installs, for a
29 + * test that needs nothing else from the full `TestLive` layer.
30 + */
31 +export const SetupTest = (data?: {
32 + readonly commandRunner?: CommandRunnerShape;
33 + readonly setupSkillInstaller?: SetupSkillInstallerShape;
34 +}) =>
35 + Layer.mergeAll(
36 + CommandRunnerTest(data?.commandRunner),
37 + SetupSkillInstallerTest(data?.setupSkillInstaller)
38 + );
ts/packages/cli/test/__utils__/services/test-layer.ts
+6 -34
@@ -71,16 +71,15 @@ import type {
71 import { Stdin } from 'src/services/stdin';
72 import { ProjectContext } from 'src/services/project-context';
73 import { ProjectEnvironmentDetector } from 'src/services/project-environment-detector';
74 -import { CommandRunner, type CommandRunnerShape } from 'src/services/command-runner';
74 +import type { CommandRunnerShape } from 'src/services/command-runner';
75 import { TerminalUI } from 'src/services/terminal-ui';
76 -import {
77 - SetupSkillInstaller,
78 - type SetupSkillInstallerShape,
79 -} from 'src/services/setup-skill-installer';
76 +import type { SetupSkillInstallerShape } from 'src/services/setup-skill-installer';
77 import { FetchHttpClient, HttpClient } from 'effect/http';
78 import * as BunServices from '@effect/platform-bun/BunServices';
79 import { notFoundError } from '../layers/not-found';
80 import { DEFAULT_PAGE_LIMIT } from '../layers/page';
81 +import { CommandRunnerTest } from '../layers/command-runner';
82 +import { SetupSkillInstallerTest } from '../layers/setup';
83 import {
84 resolveToolkitsTestData,
85 toolkitCatalogMethods,
@@ -853,38 +852,11 @@ export const TestLayer = (input?: TestLiveInput) =>
852
853 const CliConfigLive = CliConfig.layer(ComposioCliConfig);
854
856 - // CommandRunner mock — default returns exit code 0
857 - const CommandRunnerTest = input?.commandRunner
858 - ? Layer.succeed(CommandRunner, input.commandRunner)
859 - : Layer.succeed(
860 - CommandRunner,
861 - CommandRunner.of({
862 - run: () => Effect.succeed(0),
863 - capture: () =>
864 - Effect.succeed({
865 - exitCode: 0,
866 - stdout: '',
867 - stderr: '',
868 - }),
869 - })
870 - );
871 -
855 // TerminalUI — use provided override or default TerminalUITest
856 const TerminalUILayer = input?.terminalUI
857 ? Layer.succeed(TerminalUI, input.terminalUI)
858 : TerminalUITest;
859
877 - const SetupSkillInstallerTest = Layer.succeed(
878 - SetupSkillInstaller,
879 - input?.setupSkillInstaller ??
880 - SetupSkillInstaller.of({
881 - isClaudeSkillReady: Effect.succeed(false),
882 - hasManagedClaudeSkill: Effect.succeed(false),
883 - ensureClaudeSkill: Effect.succeed(false),
884 - removeClaudeSkill: Effect.succeed(false),
885 - })
886 - );
887 -
860 const _console = yield* MockConsole.make;
861
862 const layers = Layer.mergeAll(
@@ -905,8 +877,8 @@ export const TestLayer = (input?: TestLiveInput) =>
877 ToolkitSlugCatalogTest,
878 JsPackageManagerDetector.Default,
879 ProjectEnvironmentDetector.Default,
908 - CommandRunnerTest,
909 - SetupSkillInstallerTest,
880 + CommandRunnerTest(input?.commandRunner),
881 + SetupSkillInstallerTest(input?.setupSkillInstaller),
882 ToolsExecutorTest,
883 BunFileSystem.layer,
884 BunServices.layer,
ts/packages/cli/test/src/services/test-layer.test.ts
+116 -2
@@ -1,6 +1,13 @@
1 import { describe, expect, it, vi } from '@effect/vitest';
2 -import { Effect, Exit } from 'effect';
2 +import * as BunFileSystem from '@effect/platform-bun/BunFileSystem';
3 +import * as BunPath from '@effect/platform-bun/BunPath';
4 +import { Effect, Exit, Layer } from 'effect';
5 +import { FetchHttpClient } from 'effect/http';
6 +import { ChildProcess, ChildProcessSpawner } from 'effect/process';
7 +import { CommandRunner } from 'src/services/command-runner';
8 import { ComposioToolkitsRepository } from 'src/services/composio-clients';
9 +import { NodeOs } from 'src/services/node-os';
10 +import { SetupSkillInstaller } from 'src/services/setup-skill-installer';
11 import {
12 getSessionInfoByUserApiKey,
13 listOrganizations,
@@ -8,9 +15,16 @@ import {
15 } from 'src/services/composio-account';
16 import type { AuthConfigItem } from 'src/models/auth-configs';
17 import type { ConnectedAccountItem } from 'src/models/connected-accounts';
11 -import { ConnectedAccountsTest, TestLive, ToolkitsTest } from 'test/__utils__';
18 +import {
19 + CommandRunnerTest,
20 + ConnectedAccountsTest,
21 + SetupTest,
22 + TestLive,
23 + ToolkitsTest,
24 +} from 'test/__utils__';
25 import { makeSessionInfo } from 'test/__utils__/models/account';
26 import { makeToolkitFixture } from 'test/__utils__/models/toolkits';
27 +import { TerminalUITest } from 'test/__utils__/services/terminal-ui-test';
28
29 describe('TestLayer', () => {
30 it.effect('leaves globalThis.fetch untouched', () =>
@@ -151,3 +165,103 @@ describe('ConnectedAccountsTest', () => {
165 }).pipe(Effect.provide(ConnectedAccountsTest()))
166 );
167 });
168 +
169 +// The runner doubles never spawn; a spawner that dies on use proves it.
170 +const noSpawn = Layer.succeed(
171 + ChildProcessSpawner.ChildProcessSpawner,
172 + ChildProcessSpawner.make(() => Effect.die('a runner double spawned a process'))
173 +);
174 +const failingRunner = CommandRunner.of({
175 + run: () => Effect.succeed(3),
176 + capture: () => Effect.succeed({ exitCode: 3, stdout: 'out', stderr: 'err' }),
177 +});
178 +
179 +describe('CommandRunnerTest', () => {
180 + const command = ChildProcess.make('false');
181 +
182 + it.effect.each([
183 + { name: 'CommandRunnerTest', layer: CommandRunnerTest() },
184 + { name: 'TestLive', layer: TestLive() },
185 + ])('exits 0 with empty output without spawning through $name', ({ layer }) =>
186 + Effect.gen(function* () {
187 + const runner = yield* CommandRunner;
188 + const exitCode = yield* runner.run(command);
189 + const captured = yield* runner.capture(command);
190 +
191 + expect(exitCode).toBe(0);
192 + expect(captured).toEqual({ exitCode: 0, stdout: '', stderr: '' });
193 + }).pipe(Effect.provide(Layer.merge(layer, noSpawn)), Effect.scoped)
194 + );
195 +
196 + it.effect.each([
197 + { name: 'CommandRunnerTest', layer: CommandRunnerTest(failingRunner) },
198 + { name: 'TestLive', layer: TestLive({ commandRunner: failingRunner }) },
199 + ])('answers with the runner the test passes through $name', ({ layer }) =>
200 + Effect.gen(function* () {
201 + const runner = yield* CommandRunner;
202 + const captured = yield* runner.capture(command);
203 +
204 + expect(captured).toEqual({ exitCode: 3, stdout: 'out', stderr: 'err' });
205 + }).pipe(Effect.provide(Layer.merge(layer, noSpawn)), Effect.scoped)
206 + );
207 +});
208 +
209 +describe('SetupTest', () => {
210 + // `SetupSkillInstallerShape` names the services the real installer reads; the doubles read none.
211 + const withInstallerServices = (layer: ReturnType<typeof SetupTest>) =>
212 + Layer.mergeAll(
213 + layer,
214 + BunFileSystem.layer,
215 + BunPath.layer,
216 + FetchHttpClient.layer,
217 + NodeOs.Default,
218 + TerminalUITest
219 + );
220 + const readyInstaller = SetupSkillInstaller.of({
221 + isClaudeSkillReady: Effect.succeed(true),
222 + hasManagedClaudeSkill: Effect.succeed(true),
223 + ensureClaudeSkill: Effect.succeed(false),
224 + removeClaudeSkill: Effect.succeed(true),
225 + });
226 +
227 + it.effect.each([
228 + { name: 'SetupTest', layer: withInstallerServices(SetupTest()) },
229 + { name: 'TestLive', layer: TestLive() },
230 + ])('installs no Claude skill and changes nothing, however often, through $name', ({ layer }) =>
231 + Effect.gen(function* () {
232 + const installer = yield* SetupSkillInstaller;
233 + const answers = yield* Effect.all([
234 + installer.ensureClaudeSkill,
235 + installer.ensureClaudeSkill,
236 + installer.isClaudeSkillReady,
237 + installer.hasManagedClaudeSkill,
238 + installer.removeClaudeSkill,
239 + ]);
240 +
241 + expect(answers).toEqual([false, false, false, false, false]);
242 + }).pipe(Effect.provide(layer), Effect.scoped)
243 + );
244 +
245 + it.effect.each([
246 + {
247 + name: 'SetupTest',
248 + layer: withInstallerServices(
249 + SetupTest({ commandRunner: failingRunner, setupSkillInstaller: readyInstaller })
250 + ),
251 + },
252 + {
253 + name: 'TestLive',
254 + layer: TestLive({ commandRunner: failingRunner, setupSkillInstaller: readyInstaller }),
255 + },
256 + ])('answers with the runner and installer the test passes through $name', ({ layer }) =>
257 + Effect.gen(function* () {
258 + const installer = yield* SetupSkillInstaller;
259 + const runner = yield* CommandRunner;
260 + const ready = yield* installer.isClaudeSkillReady;
261 + const exitCode = yield* runner.run(ChildProcess.make('claude', ['--version']));
262 +
263 + expect(ready).toBe(true);
264 + expect(exitCode).toBe(3);
265 + }).pipe(Effect.provide(Layer.merge(layer, noSpawn)), Effect.scoped)
266 + );
267 +});