Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/installer/src/commands/repair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,15 @@ export async function repair(opts: Opts = {}): Promise<void> {
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") {
Expand Down Expand Up @@ -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<void> {
if (platform() !== "darwin" || !appRoot) return;

Expand Down
25 changes: 25 additions & 0 deletions packages/installer/test/repair-running-codex.test.ts
Original file line number Diff line number Diff line change
@@ -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,
);
});