feat(protocol): define strict first-slice wire contracts

This commit is contained in:
2026-09-05 02:06:46 +08:00
parent a173d410e0
commit 0a7951ba32
11 changed files with 851 additions and 0 deletions
@@ -0,0 +1,31 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import {
FIRST_SLICE_RPC_ROUTE,
routeForFirstSlice,
} from '../../YouleNexus/assets/framework/protocol/first-slice-routes.ts';
test('FIRST_SLICE_RPC_ROUTE 是第一纵向切片唯一且精确的 rpc route 表', () => {
assert.deepEqual(FIRST_SLICE_RPC_ROUTE, {
player_login: 'agent',
self_join_room: 'agent',
player_prepare: 'room',
self_exit_room: 'room',
other_join_room: 'room',
other_exit_room: 'room',
other_offline: 'room',
other_online: 'room',
connect_roomserver: 'room',
connect_agentserver: 'agent',
kick_server: 'agent',
});
});
test('routeForFirstSlice 从单源映射取 route,未知 rpc 显式失败', () => {
assert.equal(routeForFirstSlice('self_join_room'), 'agent');
assert.equal(routeForFirstSlice('connect_roomserver'), 'room');
assert.throws(
() => routeForFirstSlice('unknown_rpc' as never),
/unknown_rpc/,
);
});