merge: verify invader monthly actions at boundary

This commit is contained in:
2026-07-25 23:13:16 +00:00
2 changed files with 50 additions and 35 deletions
@@ -288,28 +288,37 @@ describe('invader monthly actions', () => {
generals: [buildGeneral(), buildGeneral({ id: 2, name: 'ⓞ도시2대왕', nationId: 2, cityId: 2 })], generals: [buildGeneral(), buildGeneral({ id: 2, name: 'ⓞ도시2대왕', nationId: 2, cityId: 2 })],
events: [autoDeleteEvent], events: [autoDeleteEvent],
}); });
harness.world.applyDiplomacyPatch({ const state = { ...harness.state, currentYear: 199, currentMonth: 12 };
let world: InMemoryTurnWorld | null = null;
const handler = createAutoDeleteInvaderHandler({
getWorld: () => world,
reservedTurns: harness.reservedTurns,
});
world = new InMemoryTurnWorld(state, harness.snapshot, {
schedule: { entries: [{ startMinute: 0, tickMinutes: 10 }] },
calendarHandler: createMonthlyEventHandler({
getWorld: () => world,
startYear: 190,
actions: new Map([['AutoDeleteInvader', handler]]),
}),
});
world.applyDiplomacyPatch({
srcNationId: 2, srcNationId: 2,
destNationId: 1, destNationId: 1,
patch: { state: 1, term: 24 }, patch: { state: 1, term: 24 },
}); });
const handler = createAutoDeleteInvaderHandler({
getWorld: () => harness.world,
reservedTurns: harness.reservedTurns,
});
const environment = { ...harness.environment, currentEventID: 8 };
await handler([2], environment, autoDeleteEvent); await world.advanceMonth(new Date('0200-01-01T00:00:00.000Z'));
expect(harness.world.listEvents().map((entry) => entry.id)).toContain(8); expect(world.listEvents().map((entry) => entry.id)).toContain(8);
harness.world.applyDiplomacyPatch({ world.applyDiplomacyPatch({
srcNationId: 2, srcNationId: 2,
destNationId: 1, destNationId: 1,
patch: { state: 2, term: 0 }, patch: { state: 2, term: 0 },
}); });
await handler([2], environment, autoDeleteEvent); await world.advanceMonth(new Date('0200-02-01T00:00:00.000Z'));
expect(harness.world.listEvents().map((entry) => entry.id)).not.toContain(8); expect(world.listEvents().map((entry) => entry.id)).not.toContain(8);
expect(harness.reservedTurns.getGeneralTurns(2)).toEqual( expect(harness.reservedTurns.getGeneralTurns(2)).toEqual(
Array.from({ length: 30 }, () => ({ action: 'che_방랑', args: {} })) Array.from({ length: 30 }, () => ({ action: 'che_방랑', args: {} }))
); );
@@ -330,14 +339,23 @@ describe('invader monthly actions', () => {
events: [endingEvent], events: [endingEvent],
meta: { isunited: 1, refreshLimit: 3 }, meta: { isunited: 1, refreshLimit: 3 },
}); });
const handler = createInvaderEndingHandler({ getWorld: () => harness.world }); const state = { ...harness.state, currentYear: 199, currentMonth: 12 };
const environment = { ...harness.environment, currentEventID: 9 }; let world: InMemoryTurnWorld | null = null;
const handler = createInvaderEndingHandler({ getWorld: () => world });
world = new InMemoryTurnWorld(state, harness.snapshot, {
schedule: { entries: [{ startMinute: 0, tickMinutes: 10 }] },
calendarHandler: createMonthlyEventHandler({
getWorld: () => world,
startYear: 190,
actions: new Map([['InvaderEnding', handler]]),
}),
});
await handler([], environment, endingEvent); await world.advanceMonth(new Date('0200-01-01T00:00:00.000Z'));
expect(harness.world.getState().meta).toMatchObject({ isunited: 3, refreshLimit: 300 }); expect(world.getState().meta).toMatchObject({ isunited: 3, refreshLimit: 300 });
expect(harness.world.listEvents()).toHaveLength(0); expect(world.listEvents()).toHaveLength(0);
expect(harness.world.peekDirtyState().logs.map((log) => log.text)).toEqual([ expect(world.peekDirtyState().logs.map((log) => log.text)).toEqual([
'<L><b>【이벤트】</b></>이민족을 모두 소탕했습니다!', '<L><b>【이벤트】</b></>이민족을 모두 소탕했습니다!',
'<L><b>【이벤트】</b></>중원은 당분간 태평성대를 누릴 것입니다.', '<L><b>【이벤트】</b></>중원은 당분간 태평성대를 누릴 것입니다.',
]); ]);
@@ -5,6 +5,7 @@ import type { City, Nation } from '@sammo-ts/logic';
import { createDatabaseTurnHooks } from '../src/turn/databaseHooks.js'; import { createDatabaseTurnHooks } from '../src/turn/databaseHooks.js';
import { InMemoryTurnWorld } from '../src/turn/inMemoryWorld.js'; import { InMemoryTurnWorld } from '../src/turn/inMemoryWorld.js';
import { createRaiseInvaderHandler } from '../src/turn/monthlyInvaderAction.js'; import { createRaiseInvaderHandler } from '../src/turn/monthlyInvaderAction.js';
import { createMonthlyEventHandler } from '../src/turn/monthlyEventHandler.js';
import { InMemoryReservedTurnStore } from '../src/turn/reservedTurnStore.js'; import { InMemoryReservedTurnStore } from '../src/turn/reservedTurnStore.js';
import { buildCommandEnv } from '../src/turn/reservedTurnCommands.js'; import { buildCommandEnv } from '../src/turn/reservedTurnCommands.js';
import type { TurnEvent, TurnGeneral, TurnWorldSnapshot, TurnWorldState } from '../src/turn/types.js'; import type { TurnEvent, TurnGeneral, TurnWorldSnapshot, TurnWorldState } from '../src/turn/types.js';
@@ -234,8 +235,8 @@ integration('RaiseInvader database persistence', () => {
const stateRow = await db.worldState.create({ const stateRow = await db.worldState.create({
data: { data: {
scenarioCode: 'monthly-invader-persistence', scenarioCode: 'monthly-invader-persistence',
currentYear: 200, currentYear: 199,
currentMonth: 1, currentMonth: 12,
tickSeconds: 600, tickSeconds: 600,
config: {}, config: {},
meta: { meta: {
@@ -248,8 +249,8 @@ integration('RaiseInvader database persistence', () => {
}); });
const state: TurnWorldState = { const state: TurnWorldState = {
id: stateRow.id, id: stateRow.id,
currentYear: 200, currentYear: 199,
currentMonth: 1, currentMonth: 12,
tickSeconds: 600, tickSeconds: 600,
lastTurnTime: new Date('0200-01-01T00:00:00.000Z'), lastTurnTime: new Date('0200-01-01T00:00:00.000Z'),
meta: { meta: {
@@ -276,30 +277,26 @@ integration('RaiseInvader database persistence', () => {
events: [sourceEvent], events: [sourceEvent],
initialEvents: [], initialEvents: [],
}; };
const world = new InMemoryTurnWorld(state, snapshot, {
schedule: { entries: [{ startMinute: 0, tickMinutes: 10 }] },
});
const reservedTurns = new InMemoryReservedTurnStore(db, { maxGeneralTurns: 30, maxNationTurns: 12 }); const reservedTurns = new InMemoryReservedTurnStore(db, { maxGeneralTurns: 30, maxNationTurns: 12 });
let world: InMemoryTurnWorld | null = null;
const handler = createRaiseInvaderHandler({ const handler = createRaiseInvaderHandler({
getWorld: () => world, getWorld: () => world,
reservedTurns, reservedTurns,
env: buildCommandEnv(snapshot.scenarioConfig), env: buildCommandEnv(snapshot.scenarioConfig),
loadArchivedNationMaxId: async () => 0, loadArchivedNationMaxId: async () => 0,
}); });
world = new InMemoryTurnWorld(state, snapshot, {
schedule: { entries: [{ startMinute: 0, tickMinutes: 10 }] },
calendarHandler: createMonthlyEventHandler({
getWorld: () => world,
startYear: 190,
actions: new Map([['RaiseInvader', handler]]),
}),
});
const dbHooks = await createDatabaseTurnHooks(databaseUrl!, world, { reservedTurns }); const dbHooks = await createDatabaseTurnHooks(databaseUrl!, world, { reservedTurns });
try { try {
await handler( await world.advanceMonth(new Date('0200-01-01T00:00:00.000Z'));
[10, 150, 100, 20],
{
year: 200,
month: 1,
startyear: 190,
currentEventID: sourceEventId,
turnTime: state.lastTurnTime,
},
sourceEvent
);
await dbHooks.hooks.flushChanges?.({ await dbHooks.hooks.flushChanges?.({
lastTurnTime: state.lastTurnTime.toISOString(), lastTurnTime: state.lastTurnTime.toISOString(),
processedGenerals: 0, processedGenerals: 0,