diff --git a/src/commands/proxy-command.ts b/src/commands/proxy-command.ts index c3dca91d..87fd8220 100644 --- a/src/commands/proxy-command.ts +++ b/src/commands/proxy-command.ts @@ -33,7 +33,7 @@ export function findPositionalArg( for (let i = 0; i < args.length; i += 1) { const arg = args[i]; if (arg === '--') { - return args[i + 1]; + return i + 1 < args.length ? args[i + 1] : undefined; } if (arg.startsWith('-')) { if (optionsWithValues.includes(arg)) { diff --git a/src/proxy/proxy-daemon.ts b/src/proxy/proxy-daemon.ts index 2a72f15d..8b5891dd 100644 --- a/src/proxy/proxy-daemon.ts +++ b/src/proxy/proxy-daemon.ts @@ -467,14 +467,14 @@ export async function startOpenAICompatProxy( proc.stderr?.on('data', (chunk) => { stderr += chunk; }); - if (persistState) { - commitState(); - } let attempts = 0; const poll = async () => { attempts += 1; if (await isOpenAICompatProxyRunning(port)) { + if (persistState) { + commitState(); + } finish({ success: true, pid: proc.pid, diff --git a/tests/unit/commands/proxy-command.test.ts b/tests/unit/commands/proxy-command.test.ts index ff71eb90..a1913dfc 100644 --- a/tests/unit/commands/proxy-command.test.ts +++ b/tests/unit/commands/proxy-command.test.ts @@ -9,4 +9,8 @@ describe('findPositionalArg', () => { it('treats arguments after -- as positional', () => { expect(findPositionalArg(['--', '--port', '3456'], ['--port'])).toBe('--port'); }); + + it('returns undefined when -- is the final argument', () => { + expect(findPositionalArg(['--'], ['--port'])).toBeUndefined(); + }); });