From 92ad049b2b65c859bd3141a66a417b1cc2acacc4 Mon Sep 17 00:00:00 2001 From: i-trytoohard <193449657+i-trytoohard@users.noreply.github.com> Date: Thu, 21 May 2026 04:17:08 +0530 Subject: [PATCH] fix(cli): avoid restart after orphan cleanup --- .../cli/__tests__/commands/update.test.ts | 31 +++++++++++++++++++ packages/cli/src/commands/update.ts | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/cli/__tests__/commands/update.test.ts b/packages/cli/__tests__/commands/update.test.ts index 62db6bdfe..47e408ad8 100644 --- a/packages/cli/__tests__/commands/update.test.ts +++ b/packages/cli/__tests__/commands/update.test.ts @@ -639,6 +639,37 @@ describe("update command", () => { expect(mockSpawn.mock.calls[1][1]).toEqual(["--version"]); }); + it("cleans up orphaned active sessions without starting a daemon that was not running", async () => { + mockGetRunning.mockReset(); + mockGetRunning.mockResolvedValue(null); + mockExistsSync.mockReturnValue(true); + mockLoadGlobalConfig.mockReturnValue({ + projects: { "my-app": { path: "/tmp/foo" } }, + }); + mockSessions.value = [{ id: "orphan-1", status: "working", projectId: "my-app" }]; + mockSpawn.mockImplementation((cmd: string, args: string[]) => { + if (cmd === "ao" && args[0] === "stop") { + mockSessions.value = []; + return createMockChild(0, undefined, { stdout: "" }); + } + if (cmd === "ao" && args[0] === "--version") { + return createMockChild(0, undefined, { stdout: "0.3.0\n" }); + } + return createMockChild(0, undefined, { stdout: "" }); + }); + + await program.parseAsync(["node", "test", "update"]); + + expect(mockSpawn.mock.calls[0][0]).toBe("ao"); + expect(mockSpawn.mock.calls[0][1]).toEqual(["stop", "--yes"]); + expect(mockSpawn.mock.calls[1][0]).toBe("pnpm"); + expect(mockSpawn.mock.calls[2][0]).toBe("ao"); + expect(mockSpawn.mock.calls[2][1]).toEqual(["--version"]); + expect(mockSpawn.mock.calls.some((call) => call[0] === "ao" && call[1][0] === "start")).toBe( + false, + ); + }); + it("honors --no-restore when restarting after update", async () => { mockSpawn.mockImplementation((cmd: string, args: string[]) => { if (cmd === "ao" && args[0] === "--version") { diff --git a/packages/cli/src/commands/update.ts b/packages/cli/src/commands/update.ts index e9daaebb2..16f13ede0 100644 --- a/packages/cli/src/commands/update.ts +++ b/packages/cli/src/commands/update.ts @@ -276,7 +276,7 @@ async function pauseAoForUpdate(plan: UpdateLifecyclePlan): Promise { process.exit(1); } - return true; + return plan.runningBeforeUpdate; } async function restartAoAfterUpdate(