hololake-system-architecture/product-source/hololake-native-desktop/scripts/direct-local-broker-numbered.test.mjs

25 lines
1.4 KiB
JavaScript
Raw Normal View History

import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
const registry = JSON.parse(readFileSync(new URL('../contracts/direct-local-broker-numbered-registry.json', import.meta.url), 'utf8'))
const broker = readFileSync(new URL('../src-tauri/src/direct_local_broker.rs', import.meta.url), 'utf8')
test('the external local broker accepts only complete numbered coordinates', () => {
assert.equal(registry.record_id, 'HLP-NBROKER-ROOT-001')
assert.equal(registry.runtime.protocol_version, 'HLP-NBROKER-v1')
assert.equal(registry.runtime.legacy_string_operation_allowed, false)
assert.equal(registry.runtime.unknown_or_mismatched_coordinate, 'FAIL_CLOSED')
assert.equal(registry.runtime.transport_is_authority, false)
assert.equal(registry.operations.length, 25)
assert.equal(new Set(registry.operations.map((route) => route.operation_number)).size, 25)
assert.equal(new Set(registry.operations.map((route) => route.alias)).size, 25)
for (const route of registry.operations) {
assert.match(route.operation_number, /^HLP-NBROKER-OP-\d{4}$/)
assert.match(route.channel_number, /^HLP-NBROKER-CH-\d{4}$/)
assert.match(route.module_number, /^HLP-NBROKER-MOD-\d{4}$/)
assert.match(route.target_number, /^HLP-NBROKER-TGT-\d{4}$/)
}
assert.match(broker, /decode_numbered_broker_request/)
assert.match(broker, /HOLOLAKE_NUMBERED_BROKER_ROUTE_COORDINATE_MISMATCH/)
})