fix(platform): serialize runtime session transitions

This commit is contained in:
2026-09-05 06:17:04 +08:00
parent 1c124cf216
commit 7e5a950cc7
13 changed files with 1297 additions and 157 deletions
@@ -9,6 +9,7 @@ import type {
} from '../../YouleNexus/assets/framework/sdk/contracts/index.ts';
import { GameSessionHost } from '../../YouleNexus/assets/framework/sdk/runtime/game-session-host.ts';
import { Router } from '../../YouleNexus/assets/framework/protocol/router.ts';
import { FIRST_SLICE_RPC_ROUTE } from '../../YouleNexus/assets/framework/protocol/first-slice-routes.ts';
class LoginGateFixture {
private pending = false;
@@ -110,6 +111,41 @@ test('Router lets kick_server through the login gate but ignores every other rpc
assert.deepEqual(calls, [kick]);
});
test('Router login gate enforces the complete route by rpc cross matrix', () => {
const platformRoutes = ['platform', 'agent', 'room'] as const;
const routes = [...platformRoutes, 'fixture-game'] as const;
const rpcs = [...Object.keys(FIRST_SLICE_RPC_ROUTE), 'unknown_rpc'];
for (const route of routes) {
for (const rpc of rpcs) {
const gate = new LoginGateFixture();
const platformCalls: InboundMessage[] = [];
const gameCalls: InboundMessage[] = [];
const router = new Router({
session: gate,
platform: {
dispatch(message: InboundMessage) {
platformCalls.push(message);
return 'handled-platform' as const;
},
},
gameSession: makeGameSession(gameCalls),
});
const message: InboundMessage = { route, rpc, data: { marker: `${route}:${rpc}` } };
gate.markLoginPending();
const passes = route === 'agent' && (rpc === 'player_login' || rpc === 'kick_server');
assert.equal(
router.dispatch(message),
passes ? 'handled-platform' : 'ignored-login-gate',
`${route}:${rpc}`,
);
assert.deepEqual(platformCalls, passes ? [message] : [], `${route}:${rpc}`);
assert.deepEqual(gameCalls, [], `${route}:${rpc}`);
}
}
});
test('Router sends all platform routes to PlatformHandlers exactly once', () => {
const gate = new LoginGateFixture();
const calls: InboundMessage[] = [];