diff --git a/src/cliproxy/executor/__tests__/claude-launcher.test.ts b/src/cliproxy/executor/__tests__/claude-launcher.test.ts index e6111e50..3e587ca9 100644 --- a/src/cliproxy/executor/__tests__/claude-launcher.test.ts +++ b/src/cliproxy/executor/__tests__/claude-launcher.test.ts @@ -87,6 +87,16 @@ mock.module('../../quota/quota-manager', () => ({ stopQuotaMonitor: jest.fn(), })); +const mockCleanupLaunchSettings = jest.fn(); +const mockPrepareLaunchSettings = jest.fn().mockReturnValue({ + settingsPath: '/tmp/fake-settings-overlay.json', + cleanup: mockCleanupLaunchSettings, +}); + +mock.module('../launch-settings', () => ({ + prepareLaunchSettings: mockPrepareLaunchSettings, +})); + // ── Subject under test ──────────────────────────────────────────────────────── import { launchClaude } from '../claude-launcher'; @@ -131,6 +141,12 @@ describe('launchClaude', () => { mockSpawn.mockClear(); mockSetupCleanupHandlers.mockClear(); mockEscapeShellArg.mockClear(); + mockCleanupLaunchSettings.mockClear(); + mockPrepareLaunchSettings.mockClear(); + mockPrepareLaunchSettings.mockReturnValue({ + settingsPath: '/tmp/fake-settings-overlay.json', + cleanup: mockCleanupLaunchSettings, + }); }); it('calls spawn with claudeCli and includes --settings arg', async () => { @@ -189,6 +205,16 @@ describe('launchClaude', () => { expect(result).toBe(mockSpawnResult); }); + it('calls cleanup and rethrows when spawn throws synchronously', async () => { + const spawnErr = new Error('ERR_INVALID_ARG_VALUE'); + mockSpawn.mockImplementationOnce(() => { + throw spawnErr; + }); + + await expect(launchClaude(baseContext())).rejects.toThrow('ERR_INVALID_ARG_VALUE'); + expect(mockCleanupLaunchSettings).toHaveBeenCalledTimes(1); + }); + describe('Windows shell escaping', () => { const originalPlatform = process.platform; diff --git a/src/cliproxy/executor/claude-launcher.ts b/src/cliproxy/executor/claude-launcher.ts index ca539971..ff189bbf 100644 --- a/src/cliproxy/executor/claude-launcher.ts +++ b/src/cliproxy/executor/claude-launcher.ts @@ -144,20 +144,28 @@ export async function launchClaude(context: ClaudeLaunchContext): Promise