From ceeda4db442815085202e926da033f4c661fd90e Mon Sep 17 00:00:00 2001 From: Adidas8023 <2784281293@qq.com> Date: Sun, 24 May 2026 01:20:53 +0800 Subject: [PATCH] Fix watcher repair while Codex is running --- packages/installer/src/commands/repair.ts | 18 ++++++++++++- .../test/repair-running-codex.test.ts | 25 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 packages/installer/test/repair-running-codex.test.ts diff --git a/packages/installer/src/commands/repair.ts b/packages/installer/src/commands/repair.ts index f0f70c9..ddf1eef 100644 --- a/packages/installer/src/commands/repair.ts +++ b/packages/installer/src/commands/repair.ts @@ -131,7 +131,15 @@ export async function repair(opts: Opts = {}): Promise { const codex = locateCodex(opts.app ?? state?.appRoot); repairedAppRoot = codex.appRoot; codexWasRunning = isCodexRunning(codex.appRoot); - if (codexWasRunning && process.platform === "darwin" && promptRestartCodexToRepatch(codex.appRoot)) { + if (shouldPatchWhileCodexRuns({ + codexWasRunning, + watcherRepair: isWatcherRepair(opts), + platform: process.platform, + })) { + if (!opts.quiet) { + console.log(kleur.yellow("Codex is running; patching the app on disk and prompting for restart after repair.")); + } + } else if (codexWasRunning && process.platform === "darwin" && promptRestartCodexToRepatch(codex.appRoot)) { reopenAfterRepair = true; codexWasRunning = false; } else if (codexWasRunning && process.platform === "darwin") { @@ -223,6 +231,14 @@ function isWatcherRepair(opts: Opts): boolean { return opts.watcher === true || process.env.CODEX_PLUSPLUS_WATCHER === "1"; } +export function shouldPatchWhileCodexRuns(opts: { + codexWasRunning: boolean; + watcherRepair: boolean; + platform: NodeJS.Platform; +}): boolean { + return opts.codexWasRunning && opts.watcherRepair && opts.platform === "darwin"; +} + async function waitForMacAppUpdateToSettle(appRoot: string | undefined, opts: SettleOptions = {}): Promise { if (platform() !== "darwin" || !appRoot) return; diff --git a/packages/installer/test/repair-running-codex.test.ts b/packages/installer/test/repair-running-codex.test.ts new file mode 100644 index 0000000..c11e5dd --- /dev/null +++ b/packages/installer/test/repair-running-codex.test.ts @@ -0,0 +1,25 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { shouldPatchWhileCodexRuns } from "../src/commands/repair"; + +test("watcher repair patches the app on disk even when Codex is running", () => { + assert.equal( + shouldPatchWhileCodexRuns({ + codexWasRunning: true, + watcherRepair: true, + platform: "darwin", + }), + true, + ); +}); + +test("interactive repair still prompts before patching a running Codex app", () => { + assert.equal( + shouldPatchWhileCodexRuns({ + codexWasRunning: true, + watcherRepair: false, + platform: "darwin", + }), + false, + ); +});