import assert from 'node:assert/strict' import path from 'node:path' import { readFile } from 'node:fs/promises' const root = process.cwd() const storePath = path.join(root, 'app/lib/mcpServerStore.ts') const brokerStorePath = path.join(root, 'app/lib/mcpBrokerStore.ts') const brokerClientPath = path.join(root, 'app/lib/mcpBrokerClient.ts') const brokerProtocolPath = path.join(root, 'app/lib/mcpBrokerProtocol.ts') const sandboxAutoSyncPath = path.join(root, 'app/lib/mcpSandboxAutoSync.ts') const manifestPath = path.join(root, 'app/lib/sandboxMcpManifest.ts') const privilegedFilesPath = path.join(root, 'app/lib/sandboxPrivilegedFiles.ts') const routePath = path.join(root, 'app/api/mcp/route.ts') const uploadRoutePath = path.join(root, 'app/api/mcp/upload/route.ts') const preflightRoutePath = path.join(root, 'app/api/mcp/preflight/route.ts') const healthRoutePath = path.join(root, 'app/api/mcp/health/route.ts') const registryRoutePath = path.join(root, 'app/api/mcp/registry/route.ts') const registriesRoutePath = path.join(root, 'app/api/mcp/registries/route.ts') const registriesAssistRoutePath = path.join(root, 'app/api/mcp/registries/assist/route.ts') const installAssistRoutePath = path.join(root, 'app/api/mcp/install-assist/route.ts') const registryStorePath = path.join(root, 'app/lib/mcpRegistryStore.ts') const inferenceModelPath = path.join(root, 'app/lib/inferenceModel.ts') const brokerCapabilitiesRoutePath = path.join(root, 'app/api/mcp/broker/capabilities/route.ts') const brokerCallRoutePath = path.join(root, 'app/api/mcp/broker/call/route.ts') const brokerMcpRoutePath = path.join(root, 'app/api/mcp/broker/mcp/route.ts') const sandboxMcpRoutePath = path.join(root, 'app/api/sandbox/[sandboxId]/mcp/route.ts') const brokerUrlPath = path.join(root, 'app/lib/mcpBrokerUrl.ts') const sandboxOpenClawMcpConfigPath = path.join(root, 'app/lib/sandboxOpenClawMcpConfig.ts') const sandboxPermissionsPath = path.join(root, 'app/lib/sandboxPermissions.ts') const preflightLibPath = path.join(root, 'app/lib/mcpPreflight.ts') const preflightRepairLibPath = path.join(root, 'app/lib/mcpPreflightRepair.ts') const mcpServerSpecsPath = path.join(root, 'mcp_server_specs.md') const middlewarePath = path.join(root, 'middleware.ts') const panelPath = path.join(root, 'app/components/McpConfigurationPanel.tsx') const helpPath = path.join(root, 'app/components/HelpPanel.tsx') const sidebarPath = path.join(root, 'app/components/Sidebar.tsx') const sandboxListPath = path.join(root, 'app/components/SandboxList.tsx') const pagePath = path.join(root, 'app/page.tsx') const serverPath = path.join(root, 'server.mjs') const interSandboxChatCorePath = path.join(root, 'scripts/inter-sandbox-chat-core.mjs') const interSandboxChatPath = path.join(root, 'scripts/inter-sandbox-chat-mcp.mjs') const interSandboxChatOpenClawDispatchPath = path.join(root, 'scripts/inter-sandbox-chat-openclaw-dispatch.mjs') const interSandboxChatSidecarPath = path.join(root, 'scripts/inter-sandbox-chat-sidecar.mjs') const [storeSource, brokerStoreSource, brokerClientSource, brokerProtocolSource, sandboxAutoSyncSource, manifestSource, privilegedFilesSource, routeSource, uploadRouteSource, preflightRouteSource, healthRouteSource, registryRouteSource, registriesRouteSource, registriesAssistRouteSource, installAssistRouteSource, registryStoreSource, inferenceModelSource, brokerCapabilitiesRouteSource, brokerCallRouteSource, brokerMcpRouteSource, sandboxMcpRouteSource, brokerUrlSource, sandboxOpenClawMcpConfigSource, sandboxPermissionsSource, preflightLibSource, preflightRepairLibSource, mcpServerSpecsSource, middlewareSource, panelSource, helpSource, sidebarSource, sandboxListSource, pageSource, interSandboxChatCoreSource, interSandboxChatSource, interSandboxChatOpenClawDispatchSource, interSandboxChatSidecarSource, serverSource] = await Promise.all([ readFile(storePath, 'utf8'), readFile(brokerStorePath, 'utf8'), readFile(brokerClientPath, 'utf8'), readFile(brokerProtocolPath, 'utf8'), readFile(sandboxAutoSyncPath, 'utf8'), readFile(manifestPath, 'utf8'), readFile(privilegedFilesPath, 'utf8'), readFile(routePath, 'utf8'), readFile(uploadRoutePath, 'utf8'), readFile(preflightRoutePath, 'utf8'), readFile(healthRoutePath, 'utf8'), readFile(registryRoutePath, 'utf8'), readFile(registriesRoutePath, 'utf8'), readFile(registriesAssistRoutePath, 'utf8'), readFile(installAssistRoutePath, 'utf8'), readFile(registryStorePath, 'utf8'), readFile(inferenceModelPath, 'utf8'), readFile(brokerCapabilitiesRoutePath, 'utf8'), readFile(brokerCallRoutePath, 'utf8'), readFile(brokerMcpRoutePath, 'utf8'), readFile(sandboxMcpRoutePath, 'utf8'), readFile(brokerUrlPath, 'utf8'), readFile(sandboxOpenClawMcpConfigPath, 'utf8'), readFile(sandboxPermissionsPath, 'utf8'), readFile(preflightLibPath, 'utf8'), readFile(preflightRepairLibPath, 'utf8'), readFile(mcpServerSpecsPath, 'utf8'), readFile(middlewarePath, 'utf8'), readFile(panelPath, 'utf8'), readFile(helpPath, 'utf8'), readFile(sidebarPath, 'utf8'), readFile(sandboxListPath, 'utf8'), readFile(pagePath, 'utf8'), readFile(interSandboxChatCorePath, 'utf8'), readFile(interSandboxChatPath, 'utf8'), readFile(interSandboxChatOpenClawDispatchPath, 'utf8'), readFile(interSandboxChatSidecarPath, 'utf8'), readFile(serverPath, 'utf8'), ]) assert.match(storeSource, /export const MCP_SERVER_CATALOG/, 'MCP store must expose an install catalog') assert.match(storeSource, /blendermcp\.org/, 'MCP catalog must include the requested BlenderMCP site') assert.match(storeSource, /args:\s*\["blender-mcp"\]/, 'MCP catalog must install BlenderMCP via uvx blender-mcp') assert.match(storeSource, /id: "inter-sandbox-chat"/, 'MCP catalog must include Inter-Sandbox Chat') assert.match(storeSource, /Inter-Sandbox Chat/, 'MCP catalog must expose the Inter-Sandbox Chat display name') assert.match(storeSource, /inter-sandbox-chat-mcp\.mjs/, 'MCP catalog must launch the local Inter-Sandbox Chat server') assert.match(storeSource, /BASELINE_MCP_SERVER_IDS = \["memory", "inter-sandbox-chat"\]/, 'MCP dashboard should install Memory and Inter-Sandbox Chat as baseline servers') assert.match(storeSource, /ensureBaselineMcpServers/, 'MCP store must seed baseline servers into dashboard state') assert.match(storeSource, /mcp-servers\.json/, 'MCP installs must persist to dashboard state') assert.match(storeSource, /accessMode/, 'MCP installs must persist sandbox access mode') assert.match(storeSource, /allowedSandboxIds/, 'MCP installs must persist allowed sandbox lists') assert.match(storeSource, /withoutUndefined/, 'MCP catalog installs must not let omitted API fields erase preset command definitions') assert.match(storeSource, /existing\?\.accessMode \|\| "disabled"/, 'MCP server access should default to disabled for sandboxes') assert.match(storeSource, /refreshCatalogMcpServers/, 'MCP catalog-backed installs must refresh metadata when bundled catalog definitions change') assert.match(storeSource, /export function buildMcpClientConfig/, 'MCP store must export client config JSON') assert.match(storeSource, /mcpServers/, 'MCP client config must use the common mcpServers shape') assert.match(brokerStoreSource, /mcp-broker-sessions\.json/, 'MCP broker sessions must persist server-side') assert.match(brokerStoreSource, /verifySandboxMcpBrokerToken/, 'MCP broker must verify sandbox tokens server-side') assert.match(brokerStoreSource, /listAllowedBrokerServers/, 'MCP broker must filter servers by access policy') assert.match(brokerClientSource, /@modelcontextprotocol\/sdk\/client\/index\.js/, 'MCP broker must use the official SDK client') assert.match(brokerClientSource, /StdioClientTransport/, 'MCP broker must support stdio servers') assert.match(brokerClientSource, /StreamableHTTPClientTransport/, 'MCP broker must support streamable HTTP servers') assert.match(brokerClientSource, /callBrokerServerTool/, 'MCP broker must forward allowed tool calls') assert.match(interSandboxChatSource, /post_message/, 'Inter-Sandbox Chat MCP server must let agents post messages') assert.match(interSandboxChatSource, /post_operator_message/, 'Inter-Sandbox Chat MCP server must provide a dedicated operator post path that requires acknowledgements') assert.match(interSandboxChatSource, /read_messages/, 'Inter-Sandbox Chat MCP server must let agents read messages') assert.match(interSandboxChatSource, /claim_operator_messages/, 'Inter-Sandbox Chat MCP server must let sidecars claim targeted operator messages without LLM polling') assert.match(interSandboxChatSource, /list_rooms/, 'Inter-Sandbox Chat MCP server must let agents discover rooms') assert.match(interSandboxChatSource, /ack_message/, 'Inter-Sandbox Chat MCP server must let agents acknowledge operator messages') assert.match(interSandboxChatSource, /get_message_receipts/, 'Inter-Sandbox Chat MCP server must expose parseable operator message receipts') assert.match(interSandboxChatSource, /list_operator_ack_status/, 'Inter-Sandbox Chat MCP server must expose dashboard-friendly operator ack status') assert.match(interSandboxChatSource, /origin.*operator|operator.*origin/s, 'Inter-Sandbox Chat MCP server must tag operator-originated messages') assert.match(interSandboxChatCoreSource, /messageOrigin === "operator"/, 'Inter-Sandbox Chat core must require acknowledgements only for operator messages') assert.match(interSandboxChatCoreSource, /messageTargetsAgent/, 'Inter-Sandbox Chat core must support target-aware claim filtering') assert.match(interSandboxChatCoreSource, /messageFromActor/, 'Inter-Sandbox Chat core must avoid echoing sandbox messages back to their sender') assert.match(interSandboxChatCoreSource, /claimOperatorMessages/, 'Inter-Sandbox Chat core must expose deterministic claim/cursor behavior') assert.match(interSandboxChatCoreSource, /claimTargetedMessages/, 'Inter-Sandbox Chat core must let the sidecar claim targeted sandbox-originated messages') assert.match(interSandboxChatSource, /Do not acknowledge sandbox-originated messages/, 'Inter-Sandbox Chat MCP tool guidance must tell agents not to ack sandbox-to-sandbox chat') assert.match(interSandboxChatSource, /targetSandboxIds/, 'Inter-Sandbox Chat MCP posts must support explicit sandbox targets') assert.match(interSandboxChatCoreSource, /inter-sandbox-chat\.json/, 'Inter-Sandbox Chat core must persist chat state in dashboard storage') assert.match(interSandboxChatSidecarSource, /mcp-servers\.json/, 'Inter-Sandbox Chat sidecar must watch MCP server access policy') assert.match(interSandboxChatSidecarSource, /mcp-broker-sessions\.json/, 'Inter-Sandbox Chat sidecar must discover sandbox MCP broker sessions') assert.match(interSandboxChatSidecarSource, /INTER_SANDBOX_CHAT_DISPATCH_COMMAND/, 'Inter-Sandbox Chat sidecar must use an explicit dispatch command hook') assert.match(interSandboxChatSidecarSource, /inter-sandbox-chat-openclaw-dispatch\.mjs/, 'Inter-Sandbox Chat sidecar must default to the built-in OpenClaw chat dispatch adapter') assert.match(interSandboxChatSidecarSource, /claimOperatorMessages/, 'Inter-Sandbox Chat sidecar must claim targeted operator messages') assert.match(interSandboxChatSidecarSource, /RELAY_SANDBOX_MESSAGES/, 'Inter-Sandbox Chat sidecar must relay targeted sandbox-to-sandbox messages') assert.match(interSandboxChatSidecarSource, /SANDBOX_RELAY_LATEST_ONLY/, 'Inter-Sandbox Chat sidecar must be able to send only the latest sandbox chat message') assert.match(interSandboxChatSidecarSource, /ackChatMessage/, 'Inter-Sandbox Chat sidecar must write received, processed, and failed receipts') assert.match(interSandboxChatSidecarSource, /recordChatMessageReceipt/, 'Inter-Sandbox Chat sidecar must record delivery receipts for sandbox-originated messages without operator acks') assert.match(interSandboxChatSidecarSource, /postChatMessage/, 'Inter-Sandbox Chat sidecar must be able to post sandbox replies') assert.match(interSandboxChatOpenClawDispatchSource, /chat\.send/, 'Inter-Sandbox Chat OpenClaw dispatch must send claimed messages through OpenClaw chat') assert.match(interSandboxChatOpenClawDispatchSource, /inter-sandbox-chat/, 'Inter-Sandbox Chat OpenClaw dispatch must default to a dedicated chat session instead of polluting main') assert.match(interSandboxChatOpenClawDispatchSource, /WebSocket/, 'Inter-Sandbox Chat OpenClaw dispatch must use the OpenClaw websocket gateway') assert.match(interSandboxChatOpenClawDispatchSource, /openclaw\.json/, 'Inter-Sandbox Chat OpenClaw dispatch must read the sandbox gateway token from OpenClaw config') assert.match(interSandboxChatOpenClawDispatchSource, /ssh-proxy/, 'Inter-Sandbox Chat OpenClaw dispatch must route through the OpenShell sandbox SSH proxy') assert.match(interSandboxChatOpenClawDispatchSource, /OPENCLAW_SANDBOX_DASHBOARD_PORT_BASE/, 'Inter-Sandbox Chat OpenClaw dispatch must share controller sandbox dashboard port mapping') assert.match(serverSource, /inter-sandbox-chat-sidecar\.mjs/, 'OpenShell controller must start the Inter-Sandbox Chat sidecar with the server') assert.match(serverSource, /INTER_SANDBOX_CHAT_SIDECAR_AUTOSTART/, 'OpenShell controller must let operators disable the chat sidecar autostart') assert.match(brokerProtocolSource, /tools\/list/, 'MCP broker protocol adapter must expose an MCP tools/list JSON-RPC method') assert.match(brokerProtocolSource, /tools\/call/, 'MCP broker protocol adapter must expose an MCP tools/call JSON-RPC method') assert.match(brokerProtocolSource, /listAllowedBrokerServers/, 'MCP broker protocol adapter must reuse broker access policy') assert.match(brokerProtocolSource, /reserveToolName/, 'MCP broker protocol adapter must namespace tools by broker server') assert.match(sandboxAutoSyncSource, /autoSyncSandboxMcpAccess/, 'MCP access updates must have a server-side sandbox sync helper') assert.match(sandboxAutoSyncSource, /syncSandboxMcpManifest/, 'MCP access grants must issue sandbox OpenClaw MCP config') assert.match(sandboxAutoSyncSource, /revokeSandboxMcpManifest/, 'MCP access revokes must remove sandbox OpenClaw MCP config when no access remains') assert.match(sandboxAutoSyncSource, /changedServerAccessChanged/, 'MCP sandbox auto-sync must target sandboxes touched by the changed server') assert.match(manifestSource, /openshell_control_mcp\.md/, 'MCP sandbox manifest must use the requested filename') assert.match(manifestSource, /syncSandboxMcpManifest/, 'MCP sandbox manifest must be syncable into a sandbox') assert.match(manifestSource, /writeSandboxFilePrivileged/, 'MCP sandbox manifest must use a privileged write path for root-owned /sandbox mounts') assert.match(manifestSource, /syncSandboxOpenClawMcpConfig/, 'MCP sandbox manifest sync must also configure OpenClaw MCP') assert.match(manifestSource, /\/mcp/, 'MCP sandbox handoff must include the protocol-compatible MCP endpoint') assert.match(manifestSource, /Quick Check/, 'MCP sandbox handoff must include a token-safe local verification snippet') assert.match(manifestSource, /tools\/list/, 'MCP sandbox handoff quick check should verify tool discovery') assert.match(privilegedFilesSource, /\["sandbox", "exec", "-n", sandboxName/, 'privileged sandbox file writes must use the OpenShell sandbox exec path') assert.match(privilegedFilesSource, /hostCommandEnv/, 'privileged sandbox file writes must use the shared OpenShell command environment') assert.doesNotMatch(manifestSource, /allowedServers|renderServer|commandLine/, 'MCP sandbox handoff must not disclose server inventory or launch specs') assert.match(manifestSource, /control plane enforces/, 'MCP sandbox handoff must explain broker-side enforcement') assert.match(brokerCapabilitiesRouteSource, /listAllowedBrokerServers/, 'MCP broker capabilities must only list allowed servers') assert.match(brokerCapabilitiesRouteSource, /listBrokerServerTools/, 'MCP broker capabilities must inspect allowed server tools') assert.match(brokerCallRouteSource, /Requested MCP capability is unavailable/, 'MCP broker denied calls must not disclose blocked server names') assert.match(brokerCallRouteSource, /callBrokerServerTool/, 'MCP broker call route must forward allowed calls') assert.match(brokerCallRouteSource, /isBrokerMcpJsonRpcBody/, 'Existing broker call route must also accept MCP JSON-RPC payloads') assert.match(brokerCallRouteSource, /handleBrokerMcpJsonRpcBody/, 'Existing broker call route must bridge MCP JSON-RPC through broker policy') assert.match(brokerMcpRouteSource, /handleBrokerMcpJsonRpcBody/, 'MCP protocol endpoint must use the shared broker protocol adapter') assert.match(brokerMcpRouteSource, /readBrokerToken/, 'MCP protocol endpoint must use broker token authentication') assert.match(sandboxMcpRouteSource, /export async function POST/, 'Sandbox MCP route must write the broker handoff') assert.match(sandboxMcpRouteSource, /action === "revoke"/, 'Sandbox MCP route must revoke broker handoff when MCP access is removed') assert.match(sandboxMcpRouteSource, /syncBrokerNetworkAccess/, 'Sandbox MCP route must synchronize broker network access when MCP is enabled') assert.match(sandboxMcpRouteSource, /revokeBrokerNetworkAccess/, 'Sandbox MCP route must remove broker network access when MCP is revoked') 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, /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') assert.match(brokerUrlSource, /discoverSandboxProxyOrigin/, 'Sandbox MCP broker handoff must discover each sandbox proxy endpoint') assert.match(brokerUrlSource, /HTTP_PROXY/, 'Sandbox MCP broker handoff must derive the proxy endpoint from sandbox environment') assert.match(brokerUrlSource, /FALLBACK_SANDBOX_PROXY_ORIGIN/, 'Sandbox MCP broker handoff may keep a fallback for older OpenShell layouts') assert.match(sandboxOpenClawMcpConfigSource, /mcp\.servers = servers/, 'Sandbox MCP sync must write mcp.servers into OpenClaw config') assert.match(sandboxOpenClawMcpConfigSource, /streamable-http/, 'OpenClaw MCP broker config must use streamable HTTP transport') assert.match(sandboxOpenClawMcpConfigSource, /Authorization: `Bearer \$\{token\}`/, 'OpenClaw MCP broker config must pass the sandbox broker token as bearer auth') assert.match(sandboxOpenClawMcpConfigSource, /restartOpenClawGatewayIfRunning/, 'OpenClaw gateway must restart after MCP config changes') assert.match(sandboxPermissionsSource, /method: "initialize"[\s\S]*method: "POST"/, 'MCP broker network sync must probe the actual streamable HTTP POST initialize path') assert.match(sandboxPermissionsSource, /"--input-type=module"/, 'MCP broker network sync probe must support top-level await') assert.match(sandboxPermissionsSource, /await fetch\(/, 'MCP broker network sync probe must wait for the policy-generating request') assert.match(sandboxPermissionsSource, /extractProxiedTargetUrl/, 'MCP broker network sync must inspect proxy-wrapped target URLs') assert.match(sandboxPermissionsSource, /const proxiedTarget = extractProxiedTargetUrl\(brokerBaseUrl\)/, 'MCP broker network sync must derive the target host behind the sandbox HTTP proxy') assert.match(sandboxPermissionsSource, /if \(proxiedTarget\) addEndpointCandidate\(candidates, proxiedTarget\)/, 'MCP broker network sync must approve the proxied broker target host') assert.match(middlewareSource, /\/api\/mcp\/broker/, 'MCP broker endpoints must bypass dashboard cookie auth and rely on broker token auth') assert.match(routeSource, /export async function GET/, 'MCP API must list server configuration') assert.match(routeSource, /export async function POST/, 'MCP API must install and update server configuration') assert.match(routeSource, /installMcpServer/, 'MCP API must support installing servers') assert.match(routeSource, /uninstallMcpServer/, 'MCP API must support removing servers') assert.match(routeSource, /updateMcpServerAccess/, 'MCP API must support access policy updates') assert.match(routeSource, /autoSyncSandboxMcpAccess/, 'MCP API access changes must automatically sync affected sandbox OpenClaw MCP config') assert.match(routeSource, /sandboxSync/, 'MCP API responses must report automatic sandbox sync results') assert.match(uploadRouteSource, /request\.formData\(\)/, 'MCP upload API must accept multipart server bundles') assert.match(uploadRouteSource, /writeDirectoryUpload/, 'MCP upload API must support directory uploads') assert.match(uploadRouteSource, /writeArchiveUpload/, 'MCP upload API must support archive uploads') assert.match(uploadRouteSource, /bootstrapUploadedServer/, 'MCP upload API must bootstrap uploaded server dependencies') assert.match(uploadRouteSource, /requirements\.txt/, 'MCP upload API must install Python requirements when present') assert.match(uploadRouteSource, /pyproject\.toml/, 'MCP upload API must install Python projects when present') assert.match(uploadRouteSource, /package\.json/, 'MCP upload API must install Node dependencies when present') assert.match(uploadRouteSource, /\.venv/, 'MCP upload API must isolate Python uploads in a per-server virtualenv') assert.match(uploadRouteSource, /entryMode/, 'MCP upload API must support non-file launch modes') assert.match(uploadRouteSource, /python-module/, 'MCP upload API must support Python module launch') assert.match(uploadRouteSource, /console-script/, 'MCP upload API must support installed console script launch') assert.match(uploadRouteSource, /resolveProjectRoot/, 'MCP upload API must find project manifests inside uploaded directories') assert.match(uploadRouteSource, /inferUploadLaunch/, 'MCP upload API must infer uploaded server runtime and launch metadata') assert.match(uploadRouteSource, /inferPythonConsoleScript/, 'MCP upload API must detect Python console-script entrypoints') assert.match(uploadRouteSource, /package\.json/, 'MCP upload API must inspect package.json for Node entrypoints') assert.match(uploadRouteSource, /preflightMcpServer/, 'MCP upload API must preflight uploaded server bundles') assert.match(uploadRouteSource, /repairUploadedMcpServerWithLlm/, 'MCP upload API must attempt bounded LLM repair when uploaded server preflight fails') assert.match(uploadRouteSource, /mode"\).*"stage"/s, 'MCP upload API must support a file-staging mode') assert.match(uploadRouteSource, /mode === "preflight"/, 'MCP upload API must support preflighting staged uploads') assert.match(uploadRouteSource, /mode === "install-staged"/, 'MCP upload API must support installing staged uploads') assert.match(uploadRouteSource, /form\.get\("sandboxId"\)/, 'MCP upload API must accept a sandbox id so repair can mirror that sandbox LLM route') assert.match(uploadRouteSource, /preflight-failed/, 'MCP upload API must mark failed preflight installs') assert.match(uploadRouteSource, /installMcpServer/, 'MCP upload API must install uploaded server bundles') assert.match(preflightRouteSource, /export async function POST/, 'MCP preflight API must expose a POST check endpoint') assert.match(preflightRouteSource, /preflightMcpServer/, 'MCP preflight API must call the shared preflight helper') assert.match(preflightLibSource, /listBrokerServerTools/, 'MCP preflight must validate servers through SDK tool discovery') assert.match(preflightLibSource, /attempted relative import/, 'MCP preflight assistant must recognize Python package launch failures') assert.match(preflightLibSource, /FastMCP/, 'MCP preflight assistant must recognize MCP SDK compatibility failures') assert.match(preflightRepairLibSource, /getSandboxInferenceConfig/, 'MCP preflight repair must reuse the selected sandbox inference profile when available') assert.match(preflightRepairLibSource, /chat\/completions/, 'MCP preflight repair must call an OpenAI-compatible chat endpoint') assert.match(preflightRepairLibSource, /response_format: \{ type: "json_object" \}/, 'MCP preflight repair must ask the model for structured JSON') assert.match(preflightRepairLibSource, /repair path must stay inside the uploaded server/, 'MCP preflight repair must confine edits to the uploaded server') assert.match(preflightRepairLibSource, /provided context/, 'MCP preflight repair must only edit files shown to the model') assert.match(preflightRepairLibSource, /mcp_server_specs\.md/, 'MCP preflight repair must read the uploaded-server requirements spec') assert.match(preflightRepairLibSource, /You are inspecting an MCP server/, 'MCP preflight repair must use the dedicated inspection prompt') assert.match(mcpServerSpecsSource, /per-server virtual environment/, 'MCP server spec must document isolated Python virtualenvs') assert.match(mcpServerSpecsSource, /Broker Expectations/, 'MCP server spec must document broker preflight expectations') assert.match(healthRouteSource, /listBrokerServerTools/, 'MCP health API must inspect server tools through the broker client') assert.match(healthRouteSource, /enabledServers/, 'MCP health API must check enabled MCP servers') assert.match(registryRouteSource, /registry\.modelcontextprotocol\.io/, 'MCP registry search should default to the official registry') assert.match(registryRouteSource, /\/v0\/servers/, 'MCP registry search should call the registry server list endpoint') assert.match(registryRouteSource, /normalizeRegistryEntry/, 'MCP registry search should normalize results into installable entries') assert.match(registryRouteSource, /packageInstall/, 'MCP registry search should support package-backed stdio installs') assert.match(registryRouteSource, /remoteInstall/, 'MCP registry search should support remote HTTP installs') assert.match(registryRouteSource, /searchParams\.get\("baseUrl"\)/, 'MCP registry search must accept a selected registry base URL') assert.match(registryStoreSource, /mcp-registries\.json/, 'MCP registries must persist to dashboard state') assert.match(registryStoreSource, /DEFAULT_MCP_REGISTRY/, 'MCP registries should start with the official registry before user changes') assert.match(registriesRouteSource, /listMcpRegistries/, 'MCP registries API must list registries') assert.match(registriesRouteSource, /saveMcpRegistry/, 'MCP registries API must save registries') assert.match(registriesRouteSource, /deleteMcpRegistry/, 'MCP registries API must delete registries') assert.match(registriesAssistRouteSource, /chat\/completions/, 'MCP registry assistant must use the running OpenAI-compatible LLM endpoint') assert.match(registriesAssistRouteSource, /response_format: \{ type: "json_object" \}/, 'MCP registry assistant must request structured JSON') assert.match(registriesAssistRouteSource, /resolvePrimaryInferenceModel/, 'MCP registry assistant must use the configured primary inference model') assert.match(installAssistRouteSource, /chat\/completions/, 'MCP install wizard assistant must use the running OpenAI-compatible LLM endpoint') assert.match(installAssistRouteSource, /uploadRuntime/, 'MCP install wizard assistant must draft upload metadata') assert.match(installAssistRouteSource, /response_format: \{ type: "json_object" \}/, 'MCP install wizard assistant must request structured JSON') assert.match(installAssistRouteSource, /resolvePrimaryInferenceModel/, 'MCP install wizard assistant must use the configured primary inference model') assert.match(inferenceModelSource, /\["inference", "get"\]/, 'MCP LLM assistants must resolve the configured OpenShell inference route') assert.match(inferenceModelSource, /Gateway inference/, 'MCP LLM assistants must prefer gateway inference model resolution') assert.match(inferenceModelSource, /System inference/, 'MCP LLM assistants may fall back to system inference model resolution') assert.doesNotMatch(inferenceModelSource, /gpt-4o-mini/, 'MCP LLM assistants must not hardcode a ChatGPT model fallback') assert.match(panelSource, /Server Install Wizard/, 'MCP page must present custom installation as a wizard') assert.match(panelSource, /Upload Server Files/, 'MCP server install wizard must use a clear upload step') assert.match(panelSource, /Preflight Check/, 'MCP server install wizard must use a clear preflight step') assert.match(panelSource, /Review/, 'MCP server install wizard must use a clear review step') assert.match(panelSource, /Install/, 'MCP server install wizard must use a clear install step') assert.match(panelSource, /Choose Directory/, 'MCP custom server upload must accept directories') assert.match(panelSource, /Choose Archive/, 'MCP custom server upload must accept archives') assert.match(panelSource, /\/api\/mcp\/upload/, 'MCP custom server upload must call the upload API') assert.match(panelSource, /dependencyInstall/, 'MCP custom server upload must surface dependency bootstrap results') assert.match(panelSource, /Detected \{stagedUpload\.runtime\}/, 'MCP custom server upload must display inferred runtime and launch metadata') assert.doesNotMatch(panelSource, /Upload Runtime/, 'MCP custom server upload must not ask the user for runtime') assert.doesNotMatch(panelSource, /Upload Launch Mode/, 'MCP custom server upload must not ask the user for launch mode') assert.doesNotMatch(panelSource, /Upload Entrypoint/, 'MCP custom server upload must not ask the user for an entrypoint') assert.match(panelSource, /uploadRepair/, 'MCP custom server upload must expose LLM repair controls') assert.match(panelSource, /repairSandboxId/, 'MCP custom server upload must let operators pick a sandbox LLM route for repair') assert.match(panelSource, /LLM repair/, 'MCP custom server upload must summarize LLM-assisted repair results') assert.match(panelSource, /FieldHint/, 'MCP server install wizard fields must include tooltips') assert.match(panelSource, /wizardStep/, 'MCP server install wizard must expose install workflow steps') assert.match(panelSource, /Back/, 'MCP server install wizard must expose back navigation') assert.match(panelSource, /Next/, 'MCP server install wizard must expose next navigation') assert.match(panelSource, /Cancel/, 'MCP server install wizard must expose cancel navigation') assert.match(panelSource, /resetWizardWorkflow/, 'MCP server install wizard must reset after success or cancel') assert.match(panelSource, /Start Preflight checks/, 'MCP server install wizard must expose a preflight-step action') assert.match(panelSource, /Install Server/, 'MCP server install wizard must expose an install-step action') assert.match(panelSource, /stageUploadServer/, 'MCP server install wizard must stage uploads before preflight') assert.match(panelSource, /startWizardPreflightChecks/, 'MCP server install wizard must run preflight separately from upload') assert.match(panelSource, /installStagedUpload/, 'MCP server install wizard must install only after review') assert.doesNotMatch(panelSource, /Upload and Preflight/, 'MCP server install wizard must not collapse upload and preflight into one action') assert.match(panelSource, /preflightServer/, 'MCP page must let operators preflight installed servers') assert.match(panelSource, /Preflight/, 'MCP page must show preflight controls and results') assert.match(panelSource, /serverPayloadFromJson/, 'MCP page must parse edited server JSON') assert.match(panelSource, /startEditingServer/, 'MCP installed server list must expose edit state') assert.match(panelSource, /Server JSON/, 'MCP installed server editor must render an inline JSON file editor') assert.match(panelSource, /MCP Repo Search and Preconfigured Servers/, 'MCP page must combine repo search and preconfigured servers') assert.match(panelSource, /Available Registries/, 'MCP page must display available registries') assert.match(panelSource, /Add an MCP Registry/, 'MCP page must show an add-registry empty state') assert.match(panelSource, /Draft With LLM/, 'MCP page must let the running LLM draft registry fields') assert.match(panelSource, /Delete Selected Registry/, 'MCP page must allow deleting registries') assert.match(panelSource, /selectedRegistryId/, 'MCP page must track and highlight the selected registry') assert.match(panelSource, /\/api\/mcp\/registry/, 'MCP page must query the registry search API') assert.match(panelSource, /\/api\/mcp\/registries/, 'MCP page must manage registry sources through the registry API') assert.match(panelSource, /const REGISTRY_PAGE_SIZE = 4/, 'MCP registry search should page results four at a time') assert.match(panelSource, /setRegistryResults\(\[\]\)/, 'MCP registry search should clear stale results before a new search') assert.match(panelSource, /pagedRegistryResults/, 'MCP registry search should render paged results instead of the full result set') assert.match(panelSource, /Preconfigured Servers/, 'MCP page should label catalog presets as preconfigured servers') assert.match(panelSource, /aria-expanded=\{catalogOpen\}/, 'MCP preconfigured servers should render as an accordion') assert.match(panelSource, /aria-expanded=\{customOpen\}/, 'MCP custom server form should render as an accordion') assert.match(panelSource, /MCP Security/, 'MCP page must expose sandbox access controls') assert.match(panelSource, /openSecurityServers/, 'MCP security must render installed servers as sub accordions') assert.match(panelSource, /aria-expanded=\{securityOpen\}/, 'MCP security must render as an accordion') assert.match(panelSource, /Allow All/, 'MCP security must support allow-all access') assert.match(panelSource, /Allow Only/, 'MCP security must support allow-list access') assert.doesNotMatch(panelSource, /syncSandboxBrokerConfig/, 'MCP configuration grants should rely on server-side sandbox sync instead of duplicate client sync') assert.match(panelSource, /syncAccessModeChange/, 'MCP availability changes must update broker policy through the MCP API') assert.match(panelSource, /Setup Guide/, 'MCP catalog cards should link out to app setup guides') assert.match(panelSource, /Client JSON/, 'MCP page must surface generated client JSON') assert.match(helpSource, /MCP Server Health/, 'Help must expose MCP server health checks') assert.match(helpSource, /\/api\/mcp\/health/, 'Help MCP health check must call the health API') assert.match(helpSource, /Refresh MCP Health/, 'Help MCP health check must be refreshable') assert.match(sandboxListSource, /Allowed MCP Server Access/, 'Sandbox page must expose allowed MCP server access accordion') assert.match(sandboxListSource, /Issue Broker Config/, 'Sandbox MCP access controls must keep a manual broker config repair action') assert.match(sandboxListSource, /syncMcpManifest/, 'Sandbox MCP access controls must expose manual broker config sync') assert.match(sandboxListSource, /\/sandbox\/openshell_control_mcp\.md/, 'Sandbox MCP access controls must name the manifest path') assert.match(sandboxListSource, /sandboxCanAccessMcpServer/, 'Sandbox page must derive MCP access per sandbox') assert.match(sandboxListSource, /MCP access allowed/, 'Sandbox cards must show a lit MCP access indicator') assert.match(sandboxListSource, /Revoke/, 'Sandbox MCP access controls must include revoke') assert.match(sidebarSource, /onMcpClick/, 'Sidebar must include MCP navigation callback') assert.match(sidebarSource, /activeView === 'mcp'/, 'Sidebar must mark MCP view active') assert.match(pageSource, /McpConfigurationPanel/, 'Dashboard must render MCP configuration panel') assert.match(pageSource, /setActiveView\('mcp'\)/, 'Dashboard must switch to MCP view') console.log('mcp-configuration-page-check: PASS MCP dashboard assertions')