Stabilize dashboard runtime proxy
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFile } from 'node:fs/promises'
|
||||
import path from 'node:path'
|
||||
import vm from 'node:vm'
|
||||
|
||||
const root = process.cwd()
|
||||
const helperPath = path.join(root, 'app/lib/dashboardSession.ts')
|
||||
const routePath = path.join(root, 'app/api/openshell/terminal/live/route.ts')
|
||||
const terminalPath = path.join(root, 'terminal-server.mjs')
|
||||
|
||||
const helperSource = await readFile(helperPath, 'utf8')
|
||||
assert.match(helperSource, /buildOperatorTerminalRoute/, 'dashboard session helper must define buildOperatorTerminalRoute')
|
||||
assert.match(helperSource, /dashboardSessionId/, 'dashboard session helper must include dashboardSessionId handling')
|
||||
assert.match(helperSource, /sessionStorage/, 'dashboard session helper should persist tab-scoped state in sessionStorage')
|
||||
assert.match(
|
||||
helperSource,
|
||||
/searchParams\.set\('dashboardSessionId', params\.dashboardSessionId\)/,
|
||||
'operator terminal route builder must thread dashboardSessionId'
|
||||
)
|
||||
|
||||
const routeSource = await readFile(routePath, 'utf8')
|
||||
assert.match(routeSource, /dashboardSessionId/, 'terminal live route must accept dashboardSessionId')
|
||||
assert.match(
|
||||
routeSource,
|
||||
/websocketUrl\.searchParams\.set\('dashboardSessionId', params\.dashboardSessionId\)/,
|
||||
'terminal websocket URL must include dashboardSessionId'
|
||||
)
|
||||
assert.match(
|
||||
routeSource,
|
||||
/body: JSON\.stringify\([\s\S]*dashboardSessionId[\s\S]*\)/,
|
||||
'terminal live route must forward dashboardSessionId to terminal server'
|
||||
)
|
||||
|
||||
const terminalSource = await readFile(terminalPath, 'utf8')
|
||||
assert.match(
|
||||
terminalSource,
|
||||
/existing\.dashboardSessionId === identity\.dashboardSessionId/,
|
||||
'terminal server must only reuse sessions when dashboardSessionId matches'
|
||||
)
|
||||
assert.match(
|
||||
terminalSource,
|
||||
/dashboardSessionId: session\.dashboardSessionId/,
|
||||
'terminal server responses must expose dashboardSessionId metadata'
|
||||
)
|
||||
|
||||
const buildOperatorTerminalRoute = ({ sandboxId, dashboardSessionId }) => {
|
||||
const searchParams = new URLSearchParams()
|
||||
if (sandboxId) searchParams.set('sandboxId', sandboxId)
|
||||
searchParams.set('dashboardSessionId', dashboardSessionId)
|
||||
const query = searchParams.toString()
|
||||
return query ? `/operator-terminal?${query}` : '/operator-terminal'
|
||||
}
|
||||
|
||||
assert.equal(
|
||||
buildOperatorTerminalRoute({ sandboxId: 'sandbox-a', dashboardSessionId: 'dash-123' }),
|
||||
'/operator-terminal?sandboxId=sandbox-a&dashboardSessionId=dash-123'
|
||||
)
|
||||
assert.equal(
|
||||
buildOperatorTerminalRoute({ sandboxId: null, dashboardSessionId: 'dash-123' }),
|
||||
'/operator-terminal?dashboardSessionId=dash-123'
|
||||
)
|
||||
|
||||
console.log('dashboard-session-check: PASS route/session scope assertions')
|
||||
@@ -0,0 +1,26 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFile } from 'node:fs/promises'
|
||||
import path from 'node:path'
|
||||
|
||||
const root = process.cwd()
|
||||
const pagePath = path.join(root, 'app/page.tsx')
|
||||
const sandboxListPath = path.join(root, 'app/components/SandboxList.tsx')
|
||||
const hookPath = path.join(root, 'app/hooks/useSandboxInventory.ts')
|
||||
|
||||
const pageSource = await readFile(pagePath, 'utf8')
|
||||
const sandboxListSource = await readFile(sandboxListPath, 'utf8')
|
||||
const hookSource = await readFile(hookPath, 'utf8')
|
||||
|
||||
assert.match(hookSource, /const \[loading, setLoading\] = useState\(false\)/, 'authoritative inventory hook must use SSR-safe loading initialization')
|
||||
assert.match(hookSource, /const \[error, setError\] = useState<string \| null>\(null\)/, 'authoritative inventory hook must own error state')
|
||||
assert.match(pageSource, /const \{ sandboxes, nemoclaw, loading, error, refresh \} = useSandboxInventory\(/, 'page must read loading and error from useSandboxInventory')
|
||||
assert.match(pageSource, /inventoryEnabled && loading \? \(/, 'page must render initializing from authoritative inventory state')
|
||||
assert.match(pageSource, /data-testid="inventory-loading-state"/, 'page must expose loading state marker')
|
||||
assert.match(pageSource, /inventoryEnabled && error \? \(/, 'page must render error state from authoritative inventory state')
|
||||
assert.match(pageSource, /data-testid="inventory-error-state"/, 'page must expose error state marker')
|
||||
assert.match(pageSource, /sandboxes\.length === 0 \? \(/, 'page must render explicit empty state when inventory is valid but empty')
|
||||
assert.match(pageSource, /data-testid="inventory-empty-state"/, 'page must expose empty state marker')
|
||||
assert.doesNotMatch(sandboxListSource, /const \[loading, setLoading\] = useState\(/, 'SandboxList must not own a local loading latch')
|
||||
assert.doesNotMatch(sandboxListSource, /INITIALIZING\.\.\./, 'SandboxList must not render initializing placeholder')
|
||||
|
||||
console.log('initializing-hang-check: PASS page-owned startup/error/empty state assertions')
|
||||
@@ -0,0 +1,81 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFile } from 'node:fs/promises'
|
||||
import path from 'node:path'
|
||||
|
||||
const root = process.cwd()
|
||||
const instancesPath = path.join(root, 'app/lib/openclawInstances.ts')
|
||||
const routePath = path.join(root, 'app/api/openshell/dashboard/open/route.ts')
|
||||
const sandboxListPath = path.join(root, 'app/components/SandboxList.tsx')
|
||||
|
||||
const instancesSource = await readFile(instancesPath, 'utf8')
|
||||
assert.match(
|
||||
instancesSource,
|
||||
/MY_ASSISTANT_OPENCLAW_INSTANCE_ID/,
|
||||
'openclaw instance registry should expose a dedicated my-assistant env mapping seam'
|
||||
)
|
||||
assert.match(
|
||||
instancesSource,
|
||||
/OPENCLAW_SANDBOX_INSTANCE_MAP_JSON/,
|
||||
'openclaw instance registry should allow additive sandbox->instance JSON mappings'
|
||||
)
|
||||
assert.match(
|
||||
instancesSource,
|
||||
/export function resolveOpenClawInstanceForSandbox\(sandboxId\?: string \| null\)/,
|
||||
'openclaw instance registry should expose sandbox-aware instance resolution'
|
||||
)
|
||||
assert.match(
|
||||
instancesSource,
|
||||
/getOpenClawInstanceIdForSandbox\(sandboxId\?: string \| null\)/,
|
||||
'openclaw instance registry should expose sandbox mapping lookup'
|
||||
)
|
||||
|
||||
const routeSource = await readFile(routePath, 'utf8')
|
||||
assert.match(
|
||||
routeSource,
|
||||
/const sandboxId = requestUrl\.searchParams\.get\('sandboxId'\)/,
|
||||
'dashboard open route must accept sandboxId'
|
||||
)
|
||||
assert.match(
|
||||
routeSource,
|
||||
/resolveOpenClawInstanceForSandbox\(sandboxId\)/,
|
||||
'dashboard open route must resolve instances from sandbox context when instanceId is absent'
|
||||
)
|
||||
assert.match(
|
||||
routeSource,
|
||||
/sandboxInstanceId: mappedSandboxInstanceId/,
|
||||
'dashboard open route response should expose mapped sandbox instance metadata'
|
||||
)
|
||||
assert.match(
|
||||
routeSource,
|
||||
/sandboxId,\s*\n\s*sandboxInstanceId: mappedSandboxInstanceId,\s*\n\s*instanceId: instance\.id/,
|
||||
'dashboard open route response should include sandboxId alongside resolved instance metadata'
|
||||
)
|
||||
assert.match(
|
||||
routeSource,
|
||||
/bootstrapUrl: probe\.bootstrapUrl/,
|
||||
'dashboard open route should return explicit bootstrap URL metadata'
|
||||
)
|
||||
assert.match(
|
||||
routeSource,
|
||||
/bootstrapTokenPresent: probe\.bootstrapTokenPresent/,
|
||||
'dashboard open route should expose whether the bootstrap contract is tokenized'
|
||||
)
|
||||
|
||||
const sandboxListSource = await readFile(sandboxListPath, 'utf8')
|
||||
assert.match(
|
||||
sandboxListSource,
|
||||
/searchParams\.set\('sandboxId', selectedSandbox\.id\)/,
|
||||
'sandbox list must pass selected sandboxId when opening the dashboard'
|
||||
)
|
||||
assert.match(
|
||||
sandboxListSource,
|
||||
/fetch\(`\/api\/openshell\/dashboard\/open\?\$\{searchParams\.toString\(\)\}`\)/,
|
||||
'sandbox list should call the sandbox-aware dashboard open route'
|
||||
)
|
||||
assert.match(
|
||||
sandboxListSource,
|
||||
/Sandbox \$\{data\.sandboxId\} resolved to OpenClaw instance \$\{data\.instanceId\}/,
|
||||
'sandbox list should surface sandbox-aware resolution feedback'
|
||||
)
|
||||
|
||||
console.log('openclaw-dashboard-instance-resolution-check: PASS sandbox-aware dashboard resolution assertions')
|
||||
@@ -0,0 +1,48 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFile } from 'node:fs/promises'
|
||||
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 routeSource = await readFile(routePath, 'utf8')
|
||||
assert.match(
|
||||
routeSource,
|
||||
/throw new Error\('No routable browser host available for terminal websocket URL\. Set PUBLIC_BROWSER_HOST or PUBLIC_BASE_URL\.'\)/,
|
||||
'terminal live route must fail closed when only non-routable browser hosts are available'
|
||||
)
|
||||
assert.doesNotMatch(
|
||||
routeSource,
|
||||
/return requestUrl\.host/,
|
||||
'terminal live route must not fall back to requestUrl.host when it is non-routable'
|
||||
)
|
||||
assert.match(
|
||||
routeSource,
|
||||
/const requestHostHeader = requestUrl\.host/,
|
||||
'terminal live route should inspect request host before deciding routability'
|
||||
)
|
||||
assert.match(
|
||||
routeSource,
|
||||
/return null/,
|
||||
'terminal live route must return null when no routable browser host is available'
|
||||
)
|
||||
|
||||
const pageSource = await readFile(pagePath, 'utf8')
|
||||
assert.match(
|
||||
pageSource,
|
||||
/sandboxId \? 'Live operator terminal for the selected sandbox, brokered through the dashboard-owned terminal bridge\.'/,
|
||||
'operator terminal page must describe sandbox-scoped terminal behavior honestly'
|
||||
)
|
||||
assert.match(
|
||||
pageSource,
|
||||
/: 'Live operator terminal for host mode, brokered through the dashboard-owned terminal bridge\.'/,
|
||||
'operator terminal page must distinguish host mode from sandbox mode'
|
||||
)
|
||||
assert.doesNotMatch(
|
||||
pageSource,
|
||||
/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'
|
||||
)
|
||||
|
||||
console.log('post-authority-terminal-contract-check: PASS websocket host + UI honesty assertions')
|
||||
@@ -0,0 +1,58 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import path from 'node:path'
|
||||
import { readFile } from 'node:fs/promises'
|
||||
|
||||
const root = process.cwd()
|
||||
|
||||
const runtimeAuthorityPath = path.join(root, 'app/lib/runtimeAuthority.ts')
|
||||
const dashboardOpenPath = path.join(root, 'app/api/openshell/dashboard/open/route.ts')
|
||||
const dashboardProxySharedPath = path.join(root, 'app/api/openshell/dashboard/proxy/shared.ts')
|
||||
const terminalLivePath = path.join(root, 'app/api/openshell/terminal/live/route.ts')
|
||||
const terminalReadinessPath = path.join(root, 'app/api/openshell/terminal/readiness/route.ts')
|
||||
const telemetryPath = path.join(root, 'app/api/telemetry/real/route.ts')
|
||||
const openshellHostPath = path.join(root, 'app/lib/openshellHost.ts')
|
||||
const packageJsonPath = path.join(root, 'package.json')
|
||||
const serverPath = path.join(root, 'server.mjs')
|
||||
|
||||
const [runtimeAuthoritySource, dashboardOpenSource, dashboardProxySource, terminalLiveSource, terminalReadinessSource, telemetrySource, openshellHostSource, packageJsonSource, serverSource] = await Promise.all([
|
||||
readFile(runtimeAuthorityPath, 'utf8'),
|
||||
readFile(dashboardOpenPath, 'utf8'),
|
||||
readFile(dashboardProxySharedPath, 'utf8'),
|
||||
readFile(terminalLivePath, 'utf8'),
|
||||
readFile(terminalReadinessPath, 'utf8'),
|
||||
readFile(telemetryPath, 'utf8'),
|
||||
readFile(openshellHostPath, 'utf8'),
|
||||
readFile(packageJsonPath, 'utf8'),
|
||||
readFile(serverPath, 'utf8'),
|
||||
])
|
||||
|
||||
assert.match(runtimeAuthoritySource, /export function resolveRuntimeAuthority\(/, 'runtime authority resolver must exist')
|
||||
assert.match(runtimeAuthoritySource, /mappedSandboxInstanceId = getOpenClawInstanceIdForSandbox\(resolvedSandboxId\)/, 'runtime authority must derive sandbox instance mapping from resolved sandbox id')
|
||||
assert.match(runtimeAuthoritySource, /requestedInstanceId\s*\?\s*resolveOpenClawInstance\(requestedInstanceId\)/, 'runtime authority must allow explicit instance override')
|
||||
|
||||
assert.match(dashboardOpenSource, /const sandboxId = requestUrl\.searchParams\.get\('sandboxId'\)/, 'dashboard open route must still read sandboxId explicitly')
|
||||
assert.match(dashboardOpenSource, /const authority = resolveRuntimeAuthority\(/, 'dashboard open route must use shared runtime authority resolution')
|
||||
assert.match(dashboardOpenSource, /authority:\s*\{[\s\S]*sandboxAuthority:/, 'dashboard open route must expose authority provenance')
|
||||
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(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')
|
||||
assert.match(dashboardProxySource, /copyRequestHeaders/, 'dashboard proxy should forward browser request headers upstream')
|
||||
assert.match(dashboardProxySource, /upstreamInit\.duplex = 'half'/, 'dashboard proxy should forward non-GET request bodies upstream')
|
||||
|
||||
assert.match(terminalLiveSource, /const authority = resolveRuntimeAuthority\(/, 'terminal live route must use shared runtime authority resolution')
|
||||
assert.match(terminalLiveSource, /authority:\s*\{[\s\S]*usedMappedSandboxInstance:/, 'terminal live route must expose authority provenance')
|
||||
|
||||
assert.match(terminalReadinessSource, /terminalFallback: true/, 'terminal readiness must explicitly represent terminal fallback state')
|
||||
assert.match(terminalReadinessSource, /const authority = resolveRuntimeAuthority\(/, 'terminal readiness must use shared runtime authority resolution')
|
||||
|
||||
assert.match(telemetrySource, /authoritySource: "runtimeAuthority"/, 'inventory route must declare shared authority source')
|
||||
assert.match(telemetrySource, /authorities: authorities\.map\(/, 'inventory route must expose per-sandbox authority metadata')
|
||||
assert.match(openshellHostSource, /const canMintBootstrapFromCli = instance\.id === defaultInstance\.id/, 'bootstrap minting should only use CLI for the default OpenClaw instance')
|
||||
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 dashboardWss = new WebSocketServer\(\{ noServer: true \}\)/, 'custom server must provision a dedicated dashboard websocket bridge')
|
||||
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')
|
||||
Reference in New Issue
Block a user