Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
feat(cli): add script to copy cached responses in mocks for tests
jkomyno committed
Jul 29, 2025 at 06:18 UTC
d977785dd7f2a2389ebd33f89bb719cc80f0afc2
4 files changed
+92
-2
ts/packages/cli/package.json
+1
@@ -26,6 +26,7 @@
26
"cli": "bun run src/bin.ts",
27
"build:bin": "bun run ./scripts/build-binary.ts",
28
"install:bin": "bun run ./scripts/install-binary.ts ./dist/composio",
29
+ "mock": "bun run ./scripts/copy-mocks-from-cache.ts",
30
"prebuild": "bun run typecheck",
31
"build": "tsup",
32
"bin": "./dist/composio",
ts/packages/cli/scripts/build-binary.ts
+1
-1
@@ -106,7 +106,7 @@ if (require.main === module) {
106
Effect.provide(Logger.pretty),
107
Effect.provide(BunContext.layer),
108
Effect.scoped,
109
- Effect.map(() => ({ message: 'Build process completed successfully.' })),
109
+ Effect.map(() => ({ message: 'Process completed successfully.' })),
110
BunRuntime.runMain({
111
teardown,
112
})
ts/packages/cli/scripts/copy-mocks-from-cache.ts
new
+89
@@ -0,0 +1,89 @@
1
+import process from 'node:process';
2
+import {
3
+ Cause,
4
+ Config,
5
+ ConfigProvider,
6
+ Console,
7
+ Effect,
8
+ Exit,
9
+ Logger,
10
+ Layer,
11
+ LogLevel,
12
+} from 'effect';
13
+import { BunContext, BunFileSystem, BunRuntime } from '@effect/platform-bun';
14
+import { FileSystem } from '@effect/platform';
15
+import type { Teardown } from '@effect/platform/Runtime';
16
+import path from 'node:path';
17
+import { $ } from 'bun';
18
+import { CACHE_FILES } from '../src/services/composio-clients-cached';
19
+import { setupCacheDir } from 'src/effects/setup-cache-dir';
20
+import { NodeOs } from 'src/services/node-os';
21
+
22
+/**
23
+ * Usage: `bun scripts/copy-mocks-from-cache.ts`.
24
+ *
25
+ * Copies cached mock responses from the cache directory to the specified mocks directory.
26
+ */
27
+export function copyMocksFromCache() {
28
+ return Effect.gen(function* () {
29
+ const fs = yield* FileSystem.FileSystem;
30
+ const defaultMocksDir = path.join(process.cwd(), 'test', '__mocks__');
31
+
32
+ const cacheDir = yield* setupCacheDir;
33
+
34
+ const mocksDir = yield* Config.string('COMPOSIO_MOCKS_DIR').pipe(
35
+ Config.withDefault(defaultMocksDir)
36
+ );
37
+
38
+ yield* Effect.logDebug(`Copying mocks to ${mocksDir}`);
39
+
40
+ for (const [key, cacheFileName] of Object.entries(CACHE_FILES)) {
41
+ const cacheFilePath = path.join(cacheDir, cacheFileName);
42
+ const mocksFilePath = path.join(mocksDir, cacheFileName);
43
+
44
+ yield* Effect.logDebug(`Copying ${key} from ${cacheFilePath}`);
45
+
46
+ const cacheFileExists = yield* fs
47
+ .exists(cacheFilePath)
48
+ .pipe(Effect.orElse(() => Effect.succeed(false)));
49
+
50
+ if (!cacheFileExists) {
51
+ yield* Effect.logWarning(`Cache file ${cacheFilePath} does not exist, skipping.`);
52
+ continue;
53
+ }
54
+
55
+ yield* Effect.tryPromise(() => $`cp ${cacheFilePath} ${mocksFilePath}`.quiet());
56
+ }
57
+
58
+ yield* Console.log('Cached responses successfully copied into mocks folder:', mocksDir);
59
+ });
60
+}
61
+
62
+export const teardown: Teardown = <E, A>(exit: Exit.Exit<E, A>, onExit: (code: number) => void) => {
63
+ const shouldFail = Exit.isFailure(exit) && !Cause.isInterruptedOnly(exit.cause);
64
+ const errorCode = Number(process.exitCode ?? 1);
65
+ onExit(shouldFail ? errorCode : 0);
66
+};
67
+
68
+const ConfigLive = Effect.gen(function* () {
69
+ const logLevel = yield* Config.logLevel('COMPOSIO_LOG_LEVEL').pipe(
70
+ Config.withDefault(LogLevel.Info)
71
+ );
72
+
73
+ return Logger.minimumLogLevel(logLevel);
74
+}).pipe(Layer.unwrapEffect, Layer.merge(Layer.setConfigProvider(ConfigProvider.fromEnv())));
75
+
76
+if (require.main === module) {
77
+ copyMocksFromCache().pipe(
78
+ Effect.provide(ConfigLive),
79
+ Effect.provide(Logger.pretty),
80
+ Effect.provide(BunContext.layer),
81
+ Effect.provide(BunFileSystem.layer),
82
+ Effect.provide(NodeOs.Default),
83
+ Effect.scoped,
84
+ Effect.map(() => ({ message: 'Process completed successfully.' })),
85
+ BunRuntime.runMain({
86
+ teardown,
87
+ })
88
+ );
89
+}
ts/packages/cli/scripts/install-binary.ts
+1
-1
@@ -60,7 +60,7 @@ if (require.main === module) {
60
Effect.provide(Logger.pretty),
61
Effect.provide(BunContext.layer),
62
Effect.scoped,
63
- Effect.map(() => ({ message: 'Binary installed successfully.' })),
63
+ Effect.map(() => ({ message: 'Process completed successfully.' })),
64
BunRuntime.runMain({
65
teardown,
66
})