Skip to content

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(ts/cli): improve test isolation in test-layer.ts

jkomynoa6319e3f1f6d
diff --git a/ts/packages/cli/test/__utils__/services/test-layer.ts b/ts/packages/cli/test/__utils__/services/test-layer.ts
index 4c2323270..0fad5e717 100644
--- a/ts/packages/cli/test/__utils__/services/test-layer.ts
+++ b/ts/packages/cli/test/__utils__/services/test-layer.ts
@@ -1,7 +1,7 @@
import path from 'node:path';
import * as tempy from 'tempy';
import { CliApp, CliConfig } from '@effect/cli';
-import { FetchHttpClient, FileSystem } from '@effect/platform';
+import { Command, FetchHttpClient, FileSystem } from '@effect/platform';
import { BunFileSystem, BunContext, BunPath } from '@effect/platform-bun';
import {
ConfigProvider,
@@ -225,10 +225,115 @@ function setupFixtureFolder({ fixture, tempDir }: { fixture?: string; tempDir: s
yield* Effect.logDebug(`Copied fixture to: ${tmpFixturesPath}`);
+ // Break symlinks in node_modules to isolate test from real packages
+ const nodeModulesPath = path.join(tmpFixturesPath, 'node_modules');
+ yield* breakSymlinksInNodeModules(fs, nodeModulesPath);
+
return tmpFixturesPath;
}).pipe(Effect.provide(BunFileSystem.layer));
}
+/**
+ * Breaks symlinks in node_modules to ensure test isolation.
+ * - On Unix: Uses `find -type l` for O(1) shell call to detect all symlinks
+ * - On Windows: Uses O(n) readLink approach for compatibility
+ */
+function breakSymlinksInNodeModules(
+ fs: FileSystem.FileSystem,
+ nodeModulesPath: string
+): Effect.Effect<void, never, never> {
+ // Helper: break a symlink by replacing it with a copy of its target
+ const breakSymlink = (symlinkPath: string) =>
+ Effect.gen(function* () {
+ const realPath = yield* fs.realPath(symlinkPath);
+ yield* Effect.logDebug(`Breaking symlink: ${symlinkPath} -> ${realPath}`);
+ yield* fs.remove(symlinkPath, { recursive: true });
+ yield* fs.copy(realPath, symlinkPath);
+ });
+
+ // Unix: Use `find` command for fast symlink detection
+ const breakSymlinksUnix = Effect.gen(function* () {
+ const findCmd = Command.make(
+ 'find',
+ nodeModulesPath,
+ '-maxdepth',
+ '2',
+ '-type',
+ 'l',
+ '-not',
+ '-path',
+ '*/.*'
+ );
+ const output = yield* findCmd.pipe(Command.string, Effect.provide(BunContext.layer));
+ const symlinks = output.trim().split('\n').filter(Boolean);
+
+ if (symlinks.length === 0) {
+ return;
+ }
+
+ yield* Effect.logDebug(`Found ${symlinks.length} symlinks to break`);
+ yield* Effect.all(symlinks.map(breakSymlink), { concurrency: 'unbounded' });
+ });
+
+ // Windows: Use readLink to detect symlinks (O(n) but compatible)
+ const breakSymlinksWindows = Effect.gen(function* () {
+ const isSymlink = (p: string) =>
+ fs.readLink(p).pipe(
+ Effect.map(() => true),
+ Effect.catchAll(() => Effect.succeed(false))
+ );
+
+ const entries = yield* fs.readDirectory(nodeModulesPath);
+
+ yield* Effect.all(
+ entries.map(entry => {
+ if (entry.startsWith('.')) {
+ return Effect.void;
+ }
+
+ const entryPath = path.join(nodeModulesPath, entry);
+ return Effect.gen(function* () {
+ const isLink = yield* isSymlink(entryPath);
+
+ if (isLink) {
+ yield* breakSymlink(entryPath);
+ } else if (entry.startsWith('@')) {
+ const scopedEntries = yield* fs.readDirectory(entryPath);
+ yield* Effect.all(
+ scopedEntries.map(scopedEntry => {
+ const scopedPath = path.join(entryPath, scopedEntry);
+ return Effect.gen(function* () {
+ const isScopedLink = yield* isSymlink(scopedPath);
+ if (isScopedLink) {
+ yield* breakSymlink(scopedPath);
+ }
+ });
+ }),
+ { concurrency: 'unbounded' }
+ );
+ }
+ });
+ }),
+ { concurrency: 'unbounded' }
+ );
+ });
+
+ return Effect.gen(function* () {
+ const exists = yield* fs.exists(nodeModulesPath);
+ if (!exists) {
+ return;
+ }
+
+ const isWindows = process.platform === 'win32';
+
+ if (isWindows) {
+ yield* breakSymlinksWindows;
+ } else {
+ yield* breakSymlinksUnix;
+ }
+ }).pipe(Effect.catchAll(() => Effect.void));
+}
+
function setupComposioSessionRepository() {
return Effect.gen(function* () {
const now = yield* DateTime.now;