Files
openshell_controller/tests/post-authority-terminal-contract-check.mjs
T

77 lines
2.8 KiB
JavaScript

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 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\.'\)/,
'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'
)
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(
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'
)
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')