From f3952c7250f765923e3a110a2846870bd0ea3d3e Mon Sep 17 00:00:00 2001 From: Aaron Erickson Date: Mon, 13 Jul 2026 15:41:21 -0700 Subject: [PATCH] refactor(openshell): remove temp SSH config helper Signed-off-by: Aaron Erickson --- src/lib/sandbox/temp-ssh-config.test.ts | 50 ------------------------- src/lib/sandbox/temp-ssh-config.ts | 39 ------------------- 2 files changed, 89 deletions(-) delete mode 100644 src/lib/sandbox/temp-ssh-config.test.ts delete mode 100644 src/lib/sandbox/temp-ssh-config.ts diff --git a/src/lib/sandbox/temp-ssh-config.test.ts b/src/lib/sandbox/temp-ssh-config.test.ts deleted file mode 100644 index 98c085e6289..00000000000 --- a/src/lib/sandbox/temp-ssh-config.test.ts +++ /dev/null @@ -1,50 +0,0 @@ -// 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 { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; - -import { createTempSshConfig } from "./temp-ssh-config.js"; - -describe("createTempSshConfig", () => { - let tmpRoot: string; - - beforeEach(() => { - tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-temp-ssh-test-")); - vi.spyOn(os, "tmpdir").mockReturnValue(tmpRoot); - }); - - afterEach(() => { - vi.restoreAllMocks(); - fs.rmSync(tmpRoot, { recursive: true, force: true }); - }); - - it("writes the SSH config inside a private mkdtemp directory and cleans it up", () => { - const temp = createTempSshConfig("Host openshell-alpha\n", "nemoclaw-ssh-test-"); - const expectedParentPrefix = path.join(tmpRoot, "nemoclaw-ssh-test-"); - - expect(temp.dir).not.toBe(tmpRoot); - expect(temp.dir.startsWith(expectedParentPrefix)).toBe(true); - expect(temp.file).toBe(path.join(temp.dir, "ssh_config")); - expect(fs.readFileSync(temp.file, "utf-8")).toBe("Host openshell-alpha\n"); - expect((fs.statSync(temp.file).mode & 0o777).toString(8)).toBe("600"); - - temp.cleanup(); - - expect(fs.existsSync(temp.dir)).toBe(false); - }); - - it("removes the private directory when writing the SSH config fails", () => { - vi.spyOn(fs, "writeFileSync").mockImplementationOnce(() => { - throw new Error("write failed"); - }); - - expect(() => createTempSshConfig("Host openshell-alpha\n", "nemoclaw-ssh-fail-")).toThrow( - "write failed", - ); - - expect(fs.readdirSync(tmpRoot)).toEqual([]); - }); -}); diff --git a/src/lib/sandbox/temp-ssh-config.ts b/src/lib/sandbox/temp-ssh-config.ts deleted file mode 100644 index a66942e8594..00000000000 --- a/src/lib/sandbox/temp-ssh-config.ts +++ /dev/null @@ -1,39 +0,0 @@ -// 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"; - -export type TempSshConfig = { - dir: string; - file: string; - cleanup: () => void; -}; - -function removeTempDir(dir: string): void { - try { - fs.rmSync(dir, { recursive: true, force: true }); - } catch { - /* best effort */ - } -} - -export function createTempSshConfig(contents: string, prefix: string): TempSshConfig { - const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix)); - const file = path.join(dir, "ssh_config"); - try { - fs.writeFileSync(file, contents, { mode: 0o600 }); - } catch (error) { - removeTempDir(dir); - throw error; - } - - return { - dir, - file, - cleanup: () => { - removeTempDir(dir); - }, - }; -}