The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
fix(harnessd): keep external Node symlinks at their original path (#887)
Dee90c8dfd22c07
diff --git a/cli/e2e/cli.e2e.ts b/cli/e2e/cli.e2e.tsindex 6bcb238b6..0fcb01164 100644--- a/cli/e2e/cli.e2e.ts+++ b/cli/e2e/cli.e2e.ts@@ -162,6 +162,19 @@ describe('harness start, stop and status from the installed bundle', () => {return m}+ it('starts on an external Node reached through a managed-runtime symlink without relocating it', async () => {+ // Found by QA on a quiet machine: a Homebrew Node hard-linked under a daemon name aborted in dyld.+ // install() deliberately points this managed path at the external interpreter running the fixture.+ const m = await install()+ const started = await harness(m, 'start')+ expect(started.status, said(started)).toBe(0)+ seen.add(pidOf(m)!)+ expect((await fetch(`http://127.0.0.1:${m.daemon.port}/api/health`)).ok).toBe(true)+ expect(existsSync(join(dirname(dirname(m.node)), 'libexec', 'harnessd', 'harnessd'))).toBe(false)+ const stopped = await harness(m, 'stop')+ expect(stopped.status, said(stopped)).toBe(0)+ })+it('without the service: start runs a master and core, an agent outlives stop in tmux and is back on the next start, and no platform is asked', async () => {const m = await install()const started = await harness(m, 'start')diff --git a/cli/src/harnessd/processName.spec.ts b/cli/src/harnessd/processName.spec.tsindex f61070207..bb9941c7b 100644--- a/cli/src/harnessd/processName.spec.ts+++ b/cli/src/harnessd/processName.spec.ts@@ -1,4 +1,4 @@-import { linkSync, mkdirSync, mkdtempSync, rmSync, statSync } from 'node:fs'+import { linkSync, mkdirSync, mkdtempSync, rmSync, statSync, symlinkSync } from 'node:fs'import { tmpdir } from 'node:os'import { join } from 'node:path'import { afterEach, describe, expect, it, vi } from 'vitest'@@ -12,6 +12,7 @@ const libexec = `${runtime}/node-v22/libexec/harnessd`function memFs(files: Record<string, { dev: number; ino: number }>, fail: Partial<Record<keyof NamedNodeFs, Error>> = {}) {const calls: string[] = []const fs: NamedNodeFs = {+ realpath: (path) => { if (fail.realpath) throw fail.realpath; return path },identity: (path) => files[path] ?? null,mkdir: (path) => { calls.push(`mkdir ${path}`); if (fail.mkdir) throw fail.mkdir },link: (from, to) => { calls.push(`link ${to}`); if (fail.link) throw fail.link; files[to] = files[from] },@@ -48,6 +49,22 @@ describe('namedNode', () => {expect(calls).toEqual([])})+ it('resolves runtime aliases too, and refuses a path resolving to the runtime root', () => {+ const { fs, calls } = memFs({ [node]: { dev: 1, ino: 7 } })+ fs.realpath = path => path.replace(runtime, '/resolved/runtime')+ expect(namedNode(node, 'harnessd', runtime, { fs, platform: 'darwin' })).toBe(`${libexec}/harnessd`)+ calls.length = 0+ fs.realpath = () => '/resolved/runtime'+ expect(namedNode(node, 'harnessd', runtime, { fs, platform: 'darwin' })).toBe(node)+ expect(calls).toEqual([])+ })++ it('leaves the executable alone when resolving its path fails', () => {+ const { fs, calls } = memFs({ [node]: { dev: 1, ino: 7 } }, { realpath: new Error('EACCES') })+ expect(namedNode(node, 'harnessd', runtime, { fs, platform: 'darwin' })).toBe(node)+ expect(calls).toEqual([])+ })+it('runs as node when the link cannot be made, and says why once per name', () => {const log = vi.fn()const missing = memFs({})@@ -69,6 +86,19 @@ describe('namedNode', () => {expect(Object.keys(files)).toEqual([node])})+ it('keeps a managed symlink to an external Node at its original executable path', () => {+ // Found by QA on a quiet machine: naming this symlink hard-linked Homebrew Node itself on macOS,+ // and dyld aborted it because its relative libnode dependency was no longer beside the executable.+ const dir = mkdtempSync(join(tmpdir(), 'harnessd-node-symlink-'))+ try {+ const bin = join(dir, 'node-v1', 'bin')+ mkdirSync(bin, { recursive: true })+ const externalNode = join(bin, 'node')+ symlinkSync(process.execPath, externalNode)+ expect(namedNode(externalNode, 'harnessd', dir)).toBe(externalNode)+ } finally { rmSync(dir, { recursive: true, force: true }) }+ })+it('makes a real hard link the kernel names the process by', () => {const dir = mkdtempSync(join(tmpdir(), 'harnessd-name-'))try {diff --git a/cli/src/harnessd/processName.ts b/cli/src/harnessd/processName.tsindex 2e137845d..5caeb4a4c 100644--- a/cli/src/harnessd/processName.ts+++ b/cli/src/harnessd/processName.ts@@ -13,7 +13,7 @@* not ours to write in. Anything that goes wrong leaves the process running as `node`, as before: a name* is never worth a process that does not start.*/-import { linkSync, mkdirSync, renameSync, statSync, unlinkSync } from 'node:fs'+import { linkSync, mkdirSync, realpathSync, renameSync, statSync, unlinkSync } from 'node:fs'import { basename, dirname, isAbsolute, join, relative } from 'node:path'export { baseNode } from './baseNode.js'@@ -21,6 +21,7 @@ export { baseNode } from './baseNode.js'const LINK_DIR = join('libexec', 'harnessd')export interface NamedNodeFs {+ realpath(path: string): string/** The file's identity, or null when it is not there. */identity(path: string): { dev: number; ino: number } | nullmkdir(path: string): void@@ -30,6 +31,7 @@ export interface NamedNodeFs {}export const nodeFs: NamedNodeFs = {+ realpath: realpathSync,identity: (path) => {const stat = statSync(path, { throwIfNoEntry: false })return stat ? { dev: stat.dev, ino: stat.ino } : null@@ -71,6 +73,11 @@ export function namedNode(node: string, name: string, runtimeDir: string | undefconst link = join(dir, name)const temp = `${link}.${options.pid ?? process.pid}.tmp`try {+ // Found by QA on a quiet machine: a managed symlink to Homebrew Node passed the lexical check.+ // macOS hard-linked its target, and dyld aborted the relocated executable: libnode was left behind.+ // Resolve both paths so a symlinked runtime still works, but an external interpreter stays put.+ const resolved = relative(fs.realpath(runtimeDir!), fs.realpath(node))+ if (!resolved || resolved.startsWith('..') || isAbsolute(resolved)) return fallBack('node resolves outside the managed runtime')const target = fs.identity(node)if (!target) return fallBack('no node binary')const current = fs.identity(link)