From c042b77103c482e440b42be9d8c6f373dda6a889 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Wed, 28 Oct 2026 21:07:03 -0500 Subject: [PATCH] fix(proxy-supervise): entry-point guard compares realpaths so symlinked invocations run main() (#2083) --- bin/proxy-supervise.mjs | 17 ++++++++++++++++- bin/proxy-supervise.test.mjs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/bin/proxy-supervise.mjs b/bin/proxy-supervise.mjs index a859d4f758..56f05a63f1 100644 --- a/bin/proxy-supervise.mjs +++ b/bin/proxy-supervise.mjs @@ -60,6 +60,7 @@ import fs from 'node:fs'; import http from 'node:http'; import os from 'node:os'; import path from 'node:path'; +import { fileURLToPath } from 'node:url'; // ---------- small utilities ---------- @@ -639,6 +640,20 @@ const main = async () => { process.exit(failures > 0 ? 1 : 0); }; -if (import.meta.url === `file://${process.argv[1]}`) { +// Entry-point check: compare realpaths, not the raw strings. +// process.argv[1] keeps the path exactly as invoked (e.g. through the +// ~/code -> ~/git/code symlink) while import.meta.url is the resolved +// module URL, so a string compare silently never matches and main() +// never runs -- the supervisor timer no-oped that way (#2083). +const isMain = (() => { + try { + if (!process.argv[1]) return false; + return fs.realpathSync(process.argv[1]) === fs.realpathSync(fileURLToPath(import.meta.url)); + } catch { + return false; + } +})(); + +if (isMain) { main(); } diff --git a/bin/proxy-supervise.test.mjs b/bin/proxy-supervise.test.mjs index d5b66197ec..24eb8f50f1 100644 --- a/bin/proxy-supervise.test.mjs +++ b/bin/proxy-supervise.test.mjs @@ -239,3 +239,34 @@ test('foreign healthy instance is adopted, not duplicated', async (t) => { test('module under test is the worktree copy', () => { assert.ok(fs.existsSync(path.join(here, 'proxy-supervise.mjs'))); }); + +test('CLI entry point still runs when invoked through a symlinked path (#2083)', async () => { + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'proxy-supervise-symlink-')); + try { + const link = path.join(root, 'proxy-supervise-link.mjs'); + fs.symlinkSync(path.join(here, 'proxy-supervise.mjs'), link); + const cfgFile = path.join(root, 'config.json'); + fs.writeFileSync( + cfgFile, + JSON.stringify({ + stateDir: path.join(root, 'state'), + endpointDir: path.join(root, 'endpoints'), + proxies: [ + { name: 'ghost-proxy', canonicalPort: 19999, portEnv: 'GHOST_PROXY_PORT', command: ['/bin/true'], hashFiles: [] }, + ], + }), + ); + const out = await new Promise((resolve, reject) => { + const child = spawn(process.execPath, [link, '--config', cfgFile, '--only', 'ghost-proxy', '--status']); + let buf = ''; + child.stdout.on('data', (d) => (buf += d)); + child.on('error', reject); + child.on('close', () => resolve(buf)); + }); + // With the old string-compare guard, main() never ran through a + // symlink and this printed nothing at all. + assert.match(out, /"name":"ghost-proxy"/); + } finally { + fs.rmSync(root, { recursive: true, force: true }); + } +});