fix(sync-ui): exit CLI cleanly when sync window closes

- Use runAppCommandInteractive so sync-window inherits the terminal directly
- Quit app on window-all-closed when launched with --sync-window on macOS
- Catch synchronous onWillQuitCleanup errors to prevent quit getting stuck
This commit is contained in:
2026-07-12 16:39:13 -07:00
parent a013a7ea55
commit a4c12165af
5 changed files with 73 additions and 4 deletions
+39
View File
@@ -172,6 +172,26 @@ test('startAppLifecycle defers quit until async cleanup settles', async () => {
assert.deepEqual(calls, ['quitApp']);
});
test('startAppLifecycle contains synchronous quit cleanup failures', () => {
let willQuit: ((event: { preventDefault(): void }) => void) | null = null;
const { deps, calls } = createDeps({
shouldStartApp: () => true,
onWillQuit: (handler) => {
willQuit = handler;
},
onWillQuitCleanup: () => {
throw new Error('cleanup exploded');
},
});
startAppLifecycle(makeArgs({ start: true }), deps);
assert.ok(willQuit);
assert.doesNotThrow(() =>
(willQuit as (event: { preventDefault(): void }) => void)({ preventDefault: () => {} }),
);
assert.deepEqual(calls, []);
});
test('startAppLifecycle app ping exits non-zero immediately when no running instance owns the lock', () => {
const { deps, calls, getLockCalls } = createDeps({
shouldStartApp: () => false,
@@ -385,3 +405,22 @@ test('startAppLifecycle quits macOS setup-only launch when all windows close', (
handler();
assert.deepEqual(calls, ['quitApp']);
});
test('startAppLifecycle quits macOS sync-window launch when its window closes', () => {
let windowAllClosedHandler: (() => void) | null = null;
const { deps, calls } = createDeps({
shouldStartApp: () => true,
isDarwinPlatform: () => true,
shouldQuitOnWindowAllClosed: () => true,
onWindowAllClosed: (handler) => {
windowAllClosedHandler = handler;
},
});
startAppLifecycle(makeArgs({ syncWindow: true }), deps);
const handler = windowAllClosedHandler as (() => void) | null;
assert.ok(handler);
handler();
assert.deepEqual(calls, ['quitApp']);
});