-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(uninstall): ignore desktop metadata in the gateway scan #8457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e7f2554
fix(uninstall): ignore desktop metadata in the gateway scan
Dongni-Yang 09bcb73
test(uninstall): pin the desktop metadata name on a directory
Dongni-Yang 2bf71d0
fix(uninstall): require a name after the resource-fork prefix
Dongni-Yang a8c9939
test(uninstall): cover metadata symlink retention
apurvvkumaria File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
159 changes: 159 additions & 0 deletions
159
src/lib/actions/uninstall/run-plan-gateway-scan-entries.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| // 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"; | ||
|
|
||
| function ok(stdout = ""): RunResult { | ||
| return { status: 0, 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, | ||
| }); | ||
| } | ||
|
|
||
| function okWithKnownGatewayList(command: string, args: readonly string[]): RunResult { | ||
| return command === "openshell" && args[0] === "gateway" && args[1] === "list" | ||
| ? ok(JSON.stringify([{ name: "nemoclaw" }])) | ||
| : ok(); | ||
| } | ||
|
|
||
| const SCOPED_RETENTION_LOG = | ||
| "Sibling gateways remain; kept the shared NemoClaw CLI and shell shims."; | ||
|
|
||
| function managedWrapper(binName: string): string { | ||
| return [ | ||
| "#!/usr/bin/env bash", | ||
| 'export PATH="/tmp/node-bin:$PATH"', | ||
| `exec "/tmp/prefix/bin/${binName}" "$@"`, | ||
| "", | ||
| ].join("\n"); | ||
| } | ||
|
|
||
| /** | ||
| * Builds a home whose gateways directory holds only the named entries, plus a | ||
| * managed wrapper shim for every CLI alias. An entry ending in "/" is created | ||
| * as a directory. Returns the shim paths so a test can assert on removal. | ||
| */ | ||
| function makeHome(prefix: string, entries: readonly string[]): { home: string; shims: string[] } { | ||
| const home = fs.mkdtempSync(path.join(os.tmpdir(), prefix)); | ||
| const gatewaysDir = path.join(home, ".nemoclaw", "gateways"); | ||
| fs.mkdirSync(gatewaysDir, { recursive: true }); | ||
| for (const entry of entries) { | ||
| const target = path.join(gatewaysDir, entry.replace(/\/$/, "")); | ||
| entry.endsWith("/") ? fs.mkdirSync(target) : fs.writeFileSync(target, ""); | ||
| } | ||
| const userBin = path.join(home, ".local", "bin"); | ||
| fs.mkdirSync(userBin, { recursive: true }); | ||
| const shims = ["nemoclaw", "nemohermes", "nemo-deepagents"].map((binName) => { | ||
| const shimPath = path.join(userBin, binName); | ||
| fs.writeFileSync(shimPath, managedWrapper(binName), { mode: 0o755 }); | ||
| return shimPath; | ||
| }); | ||
| return { home, shims }; | ||
| } | ||
|
|
||
| /** | ||
| * Runs the plan and reports which shims are still on disk afterwards. Removal | ||
| * goes through the real filesystem, restricted to the temporary home, so the | ||
| * assertions read the outcome rather than the calls a test double recorded. | ||
| */ | ||
| function uninstall(home: string, shims: readonly string[]) { | ||
| const logs: string[] = []; | ||
| const result = runUninstallPlan( | ||
| { assumeYes: true, deleteModels: false, keepOpenShell: false }, | ||
| { | ||
| commandExists: (command) => command !== "docker" && command !== "lsof" && command !== "pgrep", | ||
| env: { HOME: home } as NodeJS.ProcessEnv, | ||
| existsSync: (target) => shims.includes(target) && fs.existsSync(target), | ||
| isTty: false, | ||
| log: (line) => logs.push(line), | ||
| rmSync: vi.fn((target: fs.PathLike, options?: fs.RmOptions) => { | ||
| String(target).startsWith(home) ? fs.rmSync(target, options) : undefined; | ||
| }), | ||
| run: vi.fn(okWithKnownGatewayList), | ||
| runDocker: () => ok(""), | ||
| }, | ||
| ); | ||
| return { result, logs, survivors: shims.filter((shim) => fs.existsSync(shim)) }; | ||
| } | ||
|
|
||
| describe("uninstall gateway-directory scan", () => { | ||
| it.each([ | ||
| [".DS_Store"], | ||
| [".localized"], | ||
| ["._sandboxes.json"], | ||
| ])("removes the CLI shims when the gateways directory holds only %s (#7905)", (entry) => { | ||
| const { home, shims } = makeHome("nemoclaw-uninstall-metadata-", [entry]); | ||
|
|
||
| try { | ||
| const { result, logs, survivors } = uninstall(home, shims); | ||
|
|
||
| expect(result.exitCode).toBe(0); | ||
| expect(logs).not.toContain(SCOPED_RETENTION_LOG); | ||
| expect(survivors).toEqual([]); | ||
| } finally { | ||
| fs.rmSync(home, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| // "._" carries no name, and a directory or symlink is a shape that may hide | ||
| // live gateway state, so each of these keeps the conservative treatment. | ||
| it.each([ | ||
| ["not-a-port"], | ||
| ["._"], | ||
| [".DS_Store/"], | ||
| ])("keeps the CLI shims when the gateways directory holds %s (#7905)", (entry) => { | ||
| const { home, shims } = makeHome("nemoclaw-uninstall-conservative-", [entry]); | ||
|
|
||
| try { | ||
| const { result, logs, survivors } = uninstall(home, shims); | ||
|
|
||
| expect(result.exitCode).toBe(0); | ||
| expect(logs).toContain(SCOPED_RETENTION_LOG); | ||
| expect(survivors).toEqual(shims); | ||
| } finally { | ||
| fs.rmSync(home, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| it("keeps the CLI shims for a desktop-metadata symlink (#7905)", () => { | ||
| const { home, shims } = makeHome("nemoclaw-uninstall-conservative-", []); | ||
| fs.symlinkSync( | ||
| "concealed-gateway-state", | ||
| path.join(home, ".nemoclaw", "gateways", ".DS_Store"), | ||
| ); | ||
|
|
||
| try { | ||
| const { result, logs, survivors } = uninstall(home, shims); | ||
|
|
||
| expect(result.exitCode).toBe(0); | ||
| expect(logs).toContain(SCOPED_RETENTION_LOG); | ||
| expect(survivors).toEqual(shims); | ||
| } finally { | ||
| fs.rmSync(home, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.