Skip to content

Commit 3a75d6e

Browse files
committed
fix(runtime): expand bare ~ in XCODEBUILDMCP_CWD
resolveCwdOverride only matched `~/` so a bare `~` was passed to process.chdir as a literal path and failed with ENOENT. Replace the inlined logic with the canonical expandHomePrefix() helper from utils/path.ts (which handles bare `~`, `~/...`, and empty input) and add a test for the bare-~ case. Reported by Cursor Bugbot in #374.
1 parent 48dfc6c commit 3a75d6e

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/runtime/__tests__/bootstrap-runtime.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
22
import path from 'node:path';
3+
import os from 'node:os';
34

45
const { scheduleSimulatorDefaultsRefreshMock } = vi.hoisted(() => ({
56
scheduleSimulatorDefaultsRefreshMock: vi.fn(),
@@ -183,6 +184,12 @@ describe('bootstrapRuntime', () => {
183184
expect(calledWith.startsWith('~')).toBe(false);
184185
});
185186

187+
it('expands a bare ~ to the home directory', async () => {
188+
process.env.XCODEBUILDMCP_CWD = '~';
189+
await bootstrapRuntime({ runtime: 'cli', fs: createFsWithSessionDefaults() });
190+
expect(chdirSpy).toHaveBeenCalledWith(os.homedir());
191+
});
192+
186193
it('falls back gracefully when chdir throws', async () => {
187194
process.env.XCODEBUILDMCP_CWD = '/nonexistent';
188195
chdirSpy?.mockImplementation(() => {

src/runtime/bootstrap-runtime.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import process from 'node:process';
2-
import os from 'node:os';
32
import {
43
initConfigStore,
54
getConfig,
@@ -11,6 +10,7 @@ import { getDefaultFileSystemExecutor } from '../utils/command.ts';
1110
import { log } from '../utils/logger.ts';
1211
import type { FileSystemExecutor } from '../utils/FileSystemExecutor.ts';
1312
import { scheduleSimulatorDefaultsRefresh } from '../utils/simulator-defaults-refresh.ts';
13+
import { expandHomePrefix } from '../utils/path.ts';
1414

1515
export type RuntimeKind = 'cli' | 'daemon' | 'mcp';
1616

@@ -100,10 +100,7 @@ function resolveCwdOverride(): string | undefined {
100100
if (!raw) {
101101
return undefined;
102102
}
103-
if (raw.startsWith('~/')) {
104-
return `${os.homedir()}${raw.slice(1)}`;
105-
}
106-
return raw;
103+
return expandHomePrefix(raw);
107104
}
108105

109106
export async function bootstrapRuntime(

0 commit comments

Comments
 (0)