Improve dashboard portability and installer smoke checks

This commit is contained in:
Codex
2026-04-27 15:25:47 +00:00
parent 8b97d6fb60
commit 4e123f8e27
20 changed files with 490 additions and 186 deletions
+79
View File
@@ -0,0 +1,79 @@
import assert from 'node:assert/strict'
import { existsSync, readFileSync } from 'node:fs'
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
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/controlAuthConfig.ts')
const source = readFileSync(sourcePath, 'utf8')
const compiled = ts.transpileModule(source, {
compilerOptions: {
module: ts.ModuleKind.CommonJS,
target: ts.ScriptTarget.ES2022,
esModuleInterop: true,
},
}).outputText
const tempDir = await mkdtemp(path.join(tmpdir(), 'nemoclaw-auth-config-'))
const envPath = path.join(tempDir, '.env.local')
const originalCwd = process.cwd()
const originalEnv = {
password: process.env.OPENSHELL_CONTROL_PASSWORD,
secret: process.env.OPENSHELL_CONTROL_AUTH_SECRET,
recoveryToken: process.env.OPENSHELL_CONTROL_RECOVERY_TOKEN,
}
try {
process.chdir(tempDir)
const module = { exports: {} }
vm.runInNewContext(compiled, {
require: createRequire(sourcePath),
exports: module.exports,
module,
process,
}, { filename: sourcePath })
await writeFile(envPath, [
'OPENSHELL_CONTROL_PASSWORD=old-first',
'NEXT_PUBLIC_API_BASE=/api',
'export OPENSHELL_CONTROL_PASSWORD=old-second',
'OPENSHELL_CONTROL_AUTH_SECRET=old-secret',
'OPENSHELL_CONTROL_RECOVERY_TOKEN=old-token',
'',
].join('\n'), 'utf8')
await module.exports.updateLocalAuthCredentials('new password with spaces')
const updated = readFileSync(envPath, 'utf8')
assert.match(updated, /^OPENSHELL_CONTROL_PASSWORD="new password with spaces"$/m)
assert.equal([...updated.matchAll(/OPENSHELL_CONTROL_PASSWORD\s*=/g)].length, 1)
assert.equal([...updated.matchAll(/OPENSHELL_CONTROL_AUTH_SECRET\s*=/g)].length, 1)
assert.equal([...updated.matchAll(/OPENSHELL_CONTROL_RECOVERY_TOKEN\s*=/g)].length, 1)
assert.match(updated, /^NEXT_PUBLIC_API_BASE=\/api$/m)
assert.equal(process.env.OPENSHELL_CONTROL_PASSWORD, 'new password with spaces')
assert.ok(existsSync(envPath))
} finally {
process.chdir(originalCwd)
if (originalEnv.password === undefined) {
delete process.env.OPENSHELL_CONTROL_PASSWORD
} else {
process.env.OPENSHELL_CONTROL_PASSWORD = originalEnv.password
}
if (originalEnv.secret === undefined) {
delete process.env.OPENSHELL_CONTROL_AUTH_SECRET
} else {
process.env.OPENSHELL_CONTROL_AUTH_SECRET = originalEnv.secret
}
if (originalEnv.recoveryToken === undefined) {
delete process.env.OPENSHELL_CONTROL_RECOVERY_TOKEN
} else {
process.env.OPENSHELL_CONTROL_RECOVERY_TOKEN = originalEnv.recoveryToken
}
await rm(tempDir, { recursive: true, force: true })
}
console.log('control-auth-config-check: PASS env auth credential update assertions')
+60
View File
@@ -0,0 +1,60 @@
import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
import path from 'node:path'
const root = process.cwd()
const [
installSource,
hostCommandsSource,
createRouteSource,
deleteRouteSource,
telemetrySource,
openshellHostSource,
sandboxFilesSource,
sandboxPermissionsSource,
inferenceSource,
supportBundleSource,
] = await Promise.all([
readFile(path.join(root, 'install.sh'), 'utf8'),
readFile(path.join(root, 'app/lib/hostCommands.ts'), 'utf8'),
readFile(path.join(root, 'app/api/sandbox/create/route.ts'), 'utf8'),
readFile(path.join(root, 'app/api/sandbox/delete/route.ts'), 'utf8'),
readFile(path.join(root, 'app/api/telemetry/real/route.ts'), 'utf8'),
readFile(path.join(root, 'app/lib/openshellHost.ts'), 'utf8'),
readFile(path.join(root, 'app/lib/sandboxFiles.ts'), 'utf8'),
readFile(path.join(root, 'app/lib/sandboxPermissions.ts'), 'utf8'),
readFile(path.join(root, 'app/api/inference/route.ts'), 'utf8'),
readFile(path.join(root, 'app/api/support-bundle/route.ts'), 'utf8'),
])
assert.match(installSource, /find_nemoclaw_bin\(\)/, 'installer must discover NemoClaw CLI')
assert.match(installSource, /find_nemoclaw_setup\(\)/, 'installer must discover NemoClaw setup workflow')
assert.match(installSource, /set_env "NEMOCLAW_SETUP"/, 'installer must persist discovered NemoClaw setup path')
assert.match(installSource, /set_env "NEMOCLAW_BIN"/, 'installer must persist discovered NemoClaw CLI path')
assert.match(installSource, /set_env "OPENSHELL_BIN"/, 'installer must persist discovered OpenShell path')
assert.match(installSource, /upsert_env "TERMINAL_SERVER_AUTOSTART" "true"/, 'installer must enable terminal bridge autostart by default')
assert.match(hostCommandsSource, /export const HOST_PATH/, 'host command resolution must centralize PATH construction')
assert.match(hostCommandsSource, /\.nemoclaw\/source\/bin\/nemoclaw\.js/, 'host command resolution must support standard ~/.nemoclaw installs')
assert.match(hostCommandsSource, /\.nemoclaw\/source\/scripts\/setup\.sh/, 'host command resolution must support standard ~/.nemoclaw setup workflow')
assert.doesNotMatch(hostCommandsSource, /\/Users\/markmckeen|\/home\/nvidia/, 'host command resolution must not bake in developer machine paths')
assert.match(createRouteSource, /requireNemoClawSetup\(\)/, 'NemoClaw blueprint create must validate setup workflow before running bash')
assert.match(createRouteSource, /NemoClaw blueprint setup script was not found/, 'missing setup workflow must produce an actionable error')
assert.match(createRouteSource, /from "@\/app\/lib\/hostCommands"/, 'create route must use shared command resolution')
assert.match(deleteRouteSource, /NEMOCLAW_CWD/, 'delete route must use resolved NemoClaw working directory')
for (const [label, source] of [
['telemetry', telemetrySource],
['openshell host', openshellHostSource],
['sandbox files', sandboxFilesSource],
['sandbox permissions', sandboxPermissionsSource],
['inference', inferenceSource],
['support bundle', supportBundleSource],
]) {
assert.match(source, /hostCommands/, `${label} must use shared host command resolution`)
assert.doesNotMatch(source, /\/Users\/markmckeen|\/home\/nvidia/, `${label} must not bake in developer machine paths`)
}
console.log('portable-install-check: PASS installer and host command portability assertions')
@@ -5,8 +5,10 @@ import path from 'node:path'
const root = process.cwd()
const routePath = path.join(root, 'app/api/openshell/terminal/live/route.ts')
const pagePath = path.join(root, 'app/operator-terminal/page.tsx')
const serverPath = path.join(root, 'server.mjs')
const routeSource = await readFile(routePath, 'utf8')
const serverSource = await readFile(serverPath, 'utf8')
assert.match(
routeSource,
/throw new Error\('No routable browser host available for terminal websocket URL\. Set PUBLIC_BROWSER_HOST or PUBLIC_BASE_URL\.'\)/,
@@ -27,6 +29,27 @@ assert.match(
/return null/,
'terminal live route must return null when no routable browser host is available'
)
assert.match(
routeSource,
/Could not reach the operator terminal bridge at \$\{terminalServerUrl\}/,
'terminal live route must explain terminal bridge connection failures'
)
assert.match(
serverSource,
/startLocalTerminalServerIfNeeded/,
'custom dashboard server must provision the local terminal bridge'
)
assert.match(
serverSource,
/TERMINAL_SERVER_AUTOSTART/,
'terminal bridge autostart must have an environment override'
)
assert.match(
serverSource,
/spawn\(process\.execPath, \['terminal-server\.mjs'\]/,
'dashboard dev server should start terminal-server.mjs for local terminal sessions'
)
const pageSource = await readFile(pagePath, 'utf8')
assert.match(
@@ -44,5 +67,10 @@ assert.doesNotMatch(
/Live operator terminal for the host machine\. The selected sandbox is preserved as context for helper commands and status lookups, but this shell is intentionally machine-scoped\./,
'operator terminal page must not keep the stale host-machine-only description'
)
assert.doesNotMatch(
pageSource,
/throw new Error\(result\.error \|\| 'Failed to initialize live terminal session\.'\)/,
'operator terminal page should render terminal init failures instead of throwing'
)
console.log('post-authority-terminal-contract-check: PASS websocket host + UI honesty assertions')
+11 -6
View File
@@ -5,11 +5,13 @@ import path from 'node:path'
const root = process.cwd()
const createRoutePath = path.join(root, 'app/api/sandbox/create/route.ts')
const deleteRoutePath = path.join(root, 'app/api/sandbox/delete/route.ts')
const hostCommandsPath = path.join(root, 'app/lib/hostCommands.ts')
const telemetryRoutePath = path.join(root, 'app/api/telemetry/real/route.ts')
const inferenceRoutePath = path.join(root, 'app/api/inference/route.ts')
const ollamaModelsRoutePath = path.join(root, 'app/api/ollama/models/route.ts')
const sandboxInferenceRoutePath = path.join(root, 'app/api/sandbox/[sandboxId]/inference/route.ts')
const sandboxInferenceApplyRoutePath = path.join(root, 'app/api/sandbox/[sandboxId]/inference/apply/route.ts')
const sandboxInferenceApplyLibPath = path.join(root, 'app/lib/sandboxInferenceApply.ts')
const sandboxRestartRoutePath = path.join(root, 'app/api/sandbox/[sandboxId]/restart/route.ts')
const hookPath = path.join(root, 'app/hooks/useSandboxInventory.ts')
const pagePath = path.join(root, 'app/page.tsx')
@@ -21,11 +23,13 @@ const sandboxListPath = path.join(root, 'app/components/SandboxList.tsx')
const createRouteSource = await readFile(createRoutePath, 'utf8')
const deleteRouteSource = await readFile(deleteRoutePath, 'utf8')
const hostCommandsSource = await readFile(hostCommandsPath, 'utf8')
const telemetryRouteSource = await readFile(telemetryRoutePath, 'utf8')
const inferenceRouteSource = await readFile(inferenceRoutePath, 'utf8')
const ollamaModelsRouteSource = await readFile(ollamaModelsRoutePath, 'utf8')
const sandboxInferenceRouteSource = await readFile(sandboxInferenceRoutePath, 'utf8')
const sandboxInferenceApplyRouteSource = await readFile(sandboxInferenceApplyRoutePath, 'utf8')
const sandboxInferenceApplyLibSource = await readFile(sandboxInferenceApplyLibPath, 'utf8')
const sandboxRestartRouteSource = await readFile(sandboxRestartRoutePath, 'utf8')
const hookSource = await readFile(hookPath, 'utf8')
const pageSource = await readFile(pagePath, 'utf8')
@@ -50,7 +54,8 @@ assert.match(hookSource, /type RefreshOptions = \{\s*force\?: boolean\s*\}/, 'in
assert.match(hookSource, /!refreshOptions\?\.force && inFlightRef\.current/, 'forced inventory refresh must bypass existing in-flight reads')
assert.match(hookSource, /requestIdRef = useRef\(0\)/, 'inventory refresh must guard against stale concurrent responses')
assert.match(deleteRouteSource, /OPENSHELL_BIN.*openshell/, 'delete route must use the OpenShell CLI')
assert.match(deleteRouteSource, /OPENSHELL_BIN/, 'delete route must use the shared OpenShell CLI resolver')
assert.match(hostCommandsSource, /export const OPENSHELL_BIN[\s\S]*"openshell"/, 'shared command resolver must fall back to the OpenShell CLI')
assert.match(deleteRouteSource, /\["sandbox", "delete", sandboxName\]/, 'delete route must call openshell sandbox delete with the sandbox name')
assert.match(deleteRouteSource, /validateSandboxName/, 'delete route must validate sandbox names before execution')
assert.match(deleteRouteSource, /resolveSandboxRef/, 'delete route must resolve sandbox ids to names before deleting')
@@ -81,15 +86,15 @@ assert.match(sandboxInferencePanelSource, /\/api\/sandbox\/\$\{encodeURIComponen
assert.match(sandboxInferencePanelSource, /\/api\/ollama\/models/, 'selected sandbox UI must offer Ollama model selection')
assert.match(sandboxInferencePanelSource, /Enabled Routes/, 'selected sandbox UI must show multiple enabled inference routes')
assert.match(sandboxInferencePanelSource, /Add Route/, 'selected sandbox UI must allow adding provider/model routes')
assert.match(sandboxInferenceApplyRouteSource, /\/sandbox\/\.openclaw\/openclaw\.json/, 'live apply must patch OpenClaw config inside the running sandbox')
assert.match(sandboxInferenceApplyRouteSource, /sha256sum \/sandbox\/\.openclaw\/openclaw\.json > \/sandbox\/\.openclaw\/\.config-hash/, 'live apply must refresh the immutable OpenClaw config hash')
assert.match(sandboxInferenceApplyRouteSource, /\["inference", "set", "--no-verify", "--provider", primary\.provider, "--model", primary\.model\]/, 'live apply must point OpenShell inference at the primary route')
assert.match(sandboxInferenceApplyLibSource, /\/sandbox\/\.openclaw\/openclaw\.json/, 'live apply must patch OpenClaw config inside the running sandbox')
assert.match(sandboxInferenceApplyLibSource, /sha256sum \/sandbox\/\.openclaw\/openclaw\.json > \/sandbox\/\.openclaw\/\.config-hash/, 'live apply must refresh the immutable OpenClaw config hash')
assert.match(sandboxInferenceApplyLibSource, /\["inference", "set", "--no-verify", "--provider", primary\.provider, "--model", primary\.model\]/, 'live apply must point OpenShell inference at the primary route')
assert.match(sandboxRestartRouteSource, /\["delete", "pod", sandboxName, "-n", OPENSHELL_SANDBOX_NAMESPACE, "--wait=false"\]/, 'restart route must restart the backing sandbox pod')
assert.match(sandboxRestartRouteSource, /waitForSandboxReady\(sandboxName, 90000, 2000\)/, 'restart route must wait for OpenShell to report the sandbox ready')
assert.match(sandboxListSource, /Restart Sandbox/, 'sandbox details must expose a restart sandbox button')
assert.match(sandboxListSource, /\/api\/sandbox\/\$\{encodeURIComponent\(selectedSandbox\.id\)\}\/restart/, 'restart button must call the sandbox restart endpoint')
assert.match(sandboxListSource, /<SandboxInferencePanel sandbox=\{selectedSandbox\} \/>/, 'sandbox list must render the per-sandbox inference profile panel for the selected sandbox')
assert.match(sidebarSource, /Inference Endpoints/, 'sidebar settings item must be named Inference Endpoints')
assert.match(sandboxListSource, /<SandboxInferencePanel sandbox=\{selectedSandbox\}/, 'sandbox list must render the per-sandbox inference profile panel for the selected sandbox')
assert.match(sidebarSource, />Inference</, 'sidebar settings item must expose inference settings')
assert.match(pageSource, /<InferenceEndpointPanel \/>/, 'settings view must render inference endpoint panel')
assert.match(pageSource, /fetch\('\/api\/sandbox\/delete'/, 'destroy workflow must call the real sandbox delete endpoint')