@devries-cameron20 / composio Mirror · read-only / commits / a6319e3f1
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.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 22, 14:30 UTC

feat(ts/cli): improve test isolation in test-layer.ts

jkomyno committed Jan 14, 2026 at 19:53 UTC a6319e3f1f6df5f8d9b71bb525c0fe1d7968a35f
1 file changed +106 -1
ts/packages/cli/test/__utils__/services/test-layer.ts
+106 -1
@@ -1,7 +1,7 @@
1 import path from 'node:path';
2 import * as tempy from 'tempy';
3 import { CliApp, CliConfig } from '@effect/cli';
4 -import { FetchHttpClient, FileSystem } from '@effect/platform';
4 +import { Command, FetchHttpClient, FileSystem } from '@effect/platform';
5 import { BunFileSystem, BunContext, BunPath } from '@effect/platform-bun';
6 import {
7 ConfigProvider,
@@ -225,10 +225,115 @@ function setupFixtureFolder({ fixture, tempDir }: { fixture?: string; tempDir: s
225
226 yield* Effect.logDebug(`Copied fixture to: ${tmpFixturesPath}`);
227
228 + // Break symlinks in node_modules to isolate test from real packages
229 + const nodeModulesPath = path.join(tmpFixturesPath, 'node_modules');
230 + yield* breakSymlinksInNodeModules(fs, nodeModulesPath);
231 +
232 return tmpFixturesPath;
233 }).pipe(Effect.provide(BunFileSystem.layer));
234 }
235
236 +/**
237 + * Breaks symlinks in node_modules to ensure test isolation.
238 + * - On Unix: Uses `find -type l` for O(1) shell call to detect all symlinks
239 + * - On Windows: Uses O(n) readLink approach for compatibility
240 + */
241 +function breakSymlinksInNodeModules(
242 + fs: FileSystem.FileSystem,
243 + nodeModulesPath: string
244 +): Effect.Effect<void, never, never> {
245 + // Helper: break a symlink by replacing it with a copy of its target
246 + const breakSymlink = (symlinkPath: string) =>
247 + Effect.gen(function* () {
248 + const realPath = yield* fs.realPath(symlinkPath);
249 + yield* Effect.logDebug(`Breaking symlink: ${symlinkPath} -> ${realPath}`);
250 + yield* fs.remove(symlinkPath, { recursive: true });
251 + yield* fs.copy(realPath, symlinkPath);
252 + });
253 +
254 + // Unix: Use `find` command for fast symlink detection
255 + const breakSymlinksUnix = Effect.gen(function* () {
256 + const findCmd = Command.make(
257 + 'find',
258 + nodeModulesPath,
259 + '-maxdepth',
260 + '2',
261 + '-type',
262 + 'l',
263 + '-not',
264 + '-path',
265 + '*/.*'
266 + );
267 + const output = yield* findCmd.pipe(Command.string, Effect.provide(BunContext.layer));
268 + const symlinks = output.trim().split('\n').filter(Boolean);
269 +
270 + if (symlinks.length === 0) {
271 + return;
272 + }
273 +
274 + yield* Effect.logDebug(`Found ${symlinks.length} symlinks to break`);
275 + yield* Effect.all(symlinks.map(breakSymlink), { concurrency: 'unbounded' });
276 + });
277 +
278 + // Windows: Use readLink to detect symlinks (O(n) but compatible)
279 + const breakSymlinksWindows = Effect.gen(function* () {
280 + const isSymlink = (p: string) =>
281 + fs.readLink(p).pipe(
282 + Effect.map(() => true),
283 + Effect.catchAll(() => Effect.succeed(false))
284 + );
285 +
286 + const entries = yield* fs.readDirectory(nodeModulesPath);
287 +
288 + yield* Effect.all(
289 + entries.map(entry => {
290 + if (entry.startsWith('.')) {
291 + return Effect.void;
292 + }
293 +
294 + const entryPath = path.join(nodeModulesPath, entry);
295 + return Effect.gen(function* () {
296 + const isLink = yield* isSymlink(entryPath);
297 +
298 + if (isLink) {
299 + yield* breakSymlink(entryPath);
300 + } else if (entry.startsWith('@')) {
301 + const scopedEntries = yield* fs.readDirectory(entryPath);
302 + yield* Effect.all(
303 + scopedEntries.map(scopedEntry => {
304 + const scopedPath = path.join(entryPath, scopedEntry);
305 + return Effect.gen(function* () {
306 + const isScopedLink = yield* isSymlink(scopedPath);
307 + if (isScopedLink) {
308 + yield* breakSymlink(scopedPath);
309 + }
310 + });
311 + }),
312 + { concurrency: 'unbounded' }
313 + );
314 + }
315 + });
316 + }),
317 + { concurrency: 'unbounded' }
318 + );
319 + });
320 +
321 + return Effect.gen(function* () {
322 + const exists = yield* fs.exists(nodeModulesPath);
323 + if (!exists) {
324 + return;
325 + }
326 +
327 + const isWindows = process.platform === 'win32';
328 +
329 + if (isWindows) {
330 + yield* breakSymlinksWindows;
331 + } else {
332 + yield* breakSymlinksUnix;
333 + }
334 + }).pipe(Effect.catchAll(() => Effect.void));
335 +}
336 +
337 function setupComposioSessionRepository() {
338 return Effect.gen(function* () {
339 const now = yield* DateTime.now;