fix: skip deleted reserved turn queues during flush

This commit is contained in:
2026-08-05 01:21:16 +00:00
parent a65d630d6f
commit 6eba8e24c3
3 changed files with 75 additions and 3 deletions
@@ -0,0 +1,29 @@
import { describe, expect, it } from 'vitest';
import { excludeDeletedReservedTurnQueues } from '../src/turn/databaseHooks.js';
describe('excludeDeletedReservedTurnQueues', () => {
it('omits dirty, initialization, and leased queues owned by deleted entities', () => {
expect(
excludeDeletedReservedTurnQueues(
{
generalIds: [1, 2],
generalInitializationIds: [2, 3],
generalLeaseIds: [1, 2, 3],
nationKeys: ['10:12', '20:11'],
nationInitializationKeys: ['20:9', '30:12'],
nationLeaseKeys: ['10:12', '20:11', '30:12'],
},
[2],
[20]
)
).toEqual({
generalIds: [1],
generalInitializationIds: [3],
generalLeaseIds: [1, 3],
nationKeys: ['10:12'],
nationInitializationKeys: ['30:12'],
nationLeaseKeys: ['10:12', '30:12'],
});
});
});
@@ -524,6 +524,12 @@ integration('RaiseInvader database persistence', () => {
).toBe(30);
}
await reservedTurns.prepareTurnsForExecution(firstCreatedGeneralId, {
nationId: createdNationId,
officerLevel: 12,
});
reservedTurns.shiftGeneralTurns(firstCreatedGeneralId, -1);
reservedTurns.shiftNationTurns(createdNationId, 12, -1);
for (const generalId of createdGeneralIds) {
expect(world.removeGeneral(generalId)).toBe(true);
}
@@ -539,6 +545,20 @@ integration('RaiseInvader database persistence', () => {
});
expect(await db.event.findUnique({ where: { id: createdEventIds[1]! } })).toBeNull();
expect(await db.generalTurnRevision.findUnique({ where: { generalId: firstCreatedGeneralId } })).toBeNull();
expect(
await db.nationTurnRevision.findUnique({
where: {
nationId_officerLevel: { nationId: createdNationId, officerLevel: 12 },
},
})
).toBeNull();
expect(reservedTurns.inspectState()).toMatchObject({
dirtyGeneralIds: [],
dirtyNationKeys: [],
leasedGeneralIds: [],
leasedNationKeys: [],
});
expect(await db.worldState.findUniqueOrThrow({ where: { id: stateRow.id } })).toMatchObject({
meta: expect.objectContaining({ isunited: 3, isUnited: 3, refreshLimit: 300 }),
});