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: refuse startup dependency repair through shared worktree links (#10573)
[._.]/a71dd0fc3c29
diff --git a/scripts/ensure-deps.js b/scripts/ensure-deps.jsindex b3a651b35d..d7014ac2be 100644--- a/scripts/ensure-deps.js+++ b/scripts/ensure-deps.js@@ -1,9 +1,9 @@/*** Ensures all workspace dependencies are installed before starting.- * Runs npm install only for workspaces with missing node_modules.+ * Repairs missing or stale dependencies only in workspaces that own their tree.* Handles ENOTEMPTY npm bug by retrying with clean node_modules.*/-import { existsSync, rmSync, readFileSync, writeFileSync, mkdirSync, statSync } from 'fs';+import { existsSync, rmSync, readFileSync, writeFileSync, mkdirSync, statSync, lstatSync } from 'fs';import { execFileSync } from 'child_process';import { createHash } from 'crypto';import { join, dirname } from 'path';@@ -138,6 +138,18 @@ function install(dir, label) {// Import-safe driver: the module exposes its helpers to scripts/ensure-deps.test.js,// and only performs installs when run as `node scripts/ensure-deps.js`.function main() {+ // Ordinary CoS worktrees borrow the source checkout's dependencies. Refuse+ // the entire repair before any install, cleanup, patch or receipt write;+ // checking inside the repair loop could already mutate an earlier workspace.+ // lstat also catches dangling links and Windows directory junctions.+ for (const { dir, label } of WORKSPACES) {+ if (lstatSync(join(dir, 'node_modules'), { throwIfNoEntry: false })?.isSymbolicLink()) {+ console.error(`⛔ Refusing dependency repair: ${label}/node_modules is linked. Run startup in the source checkout; use its workspace binaries for worktree tests.`);+ process.exitCode = 1;+ return;+ }+ }+const storedHashes = loadHashes();let hashesDirty = false;let needed = false;diff --git a/scripts/ensure-deps.test.js b/scripts/ensure-deps.test.jsindex c12c01f3cf..f3c8477f43 100644--- a/scripts/ensure-deps.test.js+++ b/scripts/ensure-deps.test.js@@ -18,7 +18,7 @@import { describe, expect, it } from 'vitest';import { execFileSync } from 'child_process';import { createHash } from 'crypto';-import { mkdtempSync, mkdirSync, writeFileSync, existsSync, rmSync, readFileSync, copyFileSync, utimesSync } from 'fs';+import { mkdtempSync, mkdirSync, writeFileSync, existsSync, rmSync, readFileSync, copyFileSync, utimesSync, renameSync, symlinkSync, lstatSync } from 'fs';import { tmpdir } from 'os';import { dirname, join, relative } from 'path';import { fileURLToPath } from 'url';@@ -129,12 +129,46 @@ describe('startup dependency reconciliation', () => {}return {root,- run: () => execFileSync(process.execPath, [join(root, 'scripts', 'ensure-deps.js')], { cwd: root, encoding: 'utf8' }),+ run: () => execFileSync(process.execPath, [join(root, 'scripts', 'ensure-deps.js')], { cwd: root, encoding: 'utf8', stdio: 'pipe' }),client: join(root, 'client'),receipt: join(root, 'data', 'deps-hashes.json'),};}+ // A worktree must never repair or patch dependencies owned by its source+ // checkout. Check all workspaces before touching even an earlier local tree.+ it.each(['warm', 'changed', 'missing-package', 'dangling'])('refuses %s shared dependencies before any startup mutation', (state) => {+ const f = fixture();+ try {+ f.run();+ const modules = join(f.root, 'server', 'node_modules');+ const shared = join(f.root, 'shared-server-deps');+ renameSync(modules, shared);+ if (state === 'changed') writeFileSync(join(f.root, 'server', 'package-lock.json'), '{"version":"new"}');+ if (state === 'missing-package') rmSync(join(shared, 'pg'), { recursive: true });+ rmSync(join(shared, 'patch-applied'));+ const target = state === 'dangling' ? join(f.root, 'absent-deps') : shared;+ symlinkSync(target, modules, process.platform === 'win32' ? 'junction' : 'dir');++ // root is visited before server: a per-workspace check inside the repair+ // loop would already destroy this tree and start npm before refusing.+ writeFileSync(join(f.root, 'package-lock.json'), '{"version":"new"}');+ writeFileSync(join(f.root, 'node_modules', 'keep'), 'original');+ const receipt = readFileSync(f.receipt, 'utf8');++ expect(f.run).toThrow(/Refusing dependency repair.*server.*node_modules.*linked/);+ expect(lstatSync(modules).isSymbolicLink()).toBe(true);+ expect(readFileSync(join(f.root, 'node_modules', 'keep'), 'utf8')).toBe('original');+ expect(readFileSync(f.receipt, 'utf8')).toBe(receipt);+ expect(readFileSync(join(shared, 'installed-lock.json'), 'utf8')).toBe('{"version":"old"}');+ expect(existsSync(join(shared, 'patch-applied'))).toBe(false);+ if (state === 'missing-package') expect(existsSync(join(shared, 'pg'))).toBe(false);+ if (state === 'dangling') expect(existsSync(target)).toBe(false);+ } finally {+ rmSync(f.root, { recursive: true, force: true });+ }+ });+it('installs a lockfile-only update once and preserves the committed inputs', () => {const f = fixture();try {