diff --git a/scripts/install-openshell.sh b/scripts/install-openshell.sh index 4f68f5a4244..1e658705e22 100755 --- a/scripts/install-openshell.sh +++ b/scripts/install-openshell.sh @@ -122,7 +122,7 @@ required_driver_bins_present() { command -v openshell-gateway >/dev/null 2>&1 && command -v openshell-sandbox >/dev/null 2>&1 ;; Darwin) - command -v openshell-gateway >/dev/null 2>&1 && command -v openshell-driver-vm >/dev/null 2>&1 + command -v openshell-gateway >/dev/null 2>&1 ;; *) return 0 @@ -275,8 +275,6 @@ if command -v openshell >/dev/null 2>&1; then warn "openshell $INSTALLED_VERSION is missing Docker-driver binaries — reinstalling pinned OpenShell ${PIN_VERSION}..." elif ! openshell_has_required_messaging_features; then fail "${OPENSHELL_FEATURE_CHECK_ERROR:-openshell $INSTALLED_VERSION is missing required messaging credential rewrite support. Install an OpenShell build that includes provider aliases, WebSocket text rewrite, and request-body credential rewrite.}" - elif ! repair_existing_macos_vm_driver; then - warn "openshell $INSTALLED_VERSION has an unsigned macOS VM driver that could not be repaired in place — reinstalling pinned OpenShell ${PIN_VERSION}..." else info "openshell already installed: $INSTALLED_VERSION (>= $MIN_VERSION, <= $MAX_VERSION, messaging rewrite capable)" exit 0 @@ -311,9 +309,7 @@ case "$OS" in case "$ARCH_LABEL" in aarch64) ASSETS+=("openshell-gateway-aarch64-apple-darwin.tar.gz") - ASSETS+=("openshell-driver-vm-aarch64-apple-darwin.tar.gz") CHECKSUM_FILES+=("openshell-gateway-checksums-sha256.txt") - CHECKSUM_FILES+=("openshell-checksums-sha256.txt") ;; x86_64) fail "OpenShell ${PIN_VERSION} does not publish macOS x86_64 standalone gateway assets." diff --git a/src/lib/onboard.ts b/src/lib/onboard.ts index e8b12892632..3f7899627eb 100644 --- a/src/lib/onboard.ts +++ b/src/lib/onboard.ts @@ -295,6 +295,9 @@ const { reportDockerDriverGatewayStartFailure } = const dockerDriverGatewayEnv: typeof import("./onboard/docker-driver-gateway-env") = require("./onboard/docker-driver-gateway-env"); const { getDockerDriverGatewayEndpoint } = dockerDriverGatewayEnv; +const dockerDriverGatewayRuntimeMarker: typeof import("./onboard/docker-driver-gateway-runtime-marker") = + require("./onboard/docker-driver-gateway-runtime-marker"); +const vmDriverProcess: typeof import("./onboard/vm-driver-process") = require("./onboard/vm-driver-process"); const preflightUtils: typeof import("./onboard/preflight") = require("./onboard/preflight"); const clusterImagePatch: typeof import("./cluster-image-patch") = require("./cluster-image-patch"); const { @@ -1355,7 +1358,7 @@ function validateSandboxGpuPreflight(config: SandboxGpuConfig): void { process.exit(1); } if (!config.sandboxGpuEnabled) return; - if (!isLinuxDockerDriverGatewayPlatform()) return; + if (process.platform !== "linux") return; const cdiSpecDirs = getDockerCdiSpecDirs(); const cdiSpecFiles = findReadableNvidiaCdiSpecFiles(cdiSpecDirs); @@ -2759,7 +2762,6 @@ function getOpenShellInstallDeps(): OpenShellInstallDeps { isLinuxDockerDriverGatewayEnabled, resolveOpenShellGatewayBinary, resolveOpenShellSandboxBinary, - resolveOpenShellVmDriverBinary, isOpenshellInstalled, installOpenshell, getInstalledOpenshellVersion, @@ -2821,16 +2823,16 @@ function terminateDockerDriverGatewayProcess(pid: number): boolean { function stopDockerDriverGatewayProcess(): boolean { const pid = getDockerDriverGatewayPid(); if (pid === null || !isPidAlive(pid)) { - fs.rmSync(getDockerDriverGatewayPidFile(), { force: true }); + clearDockerDriverGatewayRuntimeFiles(); return false; } if (!isDockerDriverGatewayProcess(pid, resolveOpenShellGatewayBinary())) { - fs.rmSync(getDockerDriverGatewayPidFile(), { force: true }); + clearDockerDriverGatewayRuntimeFiles(); return false; } const stopped = terminateDockerDriverGatewayProcess(pid); - fs.rmSync(getDockerDriverGatewayPidFile(), { force: true }); + clearDockerDriverGatewayRuntimeFiles(); return stopped; } @@ -2871,7 +2873,7 @@ function retireLegacyGatewayForDockerDriverUpgrade(): void { function restartDockerDriverGatewayProcessForDrift(pid: number, reason: string): void { console.log(` Existing OpenShell Docker-driver gateway is stale (${reason}); restarting...`); terminateDockerDriverGatewayProcess(pid); - fs.rmSync(getDockerDriverGatewayPidFile(), { force: true }); + clearDockerDriverGatewayRuntimeFiles(); } async function refreshDockerDriverGatewayReuseState( @@ -3125,7 +3127,6 @@ const { run, runCapture, }); - function isLinuxDockerDriverGatewayEnabled( platform: NodeJS.Platform = process.platform, arch: NodeJS.Architecture = process.arch, @@ -3133,12 +3134,6 @@ function isLinuxDockerDriverGatewayEnabled( return platform === "linux" || (platform === "darwin" && arch === "arm64"); } -function isLinuxDockerDriverGatewayPlatform( - platform: NodeJS.Platform = process.platform, -): boolean { - return platform === "linux"; -} - function getDockerDriverGatewayStateDir(): string { const configured = process.env.NEMOCLAW_OPENSHELL_GATEWAY_STATE_DIR; if (configured && configured.trim()) return path.resolve(configured.trim()); @@ -3187,27 +3182,6 @@ function resolveOpenShellSandboxBinary(): string | null { return null; } -function resolveOpenShellVmDriverBinary(): string | null { - const configuredDir = process.env.OPENSHELL_DRIVER_DIR; - if (configuredDir && configuredDir.trim()) { - const configured = path.join(path.resolve(configuredDir.trim()), "openshell-driver-vm"); - if (fs.existsSync(configured)) return configured; - } - const sibling = resolveSiblingBinary("openshell-driver-vm"); - if (sibling) return sibling; - for (const candidate of [ - path.join(os.homedir(), ".local", "bin", "openshell-driver-vm"), - path.join(os.homedir(), ".local", "libexec", "openshell", "openshell-driver-vm"), - "/usr/local/bin/openshell-driver-vm", - "/usr/local/libexec/openshell/openshell-driver-vm", - "/usr/local/libexec/openshell-driver-vm", - "/usr/bin/openshell-driver-vm", - ]) { - if (fs.existsSync(candidate)) return candidate; - } - return null; -} - function getOpenShellDockerSupervisorImage(versionOutput: string | null = null): string { if (process.env.OPENSHELL_DOCKER_SUPERVISOR_IMAGE) { return process.env.OPENSHELL_DOCKER_SUPERVISOR_IMAGE; @@ -3229,7 +3203,6 @@ function getDockerDriverGatewayEnv( stateDir: getDockerDriverGatewayStateDir(), dockerNetworkName: process.env.OPENSHELL_DOCKER_NETWORK_NAME || "openshell-docker", getDockerSupervisorImage: () => getOpenShellDockerSupervisorImage(versionOutput), - resolveVmDriverBin: resolveOpenShellVmDriverBinary, resolveSandboxBin: resolveOpenShellSandboxBinary, }); } @@ -3350,6 +3323,32 @@ function getDockerDriverGatewayRuntimeDrift( gatewayBin?: string | null, platform: NodeJS.Platform = process.platform, ): DockerDriverGatewayRuntimeDrift | null { + if ( + platform === "darwin" && + desiredEnv.OPENSHELL_DRIVERS === "docker" + ) { + const markerDrift = + dockerDriverGatewayRuntimeMarker.getDockerDriverGatewayRuntimeMarkerDriftForStateDir( + getDockerDriverGatewayStateDir(), + { + pid, + desiredEnv, + endpoint: getDockerDriverGatewayEndpoint(), + gatewayBin, + dockerHost: process.env.DOCKER_HOST || null, + platform, + arch: process.arch, + }, + ); + if (markerDrift) return markerDrift; + if ( + vmDriverProcess.hasOpenShellVmDriverChildProcess(pid, (args) => + runCapture([...args], { ignoreError: true }), + ) + ) { + return { reason: "VM driver child process is still attached to the gateway" }; + } + } if (!shouldRequireDockerDriverEnv(platform)) return null; return getDockerDriverGatewayRuntimeDriftFromSnapshot({ processEnv: readProcessEnv(pid), @@ -3391,20 +3390,21 @@ function isDockerDriverGatewayProcessAlive(): boolean { if (!isDockerDriverGatewayProcess(pid, resolveOpenShellGatewayBinary(), { requireDockerDriverEnv: shouldRequireDockerDriverEnv(), })) { - fs.rmSync(getDockerDriverGatewayPidFile(), { force: true }); + clearDockerDriverGatewayRuntimeFiles(); return false; } return true; } +function clearDockerDriverGatewayRuntimeFiles(): void { + fs.rmSync(getDockerDriverGatewayPidFile(), { force: true }); + dockerDriverGatewayRuntimeMarker.clearDockerDriverGatewayRuntimeMarker( + getDockerDriverGatewayStateDir(), + ); +} + function rememberDockerDriverGatewayPid(pid: number): void { - if (!Number.isInteger(pid) || pid <= 0) return; - const stateDir = getDockerDriverGatewayStateDir(); - fs.mkdirSync(stateDir, { recursive: true, mode: 0o700 }); - fs.writeFileSync(getDockerDriverGatewayPidFile(), `${pid}\n`, { - encoding: "utf-8", - mode: 0o600, - }); + dockerDriverGatewayRuntimeMarker.writeDockerDriverGatewayPidFile(getDockerDriverGatewayPidFile(), pid); } function getDockerDriverGatewayPortListenerPid( @@ -3802,8 +3802,8 @@ async function preflight( if (host.runtime !== "unknown") { console.log(` ✓ Container runtime: ${host.runtime}`); } - if (isLinuxDockerDriverGatewayPlatform() && host.runtime === "podman") { - console.error(" ✗ NemoClaw Linux onboarding now uses OpenShell's Docker driver."); + if (isLinuxDockerDriverGatewayEnabled() && host.runtime === "podman") { + console.error(" ✗ NemoClaw onboarding now uses OpenShell's Docker driver."); console.error(" Podman is not supported for this NemoClaw integration path."); console.error(" Switch to Docker Engine and rerun onboarding."); process.exit(1); @@ -4448,7 +4448,7 @@ async function startDockerDriverGateway({ exitOnFailure = true, skipSandboxBridg const existingPid = getDockerDriverGatewayPid() ?? portListenerPid; if (existingPid !== null && isPidAlive(existingPid)) { if (!isDockerDriverGatewayProcess(existingPid, identityGatewayBin)) { - fs.rmSync(getDockerDriverGatewayPidFile(), { force: true }); + clearDockerDriverGatewayRuntimeFiles(); } else { console.log(` Restarting unhealthy Docker-driver gateway process (PID ${existingPid})...`); try { @@ -4486,6 +4486,7 @@ async function startDockerDriverGateway({ exitOnFailure = true, skipSandboxBridg throw new Error("OpenShell gateway process did not return a pid"); } rememberDockerDriverGatewayPid(childPid); + dockerDriverGatewayRuntimeMarker.writeDockerDriverGatewayRuntimeMarkerForStateDir(getDockerDriverGatewayStateDir(), { pid: childPid, desiredEnv: driftGatewayEnv, endpoint: getDockerDriverGatewayEndpoint(), gatewayBin: driftGatewayBin, openshellVersion: getInstalledOpenshellVersion(openshellVersionOutput), dockerHost: process.env.DOCKER_HOST || null }); const pollCount = envInt("NEMOCLAW_HEALTH_POLL_COUNT", 30); const pollInterval = envInt("NEMOCLAW_HEALTH_POLL_INTERVAL", 2); @@ -4831,11 +4832,7 @@ function getSandboxRuntimeRegistryFields( sandboxGpuEnabled: config.sandboxGpuEnabled, sandboxGpuMode: config.mode, sandboxGpuDevice: config.sandboxGpuDevice, - openshellDriver: isLinuxDockerDriverGatewayEnabled() - ? process.platform === "darwin" - ? "vm" - : "docker" - : "kubernetes", + openshellDriver: isLinuxDockerDriverGatewayEnabled() ? "docker" : "kubernetes", openshellVersion: getInstalledOpenshellVersion( runCaptureOpenshell(["--version"], { ignoreError: true }), ), @@ -5803,7 +5800,9 @@ async function createSandbox( discordGuilds, resolved ? resolved.ref : null, telegramConfig, - process.platform === "darwin", + // Docker-on-Colima uses normal container ownership; keep the old VM chmod + // compatibility path disabled unless a future VM-specific flow opts in. + false, sandboxInferenceBaseUrlOverride, ); // Only pass non-sensitive env vars to the sandbox. Credentials flow through @@ -6128,7 +6127,7 @@ async function createSandbox( // DNS proxy — run a forwarder in the sandbox pod so the isolated // sandbox namespace can resolve hostnames (fixes #626). - if (!isLinuxDockerDriverGatewayPlatform()) { + if (!isLinuxDockerDriverGatewayEnabled()) { console.log(" Setting up sandbox DNS proxy..."); runFile("bash", [path.join(SCRIPTS, "setup-dns-proxy.sh"), GATEWAY_NAME, sandboxName], { ignoreError: true, diff --git a/src/lib/onboard/docker-driver-gateway-env.test.ts b/src/lib/onboard/docker-driver-gateway-env.test.ts index 4c1c10a384f..21d82312ca2 100644 --- a/src/lib/onboard/docker-driver-gateway-env.test.ts +++ b/src/lib/onboard/docker-driver-gateway-env.test.ts @@ -20,17 +20,41 @@ describe("buildDockerDriverGatewayEnv", () => { platform: "linux", stateDir: "/tmp/nemoclaw-gateway", getDockerSupervisorImage: () => "ghcr.io/nvidia/openshell/supervisor:0.0.37", - resolveVmDriverBin: () => null, resolveSandboxBin: () => "/usr/bin/openshell-sandbox", }), ).toMatchObject({ + OPENSHELL_DRIVERS: "docker", OPENSHELL_BIND_ADDRESS: "127.0.0.1", OPENSHELL_SERVER_PORT: "8080", OPENSHELL_GRPC_ENDPOINT: "http://127.0.0.1:8080", OPENSHELL_SSH_GATEWAY_HOST: "127.0.0.1", OPENSHELL_SSH_GATEWAY_PORT: "8080", + OPENSHELL_DOCKER_NETWORK_NAME: "openshell-docker", + OPENSHELL_DOCKER_SUPERVISOR_IMAGE: "ghcr.io/nvidia/openshell/supervisor:0.0.37", + OPENSHELL_DOCKER_SUPERVISOR_BIN: "/usr/bin/openshell-sandbox", }); }); + + it("uses the Docker driver on macOS without VM helper state", () => { + const env = buildDockerDriverGatewayEnv({ + platform: "darwin", + stateDir: "/tmp/nemoclaw-gateway", + getDockerSupervisorImage: () => "ghcr.io/nvidia/openshell/supervisor:0.0.37", + resolveSandboxBin: () => "/usr/local/bin/openshell-sandbox", + }); + + expect(env).toMatchObject({ + OPENSHELL_DRIVERS: "docker", + OPENSHELL_BIND_ADDRESS: "127.0.0.1", + OPENSHELL_SERVER_PORT: "8080", + OPENSHELL_GRPC_ENDPOINT: "http://127.0.0.1:8080", + OPENSHELL_DOCKER_NETWORK_NAME: "openshell-docker", + OPENSHELL_DOCKER_SUPERVISOR_IMAGE: "ghcr.io/nvidia/openshell/supervisor:0.0.37", + }); + expect(env.OPENSHELL_DOCKER_SUPERVISOR_BIN).toBeUndefined(); + expect(env.OPENSHELL_VM_DRIVER_STATE_DIR).toBeUndefined(); + expect(env.OPENSHELL_DRIVER_DIR).toBeUndefined(); + }); }); describe("buildDockerGatewayDebEnvFile", () => { @@ -54,6 +78,7 @@ describe("buildDockerGatewayDebEnvFile", () => { OPENSHELL_SSH_GATEWAY_PORT: "8990", OPENSHELL_DOCKER_NETWORK_NAME: "openshell-docker", OPENSHELL_DOCKER_SUPERVISOR_IMAGE: "new", + OPENSHELL_VM_DRIVER_STATE_DIR: "/tmp/old-vm-driver", }, ); @@ -61,10 +86,26 @@ describe("buildDockerGatewayDebEnvFile", () => { expect(next).toContain("OPENSHELL_BIND_ADDRESS=0.0.0.0\n"); expect(next).toContain("OPENSHELL_SERVER_PORT=8990\n"); expect(next).toContain("OPENSHELL_DOCKER_SUPERVISOR_IMAGE=new\n"); + expect(next).toContain("OPENSHELL_VM_DRIVER_STATE_DIR=/tmp/old-vm-driver\n"); expect(next).not.toContain("OPENSHELL_BIND_ADDRESS=127.0.0.1"); expect(next).not.toContain("OPENSHELL_DOCKER_SUPERVISOR_IMAGE=old"); }); + it("removes stale VM driver env keys when writing a Docker-driver env file", () => { + const next = buildDockerGatewayDebEnvFile( + [ + "OPENSHELL_DRIVERS=vm", + "OPENSHELL_VM_DRIVER_STATE_DIR=/tmp/old-vm-driver", + "OPENSHELL_DRIVER_DIR=/tmp/old-driver-dir", + ].join("\n"), + { + OPENSHELL_DRIVERS: "docker", + }, + ); + + expect(next).toBe("OPENSHELL_DRIVERS=docker\n"); + }); + it("rejects multiline managed values", () => { expect(() => buildDockerGatewayDebEnvFile("", { diff --git a/src/lib/onboard/docker-driver-gateway-env.ts b/src/lib/onboard/docker-driver-gateway-env.ts index 757625bac06..5962d76106e 100644 --- a/src/lib/onboard/docker-driver-gateway-env.ts +++ b/src/lib/onboard/docker-driver-gateway-env.ts @@ -29,6 +29,8 @@ export const DOCKER_DRIVER_GATEWAY_RUNTIME_ENV_KEYS = [ "OPENSHELL_DOCKER_NETWORK_NAME", "OPENSHELL_DOCKER_SUPERVISOR_IMAGE", "OPENSHELL_DOCKER_SUPERVISOR_BIN", + "OPENSHELL_VM_DRIVER_STATE_DIR", + "OPENSHELL_DRIVER_DIR", ] as const; export interface BuildDockerDriverGatewayEnvOptions { @@ -36,7 +38,6 @@ export interface BuildDockerDriverGatewayEnvOptions { stateDir: string; dockerNetworkName?: string; getDockerSupervisorImage: () => string; - resolveVmDriverBin: () => string | null; resolveSandboxBin: () => string | null; } @@ -69,29 +70,19 @@ export function buildDockerDriverGatewayEnv({ stateDir, dockerNetworkName = "openshell-docker", getDockerSupervisorImage, - resolveVmDriverBin, resolveSandboxBin, }: BuildDockerDriverGatewayEnvOptions): Record { const env: Record = { - OPENSHELL_DRIVERS: platform === "darwin" ? "vm" : "docker", + OPENSHELL_DRIVERS: "docker", ...getGatewayStartNetworkEnv(), OPENSHELL_DISABLE_TLS: "true", OPENSHELL_DISABLE_GATEWAY_AUTH: "true", OPENSHELL_DB_URL: `sqlite:${path.join(stateDir, "openshell.db")}`, - OPENSHELL_GRPC_ENDPOINT: - platform === "darwin" - ? `http://host.containers.internal:${GATEWAY_PORT}` - : getDockerDriverGatewayEndpoint(), + OPENSHELL_GRPC_ENDPOINT: getDockerDriverGatewayEndpoint(), + OPENSHELL_DOCKER_NETWORK_NAME: dockerNetworkName, + OPENSHELL_DOCKER_SUPERVISOR_IMAGE: getDockerSupervisorImage(), }; - if (platform === "darwin") { - env.OPENSHELL_VM_DRIVER_STATE_DIR = path.join(stateDir, "vm-driver"); - const vmDriverBin = resolveVmDriverBin(); - if (vmDriverBin) { - env.OPENSHELL_DRIVER_DIR = path.dirname(vmDriverBin); - } - } else { - env.OPENSHELL_DOCKER_NETWORK_NAME = dockerNetworkName; - env.OPENSHELL_DOCKER_SUPERVISOR_IMAGE = getDockerSupervisorImage(); + if (platform === "linux") { const sandboxBin = resolveSandboxBin(); if (sandboxBin) { env.OPENSHELL_DOCKER_SUPERVISOR_BIN = sandboxBin; diff --git a/src/lib/onboard/docker-driver-gateway-runtime-marker.test.ts b/src/lib/onboard/docker-driver-gateway-runtime-marker.test.ts new file mode 100644 index 00000000000..ca9ca31aab8 --- /dev/null +++ b/src/lib/onboard/docker-driver-gateway-runtime-marker.test.ts @@ -0,0 +1,73 @@ +// 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 } from "vitest"; + +import { + buildDockerDriverGatewayRuntimeMarker, + getDockerDriverGatewayRuntimeMarkerDrift, + readDockerDriverGatewayRuntimeMarker, + writeDockerDriverGatewayRuntimeMarker, +} from "./docker-driver-gateway-runtime-marker"; + +const expected = { + pid: 1234, + desiredEnv: { + OPENSHELL_DRIVERS: "docker", + OPENSHELL_GRPC_ENDPOINT: "http://127.0.0.1:8080", + }, + endpoint: "http://127.0.0.1:8080", + gatewayBin: "/usr/local/bin/openshell-gateway", + openshellVersion: "0.0.39", + dockerHost: "unix:///Users/me/.colima/default/docker.sock", + platform: "darwin" as NodeJS.Platform, + arch: "arm64" as NodeJS.Architecture, + createdAt: "2026-05-14T00:00:00.000Z", +}; + +describe("docker-driver gateway runtime marker", () => { + it("accepts a marker that matches the desired Docker-driver runtime", () => { + const marker = buildDockerDriverGatewayRuntimeMarker(expected); + + expect(getDockerDriverGatewayRuntimeMarkerDrift(marker, expected)).toBeNull(); + }); + + it("forces recreation when the marker is missing or stale", () => { + expect(getDockerDriverGatewayRuntimeMarkerDrift(null, expected)?.reason).toContain( + "missing Docker-driver runtime marker", + ); + + const marker = buildDockerDriverGatewayRuntimeMarker(expected); + expect( + getDockerDriverGatewayRuntimeMarkerDrift(marker, { + ...expected, + desiredEnv: { ...expected.desiredEnv, OPENSHELL_GRPC_ENDPOINT: "http://127.0.0.1:9000" }, + })?.reason, + ).toContain("env hash"); + + expect( + getDockerDriverGatewayRuntimeMarkerDrift(marker, { + ...expected, + dockerHost: "unix:///Users/me/.docker/run/docker.sock", + })?.reason, + ).toContain("DOCKER_HOST"); + }); + + it("round-trips the marker with owner-only file permissions", () => { + const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-gateway-marker-")); + const markerPath = path.join(tempDir, "runtime.json"); + try { + const marker = buildDockerDriverGatewayRuntimeMarker(expected); + writeDockerDriverGatewayRuntimeMarker(markerPath, marker); + + expect(readDockerDriverGatewayRuntimeMarker(markerPath)).toEqual(marker); + expect(fs.statSync(markerPath).mode & 0o777).toBe(0o600); + } finally { + fs.rmSync(tempDir, { recursive: true, force: true }); + } + }); +}); diff --git a/src/lib/onboard/docker-driver-gateway-runtime-marker.ts b/src/lib/onboard/docker-driver-gateway-runtime-marker.ts new file mode 100644 index 00000000000..68c7c2791bb --- /dev/null +++ b/src/lib/onboard/docker-driver-gateway-runtime-marker.ts @@ -0,0 +1,212 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import crypto from "node:crypto"; +import fs from "node:fs"; +import path from "node:path"; + +export const DOCKER_DRIVER_GATEWAY_RUNTIME_MARKER_VERSION = 1; + +export type DockerDriverGatewayRuntimeMarker = { + version: typeof DOCKER_DRIVER_GATEWAY_RUNTIME_MARKER_VERSION; + pid: number; + driver: "docker"; + platform: NodeJS.Platform; + arch: NodeJS.Architecture; + endpoint: string; + desiredEnvHash: string; + gatewayBin: string | null; + openshellVersion: string | null; + dockerHost: string | null; + createdAt: string; +}; + +export type DockerDriverGatewayRuntimeMarkerInput = { + pid: number; + desiredEnv: Record; + endpoint: string; + gatewayBin?: string | null; + openshellVersion?: string | null; + dockerHost?: string | null; + platform?: NodeJS.Platform; + arch?: NodeJS.Architecture; + createdAt?: string; +}; + +export type DockerDriverGatewayRuntimeMarkerDrift = { reason: string }; + +export function hashDockerDriverGatewayEnv(env: Record): string { + const stablePairs = Object.keys(env) + .sort() + .map((key) => [key, env[key]] as const); + return crypto.createHash("sha256").update(JSON.stringify(stablePairs)).digest("hex"); +} + +function normalizeOptionalString(value: string | null | undefined): string | null { + const trimmed = String(value ?? "").trim(); + return trimmed.length > 0 ? trimmed : null; +} + +function normalizeGatewayBin(value: string | null | undefined): string | null { + const normalized = normalizeOptionalString(value); + if (!normalized) return null; + try { + return fs.realpathSync.native(normalized); + } catch { + return path.resolve(normalized); + } +} + +export function buildDockerDriverGatewayRuntimeMarker({ + pid, + desiredEnv, + endpoint, + gatewayBin = null, + openshellVersion = null, + dockerHost = null, + platform = process.platform, + arch = process.arch, + createdAt = new Date().toISOString(), +}: DockerDriverGatewayRuntimeMarkerInput): DockerDriverGatewayRuntimeMarker { + return { + version: DOCKER_DRIVER_GATEWAY_RUNTIME_MARKER_VERSION, + pid, + driver: "docker", + platform, + arch, + endpoint, + desiredEnvHash: hashDockerDriverGatewayEnv(desiredEnv), + gatewayBin: normalizeGatewayBin(gatewayBin), + openshellVersion: normalizeOptionalString(openshellVersion), + dockerHost: normalizeOptionalString(dockerHost), + createdAt, + }; +} + +function isRuntimeMarker(value: unknown): value is DockerDriverGatewayRuntimeMarker { + if (!value || typeof value !== "object") return false; + const marker = value as Partial; + return ( + marker.version === DOCKER_DRIVER_GATEWAY_RUNTIME_MARKER_VERSION && + marker.driver === "docker" && + Number.isInteger(marker.pid) && + typeof marker.platform === "string" && + typeof marker.arch === "string" && + typeof marker.endpoint === "string" && + typeof marker.desiredEnvHash === "string" && + (typeof marker.gatewayBin === "string" || marker.gatewayBin === null) && + (typeof marker.openshellVersion === "string" || marker.openshellVersion === null) && + (typeof marker.dockerHost === "string" || marker.dockerHost === null) && + typeof marker.createdAt === "string" + ); +} + +export function parseDockerDriverGatewayRuntimeMarker( + raw: string, +): DockerDriverGatewayRuntimeMarker | null { + try { + const parsed = JSON.parse(raw); + return isRuntimeMarker(parsed) ? parsed : null; + } catch { + return null; + } +} + +export function readDockerDriverGatewayRuntimeMarker( + markerPath: string, +): DockerDriverGatewayRuntimeMarker | null { + try { + return parseDockerDriverGatewayRuntimeMarker(fs.readFileSync(markerPath, "utf-8")); + } catch (error) { + if ( + error instanceof Error && + "code" in error && + (error as NodeJS.ErrnoException).code === "ENOENT" + ) { + return null; + } + return null; + } +} + +export function writeDockerDriverGatewayRuntimeMarker( + markerPath: string, + marker: DockerDriverGatewayRuntimeMarker, +): void { + fs.mkdirSync(path.dirname(markerPath), { recursive: true, mode: 0o700 }); + fs.writeFileSync(markerPath, `${JSON.stringify(marker, null, 2)}\n`, { + encoding: "utf-8", + mode: 0o600, + }); + fs.chmodSync(markerPath, 0o600); +} + +export function getDockerDriverGatewayRuntimeMarkerPath(stateDir: string): string { + return path.join(stateDir, "runtime.json"); +} + +export function clearDockerDriverGatewayRuntimeMarker(stateDir: string): void { + fs.rmSync(getDockerDriverGatewayRuntimeMarkerPath(stateDir), { force: true }); +} + +export function writeDockerDriverGatewayPidFile(pidFile: string, pid: number): void { + if (!Number.isInteger(pid) || pid <= 0) return; + fs.mkdirSync(path.dirname(pidFile), { recursive: true, mode: 0o700 }); + fs.writeFileSync(pidFile, `${pid}\n`, { encoding: "utf-8", mode: 0o600 }); +} + +export function writeDockerDriverGatewayRuntimeMarkerForStateDir( + stateDir: string, + input: DockerDriverGatewayRuntimeMarkerInput, +): void { + writeDockerDriverGatewayRuntimeMarker( + getDockerDriverGatewayRuntimeMarkerPath(stateDir), + buildDockerDriverGatewayRuntimeMarker(input), + ); +} + +export function getDockerDriverGatewayRuntimeMarkerDrift( + marker: DockerDriverGatewayRuntimeMarker | null, + expected: DockerDriverGatewayRuntimeMarkerInput, +): DockerDriverGatewayRuntimeMarkerDrift | null { + if (!marker) return { reason: "missing Docker-driver runtime marker" }; + const desired = buildDockerDriverGatewayRuntimeMarker(expected); + if (marker.pid !== desired.pid) return { reason: `runtime marker pid=${marker.pid} (expected ${desired.pid})` }; + if (marker.driver !== "docker") return { reason: `runtime marker driver=${marker.driver}` }; + if (marker.platform !== desired.platform) { + return { reason: `runtime marker platform=${marker.platform} (expected ${desired.platform})` }; + } + if (marker.arch !== desired.arch) { + return { reason: `runtime marker arch=${marker.arch} (expected ${desired.arch})` }; + } + if (marker.endpoint !== desired.endpoint) { + return { reason: `runtime marker endpoint=${marker.endpoint} (expected ${desired.endpoint})` }; + } + if (marker.desiredEnvHash !== desired.desiredEnvHash) { + return { reason: "runtime marker env hash does not match desired Docker-driver env" }; + } + if (marker.gatewayBin !== desired.gatewayBin) { + return { reason: `runtime marker gateway=${marker.gatewayBin || ""} (expected ${desired.gatewayBin || ""})` }; + } + if (expected.openshellVersion !== undefined && marker.openshellVersion !== desired.openshellVersion) { + return { + reason: `runtime marker openshell=${marker.openshellVersion || ""} (expected ${desired.openshellVersion || ""})`, + }; + } + if (marker.dockerHost !== desired.dockerHost) { + return { + reason: `runtime marker DOCKER_HOST=${marker.dockerHost || ""} (expected ${desired.dockerHost || ""})`, + }; + } + return null; +} + +export function getDockerDriverGatewayRuntimeMarkerDriftForStateDir( + stateDir: string, + expected: DockerDriverGatewayRuntimeMarkerInput, +): DockerDriverGatewayRuntimeMarkerDrift | null { + return getDockerDriverGatewayRuntimeMarkerDrift( + readDockerDriverGatewayRuntimeMarker(getDockerDriverGatewayRuntimeMarkerPath(stateDir)), + expected, + ); +} diff --git a/src/lib/onboard/openshell-install.ts b/src/lib/onboard/openshell-install.ts index 010b106ca57..f11531251f4 100644 --- a/src/lib/onboard/openshell-install.ts +++ b/src/lib/onboard/openshell-install.ts @@ -91,7 +91,6 @@ export type OpenShellInstallDeps = { ) => boolean; resolveOpenShellGatewayBinary: () => string | null; resolveOpenShellSandboxBinary: () => string | null; - resolveOpenShellVmDriverBinary: () => string | null; isOpenshellInstalled: () => boolean; installOpenshell: () => OpenShellInstallResult; getInstalledOpenshellVersion: (versionOutput?: string | null) => string | null; @@ -116,7 +115,6 @@ export function areRequiredDockerDriverBinariesPresent( | "isLinuxDockerDriverGatewayEnabled" | "resolveOpenShellGatewayBinary" | "resolveOpenShellSandboxBinary" - | "resolveOpenShellVmDriverBinary" >, platform: NodeJS.Platform = process.platform, binaries: DockerDriverBinaryOverrides = {}, @@ -129,12 +127,8 @@ export function areRequiredDockerDriverBinariesPresent( const sandboxBinary = Object.prototype.hasOwnProperty.call(binaries, "sandboxBin") ? binaries.sandboxBin : deps.resolveOpenShellSandboxBinary(); - const vmDriverBinary = Object.prototype.hasOwnProperty.call(binaries, "vmDriverBin") - ? binaries.vmDriverBin - : deps.resolveOpenShellVmDriverBinary(); if (!gatewayBinary) return false; if (platform === "linux" && !sandboxBinary) return false; - if (platform === "darwin" && !vmDriverBinary) return false; return true; } @@ -182,12 +176,7 @@ export function ensureOpenshellForOnboard(deps: OpenShellInstallDeps): OpenShell if (needsDevChannel) { deps.log(" OpenShell Docker-driver onboarding requires the dev channel. Upgrading..."); } else if (needsDockerDriverBinaries) { - const required = - platform === "linux" - ? "gateway and sandbox" - : platform === "darwin" - ? "gateway and VM driver" - : "gateway"; + const required = platform === "linux" ? "gateway and sandbox" : "gateway"; deps.log( ` OpenShell standalone gateway onboarding requires the ${required} binaries. Reinstalling...`, ); diff --git a/src/lib/onboard/vm-driver-process.ts b/src/lib/onboard/vm-driver-process.ts new file mode 100644 index 00000000000..ba49cff6b97 --- /dev/null +++ b/src/lib/onboard/vm-driver-process.ts @@ -0,0 +1,36 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +export const PROCESS_LIST_ARGS = ["ps", "-axo", "pid=,ppid=,command="] as const; + +export type ProcessListCapture = (args: typeof PROCESS_LIST_ARGS) => string; + +export function hasOpenShellVmDriverChildProcessFromPsOutput( + gatewayPid: number, + psOutput: string, +): boolean { + if (!Number.isInteger(gatewayPid) || gatewayPid <= 0) return false; + return psOutput.split(/\r?\n/).some((line) => { + const match = line.trim().match(/^(\d+)\s+(\d+)\s+(.+)$/); + if (!match) return false; + const childPid = Number.parseInt(match[1], 10); + const parentPid = Number.parseInt(match[2], 10); + const command = match[3]; + return ( + Number.isInteger(childPid) && + childPid > 0 && + parentPid === gatewayPid && + command.includes("openshell-driver-vm") + ); + }); +} + +export function hasOpenShellVmDriverChildProcess( + gatewayPid: number, + captureProcessList: ProcessListCapture, +): boolean { + return hasOpenShellVmDriverChildProcessFromPsOutput( + gatewayPid, + captureProcessList(PROCESS_LIST_ARGS), + ); +} diff --git a/test/e2e/docs/parity-inventory.generated.json b/test/e2e/docs/parity-inventory.generated.json index 38a80daff38..7bc8af28c26 100644 --- a/test/e2e/docs/parity-inventory.generated.json +++ b/test/e2e/docs/parity-inventory.generated.json @@ -10713,33 +10713,33 @@ { "script": "test/e2e/test-openshell-gateway-upgrade.sh", "line": 207, - "text": "macOS installer did not request the Darwin openshell-driver-vm asset", + "text": "macOS installer still requested the Darwin openshell-driver-vm asset", "polarity": "fail", - "normalized_id": "macos.installer.did.not.request.the.darwin.openshell.driver.vm.asset", + "normalized_id": "macos.installer.still.requested.the.darwin.openshell.driver.vm.asset", "mapping_status": "deferred" }, { "script": "test/e2e/test-openshell-gateway-upgrade.sh", "line": 211, - "text": "macOS OpenShell ${CURRENT_OPENSHELL_VERSION} incomplete install fetches Darwin gateway and VM driver assets", + "text": "macOS OpenShell ${CURRENT_OPENSHELL_VERSION} incomplete install fetches Darwin gateway asset", "polarity": "pass", - "normalized_id": "macos.openshell.current.openshell.version.incomplete.install.fetches.darwin.gateway.and.vm.driver.assets", + "normalized_id": "macos.openshell.current.openshell.version.incomplete.install.fetches.darwin.gateway.asset", "mapping_status": "deferred" }, { "script": "test/e2e/test-openshell-gateway-upgrade.sh", "line": 280, - "text": "macOS installer did not repair missing openshell-driver-vm Hypervisor entitlement", + "text": "macOS installer still required openshell-driver-vm Hypervisor entitlement", "polarity": "fail", - "normalized_id": "macos.installer.did.not.repair.missing.openshell.driver.vm.hypervisor.entitlement", + "normalized_id": "macos.installer.still.required.openshell.driver.vm.hypervisor.entitlement", "mapping_status": "deferred" }, { "script": "test/e2e/test-openshell-gateway-upgrade.sh", "line": 287, - "text": "macOS installer did not codesign openshell-driver-vm with entitlements", + "text": "macOS installer still codesigned openshell-driver-vm", "polarity": "fail", - "normalized_id": "macos.installer.did.not.codesign.openshell.driver.vm.with.entitlements", + "normalized_id": "macos.installer.still.codesigned.openshell.driver.vm", "mapping_status": "deferred" }, { @@ -10753,9 +10753,9 @@ { "script": "test/e2e/test-openshell-gateway-upgrade.sh", "line": 298, - "text": "macOS OpenShell ${CURRENT_OPENSHELL_VERSION} installer repairs missing VM driver Hypervisor entitlement", + "text": "macOS OpenShell ${CURRENT_OPENSHELL_VERSION} installer does not require VM driver Hypervisor entitlement", "polarity": "pass", - "normalized_id": "macos.openshell.current.openshell.version.installer.repairs.missing.vm.driver.hypervisor.entitlement", + "normalized_id": "macos.openshell.current.openshell.version.installer.does.not.require.vm.driver.hypervisor.entitlement", "mapping_status": "deferred" }, { @@ -10777,9 +10777,9 @@ { "script": "test/e2e/test-openshell-gateway-upgrade.sh", "line": 307, - "text": "onboard does not enable macOS VM rootfs compatibility for Darwin sandbox builds", + "text": "onboard does not keep macOS Docker sandbox builds out of the VM rootfs compatibility path", "polarity": "fail", - "normalized_id": "onboard.does.not.enable.macos.vm.rootfs.compatibility.for.darwin.sandbox.builds", + "normalized_id": "onboard.does.not.keep.macos.docker.sandbox.builds.out.of.the.vm.rootfs.compatibility.path", "mapping_status": "deferred" }, { @@ -10817,9 +10817,9 @@ { "script": "test/e2e/test-openshell-gateway-upgrade.sh", "line": 316, - "text": "macOS VM sandbox builds enable OpenClaw and Hermes rootfs ownership compatibility", + "text": "macOS Docker sandbox builds keep VM rootfs compatibility disabled", "polarity": "pass", - "normalized_id": "macos.vm.sandbox.builds.enable.openclaw.and.hermes.rootfs.ownership.compatibility", + "normalized_id": "macos.docker.sandbox.builds.keep.vm.rootfs.compatibility.disabled", "mapping_status": "deferred" }, { diff --git a/test/e2e/docs/parity-map.yaml b/test/e2e/docs/parity-map.yaml index b55263abfc5..4edb7a22632 100644 --- a/test/e2e/docs/parity-map.yaml +++ b/test/e2e/docs/parity-map.yaml @@ -6548,22 +6548,22 @@ scripts: reason: live legacy behavior requires non-deterministic infrastructure; retained for bucket parity tracking owner: e2e-maintainers runner_requirement: sandbox runner with NemoClaw/OpenShell CLIs - - legacy: macOS installer did not request the Darwin openshell-driver-vm asset + - legacy: macOS installer still requested the Darwin openshell-driver-vm asset status: deferred reason: live legacy behavior requires non-deterministic infrastructure; retained for bucket parity tracking owner: e2e-maintainers runner_requirement: sandbox runner with NemoClaw/OpenShell CLIs - - legacy: macOS OpenShell ${CURRENT_OPENSHELL_VERSION} incomplete install fetches Darwin gateway and VM driver assets + - legacy: macOS OpenShell ${CURRENT_OPENSHELL_VERSION} incomplete install fetches Darwin gateway asset status: deferred reason: live legacy behavior requires non-deterministic infrastructure; retained for bucket parity tracking owner: e2e-maintainers runner_requirement: sandbox runner with NemoClaw/OpenShell CLIs - - legacy: macOS installer did not repair missing openshell-driver-vm Hypervisor entitlement + - legacy: macOS installer still required openshell-driver-vm Hypervisor entitlement status: deferred reason: live legacy behavior requires non-deterministic infrastructure; retained for bucket parity tracking owner: e2e-maintainers runner_requirement: sandbox runner with NemoClaw/OpenShell CLIs - - legacy: macOS installer did not codesign openshell-driver-vm with entitlements + - legacy: macOS installer still codesigned openshell-driver-vm status: deferred reason: live legacy behavior requires non-deterministic infrastructure; retained for bucket parity tracking owner: e2e-maintainers @@ -6573,7 +6573,7 @@ scripts: reason: live legacy behavior requires non-deterministic infrastructure; retained for bucket parity tracking owner: e2e-maintainers runner_requirement: sandbox runner with NemoClaw/OpenShell CLIs - - legacy: macOS OpenShell ${CURRENT_OPENSHELL_VERSION} installer repairs missing VM driver Hypervisor entitlement + - legacy: macOS OpenShell ${CURRENT_OPENSHELL_VERSION} installer does not require VM driver Hypervisor entitlement status: deferred reason: live legacy behavior requires non-deterministic infrastructure; retained for bucket parity tracking owner: e2e-maintainers @@ -6588,7 +6588,7 @@ scripts: reason: live legacy behavior requires non-deterministic infrastructure; retained for bucket parity tracking owner: e2e-maintainers runner_requirement: Docker daemon - - legacy: onboard does not enable macOS VM rootfs compatibility for Darwin sandbox builds + - legacy: onboard does not keep macOS Docker sandbox builds out of the VM rootfs compatibility path status: deferred reason: live legacy behavior requires non-deterministic infrastructure; retained for bucket parity tracking owner: e2e-maintainers @@ -6613,7 +6613,7 @@ scripts: reason: live legacy behavior requires non-deterministic infrastructure; retained for bucket parity tracking owner: e2e-maintainers runner_requirement: Docker daemon - - legacy: macOS VM sandbox builds enable OpenClaw and Hermes rootfs ownership compatibility + - legacy: macOS Docker sandbox builds keep VM rootfs compatibility disabled status: deferred reason: live legacy behavior requires non-deterministic infrastructure; retained for bucket parity tracking owner: e2e-maintainers diff --git a/test/e2e/test-openshell-gateway-upgrade.sh b/test/e2e/test-openshell-gateway-upgrade.sh index 70287505702..7a0f2f78595 100755 --- a/test/e2e/test-openshell-gateway-upgrade.sh +++ b/test/e2e/test-openshell-gateway-upgrade.sh @@ -200,18 +200,18 @@ EOF rm -rf "$tmp" fail "macOS installer did not request the Darwin openshell-gateway asset" fi - if ! grep -q "openshell-driver-vm-aarch64-apple-darwin.tar.gz" "$curl_log"; then + if grep -q "openshell-driver-vm-aarch64-apple-darwin.tar.gz" "$curl_log"; then diag "curl log:" cat "$curl_log" 2>/dev/null || true rm -rf "$tmp" - fail "macOS installer did not request the Darwin openshell-driver-vm asset" + fail "macOS installer still requested the Darwin openshell-driver-vm asset" fi rm -rf "$tmp" - pass "macOS OpenShell ${CURRENT_OPENSHELL_VERSION} incomplete install fetches Darwin gateway and VM driver assets" + pass "macOS OpenShell ${CURRENT_OPENSHELL_VERSION} incomplete install fetches Darwin gateway asset" } -exercise_macos_vm_driver_entitlement_repair() { +exercise_macos_vm_driver_entitlement_not_required() { local tmp fake_bin state_file sign_log install_out install_err tmp="$(mktemp -d)" fake_bin="$tmp/bin" @@ -277,14 +277,14 @@ EOF diag "installer stderr:" cat "$install_err" 2>/dev/null || true rm -rf "$tmp" - fail "macOS installer did not repair missing openshell-driver-vm Hypervisor entitlement" + fail "macOS installer still required openshell-driver-vm Hypervisor entitlement" fi - if ! grep -q -- "--force --sign - --entitlements" "$sign_log"; then + if [ -s "$sign_log" ] && grep -q -- "--force --sign - --entitlements" "$sign_log"; then diag "codesign log:" cat "$sign_log" 2>/dev/null || true rm -rf "$tmp" - fail "macOS installer did not codesign openshell-driver-vm with entitlements" + fail "macOS installer still codesigned openshell-driver-vm" fi if grep -q "Installing OpenShell from release" "$install_out"; then @@ -295,16 +295,16 @@ EOF fi rm -rf "$tmp" - pass "macOS OpenShell ${CURRENT_OPENSHELL_VERSION} installer repairs missing VM driver Hypervisor entitlement" + pass "macOS OpenShell ${CURRENT_OPENSHELL_VERSION} installer does not require VM driver Hypervisor entitlement" } -exercise_macos_vm_rootfs_permission_regression() { +exercise_macos_docker_rootfs_permission_regression() { grep -q "ARG NEMOCLAW_DARWIN_VM_COMPAT=0" Dockerfile \ || fail "Dockerfile is missing the macOS VM rootfs compatibility ARG" grep -Fq "ARG NEMOCLAW_DARWIN_VM_COMPAT=\${sanitizeDockerArg(darwinVmCompat ? \"1\" : \"0\")}" src/lib/onboard/dockerfile-patch.ts \ || fail "Dockerfile patch helper does not patch the macOS VM rootfs compatibility ARG" - grep -q 'process.platform === "darwin"' src/lib/onboard.ts \ - || fail "onboard does not enable macOS VM rootfs compatibility for Darwin sandbox builds" + grep -Fq "Docker-on-Colima uses normal container ownership" src/lib/onboard.ts \ + || fail "onboard does not keep macOS Docker sandbox builds out of the VM rootfs compatibility path" grep -q "chmod -R a+rwX /sandbox/.openclaw" Dockerfile \ || fail "Dockerfile does not relax OpenClaw state permissions for macOS VM rootfs remapping" grep -q "ARG NEMOCLAW_DARWIN_VM_COMPAT=0" agents/hermes/Dockerfile \ @@ -313,7 +313,7 @@ exercise_macos_vm_rootfs_permission_regression() { || fail "Hermes Dockerfile does not relax Hermes state permissions for macOS VM rootfs remapping" grep -q "chmod a+rw /sandbox/.bashrc /sandbox/.profile" agents/hermes/Dockerfile \ || fail "Hermes Dockerfile does not relax trusted rc files for macOS VM ownership repair" - pass "macOS VM sandbox builds enable OpenClaw and Hermes rootfs ownership compatibility" + pass "macOS Docker sandbox builds keep VM rootfs compatibility disabled" } wait_for_survivor_ready() { @@ -586,8 +586,8 @@ load_shell_path if [ "$(uname -s)" != "Linux" ]; then exercise_macos_gateway_installer_regression - exercise_macos_vm_driver_entitlement_repair - exercise_macos_vm_rootfs_permission_regression + exercise_macos_vm_driver_entitlement_not_required + exercise_macos_docker_rootfs_permission_regression pass "Skipping live Docker-driver gateway restart regression on non-Linux host" exit 0 fi @@ -604,5 +604,5 @@ assert_survivor_sandbox_after_upgrade pass "Current NemoClaw installer upgraded old ${OLD_NEMOCLAW_REF} claw, restored state, and kept OpenClaw running on OpenShell ${CURRENT_OPENSHELL_VERSION}" exercise_macos_gateway_installer_regression -exercise_macos_vm_driver_entitlement_repair -exercise_macos_vm_rootfs_permission_regression +exercise_macos_vm_driver_entitlement_not_required +exercise_macos_docker_rootfs_permission_regression diff --git a/test/install-openshell-version-check.test.ts b/test/install-openshell-version-check.test.ts index 7a849905641..a931698a875 100644 --- a/test/install-openshell-version-check.test.ts +++ b/test/install-openshell-version-check.test.ts @@ -144,9 +144,9 @@ describe("install-openshell.sh version check", { timeout: 15_000 }, () => { expect(result.stderr).toMatch(/missing request-body-credential-rewrite support/); }); - it("accepts macOS openshell 0.0.39 when the gateway and VM driver binaries are installed", () => { + it("accepts macOS openshell 0.0.39 when the gateway binary is installed", () => { const result = runWithInstalledVersion("0.0.39", {}, { - driverBins: "gateway-vm", + driverBins: "gateway", os: "Darwin", arch: "arm64", }); @@ -154,7 +154,7 @@ describe("install-openshell.sh version check", { timeout: 15_000 }, () => { expect(result.stdout).toMatch(/already installed.*0\.0\.39/); }); - it("repairs macOS openshell-driver-vm when the Hypervisor entitlement is missing", () => { + it("does not require the macOS VM driver entitlement for Docker-driver onboarding", () => { const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-openshell-codesign-")); try { const state = path.join(tmp, "codesign-state"); @@ -174,11 +174,11 @@ describe("install-openshell.sh version check", { timeout: 15_000 }, () => { ); expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(0); - expect(result.stdout).toMatch(/missing the macOS Hypervisor entitlement/); - expect(result.stdout).toMatch(/Signing openshell-driver-vm/); expect(result.stdout).toMatch(/already installed.*0\.0\.39/); + expect(result.stdout).not.toMatch(/missing the macOS Hypervisor entitlement/); + expect(result.stdout).not.toMatch(/Signing openshell-driver-vm/); expect(result.stdout).not.toMatch(/Installing OpenShell from release/); - expect(fs.readFileSync(log, "utf-8")).toContain("--force --sign - --entitlements"); + expect(fs.existsSync(log) ? fs.readFileSync(log, "utf-8") : "").toBe(""); } finally { fs.rmSync(tmp, { recursive: true, force: true }); } @@ -195,7 +195,7 @@ describe("install-openshell.sh version check", { timeout: 15_000 }, () => { expect(result.stdout).toMatch(/Installing OpenShell from release 'v0\.0\.39'/); }); - it("downloads the macOS arm64 gateway and VM helper assets during reinstall", () => { + it("downloads the macOS arm64 gateway asset during reinstall", () => { const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-openshell-macos-assets-")); try { const fakeBin = path.join(tmp, "bin"); @@ -234,8 +234,7 @@ if [ -n "$out" ]; then case "$(basename "$out")" in openshell-checksums-sha256.txt) printf '%s\n' \ - 'ignored openshell-aarch64-apple-darwin.tar.gz' \ - 'ignored openshell-driver-vm-aarch64-apple-darwin.tar.gz' > "$out" + 'ignored openshell-aarch64-apple-darwin.tar.gz' > "$out" ;; openshell-gateway-checksums-sha256.txt) printf '%s\n' \ @@ -290,7 +289,7 @@ exit 0`, const downloads = fs.readFileSync(downloadLog, "utf-8"); expect(downloads).toContain("openshell-aarch64-apple-darwin.tar.gz"); expect(downloads).toContain("openshell-gateway-aarch64-apple-darwin.tar.gz"); - expect(downloads).toContain("openshell-driver-vm-aarch64-apple-darwin.tar.gz"); + expect(downloads).not.toContain("openshell-driver-vm-aarch64-apple-darwin.tar.gz"); expect(downloads).toContain("openshell-gateway-checksums-sha256.txt"); } finally { fs.rmSync(tmp, { recursive: true, force: true }); diff --git a/test/onboard.test.ts b/test/onboard.test.ts index 54aab7539e4..3e68ecdedbf 100644 --- a/test/onboard.test.ts +++ b/test/onboard.test.ts @@ -14,6 +14,7 @@ import type { AgentDefinition } from "../dist/lib/agent/defs.js"; import { loadAgent } from "../dist/lib/agent/defs.js"; import { buildChain, buildControlUiUrls } from "../dist/lib/dashboard/contract.js"; import { NAME_ALLOWED_FORMAT } from "../dist/lib/name-validation.js"; +import { hasOpenShellVmDriverChildProcessFromPsOutput } from "../dist/lib/onboard/vm-driver-process.js"; import { stageOptimizedSandboxBuildContext } from "../dist/lib/sandbox/build-context.js"; import { testTimeoutOptions } from "./helpers/timeouts"; @@ -488,12 +489,13 @@ network_policies: expect(linuxEnv.OPENSHELL_DOCKER_SUPERVISOR_IMAGE).toContain(":0.0.37"); const darwinEnv = getDockerDriverGatewayEnv("openshell 0.0.37", "darwin"); - expect(darwinEnv.OPENSHELL_DRIVERS).toBe("vm"); + expect(darwinEnv.OPENSHELL_DRIVERS).toBe("docker"); expect(darwinEnv.OPENSHELL_BIND_ADDRESS).toBe("127.0.0.1"); - expect(darwinEnv.OPENSHELL_GRPC_ENDPOINT).toBe("http://host.containers.internal:8080"); + expect(darwinEnv.OPENSHELL_GRPC_ENDPOINT).toBe("http://127.0.0.1:8080"); expect(darwinEnv.OPENSHELL_SSH_GATEWAY_HOST).toBe("127.0.0.1"); - expect(darwinEnv.OPENSHELL_VM_DRIVER_STATE_DIR).toContain("vm-driver"); - expect(darwinEnv.OPENSHELL_DOCKER_SUPERVISOR_IMAGE).toBeUndefined(); + expect(darwinEnv.OPENSHELL_DOCKER_SUPERVISOR_IMAGE).toContain(":0.0.37"); + expect(darwinEnv.OPENSHELL_DOCKER_SUPERVISOR_BIN).toBeUndefined(); + expect(darwinEnv.OPENSHELL_VM_DRIVER_STATE_DIR).toBeUndefined(); const originalOverlayFix = process.env.NEMOCLAW_DISABLE_OVERLAY_FIX; process.env.NEMOCLAW_DISABLE_OVERLAY_FIX = "1"; @@ -549,7 +551,7 @@ network_policies: }, "arm64", ), - ).toBe(false); + ).toBe(true); expect( areRequiredDockerDriverBinariesPresent( "darwin", @@ -579,6 +581,18 @@ network_policies: expect(shouldRequireDockerDriverEnv("win32")).toBe(false); }); + it("detects VM-driver children attached to a macOS standalone gateway", () => { + const psOutput = [ + " 1000 1 /Users/me/.local/bin/openshell-gateway", + " 1001 1000 /Users/me/.local/bin/openshell-driver-vm --bind-socket /tmp/compute.sock", + " 1002 1001 /Users/me/.local/bin/openshell-driver-vm --internal-run-vm", + " 1003 1000 /usr/bin/other-process", + ].join("\n"); + expect(hasOpenShellVmDriverChildProcessFromPsOutput(1000, psOutput)).toBe(true); + expect(hasOpenShellVmDriverChildProcessFromPsOutput(1001, psOutput)).toBe(true); + expect(hasOpenShellVmDriverChildProcessFromPsOutput(1003, psOutput)).toBe(false); + }); + it("detects stale Docker-driver gateway runtime state before reuse", () => { const desiredEnv = getDockerDriverGatewayEnv("openshell 0.0.37", "linux"); const gatewayBin = process.execPath; diff --git a/test/shellquote-sandbox.test.ts b/test/shellquote-sandbox.test.ts index f74dea52ff4..de6eb347224 100644 --- a/test/shellquote-sandbox.test.ts +++ b/test/shellquote-sandbox.test.ts @@ -105,6 +105,7 @@ try { process.env.NEMOCLAW_NON_INTERACTIVE = "1"; process.env.NEMOCLAW_HEALTH_POLL_COUNT = "1"; Object.defineProperty(process, "platform", { value: "darwin" }); + Object.defineProperty(process, "arch", { value: "x64" }); const sandboxName = await createSandbox(null, "gpt-5.4", "nvidia-prod", null, "my-assistant"); console.log(JSON.stringify({ sandboxName, commands })); } catch (error) {