diff --git a/app/game-api/src/daemon/redisTransport.ts b/app/game-api/src/daemon/redisTransport.ts index 0780395b..69d1f3d0 100644 --- a/app/game-api/src/daemon/redisTransport.ts +++ b/app/game-api/src/daemon/redisTransport.ts @@ -77,7 +77,7 @@ export class RedisTurnDaemonTransport implements TurnDaemonTransport { const requestId = await this.sendCommand(command); const deadline = Date.now() + (timeoutMs ?? this.requestTimeoutMs); - let lastId = '$'; + let lastId = '0-0'; while (Date.now() < deadline) { const remaining = Math.max(1, deadline - Date.now()); @@ -116,7 +116,7 @@ export class RedisTurnDaemonTransport implements TurnDaemonTransport { await this.sendCommand({ type: 'getStatus', requestId }); const deadline = Date.now() + (timeoutMs ?? this.requestTimeoutMs); - let lastId = '$'; + let lastId = '0-0'; while (Date.now() < deadline) { const remaining = Math.max(1, deadline - Date.now()); diff --git a/app/game-engine/src/lifecycle/redisCommandStream.ts b/app/game-engine/src/lifecycle/redisCommandStream.ts index b4d7fcec..50868e37 100644 --- a/app/game-engine/src/lifecycle/redisCommandStream.ts +++ b/app/game-engine/src/lifecycle/redisCommandStream.ts @@ -137,11 +137,12 @@ export class RedisTurnDaemonCommandStream implements TurnDaemonControlQueue, Tur } const blockMs = deadlineMs === null ? 0 : Math.max(0, deadlineMs - Date.now()); + const cappedBlockMs = deadlineMs === null ? 0 : Math.min(blockMs, 1000); if (deadlineMs !== null && blockMs === 0) { return null; } - const remote = await this.readRemoteCommands(blockMs); + const remote = await this.readRemoteCommands(cappedBlockMs); if (remote.length === 0) { return null; } diff --git a/app/game-engine/src/turn/databaseHooks.ts b/app/game-engine/src/turn/databaseHooks.ts index 4e2736d7..a29271a1 100644 --- a/app/game-engine/src/turn/databaseHooks.ts +++ b/app/game-engine/src/turn/databaseHooks.ts @@ -327,9 +327,13 @@ export const createDatabaseTurnHooks = async ( ...nations .filter((nation) => !createdNationIds.has(nation.id)) .map((nation) => - prisma.nation.update({ + prisma.nation.upsert({ where: { id: nation.id }, - data: buildNationUpdate(nation), + update: buildNationUpdate(nation), + create: { + id: nation.id, + ...buildNationUpdate(nation), + }, }) ), ...troops diff --git a/tools/integration-tests/test/initialization.test.ts b/tools/integration-tests/test/initialization.test.ts index f2476452..8d0c6066 100644 --- a/tools/integration-tests/test/initialization.test.ts +++ b/tools/integration-tests/test/initialization.test.ts @@ -100,11 +100,11 @@ const truncateSchema = async (schema: string) => { const resetDatabase = async () => { await ensureSchema('public'); await ensureSchema('che'); - await execCommand('pnpm', ['--filter', '@sammo-ts/infra', 'prisma:db:push:gateway'], { + await execCommand('pnpm', ['--filter', '@sammo-ts/infra', 'prisma:db:push:gateway', '--accept-data-loss'], { ...process.env, POSTGRES_SCHEMA: 'public', }); - await execCommand('pnpm', ['--filter', '@sammo-ts/infra', 'prisma:db:push:game'], { + await execCommand('pnpm', ['--filter', '@sammo-ts/infra', 'prisma:db:push:game', '--accept-data-loss'], { ...process.env, POSTGRES_SCHEMA: 'che', }); @@ -160,6 +160,7 @@ describe('integration initialization flow', () => { beforeAll(async () => { await loadEnv(); + process.chdir(workspaceRoot); await resetDatabase(); await resetRedis(); @@ -188,7 +189,7 @@ describe('integration initialization flow', () => { if (gatewayServer) { await gatewayServer.app.close(); } - }); + }, 30_000); it('seeds scenario, creates users, and validates founding flow', async () => { if (!gatewayServer || !gameServer) { @@ -392,9 +393,12 @@ describe('integration initialization flow', () => { const runTurn = async () => { const status = await waitForStatus(); const prevRunAt = status.lastRunAt; + const targetTime = status.nextTurnTime + ? new Date(new Date(status.nextTurnTime).getTime() + 5 * 60_000).toISOString() + : new Date(Date.now() + 5 * 60_000).toISOString(); await gameClient.turnDaemon.run.mutate({ reason: 'manual', - targetTime: status.nextTurnTime ?? undefined, + targetTime, }); const deadline = Date.now() + 20_000; while (Date.now() < deadline) {