Compare commits
2 Commits
main
...
fix/daemon
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02058c37fa | ||
|
|
20bd05bfda |
@ -3,6 +3,7 @@
|
||||
## [Unreleased]
|
||||
|
||||
### CLI
|
||||
- Skip Bun compiled `/$bunfs/...` argv entries when detached daemon restarts spawn child processes, so compiled binaries do not duplicate the virtual entry path and lose the `daemon` command. (PR #112, thanks @dedene)
|
||||
- Keep `mcporter call --output json` parseable by emitting valid JSON even when the command falls back to raw output. (PR #128, thanks @armanddp)
|
||||
- Ignore static `Authorization` headers once OAuth is active so imported editor configs cannot override fresh OAuth tokens. (PR #123, thanks @ahonn)
|
||||
- Preserve full JSON/error payloads when `data` is just one field instead of collapsing the response to `data` alone. (PR #106, thanks @AielloChan)
|
||||
|
||||
@ -15,7 +15,7 @@ export function launchDaemonDetached(options: DaemonLaunchOptions): void {
|
||||
const configArgs = options.configExplicit ? ['--config', options.configPath] : [];
|
||||
const args = [
|
||||
...process.execArgv,
|
||||
cliEntry,
|
||||
...(cliEntry ? [cliEntry] : []),
|
||||
...configArgs,
|
||||
...(options.rootDir ? ['--root', options.rootDir] : []),
|
||||
'daemon',
|
||||
@ -36,10 +36,16 @@ export function launchDaemonDetached(options: DaemonLaunchOptions): void {
|
||||
child.unref();
|
||||
}
|
||||
|
||||
function resolveCliEntry(): string {
|
||||
function resolveCliEntry(): string | undefined {
|
||||
const entry = process.argv[1];
|
||||
if (!entry) {
|
||||
throw new Error('Unable to resolve mcporter entry script.');
|
||||
}
|
||||
// In Bun compiled binaries, argv[1] is a virtual /$bunfs/... path that Bun
|
||||
// auto-injects into every spawned child. Including it explicitly would
|
||||
// duplicate it and break CLI argument parsing in the child process.
|
||||
if (entry.startsWith('/$bunfs/')) {
|
||||
return undefined;
|
||||
}
|
||||
return path.resolve(entry);
|
||||
}
|
||||
|
||||
50
tests/daemon-launch.test.ts
Normal file
50
tests/daemon-launch.test.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
const spawnMock = vi.fn(() => ({ unref: vi.fn() }));
|
||||
|
||||
vi.mock('node:child_process', () => ({
|
||||
spawn: spawnMock,
|
||||
}));
|
||||
|
||||
const originalArgv = [...process.argv];
|
||||
const originalExecArgv = [...process.execArgv];
|
||||
|
||||
describe('launchDaemonDetached', () => {
|
||||
beforeEach(() => {
|
||||
spawnMock.mockClear();
|
||||
process.argv = ['/tmp/mcporter', '/$bunfs/root/mcporter.js'];
|
||||
process.execArgv = ['--smol'];
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
process.argv = [...originalArgv];
|
||||
process.execArgv = [...originalExecArgv];
|
||||
});
|
||||
|
||||
it('omits Bun virtual entry paths from detached child args', async () => {
|
||||
const { launchDaemonDetached } = await import('../src/daemon/launch.js');
|
||||
|
||||
launchDaemonDetached({
|
||||
configPath: '/tmp/mcporter.json',
|
||||
configExplicit: true,
|
||||
rootDir: '/repo',
|
||||
socketPath: '/tmp/mcporter.sock',
|
||||
metadataPath: '/tmp/mcporter.meta.json',
|
||||
extraArgs: ['--log'],
|
||||
});
|
||||
|
||||
expect(spawnMock).toHaveBeenCalledWith(
|
||||
process.execPath,
|
||||
['--smol', '--config', '/tmp/mcporter.json', '--root', '/repo', 'daemon', 'start', '--foreground', '--log'],
|
||||
expect.objectContaining({
|
||||
detached: true,
|
||||
stdio: 'ignore',
|
||||
env: expect.objectContaining({
|
||||
MCPORTER_DAEMON_CHILD: '1',
|
||||
MCPORTER_DAEMON_SOCKET: '/tmp/mcporter.sock',
|
||||
MCPORTER_DAEMON_METADATA: '/tmp/mcporter.meta.json',
|
||||
}),
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user