Integrate NemoClaw recovery and dashboard routing
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import vm from 'node:vm'
|
||||
import ts from 'typescript'
|
||||
import { createRequire } from 'node:module'
|
||||
|
||||
const root = process.cwd()
|
||||
const sourcePath = path.join(root, 'app/lib/controlAuth.ts')
|
||||
const source = readFileSync(sourcePath, 'utf8')
|
||||
const compiled = ts.transpileModule(source, {
|
||||
compilerOptions: {
|
||||
module: ts.ModuleKind.CommonJS,
|
||||
target: ts.ScriptTarget.ES2022,
|
||||
esModuleInterop: true,
|
||||
},
|
||||
}).outputText
|
||||
|
||||
function mockRequest(protocol, headers = {}) {
|
||||
return {
|
||||
nextUrl: { protocol },
|
||||
headers: {
|
||||
get(name) {
|
||||
return headers[name.toLowerCase()] || null
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const originalEnv = {
|
||||
cookieSecure: process.env.OPENSHELL_CONTROL_COOKIE_SECURE,
|
||||
publicBaseUrl: process.env.PUBLIC_BASE_URL,
|
||||
}
|
||||
|
||||
try {
|
||||
delete process.env.OPENSHELL_CONTROL_COOKIE_SECURE
|
||||
delete process.env.PUBLIC_BASE_URL
|
||||
|
||||
const module = { exports: {} }
|
||||
vm.runInNewContext(compiled, {
|
||||
require: createRequire(sourcePath),
|
||||
exports: module.exports,
|
||||
module,
|
||||
process,
|
||||
URL,
|
||||
}, { filename: sourcePath })
|
||||
|
||||
assert.equal(module.exports.shouldUseSecureSessionCookie(mockRequest('http:')), false)
|
||||
assert.equal(module.exports.sessionCookieOptionsForRequest(mockRequest('http:')).secure, false)
|
||||
assert.equal(module.exports.shouldUseSecureSessionCookie(mockRequest('https:')), true)
|
||||
assert.equal(
|
||||
module.exports.shouldUseSecureSessionCookie(mockRequest('http:', { 'x-forwarded-proto': 'https' })),
|
||||
true,
|
||||
)
|
||||
|
||||
process.env.PUBLIC_BASE_URL = 'https://control.example.test'
|
||||
assert.equal(module.exports.shouldUseSecureSessionCookie(), true)
|
||||
|
||||
process.env.OPENSHELL_CONTROL_COOKIE_SECURE = 'false'
|
||||
assert.equal(module.exports.shouldUseSecureSessionCookie(mockRequest('https:')), false)
|
||||
|
||||
process.env.OPENSHELL_CONTROL_COOKIE_SECURE = 'true'
|
||||
assert.equal(module.exports.shouldUseSecureSessionCookie(mockRequest('http:')), true)
|
||||
} finally {
|
||||
if (originalEnv.cookieSecure === undefined) {
|
||||
delete process.env.OPENSHELL_CONTROL_COOKIE_SECURE
|
||||
} else {
|
||||
process.env.OPENSHELL_CONTROL_COOKIE_SECURE = originalEnv.cookieSecure
|
||||
}
|
||||
|
||||
if (originalEnv.publicBaseUrl === undefined) {
|
||||
delete process.env.PUBLIC_BASE_URL
|
||||
} else {
|
||||
process.env.PUBLIC_BASE_URL = originalEnv.publicBaseUrl
|
||||
}
|
||||
}
|
||||
|
||||
console.log('control-auth-cookie-check: PASS request-aware secure cookie assertions')
|
||||
@@ -0,0 +1,40 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFile } from 'node:fs/promises'
|
||||
import path from 'node:path'
|
||||
|
||||
const root = process.cwd()
|
||||
const helperPath = path.join(root, 'app/lib/nemoclawCli.ts')
|
||||
const healthRoutePath = path.join(root, 'app/api/sandbox/[sandboxId]/health/route.ts')
|
||||
const restartRoutePath = path.join(root, 'app/api/sandbox/[sandboxId]/restart/route.ts')
|
||||
|
||||
const [helperSource, healthRouteSource, restartRouteSource] = await Promise.all([
|
||||
readFile(helperPath, 'utf8'),
|
||||
readFile(healthRoutePath, 'utf8'),
|
||||
readFile(restartRoutePath, 'utf8'),
|
||||
])
|
||||
|
||||
assert.match(helperSource, /const NEMOCLAW_RECOVERY_MIN_VERSION = "0\.0\.37"/, 'NemoClaw doctor/recover integration must be gated behind the v0.0.37 CLI surface')
|
||||
assert.match(helperSource, /NEMOCLAW_BIN, NODE_BIN, commandExists, hostCommandEnv/, 'NemoClaw helper must use the shared host command resolver')
|
||||
assert.match(helperSource, /parseVersion/, 'NemoClaw helper must parse CLI versions instead of assuming latest behavior')
|
||||
assert.match(helperSource, /versionGte/, 'NemoClaw helper must compare semantic versions before using newer commands')
|
||||
assert.match(helperSource, /export async function getNemoClawDoctorReport/, 'NemoClaw helper must expose a doctor JSON probe')
|
||||
assert.match(helperSource, /\[sandboxName, "doctor", "--json"\]/, 'doctor probe must use the structured NemoClaw doctor JSON command')
|
||||
assert.match(helperSource, /export async function recoverSandboxWithNemoClaw/, 'NemoClaw helper must expose sandbox recovery')
|
||||
assert.match(helperSource, /\[sandboxName, "recover"\]/, 'sandbox recovery must use the new NemoClaw recover command')
|
||||
assert.match(helperSource, /supported: false,[\s\S]*attempted: false/, 'unsupported old NemoClaw versions must skip newer commands without failing')
|
||||
|
||||
assert.match(healthRouteSource, /getNemoClawDoctorReport/, 'sandbox health must include NemoClaw doctor integration when available')
|
||||
assert.match(healthRouteSource, /key: "nemoclaw-doctor"/, 'sandbox health must surface NemoClaw doctor as a health check')
|
||||
assert.match(healthRouteSource, /Using OpenShell compatibility checks/, 'sandbox health must explicitly fall back for current NemoClaw versions')
|
||||
assert.match(healthRouteSource, /minimumVersion/, 'sandbox health response must expose the minimum version for doctor support')
|
||||
|
||||
assert.match(restartRouteSource, /recoverSandboxWithNemoClaw/, 'sandbox restart must try NemoClaw recover when supported')
|
||||
assert.ok(
|
||||
restartRouteSource.indexOf('recoverSandboxWithNemoClaw(sandboxName)') < restartRouteSource.indexOf('runSandboxShell(sandboxName, restartOpenClawGatewayScript()'),
|
||||
'sandbox restart must try NemoClaw recover before the legacy OpenClaw runtime restart fallback',
|
||||
)
|
||||
assert.match(restartRouteSource, /restartMode: "nemoclaw-recover"/, 'restart route must report when the new NemoClaw recovery path succeeds')
|
||||
assert.match(restartRouteSource, /restartMode: "openclaw-runtime"/, 'restart route must retain the current OpenShell/OpenClaw runtime fallback')
|
||||
assert.match(restartRouteSource, /NemoClaw recover did not complete[\s\S]*fell back/, 'restart route must report fallback when modern recovery is attempted but fails')
|
||||
|
||||
console.log('nemoclaw-compat-check: PASS NemoClaw old/new compatibility assertions')
|
||||
@@ -13,13 +13,23 @@ assert.match(
|
||||
)
|
||||
assert.match(
|
||||
proxySource,
|
||||
/const sidecarGatewayUrl = protocol \+ '\/\/' \+ sidecarHost \+ proxyPrefix/,
|
||||
'dashboard bootstrap should know the dedicated websocket sidecar gateway scope'
|
||||
/const baseWsUrl = process\.env\.OPENCLAW_DASHBOARD_BASE_WS_URL\?\.trim\(\) \|\| process\.env\.BASE_WS_URL\?\.trim\(\) \|\| ''/,
|
||||
'dashboard bootstrap should accept a fully qualified websocket base URL override'
|
||||
)
|
||||
assert.match(
|
||||
proxySource,
|
||||
/const gatewayUrl = \(hashParams\.get\('gatewayUrl'\) \|\| ''\)\.trim\(\) \|\| sidecarGatewayUrl/,
|
||||
'dashboard bootstrap should honor the tokenized launch gateway URL'
|
||||
/const portGatewayUrl = wsProxyPort \? protocol \+ '\/\/' \+ window\.location\.hostname \+ ':' \+ wsProxyPort \+ proxyPrefix : ''/,
|
||||
'dashboard bootstrap should keep the dedicated websocket sidecar as an explicit opt-in scope'
|
||||
)
|
||||
assert.match(
|
||||
proxySource,
|
||||
/const defaultGatewayUrl = configuredGatewayUrl \|\| portGatewayUrl \|\| pageGatewayUrl/,
|
||||
'dashboard bootstrap should prefer configured, explicit sidecar, then same-origin websocket gateways'
|
||||
)
|
||||
assert.match(
|
||||
proxySource,
|
||||
/const gatewayUrl = normalizeGatewayUrl\(hashParams\.get\('gatewayUrl'\)\) \|\| defaultGatewayUrl/,
|
||||
'dashboard bootstrap should honor and normalize the tokenized launch gateway URL'
|
||||
)
|
||||
assert.match(
|
||||
proxySource,
|
||||
@@ -28,8 +38,13 @@ assert.match(
|
||||
)
|
||||
assert.match(
|
||||
proxySource,
|
||||
/const gatewayScopes = uniqueScopes\(\[gatewayUrl, sidecarGatewayUrl, pageGatewayUrl\]\)/,
|
||||
'dashboard bootstrap should seed token scopes for launch, sidecar, and page gateways'
|
||||
/const gatewayScopes = uniqueScopes\(\[gatewayUrl, configuredGatewayUrl, portGatewayUrl, pageGatewayUrl\]\)/,
|
||||
'dashboard bootstrap should seed token scopes for launch, configured, sidecar, and page gateways'
|
||||
)
|
||||
assert.doesNotMatch(
|
||||
proxySource,
|
||||
/\|\| '3001'/,
|
||||
'dashboard bootstrap must not hardcode the dedicated websocket sidecar port'
|
||||
)
|
||||
assert.match(
|
||||
proxySource,
|
||||
|
||||
@@ -13,7 +13,20 @@ assert.match(proxySource, /controlUiOrigin: authority\.openclaw\.controlUiOrigin
|
||||
assert.match(proxySource, /lowerKey !== 'origin'/, 'HTTP proxy must not forward browser Origin to OpenClaw')
|
||||
assert.match(proxySource, /headers\.set\('origin', controlUiOrigin\)/, 'HTTP proxy must rewrite Origin to the gateway control UI origin')
|
||||
assert.match(proxySource, /headers\.set\('referer', `\$\{controlUiOrigin\}\/`\)/, 'HTTP proxy must rewrite Referer to the gateway control UI origin')
|
||||
assert.match(proxySource, /CONTROL_AUTH_COOKIE_NAME = 'openshell_control_session'/, 'HTTP proxy must know the controller auth cookie name')
|
||||
assert.match(proxySource, /lowerKey === 'cookie' \? filterCookieHeader\(value\) : value/, 'HTTP proxy must strip controller auth cookies before forwarding to OpenClaw')
|
||||
assert.match(proxySource, /OPENCLAW_DASHBOARD_TOKEN_COOKIE/, 'HTTP proxy must know the dashboard token bridge cookie name')
|
||||
assert.match(proxySource, /headers\.set\('authorization', `Bearer \$\{dashboardToken\}`\)/, 'HTTP proxy must bridge the dashboard token cookie into upstream Authorization')
|
||||
assert.match(serverSource, /controlUiOrigin: process\.env\.OPENCLAW_SANDBOX_CONTROL_UI_ORIGIN \|\| 'http:\/\/127\.0\.0\.1:18789'/, 'sandbox instances must preserve the gateway internal control UI origin')
|
||||
assert.match(serverSource, /openClawDashboardTokenCookieName = 'openclaw_dashboard_token'/, 'WebSocket tunnel must know the dashboard token bridge cookie name')
|
||||
assert.match(serverSource, /withDashboardTokenQuery\(upstreamWsUrl, dashboardToken\)/, 'WebSocket tunnel must add the dashboard token to the upstream websocket handshake URL')
|
||||
assert.match(serverSource, /redactSensitiveUrl\(upstreamUrlWithToken\)/, 'WebSocket tunnel logs must redact tokenized upstream URLs')
|
||||
assert.match(serverSource, /const upstreamUrl = withDashboardTokenQuery\(context\.upstreamWsUrl, dashboardToken\)/, 'WebSocket bridge must add the dashboard token to the upstream websocket URL')
|
||||
assert.match(serverSource, /const redactedUpstreamUrl = redactSensitiveUrl\(upstreamUrl\)/, 'WebSocket bridge logs must redact tokenized upstream URLs')
|
||||
assert.match(serverSource, /headers\.push\(`Host: \$\{upstreamWsUrl\.host\}`\)[\s\S]*headers\.push\(`Upgrade:/, 'WebSocket tunnel must normalize handshake headers with Host before upgrade fields for OpenClaw')
|
||||
assert.match(serverSource, /headers\.push\(`Origin: \$\{controlUiOrigin\}`\)/, 'WebSocket tunnel must rewrite Origin to the gateway control UI origin')
|
||||
assert.match(serverSource, /rawHeaders\.get\('cookie'\)[\s\S]*filterCookieHeader\(header\.value\)/, 'WebSocket tunnel must strip controller auth cookies before forwarding to OpenClaw')
|
||||
assert.match(serverSource, /headers\.push\(`Authorization: Bearer \$\{dashboardToken\}`\)/, 'WebSocket tunnel must bridge the dashboard token cookie into upstream Authorization')
|
||||
assert.match(serverSource, /function handleDashboardProxyUpgrade[\s\S]*dashboardWss\.handleUpgrade/, 'dashboard websocket upgrades must use the authenticated WebSocket bridge')
|
||||
|
||||
console.log('openclaw-dashboard-origin-rewrite-check: PASS dashboard proxy origin rewrite assertions')
|
||||
|
||||
@@ -36,6 +36,8 @@ assert.match(dashboardOpenSource, /authority:\s*\{[\s\S]*sandboxAuthority:/, 'da
|
||||
assert.match(dashboardOpenSource, /bootstrapUrl: probe\.bootstrapUrl/, 'dashboard open route must surface the resolved bootstrap URL explicitly')
|
||||
assert.match(dashboardOpenSource, /bootstrapAuthority: probe\.bootstrapAuthority/, 'dashboard open route must surface tokenized bootstrap authority explicitly')
|
||||
assert.match(dashboardOpenSource, /probe\.bootstrapAuthority === 'tokenized-cli'/, 'dashboard open route truth must prefer tokenized bootstrap evidence over raw loopback fetch alone')
|
||||
assert.match(dashboardOpenSource, /process\.env\.OPENCLAW_DASHBOARD_BASE_WS_URL\?\.trim\(\) \|\| process\.env\.BASE_WS_URL\?\.trim\(\) \|\| null/, 'dashboard open route must allow a fully qualified browser websocket base URL')
|
||||
assert.match(dashboardOpenSource, /const wsProxyPort = process\.env\.OPENCLAW_DASHBOARD_WS_PROXY_PORT\?\.trim\(\) \|\| ''/, 'dashboard open route must not hardcode the dedicated websocket sidecar port')
|
||||
|
||||
assert.match(dashboardProxySource, /resolveRuntimeAuthority\(\{[\s\S]*sandboxId: requestUrl\.searchParams\.get\('sandboxId'\)/, 'dashboard proxy must resolve target from shared authority source')
|
||||
assert.match(dashboardProxySource, /x-openclaw-dashboard-bootstrap-contract/, 'dashboard proxy must mark the tokenized bootstrap bridge contract in response headers')
|
||||
@@ -54,9 +56,11 @@ assert.match(openshellHostSource, /const canMintBootstrapFromCli = instance\.id
|
||||
assert.match(openshellHostSource, /readSandboxOpenClawDashboardToken/, 'sandbox dashboard bootstrap must fall back to the sandbox OpenClaw token when CLI output is bare')
|
||||
assert.match(openshellHostSource, /openclaw dashboard', 15000\)\.catch/, 'sandbox dashboard bootstrap should let OpenClaw initialize before reading the fallback token')
|
||||
assert.match(openshellHostSource, /withDashboardToken\(tokenizedBootstrapUrl, token\)/, 'sandbox dashboard bootstrap should synthesize a tokenized launch URL from the fallback token')
|
||||
assert.match(packageJsonSource, /"dev": "node server\.mjs"/, 'development script must run through the custom server so websocket proxy bridges are active')
|
||||
assert.match(serverSource, /const dashboardWsProxyServer = http\.createServer/, 'custom server must provision a dedicated dashboard websocket sidecar')
|
||||
assert.match(serverSource, /dashboard-sidecar-listening/, 'custom server must expose the dashboard websocket sidecar listener')
|
||||
assert.match(packageJsonSource, /"dev": "NODE_ENV=development node server\.mjs"/, 'development script must run through the custom server so websocket proxy bridges are active')
|
||||
assert.match(packageJsonSource, /"start": "NODE_ENV=production node server\.mjs"/, 'production start must run the custom server without Next dev-mode heap growth')
|
||||
assert.match(serverSource, /const dashboardWsProxyPort = parseOptionalPort\(process\.env\.OPENCLAW_DASHBOARD_WS_PROXY_PORT/, 'custom server must make the dedicated dashboard websocket sidecar opt-in')
|
||||
assert.match(serverSource, /const dashboardWsProxyServer = dashboardWsProxyPort\s*\?\s*http\.createServer/, 'custom server must only provision the sidecar when explicitly configured')
|
||||
assert.match(serverSource, /dashboard-sidecar-listening/, 'custom server must still expose the optional dashboard websocket sidecar listener')
|
||||
assert.match(serverSource, /dashboard-upgrade-accepted/, 'custom server must accept dashboard websocket upgrades through the proxy path')
|
||||
|
||||
console.log('runtime-authority-resolution-check: PASS shared authority resolution assertions')
|
||||
|
||||
@@ -139,6 +139,9 @@ assert.match(inferenceRouteSource, /\["provider", "delete", name\]/, 'inference
|
||||
assert.match(inferenceRouteSource, /\["inference", "set", "--provider", name, "--model", model\]/, 'inference route must set the active OpenShell inference route')
|
||||
assert.match(inferenceRouteSource, /isVllmEndpoint\(name, baseUrl\)/, 'inference route must skip verification for vLLM-compatible endpoints')
|
||||
assert.match(inferenceRouteSource, /normalizeProviderType\(requestedType, name, baseUrl\)/, 'inference route must force vLLM endpoints through the OpenAI-compatible provider type')
|
||||
assert.match(inferenceRouteSource, /isOllamaEndpoint\(name, baseUrl\)/, 'inference route must detect local Ollama endpoints')
|
||||
assert.match(inferenceRouteSource, /isVllmEndpoint\(name, baseUrl\) \|\| isOllamaEndpoint\(name, baseUrl\)/, 'inference route must force local Ollama endpoints through the OpenAI-compatible provider type')
|
||||
assert.match(inferenceRouteSource, /body\?\.noVerify !== false \|\| isVllmEndpoint\(name, baseUrl\) \|\| isOllamaEndpoint\(name, baseUrl\)/, 'inference route must skip verification for local Ollama endpoints')
|
||||
assert.match(inferenceRouteSource, /normalizeInferenceBaseUrlForGateway\(\s*baseUrl,/, 'inference route must normalize endpoint URLs for the OpenShell gateway pod')
|
||||
assert.match(inferenceRouteSource, /OPENAI_BASE_URL=\$\{normalizedBaseUrl\}/, 'inference route must pass the normalized endpoint URL as provider config')
|
||||
assert.match(inferenceEndpointUrlSource, /host\.docker\.internal/, 'endpoint normalization must rewrite host-local URLs to a gateway-reachable host alias')
|
||||
@@ -150,7 +153,11 @@ assert.match(inferencePanelSource, /host\.docker\.internal:8000\/v1/, 'vLLM pres
|
||||
assert.doesNotMatch(inferencePanelSource, /nvidia\/NVIDIA-Nemotron-3-Super-120B-A12B-NVFP4/, 'settings UI must not default rebuilt inference routes to the NVIDIA Nemotron model')
|
||||
assert.match(inferencePanelSource, /method: "DELETE"/, 'settings UI must expose provider deletion')
|
||||
assert.match(inferencePanelSource, /\/api\/ollama\/models/, 'settings UI must poll local Ollama models')
|
||||
assert.match(inferencePanelSource, /window\.setInterval\(\(\) => loadOllamaModels\(\{ silent: true \}\), 10000\)/, 'settings UI must autopoll Ollama while selected')
|
||||
assert.match(inferencePanelSource, /window\.setInterval\(\(\) => loadOllamaModels\(\{ silent: true \}\), 10000\)/, 'settings UI must autopoll Ollama while the endpoint panel is open')
|
||||
assert.match(inferencePanelSource, /function applyOllamaModelPreset\(modelName: string\)/, 'settings UI must provide a click preset for local Ollama models')
|
||||
assert.match(inferencePanelSource, /setName\(OLLAMA_PROVIDER_NAME\)[\s\S]*setType\("openai"\)[\s\S]*setModel\(modelName\)[\s\S]*setBaseUrl\(OLLAMA_BASE_URL\)/, 'Ollama model preset must fill provider name, provider type, model, and endpoint URL')
|
||||
assert.match(inferencePanelSource, /onClick=\{\(\) => applyOllamaModelPreset\(item\.name\)\}/, 'clicking an Ollama model must load the endpoint preset')
|
||||
assert.match(inferencePanelSource, /const OLLAMA_BASE_URL = "http:\/\/host\.docker\.internal:11434\/v1"/, 'Ollama preset must use the host-reachable OpenAI-compatible endpoint')
|
||||
assert.match(ollamaModelsRouteSource, /\/api\/tags/, 'Ollama models route must query the Ollama tags API')
|
||||
assert.match(ollamaModelsRouteSource, /OLLAMA_BASE_URL/, 'Ollama models route must support a configurable Ollama base URL')
|
||||
assert.match(sandboxInferenceRouteSource, /parseRoutes/, 'sandbox inference route must accept multiple provider/model routes')
|
||||
|
||||
Reference in New Issue
Block a user