hololake-system-architecture/product-source/hololake-native-desktop/scripts/mobile-sync-admission.test.mjs

43 lines
2.5 KiB
JavaScript

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')
const contract = JSON.parse(read('contracts/mobile-sync-v1.json'))
const registry = JSON.parse(read('contracts/numbered-ipc-registry.json'))
const modulePackage = JSON.parse(read('fixtures/module-packages/HLP-MOD-OFFICIAL-MOBILE-SYNC-0001-0.1.0.ghmod'))
const rust = read('src-tauri/src/mobile_sync.rs')
const frontend = read('src/modules/mobile-sync/index.tsx')
test('mobile sync is a signed opt-in bridge, not a second persona system', () => {
assert.equal(modulePackage.manifest.moduleNumber, 'HLP-MOD-OFFICIAL-MOBILE-SYNC-0001')
assert.equal(modulePackage.manifest.registrationClass, 'OFFICIAL_LIGHTHOUSE')
assert.equal(modulePackage.manifest.adapter, 'mobile-sync-v1')
assert.equal(modulePackage.manifest.permissions.length, 5)
assert.equal(modulePackage.payload.adapterConfig.desktopRole, 'USER_LOCAL_COMPUTER_TERMINAL_ROOT_NODE')
assert.equal(modulePackage.payload.adapterConfig.iosClientPackaging, 'PENDING_SEPARATE_ADMISSION')
assert.equal(contract.hard_boundaries.second_persona_system, false)
assert.equal(contract.hard_boundaries.desktop_offline_execution, false)
})
test('all desktop controls cross one numbered route family', () => {
const routes = registry.operations.filter((route) => route.module_number === 'HLP-NIPC-MOD-0030')
assert.deepEqual(routes.map((route) => route.operation_number), Array.from({ length: 6 }, (_, index) => `HLP-NIPC-OP-${String(index + 141).padStart(4, '0')}`))
assert.ok(routes.every((route) => route.target_number === 'HLP-NIPC-TGT-0030'))
assert.ok(routes.every((route) => route.admission === 'VERIFIED_HUMAN_ROUTE'))
assert.doesNotMatch(frontend, /from ['"]@tauri-apps\/api\/core['"]/)
assert.doesNotMatch(rust, /#\[tauri::command\]/)
assert.match(rust, /require_active_module_adapter/)
})
test('transport is bounded, encrypted, replay guarded and explicitly controlled', () => {
assert.match(rust, /MAX_REQUEST_BYTES: usize = 256 \* 1024/)
assert.match(rust, /MAX_ACTIVE_CONNECTIONS: usize = 16/)
assert.match(rust, /CHACHA20_POLY1305/)
assert.match(rust, /input\.counter <= last_counter/)
assert.match(rust, /DUPLICATE_HEADER_REJECTED/)
assert.match(rust, /pub\(crate\) fn stop_for_unmount/)
assert.doesNotMatch(frontend, /setInterval/)
assert.match(frontend, /开启 iPhone 同步/)
assert.match(frontend, /关闭本机同步入口/)
})