diff --git a/app/api/sandbox/create/route.ts b/app/api/sandbox/create/route.ts index 0a1d340..cfc4200 100644 --- a/app/api/sandbox/create/route.ts +++ b/app/api/sandbox/create/route.ts @@ -20,9 +20,6 @@ import { } from "@/app/lib/hostCommands" const execFileAsync = promisify(execFile) -const DOCKER_BIN = process.env.DOCKER_BIN || "docker" -const OPENSHELL_CLUSTER_CONTAINER = process.env.OPENSHELL_CLUSTER_CONTAINER || "openshell-cluster-nemoclaw" -const OPENSHELL_NAMESPACE = process.env.OPENSHELL_SANDBOX_NAMESPACE || "openshell" const NEMOCLAW_REGISTRY_FILE = path.join(process.env.HOME || "/tmp", ".nemoclaw", "sandboxes.json") function validateSandboxName(name: string) { @@ -88,7 +85,7 @@ type CreateInferenceSettings = { } type NemoClawRegistryData = { - sandboxes?: Record + sandboxes?: Record defaultSandbox?: string | null } @@ -254,27 +251,6 @@ function resolveNemoClawBasePolicyPath() { return found } -async function readPodImage(sandboxName: string, jsonpath: string) { - const { stdout } = await execFileAsync(DOCKER_BIN, [ - "exec", - OPENSHELL_CLUSTER_CONTAINER, - "kubectl", - "get", - "pod", - sandboxName, - "-n", - OPENSHELL_NAMESPACE, - "-o", - `jsonpath=${jsonpath}`, - ], { - env: hostCommandEnv(), - timeout: 10000, - maxBuffer: 1024 * 1024, - }) - - return String(stdout).trim().split(/\s+/)[0] || null -} - function stripAnsi(value: string) { return value.replace(/\u001b\[[0-9;]*m/g, "") } @@ -323,12 +299,11 @@ async function resolveSourcePodImageFromRef(sourceSandboxRef: string) { const requested = sourceSandboxRef.trim() const source = await resolveSandboxRef(requested) const sourceName = validateSandboxName(source.name) - const sourceImage = await readPodImage(sourceName, '{.spec.containers[?(@.name=="agent")].image}') - .catch(() => null) - || await readPodImage(sourceName, "{.spec.containers[0].image}").catch(() => null) + const registryEntry = readNemoClawRegistry().sandboxes?.[sourceName] + const sourceImage = registryEntry?.imageTag?.trim() || null if (!sourceImage) { - throw new Error(`Could not resolve the running image for source sandbox '${sourceName}'.`) + throw new Error(`Could not resolve the registered image for source sandbox '${sourceName}'. Rebuild it with current NemoClaw to record imageTag.`) } return { diff --git a/app/lib/mcpBrokerUrl.ts b/app/lib/mcpBrokerUrl.ts index 61962b1..75d10ce 100644 --- a/app/lib/mcpBrokerUrl.ts +++ b/app/lib/mcpBrokerUrl.ts @@ -1,6 +1,6 @@ import { execFile } from "node:child_process" import { promisify } from "node:util" -import { HOST_PATH, OPENSHELL_BIN, hostCommandEnv } from "./hostCommands" +import { OPENSHELL_BIN, hostCommandEnv } from "./hostCommands" import { resolveSandboxRef } from "./openshellHost" const execFileAsync = promisify(execFile) @@ -12,21 +12,6 @@ function shouldUseProxyWrappedBrokerUrl() { return /^(1|true|yes|on)$/i.test(process.env.OPENSHELL_CONTROL_MCP_BROKER_PROXY_URL || "") } -async function discoverOpenShellDockerGateway() { - const container = process.env.OPEN_SHELL_CONTAINER || "openshell-cluster-nemoclaw" - const { stdout } = await execFileAsync("docker", ["inspect", container], { - env: { ...process.env, PATH: HOST_PATH }, - timeout: 5000, - maxBuffer: 1024 * 1024, - }) - const [inspect] = JSON.parse(String(stdout)) as Array<{ - NetworkSettings?: { - Networks?: Record - } - }> - const networks = inspect?.NetworkSettings?.Networks || {} - return Object.values(networks).map((network) => network.Gateway).find(Boolean) || null -} function normalizeProxyOrigin(value: string) { try { @@ -41,7 +26,7 @@ function normalizeProxyOrigin(value: string) { async function runOpenShell(args: string[]) { const { stdout } = await execFileAsync(OPENSHELL_BIN, args, { env: hostCommandEnv({ - OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw", + OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined, TERM: "dumb", }), timeout: 15000, @@ -66,8 +51,7 @@ export async function brokerBaseUrlForSandbox( const origin = new URL(request.url).origin const publicOrigin = new URL(origin) if (LOCAL_HOSTNAMES.has(publicOrigin.hostname)) { - const gateway = await discoverOpenShellDockerGateway().catch(() => null) - publicOrigin.hostname = gateway || "host.docker.internal" + publicOrigin.hostname = "host.docker.internal" } const hostBrokerUrl = `${publicOrigin.toString().replace(/\/+$/, "")}/api/mcp/broker` diff --git a/tests/mcp-configuration-page-check.mjs b/tests/mcp-configuration-page-check.mjs index 5d42086..d7e1969 100644 --- a/tests/mcp-configuration-page-check.mjs +++ b/tests/mcp-configuration-page-check.mjs @@ -176,7 +176,8 @@ assert.match(sandboxMcpRouteSource, /revokeBrokerNetworkAccess/, 'Sandbox MCP ro assert.match(sandboxMcpRouteSource, /export async function GET/, 'Sandbox MCP route must preview the broker handoff') assert.match(sandboxMcpRouteSource, /brokerBaseUrlForSandbox/, 'Sandbox MCP broker handoff must build a sandbox-routable broker URL') assert.match(sandboxMcpRouteSource, /synced\.openClaw\.path/, 'Sandbox MCP sync response must report the OpenClaw config write') -assert.match(brokerUrlSource, /discoverOpenShellDockerGateway/, 'Sandbox MCP broker handoff must discover the active OpenShell network gateway') +assert.match(brokerUrlSource, /host\.docker\.internal/, 'Sandbox MCP broker handoff must use the portable Docker host alias without inspecting a legacy cluster container') +assert.doesNotMatch(brokerUrlSource, /discoverOpenShellDockerGateway|OPEN_SHELL_CONTAINER|docker.*inspect/, 'Sandbox MCP broker handoff must not depend on obsolete cluster containers') assert.match(brokerUrlSource, /LOCAL_HOSTNAMES/, 'Sandbox MCP broker handoff must rewrite local-only browser origins') assert.match(brokerUrlSource, /shouldUseProxyWrappedBrokerUrl/, 'Sandbox MCP broker handoff must make proxy-wrapped URLs opt-in') assert.match(brokerUrlSource, /if \(!shouldUseProxyWrappedBrokerUrl\(\)\) return hostBrokerUrl/, 'Sandbox MCP broker handoff must prefer the direct gateway URL by default') diff --git a/tests/portable-install-check.mjs b/tests/portable-install-check.mjs index 7eff6f4..70a6da7 100644 --- a/tests/portable-install-check.mjs +++ b/tests/portable-install-check.mjs @@ -94,9 +94,8 @@ assert.ok( 'NemoClaw onboard must prefer the installed package root over stale legacy checkout setup paths', ) assert.doesNotMatch(hostCommandsSource, /\/Users\/markmckeen|\/home\/nvidia/, 'host command resolution must not bake in developer machine paths') -assert.match(mcpBrokerUrlSource, /discoverOpenShellDockerGateway/, 'MCP broker URL generation must discover the active OpenShell Docker gateway') -assert.match(mcpBrokerUrlSource, /OPEN_SHELL_CONTAINER/, 'MCP broker URL generation must respect the configured cluster container') -assert.match(mcpBrokerUrlSource, /host\.docker\.internal/, 'MCP broker URL generation must keep a fallback for hosts without Docker inspect') +assert.match(mcpBrokerUrlSource, /host\.docker\.internal/, 'MCP broker URL generation must use the portable host alias for local controller URLs') +assert.doesNotMatch(mcpBrokerUrlSource, /discoverOpenShellDockerGateway|OPEN_SHELL_CONTAINER|docker.*inspect/, 'MCP broker URL generation must not depend on obsolete cluster containers') assert.match(mcpBrokerUrlSource, /discoverSandboxProxyOrigin/, 'MCP broker URL generation must discover each sandbox proxy endpoint') assert.match(mcpBrokerUrlSource, /HTTP_PROXY/, 'MCP broker URL generation must use the sandbox proxy environment when available') assert.match(mcpBrokerClientSource, /PATH: HOST_PATH/, 'MCP stdio broker launches must inherit the shared host PATH') diff --git a/tests/sandbox-lifecycle-check.mjs b/tests/sandbox-lifecycle-check.mjs index 7d9f09f..456e4b0 100644 --- a/tests/sandbox-lifecycle-check.mjs +++ b/tests/sandbox-lifecycle-check.mjs @@ -106,6 +106,8 @@ assert.match(createRouteSource, /readNemoClawRegistry/, 'image redeploy must dis assert.match(createRouteSource, /listOpenShellSandboxNames/, 'image redeploy must fall back to live OpenShell inventory when registry entries are stale') assert.match(createRouteSource, /resolveSourcePodImage\(sourceSandboxName, sandboxName\)/, 'image redeploy must allow optional explicit source while defaulting automatically') assert.match(createRouteSource, /"--from",\s*sourceImage/, 'image redeploy must pass the resolved image to openshell sandbox create') +assert.match(createRouteSource, /registryEntry\?\.imageTag\?\.trim\(\)/, 'image redeploy must resolve the source image from NemoClaw registry metadata') +assert.doesNotMatch(createRouteSource, /OPENSHELL_CLUSTER_CONTAINER|readPodImage|"kubectl"/, 'image redeploy must not depend on obsolete cluster containers or in-container kubectl') assert.match(createRouteSource, /"--auto-providers"/, 'image redeploy must use OpenShell auto providers for provider-backed images') assert.match(createRouteSource, /registerNemoClawImageRedeploy/, 'image redeploy must register the new sandbox without a full NemoClaw rebuild') assert.match(createRouteSource, /readyVerification\?: SandboxVerification/, 'ready-aware create command must carry the authoritative verification result')