fix(platform): isolate game host leases

This commit is contained in:
2026-09-05 07:48:23 +08:00
parent 30547f6a54
commit 471e2e9479
5 changed files with 237 additions and 33 deletions
@@ -29,10 +29,13 @@ function fixture(name: string): { data: Record<string, unknown> } {
return JSON.parse(readFileSync(new URL(`../fixtures/contracts/${name}`, import.meta.url), 'utf8'));
}
function makeStore(location: 'outside' | 'inside', stage = 0): PlatformStore {
function makeStore(location: 'outside' | 'inside', stage = 0, infinite = 0): PlatformStore {
const store = new PlatformStore();
const source = fixture(location === 'inside' ? 'player-login-room.json' : 'player-login-success.json');
if (location === 'inside') source.data.isbattle = stage;
if (location === 'inside') {
source.data.isbattle = stage;
source.data.infinite = infinite;
}
store.applyLoginSuccess(parseLoginResponse(source.data));
return store;
}
@@ -127,6 +130,24 @@ test('joinRoom uses authenticated Store identity and requires every non-optional
assert.equal(sent.length, 1);
});
test('exitRoom sends self_exit_room while an infinite room is in battle', () => {
const { commands, sent } = makeCommands(makeStore('inside', 1, 1));
commands.exitRoom();
assert.deepEqual(sent, [{
app: 'youle',
route: 'room',
rpc: 'self_exit_room',
data: {
agentid: 'agent-from-config',
playerid: 430511,
gameid: 'game-from-config',
roomcode: '100001',
},
}]);
});
test('command preconditions reject missing authentication, wrong room location, and battle exit without sending', () => {
const unauthenticated = makeCommands(new PlatformStore());
assert.throws(