Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: remove owned dependency links after package removal (#8801)
[._.]/ Adam Eivyb761045e118b
diff --git a/server/services/worktreeManager.js b/server/services/worktreeManager.jsindex 2e2f674f3a..94821a4165 100644--- a/server/services/worktreeManager.js+++ b/server/services/worktreeManager.js@@ -45,13 +45,15 @@ const DIRT_PATHS_IN_WARNING = 5;// Dependencies are linked from the source checkout for ordinary ephemeral// worktrees. Dependency-update tasks opt out so package managers cannot mutate// the source checkout's installed tree through these links.-async function worktreeDependencyPaths(sourceWorkspace, worktreePath) {- const entries = await readdir(sourceWorkspace, { withFileTypes: true });+async function worktreeDependencyPaths(sourceWorkspace, worktreePath, { cleanup = false } = {}) {+ const entries = await readdir(worktreePath, { withFileTypes: true });const children = await Promise.all(entries.filter(entry => entry.isDirectory() && !entry.name.startsWith('.') && entry.name !== 'node_modules').map(async ({ name }) => {- const targetDirectory = await lstat(join(worktreePath, name)).catch(() => null);- if (!targetDirectory?.isDirectory()) return null;+ // Cleanup must still find owned links after a package or its source is removed.+ if (cleanup) return join(name, 'node_modules');+ const sourceDirectory = await lstat(join(sourceWorkspace, name)).catch(() => null);+ if (!sourceDirectory?.isDirectory()) return null;if (existsSync(join(sourceWorkspace, name, '.git')) || existsSync(join(worktreePath, name, '.git'))) return null;const manifest = await lstat(join(worktreePath, name, 'package.json')).catch(() => null);if (!manifest?.isFile()) return null;@@ -84,7 +86,7 @@ export async function linkWorktreeDependencies(sourceWorkspace, worktreePath) {* Real dependency directories and links managed by another tool stay intact.*/export async function unlinkWorktreeDependencies(sourceWorkspace, worktreePath) {- const dependencyPaths = await worktreeDependencyPaths(sourceWorkspace, worktreePath);+ const dependencyPaths = await worktreeDependencyPaths(sourceWorkspace, worktreePath, { cleanup: true });await Promise.all(dependencyPaths.map(async (relativePath) => {const sourcePath = join(sourceWorkspace, relativePath);const targetPath = join(worktreePath, relativePath);diff --git a/server/services/worktreeManager.test.js b/server/services/worktreeManager.test.jsindex 9c5106bbfa..52e87d99a5 100644--- a/server/services/worktreeManager.test.js+++ b/server/services/worktreeManager.test.js@@ -136,7 +136,7 @@ describe('Worktree dependency preparation', () => {? missing() : Promise.resolve({ isDirectory: () => true }));lstat.mockImplementation(path => {const normalized = normalize(path);- if (directories.filter(name => name !== 'node_modules').some(name => normalized === `/worktree/${name}`)) {+ if (directories.filter(name => name !== 'node_modules').some(name => normalized === `/repo/${name}`)) {return Promise.resolve({ isDirectory: () => true });}if (normalized.endsWith('/package.json') && normalized !== '/worktree/assets/package.json') {@@ -174,13 +174,12 @@ describe('Worktree dependency preparation', () => {});it('removes only owned links including admin, even if source dependencies were removed', async () => {- const original = lstat.getMockImplementation();lstat.mockImplementation(path => {const normalized = normalize(path);- if (normalized.endsWith('/node_modules')) {+ if (['/worktree/node_modules', '/worktree/admin/node_modules', '/worktree/client/node_modules', '/worktree/server/node_modules'].includes(normalized)) {return Promise.resolve({ isSymbolicLink: () => normalized !== '/worktree/client/node_modules' });}- return original(path);+ return missing();});stat.mockImplementation(missing);readlink.mockImplementation(path => Promise.resolve(normalize(path).includes('/server/')@@ -190,7 +189,7 @@ describe('Worktree dependency preparation', () => {await unlinkWorktreeDependencies('/repo', '/worktree');expect(unlink.mock.calls.map(([path]) => normalize(path)).sort()).toEqual([- '/worktree/admin/node_modules', '/worktree/node_modules', '/worktree/uninstalled/node_modules',+ '/worktree/admin/node_modules', '/worktree/node_modules',]);});});