import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import test from 'node:test' const read = (path) => readFileSync(new URL(`../${path}`, import.meta.url), 'utf8') test('external programming AI gateway is human-gated and fails closed', () => { const contract = JSON.parse(read('contracts/external-ai-gateway.json')) assert.equal(contract.default_exposure, 'CLOSED') assert.equal(contract.human_authorization_required, true) assert.equal(contract.mcp.role, 'DISCOVERY_AND_CAPABILITY_CATALOG') assert.equal(contract.direct_protocol.protocol, 'HOLOLAKE_TERMINAL_LINK/3') assert.equal(contract.direct_protocol.continuity_owner, 'HOLOLAKE') assert.equal(contract.boundaries.supervised_shell_execution, false) assert.equal(contract.boundaries.transport_is_authority, false) }) test('native binary exposes MCP stdio and numbered gateway controls', () => { const main = read('src-tauri/src/main.rs') const library = read('src-tauri/src/lib.rs') const gateway = read('src-tauri/src/external_ai_gateway.rs') const dispatcher = read('src-tauri/src/numbered_ipc_dispatch.rs') const frontendIpc = read('src/modules/numbered-ipc.ts') assert.match(main, /--mcp/) assert.match(library, /external_ai_gateway::run_mcp/) assert.match(gateway, /initialize/) assert.match(gateway, /tools\/list/) assert.match(gateway, /tools\/call/) assert.match(gateway, /hololake_discover/) assert.match(gateway, /hololake_connection_status/) assert.match(gateway, /hololake_registered_capabilities/) assert.match(gateway, /HOLOLAKE_MCP_EXPOSURE_CLOSED/) assert.match(gateway, /HOLOLAKE_MCP_TOOL_ARGUMENTS_NOT_EMPTY/) assert.match(dispatcher, /external_ai_gateway::get_gateway_status/) assert.match(dispatcher, /external_ai_gateway::set_gateway_exposure/) const statusRoute = dispatcher.match(/"external_ai_gateway::get_gateway_status"[\s\S]*?"external_ai_gateway::set_gateway_exposure"/)?.[0] assert.ok(statusRoute, 'gateway status route must remain discoverable') assert.match(statusRoute, /verified_user_route/) assert.match(statusRoute, /HOLOLAKE_GATEWAY_VERIFIED_HUMAN_REQUIRED/) assert.match(frontendIpc, /get_external_ai_gateway_status/) assert.match(frontendIpc, /set_external_ai_gateway_exposure/) }) test('human authorization screen renders real gateway and capability state', () => { const source = read('src/modules/human-authorization-center.tsx') assert.match(source, /允许本机编程 AI 发现 HoloLake/) assert.match(source, /已注册技能/) assert.match(source, /已接通集成/) assert.match(source, /MCP 标准入口/) assert.match(source, /HoloLake 本地直连协议/) })