Skip to content

Commit 8c42527

Browse files
recuu-pfegclaude
andcommitted
fix: symlink node_modules in worktree for test execution
Worktrees don't share node_modules with the main repo. Now symlinks both root and api/node_modules so npm test works in the worktree without a full npm install. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent bfba84e commit 8c42527

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/spawner.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { spawn, type ChildProcess } from "node:child_process";
22
import { execSync } from "node:child_process";
3-
import { rmSync, existsSync, mkdirSync } from "node:fs";
3+
import { rmSync, existsSync, mkdirSync, symlinkSync } from "node:fs";
44
import path from "node:path";
55
import type { AgentConfig, RunningAgent } from "./types.js";
66
import { getTerminal, buildShellCommand, type TerminalInfo } from "./terminal.js";
@@ -56,6 +56,22 @@ export function createWorktree(
5656
return repoDir;
5757
}
5858

59+
// Symlink node_modules from main repo so tests and builds work in worktree
60+
try {
61+
const mainNodeModules = path.join(repoDir, "node_modules");
62+
const wtNodeModules = path.join(worktreeDir, "node_modules");
63+
if (existsSync(mainNodeModules) && !existsSync(wtNodeModules)) {
64+
symlinkSync(mainNodeModules, wtNodeModules, "dir");
65+
}
66+
// Also symlink api/node_modules if it exists (monorepo)
67+
const apiMainNm = path.join(repoDir, "api", "node_modules");
68+
const apiWtDir = path.join(worktreeDir, "api");
69+
const apiWtNm = path.join(apiWtDir, "node_modules");
70+
if (existsSync(apiMainNm) && existsSync(apiWtDir) && !existsSync(apiWtNm)) {
71+
symlinkSync(apiMainNm, apiWtNm, "dir");
72+
}
73+
} catch { /* non-fatal — tests may fail but agent can still work */ }
74+
5975
return worktreeDir;
6076
}
6177

0 commit comments

Comments
 (0)