fix(bot): wire aiOpponent into joined and update server messages

This commit is contained in:
claude (blind_chess)
2026-04-28 14:22:41 -04:00
parent 73d5d0cb93
commit cb8e017792
2 changed files with 5 additions and 0 deletions
+2
View File
@@ -147,6 +147,7 @@ async function onHello(ctx: SocketCtx, msg: Extract<ClientMessage, { type: 'hell
mode: game.mode, mode: game.mode,
highlightingEnabled: game.highlightingEnabled, highlightingEnabled: game.highlightingEnabled,
opponentConnected: !!game.players[color === 'w' ? 'b' : 'w']?.socket, opponentConnected: !!game.players[color === 'w' ? 'b' : 'w']?.socket,
aiOpponent: game.aiOpponent,
}); });
// Notify peer that we're connected. // Notify peer that we're connected.
@@ -283,6 +284,7 @@ function sendUpdateTo(
drawOffer, drawOffer,
endReason: game.endReason, endReason: game.endReason,
winner: game.winner ?? null, winner: game.winner ?? null,
aiOpponent: game.aiOpponent,
}); });
} }
@@ -105,6 +105,9 @@ describe('AI game / Casual', () => {
human.send({ type: 'hello', gameId, token: creatorToken }); human.send({ type: 'hello', gameId, token: creatorToken });
const joined = await human.waitFor((m) => m.type === 'joined'); const joined = await human.waitFor((m) => m.type === 'joined');
expect(joined.type === 'joined' && joined.you).toBe('b'); expect(joined.type === 'joined' && joined.you).toBe('b');
if (joined.type === 'joined') {
expect(joined.aiOpponent).toEqual({ color: 'w', brain: 'casual' });
}
// Bot's opening move should arrive as an update (bot moves first as white). // Bot's opening move should arrive as an update (bot moves first as white).
const botMoved = await human.waitFor((m) => const botMoved = await human.waitFor((m) =>