From 4508fd5347f9ee5ec800edaa44a92c127fe69edb Mon Sep 17 00:00:00 2001 From: Vishnu Rajeev <19866703+VishnuR23@users.noreply.github.com> Date: Wed, 12 Aug 2026 16:18:19 -0700 Subject: [PATCH 1/6] fix(uninstall): remove the Homebrew-managed OpenShell formula A full uninstall on Apple Silicon macOS exited 0 while leaving openshell-gateway in the Homebrew prefix. The removal list held only /usr/local/bin and the XDG bin directory, and Apple Silicon Homebrew uses /opt/homebrew. Deleting those paths would strand the formula, because the installer creates them through the nvidia/openshell tap. Uninstall now removes the formula itself, and the fully qualified name leaves an OpenShell from any other source installed. Fixes #8882 --- .../run-plan-homebrew-openshell.test.ts | 144 ++++++++++++++++++ src/lib/actions/uninstall/run-plan.ts | 27 ++++ 2 files changed, 171 insertions(+) create mode 100644 src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts diff --git a/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts b/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts new file mode 100644 index 00000000000..f4decc75c5f --- /dev/null +++ b/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts @@ -0,0 +1,144 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; + +import { describe, expect, it, vi } from "vitest"; + +import { + type RunResult, + runUninstallPlan as runUninstallPlanBase, + type UninstallRunDeps, + type UninstallRunOptions, +} from "./run-plan"; + +const FORMULA = "nvidia/openshell/openshell"; + +function ok(stdout = ""): RunResult { + return { status: 0, stdout, stderr: "" }; +} + +function notFound(): RunResult { + return { status: 1, stdout: "", stderr: "" }; +} + +function runUninstallPlan(options: UninstallRunOptions, deps: UninstallRunDeps) { + return runUninstallPlanBase(options, { + resolveGatewayTeardownAuthority: ({ gatewayName, gatewayPort }) => ({ + gatewayName, + gatewayPort, + mode: "nemoclaw-managed", + source: gatewayPort === 8080 ? "packaged-service" : "standalone", + endpoint: null, + stateDir: null, + supervisor: null, + requiredCapabilities: [], + }), + ...deps, + }); +} + +/** + * Run a full uninstall and record every host command. + * + * `brewListStatus` decides whether Homebrew reports the NemoClaw formula as + * installed, which is the guard that keeps an unrelated OpenShell installed. + */ +function uninstallWithHomebrew(options: { + brewInstalled: boolean; + brewListStatus?: number; + brewUninstallStatus?: number; + platform: NodeJS.Platform; +}): { calls: string[][]; logs: string[]; warnings: string[] } { + const tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-uninstall-brew-")); + const calls: string[][] = []; + const logs: string[] = []; + const warnings: string[] = []; + try { + runUninstallPlan( + { assumeYes: true, deleteModels: false, keepOpenShell: false }, + { + commandExists: (command) => + command === "brew" ? options.brewInstalled : command === "openshell", + env: { HOME: tmpHome } as NodeJS.ProcessEnv, + existsSync: () => false, + isTty: false, + log: (line) => logs.push(line), + platform: options.platform, + rmSync: vi.fn(), + run: (command, args) => { + calls.push([command, ...args]); + if (command === "brew" && args[0] === "list") { + return { status: options.brewListStatus ?? 0, stdout: "", stderr: "" }; + } + if (command === "brew" && args[0] === "uninstall") { + return { status: options.brewUninstallStatus ?? 0, stdout: "", stderr: "" }; + } + if (command === "openshell" && args[0] === "gateway" && args[1] === "list") { + return ok(JSON.stringify([{ name: "nemoclaw" }])); + } + return ok(); + }, + // buildRuntime wires runtime.warn from deps.error. + error: (line) => warnings.push(line), + runDocker: () => ok(""), + }, + ); + } finally { + fs.rmSync(tmpHome, { recursive: true, force: true }); + } + return { calls, logs, warnings }; +} + +function brewArgs(calls: string[][]): string[][] { + return calls.filter((call) => call[0] === "brew"); +} + +describe("uninstall Homebrew-managed OpenShell", () => { + it("removes the managed formula so no executable stays linked in the Homebrew prefix (#8882)", () => { + const { calls, logs } = uninstallWithHomebrew({ brewInstalled: true, platform: "darwin" }); + + expect(brewArgs(calls)).toEqual([ + ["brew", "list", "--formula", FORMULA], + ["brew", "uninstall", "--formula", FORMULA], + ]); + expect(logs).toContain(`Removed Homebrew formula ${FORMULA}`); + }); + + it("keeps an OpenShell that Homebrew did not install from the NemoClaw tap (#8882)", () => { + // A non-zero `brew list` means the fully qualified formula is absent, so an + // OpenShell from another tap or a manual build must survive the uninstall. + const { calls, logs } = uninstallWithHomebrew({ + brewInstalled: true, + brewListStatus: 1, + platform: "darwin", + }); + + expect(brewArgs(calls)).toEqual([["brew", "list", "--formula", FORMULA]]); + expect(logs).not.toContain(`Removed Homebrew formula ${FORMULA}`); + }); + + it("names the manual command when the formula removal fails (#8882)", () => { + const { warnings } = uninstallWithHomebrew({ + brewInstalled: true, + brewUninstallStatus: 1, + platform: "darwin", + }); + + expect(warnings.join("\n")).toContain(`brew uninstall ${FORMULA}`); + }); + + it("does not call Homebrew on a platform that installs OpenShell directly (#8882)", () => { + const { calls } = uninstallWithHomebrew({ brewInstalled: true, platform: "linux" }); + + expect(brewArgs(calls)).toEqual([]); + }); + + it("does not call Homebrew when it is absent from the host (#8882)", () => { + const { calls } = uninstallWithHomebrew({ brewInstalled: false, platform: "darwin" }); + + expect(brewArgs(calls)).toEqual([]); + }); +}); diff --git a/src/lib/actions/uninstall/run-plan.ts b/src/lib/actions/uninstall/run-plan.ts index e5808f3940b..c22dcd26699 100644 --- a/src/lib/actions/uninstall/run-plan.ts +++ b/src/lib/actions/uninstall/run-plan.ts @@ -631,6 +631,32 @@ function runOptional( return false; } +// scripts/install-openshell.sh installs OpenShell on macOS through this +// Homebrew formula, so the executables in the Homebrew prefix are formula +// symlinks rather than files NemoClaw wrote. Deleting those paths would leave +// the formula registered and the Cellar populated, so remove the formula. The +// fully qualified name keeps an OpenShell from any other tap untouched. (#8882) +const OPENSHELL_HOMEBREW_FORMULA = "nvidia/openshell/openshell"; + +function removeHomebrewOpenShellFormula(runtime: UninstallRuntime): void { + if (runtime.platform !== "darwin") return; + if (!runtime.commandExists("brew")) return; + const installed = runtime.run("brew", ["list", "--formula", OPENSHELL_HOMEBREW_FORMULA], { + env: runtime.env, + stdio: "ignore", + }); + if (installed.status !== 0) return; + const removed = runtime.run("brew", ["uninstall", "--formula", OPENSHELL_HOMEBREW_FORMULA], { + env: runtime.env, + stdio: "ignore", + }); + if (removed.status === 0) runtime.log(`Removed Homebrew formula ${OPENSHELL_HOMEBREW_FORMULA}`); + else + runtime.warn( + `Failed to remove Homebrew formula ${OPENSHELL_HOMEBREW_FORMULA}; run: brew uninstall ${OPENSHELL_HOMEBREW_FORMULA}`, + ); +} + function deleteSelectedGatewaySandbox(runtime: UninstallRuntime, sandboxName: string): boolean { const result = runtime.run("openshell", ["sandbox", "delete", sandboxName], { env: runtime.env, @@ -2209,6 +2235,7 @@ function executePlan( } else if (GATEWAY_PORT !== DEFAULT_GATEWAY_PORT) { runtime.log("Keeping OpenShell binaries used by the default gateway service."); } else { + removeHomebrewOpenShellFormula(runtime); for (const target of paths.openshellInstallPaths) removeFileWithOptionalSudo(target, runtime); } From c1c4af449d17804d9c0661c26a268decdded32f2 Mon Sep 17 00:00:00 2001 From: Vishnu Rajeev <19866703+VishnuR23@users.noreply.github.com> Date: Fri, 14 Aug 2026 03:06:58 -0700 Subject: [PATCH 2/6] fix(uninstall): let the ownership decision stop the path deletion The first revision returned early from the formula removal but the caller still deleted every OpenShell install path, so an executable owned by another tap could be unlinked from /usr/local/bin. The removal now reports whether deletion may proceed, and a foreign or stranded formula keeps its executables. The regression missed this because it reported no file as present and never asserted the removals. It now reports the managed executables as present and asserts which ones survive. Moving the keep-or-remove decision into its own function keeps executePlan inside the cognitive-complexity budget. --- .../run-plan-homebrew-openshell.test.ts | 61 ++++++++++++---- src/lib/actions/uninstall/run-plan.ts | 69 +++++++++++++------ 2 files changed, 96 insertions(+), 34 deletions(-) diff --git a/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts b/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts index f4decc75c5f..a16a0d65d02 100644 --- a/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts +++ b/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts @@ -15,13 +15,27 @@ import { } from "./run-plan"; const FORMULA = "nvidia/openshell/openshell"; +const OPENSHELL_EXECUTABLES = new Set([ + "openshell", + "openshell-gateway", + "openshell-sandbox", + "openshell-driver-vm", +]); + +/** Executables only: the OpenShell config directory shares the `openshell` name. */ +function isOpenShellExecutablePath(target: string): boolean { + return ( + OPENSHELL_EXECUTABLES.has(path.basename(target)) && + path.basename(path.dirname(target)) === "bin" + ); +} -function ok(stdout = ""): RunResult { - return { status: 0, stdout, stderr: "" }; +function removedOpenShellExecutables(removed: string[]): string[] { + return removed.filter(isOpenShellExecutablePath); } -function notFound(): RunResult { - return { status: 1, stdout: "", stderr: "" }; +function ok(stdout = ""): RunResult { + return { status: 0, stdout, stderr: "" }; } function runUninstallPlan(options: UninstallRunOptions, deps: UninstallRunDeps) { @@ -51,11 +65,19 @@ function uninstallWithHomebrew(options: { brewListStatus?: number; brewUninstallStatus?: number; platform: NodeJS.Platform; -}): { calls: string[][]; logs: string[]; warnings: string[] } { +}): { calls: string[][]; logs: string[]; removed: string[]; warnings: string[] } { const tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-uninstall-brew-")); + // removeFileWithOptionalSudo probes the real parent directory for write + // access, so the XDG bin directory must exist for a deletion to be reachable. + fs.mkdirSync(path.join(tmpHome, ".local", "bin"), { recursive: true }); const calls: string[][] = []; const logs: string[] = []; + const removed: string[] = []; const warnings: string[] = []; + // Report every managed OpenShell executable as present so a deletion is + // observable; asserting only the brew argv cannot see a path unlink. + const isOpenShellExecutable = (target: string): boolean => + isOpenShellExecutablePath(String(target)); try { runUninstallPlan( { assumeYes: true, deleteModels: false, keepOpenShell: false }, @@ -63,11 +85,13 @@ function uninstallWithHomebrew(options: { commandExists: (command) => command === "brew" ? options.brewInstalled : command === "openshell", env: { HOME: tmpHome } as NodeJS.ProcessEnv, - existsSync: () => false, + existsSync: (target) => isOpenShellExecutable(target), isTty: false, log: (line) => logs.push(line), platform: options.platform, - rmSync: vi.fn(), + rmSync: vi.fn((target: Parameters[0]) => { + removed.push(String(target)); + }), run: (command, args) => { calls.push([command, ...args]); if (command === "brew" && args[0] === "list") { @@ -89,7 +113,7 @@ function uninstallWithHomebrew(options: { } finally { fs.rmSync(tmpHome, { recursive: true, force: true }); } - return { calls, logs, warnings }; + return { calls, logs, removed, warnings }; } function brewArgs(calls: string[][]): string[][] { @@ -98,19 +122,23 @@ function brewArgs(calls: string[][]): string[][] { describe("uninstall Homebrew-managed OpenShell", () => { it("removes the managed formula so no executable stays linked in the Homebrew prefix (#8882)", () => { - const { calls, logs } = uninstallWithHomebrew({ brewInstalled: true, platform: "darwin" }); + const { calls, logs, removed } = uninstallWithHomebrew({ + brewInstalled: true, + platform: "darwin", + }); expect(brewArgs(calls)).toEqual([ ["brew", "list", "--formula", FORMULA], ["brew", "uninstall", "--formula", FORMULA], ]); expect(logs).toContain(`Removed Homebrew formula ${FORMULA}`); + expect(removedOpenShellExecutables(removed)).not.toEqual([]); }); it("keeps an OpenShell that Homebrew did not install from the NemoClaw tap (#8882)", () => { // A non-zero `brew list` means the fully qualified formula is absent, so an // OpenShell from another tap or a manual build must survive the uninstall. - const { calls, logs } = uninstallWithHomebrew({ + const { calls, logs, removed } = uninstallWithHomebrew({ brewInstalled: true, brewListStatus: 1, platform: "darwin", @@ -118,27 +146,34 @@ describe("uninstall Homebrew-managed OpenShell", () => { expect(brewArgs(calls)).toEqual([["brew", "list", "--formula", FORMULA]]); expect(logs).not.toContain(`Removed Homebrew formula ${FORMULA}`); + // The ownership decision must also stop the path deletion, or an executable + // owned by another tap is unlinked from /usr/local/bin anyway. + expect(removedOpenShellExecutables(removed)).toEqual([]); }); it("names the manual command when the formula removal fails (#8882)", () => { - const { warnings } = uninstallWithHomebrew({ + const { removed, warnings } = uninstallWithHomebrew({ brewInstalled: true, brewUninstallStatus: 1, platform: "darwin", }); expect(warnings.join("\n")).toContain(`brew uninstall ${FORMULA}`); + // A stranded formula must keep its executables, not lose them to the loop. + expect(removedOpenShellExecutables(removed)).toEqual([]); }); it("does not call Homebrew on a platform that installs OpenShell directly (#8882)", () => { - const { calls } = uninstallWithHomebrew({ brewInstalled: true, platform: "linux" }); + const { calls, removed } = uninstallWithHomebrew({ brewInstalled: true, platform: "linux" }); expect(brewArgs(calls)).toEqual([]); + expect(removedOpenShellExecutables(removed)).not.toEqual([]); }); it("does not call Homebrew when it is absent from the host (#8882)", () => { - const { calls } = uninstallWithHomebrew({ brewInstalled: false, platform: "darwin" }); + const { calls, removed } = uninstallWithHomebrew({ brewInstalled: false, platform: "darwin" }); expect(brewArgs(calls)).toEqual([]); + expect(removedOpenShellExecutables(removed)).not.toEqual([]); }); }); diff --git a/src/lib/actions/uninstall/run-plan.ts b/src/lib/actions/uninstall/run-plan.ts index c22dcd26699..31442db2065 100644 --- a/src/lib/actions/uninstall/run-plan.ts +++ b/src/lib/actions/uninstall/run-plan.ts @@ -638,23 +638,59 @@ function runOptional( // fully qualified name keeps an OpenShell from any other tap untouched. (#8882) const OPENSHELL_HOMEBREW_FORMULA = "nvidia/openshell/openshell"; -function removeHomebrewOpenShellFormula(runtime: UninstallRuntime): void { - if (runtime.platform !== "darwin") return; - if (!runtime.commandExists("brew")) return; +/** + * Remove the NemoClaw-managed formula and report whether the caller may also + * delete the OpenShell executable paths. + * + * Returns "stop" when this host has an OpenShell that the NemoClaw tap does not + * own, or when the formula removal failed. Deleting the paths in either case + * would unlink another tap's executable or strand a still-registered formula. + */ +function removeHomebrewOpenShellFormula(runtime: UninstallRuntime): "continue" | "stop" { + if (runtime.platform !== "darwin") return "continue"; + if (!runtime.commandExists("brew")) return "continue"; const installed = runtime.run("brew", ["list", "--formula", OPENSHELL_HOMEBREW_FORMULA], { env: runtime.env, stdio: "ignore", }); - if (installed.status !== 0) return; + if (installed.status !== 0) { + runtime.log(`Keeping OpenShell executables that ${OPENSHELL_HOMEBREW_FORMULA} does not own.`); + return "stop"; + } const removed = runtime.run("brew", ["uninstall", "--formula", OPENSHELL_HOMEBREW_FORMULA], { env: runtime.env, stdio: "ignore", }); - if (removed.status === 0) runtime.log(`Removed Homebrew formula ${OPENSHELL_HOMEBREW_FORMULA}`); - else - runtime.warn( - `Failed to remove Homebrew formula ${OPENSHELL_HOMEBREW_FORMULA}; run: brew uninstall ${OPENSHELL_HOMEBREW_FORMULA}`, + if (removed.status === 0) { + runtime.log(`Removed Homebrew formula ${OPENSHELL_HOMEBREW_FORMULA}`); + return "continue"; + } + runtime.warn( + `Failed to remove Homebrew formula ${OPENSHELL_HOMEBREW_FORMULA}; kept its executables. Run: brew uninstall ${OPENSHELL_HOMEBREW_FORMULA}`, + ); + return "stop"; +} + +/** Apply every reason to keep managed OpenShell executables, then remove them. */ +function removeManagedOpenShellExecutables( + paths: UninstallPaths, + runtime: UninstallRuntime, + reasons: { externallySupervised: boolean; keepOpenShell: boolean }, +): void { + if (reasons.keepOpenShell || reasons.externallySupervised) { + runtime.log( + reasons.externallySupervised + ? "Keeping OpenShell binaries used by the externally supervised gateway." + : "Keeping OpenShell binaries as requested.", ); + return; + } + if (GATEWAY_PORT !== DEFAULT_GATEWAY_PORT) { + runtime.log("Keeping OpenShell binaries used by the default gateway service."); + return; + } + if (removeHomebrewOpenShellFormula(runtime) !== "continue") return; + for (const target of paths.openshellInstallPaths) removeFileWithOptionalSudo(target, runtime); } function deleteSelectedGatewaySandbox(runtime: UninstallRuntime, sandboxName: string): boolean { @@ -2226,19 +2262,10 @@ function executePlan( removeManagedSwap(paths, runtime, scopedToSelectedGateway); if (!scopedToSelectedGateway) { for (const pattern of paths.runtimeTempGlobs) removeGlob(pattern, runtime); - if (options.keepOpenShell || externallySupervised) { - runtime.log( - externallySupervised - ? "Keeping OpenShell binaries used by the externally supervised gateway." - : "Keeping OpenShell binaries as requested.", - ); - } else if (GATEWAY_PORT !== DEFAULT_GATEWAY_PORT) { - runtime.log("Keeping OpenShell binaries used by the default gateway service."); - } else { - removeHomebrewOpenShellFormula(runtime); - for (const target of paths.openshellInstallPaths) - removeFileWithOptionalSudo(target, runtime); - } + removeManagedOpenShellExecutables(paths, runtime, { + externallySupervised, + keepOpenShell: options.keepOpenShell, + }); } else { runtime.log("Sibling gateways remain; kept shared runtime files and OpenShell binaries."); } From c25ee4377699648cf9c65d9fbb5c2b284ce6c51c Mon Sep 17 00:00:00 2001 From: Apurv Kumaria Date: Mon, 17 Aug 2026 19:58:05 -0700 Subject: [PATCH 3/6] test(uninstall): satisfy focused test guardrails Signed-off-by: Apurv Kumaria --- .../actions/uninstall/run-plan-homebrew-openshell.test.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts b/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts index 85a5bc2807a..256fb3a49e9 100644 --- a/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts +++ b/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts @@ -60,10 +60,9 @@ it("retains a Homebrew-managed OpenShell and reports its removal command (#8882) rmSync: vi.fn((target) => removed.push(String(target))), run: vi.fn((command, args) => { calls.push([command, ...args]); - if (command === "openshell" && args[0] === "gateway" && args[1] === "list") { - return ok(JSON.stringify([{ name: "nemoclaw" }])); - } - return ok(); + return command === "openshell" && args[0] === "gateway" && args[1] === "list" + ? ok(JSON.stringify([{ name: "nemoclaw" }])) + : ok(); }), runDocker: () => ok(), }); From d10fa002781de2b5e0ca491716a058fa17c6b6ef Mon Sep 17 00:00:00 2001 From: Apurv Kumaria Date: Mon, 17 Aug 2026 20:22:26 -0700 Subject: [PATCH 4/6] fix(uninstall): preserve macOS OpenShell ownership Signed-off-by: Apurv Kumaria --- docs/manage-sandboxes/uninstall-nemoclaw.mdx | 12 +++++ .../run-plan-homebrew-openshell.test.ts | 54 +++++++++++++++++-- src/lib/actions/uninstall/run-plan.ts | 19 ++++--- 3 files changed, 75 insertions(+), 10 deletions(-) diff --git a/docs/manage-sandboxes/uninstall-nemoclaw.mdx b/docs/manage-sandboxes/uninstall-nemoclaw.mdx index 151d0af76b0..888d6a4a063 100644 --- a/docs/manage-sandboxes/uninstall-nemoclaw.mdx +++ b/docs/manage-sandboxes/uninstall-nemoclaw.mdx @@ -29,6 +29,18 @@ It preserves resources from a separate OpenClaw installation while continuing to | `--all-gateway-ports` | Uninstall every gateway port on the host instead of only the selected one. | | `--gateway ` | Optional consistency check; must match the name derived from `NEMOCLAW_GATEWAY_PORT`. | +On macOS, Homebrew owns its OpenShell formula and executable links. +Full uninstall preserves OpenShell executable paths instead of assuming NemoClaw owns them. +When Homebrew confirms the `nvidia/openshell/openshell` formula, NemoClaw reports this separate removal command: + +```bash +brew uninstall nvidia/openshell/openshell +``` + +Run this command only if you also want Homebrew to remove OpenShell. +When Homebrew is unavailable or does not confirm the formula, uninstall preserves the executable paths and reports why it could not confirm ownership. +Make `brew` available through `PATH` or inspect the formula before you remove OpenShell separately. + `NEMOCLAW_GATEWAY_PORT` selects the gateway instance to uninstall (`nemoclaw` for port `8080`, or `nemoclaw-` for a non-default port). For example, `NEMOCLAW_GATEWAY_PORT=9123 $$nemoclaw uninstall` selects `nemoclaw-9123` and its port-scoped state. Do not use `--gateway` to select another instance; when supplied for compatibility, its value must match the derived name or uninstall stops before cleanup. diff --git a/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts b/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts index 256fb3a49e9..4bb346923cb 100644 --- a/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts +++ b/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts @@ -42,13 +42,14 @@ function runUninstallPlan(deps: UninstallRunDeps) { ); } -it("retains a Homebrew-managed OpenShell and reports its removal command (#8882)", () => { +function uninstallOnMacOs(options: { brewAvailable: boolean; brewStatus: number | null }) { const calls: string[][] = []; const logs: string[] = []; const removed: string[] = []; const result = runUninstallPlan({ - commandExists: (command) => command === "brew" || command === "openshell", + commandExists: (command) => + command === "openshell" || (command === "brew" && options.brewAvailable), env: { HOME: "/tmp/nemoclaw-uninstall-homebrew" } as NodeJS.ProcessEnv, existsSync: (target) => EXECUTABLE_NAMES.has(path.basename(String(target))) && @@ -62,16 +63,61 @@ it("retains a Homebrew-managed OpenShell and reports its removal command (#8882) calls.push([command, ...args]); return command === "openshell" && args[0] === "gateway" && args[1] === "list" ? ok(JSON.stringify([{ name: "nemoclaw" }])) - : ok(); + : command === "brew" && args[0] === "list" + ? { status: options.brewStatus, stdout: "", stderr: "" } + : ok(); }), runDocker: () => ok(), }); + return { calls, logs, removed, result }; +} + +function removedOpenShellExecutables(removed: readonly string[]): string[] { + return removed.filter((target) => EXECUTABLE_NAMES.has(path.basename(target))); +} + +it("retains a Homebrew-managed OpenShell and reports its removal command (#8882)", () => { + const { calls, logs, removed, result } = uninstallOnMacOs({ + brewAvailable: true, + brewStatus: 0, + }); + expect(result.exitCode).toBe(0); expect(calls).toContainEqual(["brew", "list", "--formula", FORMULA]); expect(calls.some((call) => call[0] === "brew" && call[1] === "uninstall")).toBe(false); - expect(removed.filter((target) => EXECUTABLE_NAMES.has(path.basename(target)))).toEqual([]); + expect(removedOpenShellExecutables(removed)).toEqual([]); expect(logs).toContain( `Kept Homebrew-managed OpenShell. To remove it, run: brew uninstall ${FORMULA}`, ); }); + +it.each([ + { + label: "Homebrew is unavailable", + brewAvailable: false, + brewStatus: 0, + report: `Kept OpenShell executables because Homebrew is unavailable. If Homebrew manages OpenShell, make brew available through PATH, then run: brew uninstall ${FORMULA}`, + }, + { + label: "the formula query fails", + brewAvailable: true, + brewStatus: 1, + report: `Kept OpenShell executables because Homebrew did not confirm ${FORMULA}. Check the formula before removing OpenShell.`, + }, + { + label: "the formula query does not start", + brewAvailable: true, + brewStatus: null, + report: `Kept OpenShell executables because Homebrew did not confirm ${FORMULA}. Check the formula before removing OpenShell.`, + }, +])("retains OpenShell when $label (#8882)", ({ brewAvailable, brewStatus, report }) => { + const { calls, logs, removed, result } = uninstallOnMacOs({ brewAvailable, brewStatus }); + + expect(result.exitCode).toBe(0); + expect(calls.filter((call) => call[0] === "brew")).toEqual( + brewAvailable ? [["brew", "list", "--formula", FORMULA]] : [], + ); + expect(removedOpenShellExecutables(removed)).toEqual([]); + expect(logs).toContain(report); +}); diff --git a/src/lib/actions/uninstall/run-plan.ts b/src/lib/actions/uninstall/run-plan.ts index 077388362db..de580eb57cb 100644 --- a/src/lib/actions/uninstall/run-plan.ts +++ b/src/lib/actions/uninstall/run-plan.ts @@ -761,17 +761,22 @@ function runOptional( // removal command, but it must not infer that it installed the formula. (#8882) const OPENSHELL_HOMEBREW_FORMULA = "nvidia/openshell/openshell"; -function retainHomebrewOpenShell(runtime: UninstallRuntime): boolean { - if (runtime.platform !== "darwin" || !runtime.commandExists("brew")) return false; +function reportRetainedMacOsOpenShell(runtime: UninstallRuntime): void { + if (!runtime.commandExists("brew")) { + runtime.log( + `Kept OpenShell executables because Homebrew is unavailable. If Homebrew manages OpenShell, make brew available through PATH, then run: brew uninstall ${OPENSHELL_HOMEBREW_FORMULA}`, + ); + return; + } const installed = runtime.run("brew", ["list", "--formula", OPENSHELL_HOMEBREW_FORMULA], { env: runtime.env, stdio: "ignore", }); - if (installed.status !== 0) return false; runtime.log( - `Kept Homebrew-managed OpenShell. To remove it, run: brew uninstall ${OPENSHELL_HOMEBREW_FORMULA}`, + installed.status === 0 + ? `Kept Homebrew-managed OpenShell. To remove it, run: brew uninstall ${OPENSHELL_HOMEBREW_FORMULA}` + : `Kept OpenShell executables because Homebrew did not confirm ${OPENSHELL_HOMEBREW_FORMULA}. Check the formula before removing OpenShell.`, ); - return true; } function deleteSelectedGatewaySandbox( @@ -2847,7 +2852,9 @@ function executePlan( runtime.log(binaryKeepMessage); } else if (GATEWAY_PORT !== DEFAULT_GATEWAY_PORT) { runtime.log("Keeping OpenShell binaries used by the default gateway service."); - } else if (!retainHomebrewOpenShell(runtime)) { + } else if (runtime.platform === "darwin") { + reportRetainedMacOsOpenShell(runtime); + } else { for (const target of paths.openshellInstallPaths) removeFileWithOptionalSudo(target, runtime); } From fa28c4c18110e9372415e079409b28298c5f13a3 Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Mon, 17 Aug 2026 21:36:40 -0700 Subject: [PATCH 5/6] test(uninstall): prove Homebrew executable retention --- .../run-plan-homebrew-openshell.test.ts | 93 ++++++++++++------- 1 file changed, 59 insertions(+), 34 deletions(-) diff --git a/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts b/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts index 4bb346923cb..d178104d1c6 100644 --- a/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts +++ b/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 +import fs from "node:fs"; +import os from "node:os"; import path from "node:path"; import { expect, it, vi } from "vitest"; @@ -12,12 +14,12 @@ import { } from "./run-plan"; const FORMULA = "nvidia/openshell/openshell"; -const EXECUTABLE_NAMES = new Set([ +const EXECUTABLE_NAMES = [ "openshell", "openshell-driver-vm", "openshell-gateway", "openshell-sandbox", -]); +] as const; function ok(stdout = ""): RunResult { return { status: 0, stdout, stderr: "" }; @@ -42,43 +44,54 @@ function runUninstallPlan(deps: UninstallRunDeps) { ); } -function uninstallOnMacOs(options: { brewAvailable: boolean; brewStatus: number | null }) { +function uninstallOpenShell(options: { + brewAvailable: boolean; + brewStatus: number | null; + platform?: NodeJS.Platform; +}) { + const home = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-uninstall-homebrew-")); + const userBin = path.join(home, ".local", "bin"); + const executablePaths = EXECUTABLE_NAMES.map((name) => path.join(userBin, name)); + fs.mkdirSync(userBin, { mode: 0o700, recursive: true }); + for (const executablePath of executablePaths) { + fs.writeFileSync(executablePath, "", { mode: 0o755 }); + } + const calls: string[][] = []; const logs: string[] = []; const removed: string[] = []; + const existing = new Set(executablePaths); - const result = runUninstallPlan({ - commandExists: (command) => - command === "openshell" || (command === "brew" && options.brewAvailable), - env: { HOME: "/tmp/nemoclaw-uninstall-homebrew" } as NodeJS.ProcessEnv, - existsSync: (target) => - EXECUTABLE_NAMES.has(path.basename(String(target))) && - path.basename(path.dirname(String(target))) === "bin", - hasPortableRuntimeCleanup: () => false, - isTty: false, - log: (line) => logs.push(line), - platform: "darwin", - rmSync: vi.fn((target) => removed.push(String(target))), - run: vi.fn((command, args) => { - calls.push([command, ...args]); - return command === "openshell" && args[0] === "gateway" && args[1] === "list" - ? ok(JSON.stringify([{ name: "nemoclaw" }])) - : command === "brew" && args[0] === "list" - ? { status: options.brewStatus, stdout: "", stderr: "" } - : ok(); - }), - runDocker: () => ok(), - }); - - return { calls, logs, removed, result }; -} + try { + const result = runUninstallPlan({ + commandExists: (command) => + command === "openshell" || (command === "brew" && options.brewAvailable), + env: { HOME: home } as NodeJS.ProcessEnv, + existsSync: (target) => existing.has(target) && fs.existsSync(target), + hasPortableRuntimeCleanup: () => false, + isTty: false, + log: (line) => logs.push(line), + platform: options.platform ?? "darwin", + rmSync: vi.fn((target) => removed.push(String(target))), + run: vi.fn((command, args) => { + calls.push([command, ...args]); + return command === "openshell" && args[0] === "gateway" && args[1] === "list" + ? ok(JSON.stringify([{ name: "nemoclaw" }])) + : command === "brew" && args[0] === "list" + ? { status: options.brewStatus, stdout: "", stderr: "" } + : ok(); + }), + runDocker: () => ok(), + }); -function removedOpenShellExecutables(removed: readonly string[]): string[] { - return removed.filter((target) => EXECUTABLE_NAMES.has(path.basename(target))); + return { calls, executablePaths, logs, removed, result }; + } finally { + fs.rmSync(home, { force: true, recursive: true }); + } } it("retains a Homebrew-managed OpenShell and reports its removal command (#8882)", () => { - const { calls, logs, removed, result } = uninstallOnMacOs({ + const { calls, logs, removed, result } = uninstallOpenShell({ brewAvailable: true, brewStatus: 0, }); @@ -86,7 +99,7 @@ it("retains a Homebrew-managed OpenShell and reports its removal command (#8882) expect(result.exitCode).toBe(0); expect(calls).toContainEqual(["brew", "list", "--formula", FORMULA]); expect(calls.some((call) => call[0] === "brew" && call[1] === "uninstall")).toBe(false); - expect(removedOpenShellExecutables(removed)).toEqual([]); + expect(removed).toEqual([]); expect(logs).toContain( `Kept Homebrew-managed OpenShell. To remove it, run: brew uninstall ${FORMULA}`, ); @@ -112,12 +125,24 @@ it.each([ report: `Kept OpenShell executables because Homebrew did not confirm ${FORMULA}. Check the formula before removing OpenShell.`, }, ])("retains OpenShell when $label (#8882)", ({ brewAvailable, brewStatus, report }) => { - const { calls, logs, removed, result } = uninstallOnMacOs({ brewAvailable, brewStatus }); + const { calls, logs, removed, result } = uninstallOpenShell({ brewAvailable, brewStatus }); expect(result.exitCode).toBe(0); expect(calls.filter((call) => call[0] === "brew")).toEqual( brewAvailable ? [["brew", "list", "--formula", FORMULA]] : [], ); - expect(removedOpenShellExecutables(removed)).toEqual([]); + expect(removed).toEqual([]); expect(logs).toContain(report); }); + +it("removes managed OpenShell executables on Linux (#8882)", () => { + const { executablePaths, removed, result } = uninstallOpenShell({ + brewAvailable: false, + brewStatus: 0, + platform: "linux", + }); + + expect(result.exitCode).toBe(0); + expect(new Set(removed)).toEqual(new Set(executablePaths)); + expect(removed).toHaveLength(executablePaths.length); +}); From ae2f3f5ef984cafceb47d1a7a41f28ec4e6f8d22 Mon Sep 17 00:00:00 2001 From: Apurv Kumaria Date: Mon, 17 Aug 2026 23:19:53 -0700 Subject: [PATCH 6/6] test(uninstall): simplify Homebrew retention coverage Signed-off-by: Apurv Kumaria --- .../run-plan-homebrew-openshell.test.ts | 72 +++++++++---------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts b/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts index d178104d1c6..e2bf3d9ae54 100644 --- a/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts +++ b/src/lib/actions/uninstall/run-plan-homebrew-openshell.test.ts @@ -1,10 +1,6 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -import fs from "node:fs"; -import os from "node:os"; -import path from "node:path"; - import { expect, it, vi } from "vitest"; import { @@ -49,49 +45,45 @@ function uninstallOpenShell(options: { brewStatus: number | null; platform?: NodeJS.Platform; }) { - const home = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-uninstall-homebrew-")); - const userBin = path.join(home, ".local", "bin"); - const executablePaths = EXECUTABLE_NAMES.map((name) => path.join(userBin, name)); - fs.mkdirSync(userBin, { mode: 0o700, recursive: true }); - for (const executablePath of executablePaths) { - fs.writeFileSync(executablePath, "", { mode: 0o755 }); - } - + const home = "/tmp/nemoclaw-uninstall-test"; + const executablePaths = EXECUTABLE_NAMES.map((name) => `${home}/.local/bin/${name}`); const calls: string[][] = []; const logs: string[] = []; const removed: string[] = []; const existing = new Set(executablePaths); - - try { - const result = runUninstallPlan({ - commandExists: (command) => - command === "openshell" || (command === "brew" && options.brewAvailable), - env: { HOME: home } as NodeJS.ProcessEnv, - existsSync: (target) => existing.has(target) && fs.existsSync(target), - hasPortableRuntimeCleanup: () => false, - isTty: false, - log: (line) => logs.push(line), - platform: options.platform ?? "darwin", - rmSync: vi.fn((target) => removed.push(String(target))), - run: vi.fn((command, args) => { - calls.push([command, ...args]); - return command === "openshell" && args[0] === "gateway" && args[1] === "list" + const remove = (target: string) => { + existing.delete(target); + removed.push(target); + return ok(); + }; + const result = runUninstallPlan({ + commandExists: (command) => + command === "openshell" || (command === "brew" && options.brewAvailable), + env: { HOME: home } as NodeJS.ProcessEnv, + existsSync: (target) => existing.has(String(target)), + hasPortableRuntimeCleanup: () => false, + isTty: true, + log: (line) => logs.push(line), + platform: options.platform ?? "darwin", + rmSync: vi.fn((target) => remove(String(target))), + run: vi.fn((command, args) => { + calls.push([command, ...args]); + return command === "sudo" && args[0] === "rm" && args[1] === "-f" + ? remove(args[2]) + : command === "openshell" && args[0] === "gateway" && args[1] === "list" ? ok(JSON.stringify([{ name: "nemoclaw" }])) : command === "brew" && args[0] === "list" ? { status: options.brewStatus, stdout: "", stderr: "" } : ok(); - }), - runDocker: () => ok(), - }); + }), + runDocker: () => ok(), + }); - return { calls, executablePaths, logs, removed, result }; - } finally { - fs.rmSync(home, { force: true, recursive: true }); - } + return { calls, executablePaths, logs, remaining: [...existing], removed, result }; } it("retains a Homebrew-managed OpenShell and reports its removal command (#8882)", () => { - const { calls, logs, removed, result } = uninstallOpenShell({ + const { calls, executablePaths, logs, remaining, removed, result } = uninstallOpenShell({ brewAvailable: true, brewStatus: 0, }); @@ -100,6 +92,7 @@ it("retains a Homebrew-managed OpenShell and reports its removal command (#8882) expect(calls).toContainEqual(["brew", "list", "--formula", FORMULA]); expect(calls.some((call) => call[0] === "brew" && call[1] === "uninstall")).toBe(false); expect(removed).toEqual([]); + expect(remaining).toEqual(executablePaths); expect(logs).toContain( `Kept Homebrew-managed OpenShell. To remove it, run: brew uninstall ${FORMULA}`, ); @@ -125,18 +118,22 @@ it.each([ report: `Kept OpenShell executables because Homebrew did not confirm ${FORMULA}. Check the formula before removing OpenShell.`, }, ])("retains OpenShell when $label (#8882)", ({ brewAvailable, brewStatus, report }) => { - const { calls, logs, removed, result } = uninstallOpenShell({ brewAvailable, brewStatus }); + const { calls, executablePaths, logs, remaining, removed, result } = uninstallOpenShell({ + brewAvailable, + brewStatus, + }); expect(result.exitCode).toBe(0); expect(calls.filter((call) => call[0] === "brew")).toEqual( brewAvailable ? [["brew", "list", "--formula", FORMULA]] : [], ); expect(removed).toEqual([]); + expect(remaining).toEqual(executablePaths); expect(logs).toContain(report); }); it("removes managed OpenShell executables on Linux (#8882)", () => { - const { executablePaths, removed, result } = uninstallOpenShell({ + const { executablePaths, remaining, removed, result } = uninstallOpenShell({ brewAvailable: false, brewStatus: 0, platform: "linux", @@ -145,4 +142,5 @@ it("removes managed OpenShell executables on Linux (#8882)", () => { expect(result.exitCode).toBe(0); expect(new Set(removed)).toEqual(new Set(executablePaths)); expect(removed).toHaveLength(executablePaths.length); + expect(remaining).toEqual([]); });