merge: 최신 main 변경을 계략 명령 브랜치에 통합
# Conflicts: # app/game-api/test/commandTable.test.ts # app/game-frontend/e2e/commandArguments.spec.ts
This commit is contained in:
@@ -18,8 +18,10 @@ const GENERAL_AI_ACTIONS = [
|
||||
|
||||
const NATION_AI_ACTIONS = ['che_몰수', 'che_발령', 'che_선전포고', 'che_천도', 'che_포상'] as const;
|
||||
const GENERAL_REF_EDITOR_ACTIONS = [
|
||||
'che_은퇴',
|
||||
'che_임관',
|
||||
'che_랜덤임관',
|
||||
'che_강행',
|
||||
'che_징병',
|
||||
'che_출병',
|
||||
'che_농지개간',
|
||||
@@ -28,6 +30,7 @@ const GENERAL_REF_EDITOR_ACTIONS = [
|
||||
'che_파괴',
|
||||
'che_화계',
|
||||
'che_증여',
|
||||
'che_하야',
|
||||
'che_장비매매',
|
||||
] as const;
|
||||
const GENERAL_REF_STRATEGY_ACTIONS = ['che_선동', 'che_탈취', 'che_파괴', 'che_화계'] as const;
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
||||
import { createGamePostgresConnector, type GamePrismaClient } from '@sammo-ts/infra';
|
||||
|
||||
import { createDatabaseTurnHooks } from '../src/turn/databaseHooks.js';
|
||||
import { InMemoryTurnWorld } from '../src/turn/inMemoryWorld.js';
|
||||
import type { TurnWorldSnapshot, TurnWorldState } from '../src/turn/types.js';
|
||||
|
||||
const databaseUrl = process.env.INPUT_EVENT_DATABASE_URL;
|
||||
const integration = describe.skipIf(!databaseUrl);
|
||||
const generalId = 991_815;
|
||||
const scenarioCode = 'general-access-score-reset-persistence';
|
||||
|
||||
integration('general access score reset persistence', () => {
|
||||
let db: GamePrismaClient;
|
||||
let closeDb: (() => Promise<void>) | undefined;
|
||||
|
||||
const cleanup = async () => {
|
||||
await db.generalAccessLog.deleteMany({ where: { generalId } });
|
||||
await db.general.deleteMany({ where: { id: generalId } });
|
||||
await db.worldState.deleteMany({ where: { scenarioCode } });
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
const connector = createGamePostgresConnector({ url: databaseUrl! });
|
||||
await connector.connect();
|
||||
db = connector.prisma;
|
||||
closeDb = () => connector.disconnect();
|
||||
await cleanup();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await cleanup();
|
||||
await closeDb?.();
|
||||
});
|
||||
|
||||
it('commits the own-turn reset marker in the same world flush', async () => {
|
||||
const turnTime = new Date('2026-08-15T00:10:00.000Z');
|
||||
await db.general.create({
|
||||
data: {
|
||||
id: generalId,
|
||||
userId: 'access-reset-persistence-user',
|
||||
name: '접속점수초기화장수',
|
||||
turnTime,
|
||||
},
|
||||
});
|
||||
await db.generalAccessLog.create({
|
||||
data: {
|
||||
generalId,
|
||||
userId: 'access-reset-persistence-user',
|
||||
lastRefresh: new Date('2026-08-15T00:09:59.000Z'),
|
||||
refresh: 120,
|
||||
refreshTotal: 500,
|
||||
refreshScore: 351,
|
||||
refreshScoreTotal: 999,
|
||||
},
|
||||
});
|
||||
const row = await db.worldState.create({
|
||||
data: {
|
||||
scenarioCode,
|
||||
currentYear: 200,
|
||||
currentMonth: 1,
|
||||
tickSeconds: 600,
|
||||
config: {},
|
||||
meta: {},
|
||||
},
|
||||
});
|
||||
const state: TurnWorldState = {
|
||||
id: row.id,
|
||||
currentYear: 200,
|
||||
currentMonth: 1,
|
||||
tickSeconds: 600,
|
||||
lastTurnTime: new Date('2026-08-15T00:00:00.000Z'),
|
||||
meta: {},
|
||||
};
|
||||
const scenarioConfig: TurnWorldSnapshot['scenarioConfig'] = {
|
||||
stat: { total: 300, min: 10, max: 100, npcTotal: 150, npcMax: 75, npcMin: 10, chiefMin: 70 },
|
||||
iconPath: '.',
|
||||
map: {},
|
||||
const: {},
|
||||
environment: { mapName: 'test', unitSet: 'default' },
|
||||
};
|
||||
const world = new InMemoryTurnWorld(
|
||||
state,
|
||||
{
|
||||
scenarioConfig,
|
||||
map: { id: 'test', name: 'test', cities: [] },
|
||||
generals: [],
|
||||
cities: [],
|
||||
nations: [],
|
||||
troops: [],
|
||||
diplomacy: [],
|
||||
events: [],
|
||||
initialEvents: [],
|
||||
},
|
||||
{ schedule: { entries: [{ startMinute: 0, tickMinutes: 10 }] } }
|
||||
);
|
||||
world.markGeneralAccessScoreReset(generalId);
|
||||
const hooks = await createDatabaseTurnHooks(databaseUrl!, world);
|
||||
|
||||
try {
|
||||
await hooks.hooks.flushChanges?.({
|
||||
lastTurnTime: state.lastTurnTime.toISOString(),
|
||||
processedGenerals: 1,
|
||||
processedTurns: 1,
|
||||
durationMs: 0,
|
||||
partial: false,
|
||||
});
|
||||
|
||||
expect(await db.generalAccessLog.findUniqueOrThrow({ where: { generalId } })).toMatchObject({
|
||||
refresh: 120,
|
||||
refreshTotal: 500,
|
||||
refreshScore: 0,
|
||||
refreshScoreTotal: 999,
|
||||
});
|
||||
expect(world.peekDirtyState().accessScoreResetGeneralIds).toEqual([]);
|
||||
} finally {
|
||||
await hooks.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
buildJoinCreateGeneralSeed,
|
||||
cutJoinTurnTime,
|
||||
JOIN_WELCOME_MESSAGE,
|
||||
resolveJoinTurnTime,
|
||||
} from '../src/turn/joinCreateGeneralService.js';
|
||||
|
||||
describe('generic join legacy time contracts', () => {
|
||||
@@ -19,6 +20,35 @@ describe('generic join legacy time contracts', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('schedules a new general within one turn of the accepted game time even when the daemon cursor is stale', () => {
|
||||
const calls: Array<[number, number]> = [];
|
||||
const values = [59, 250_000];
|
||||
const rng = {
|
||||
nextRangeInt(min: number, max: number) {
|
||||
calls.push([min, max]);
|
||||
return values.shift() ?? min;
|
||||
},
|
||||
};
|
||||
const acceptedAt = new Date('2026-08-15T17:57:05.837Z');
|
||||
const staleRuntimeTurnTime = new Date('2026-08-15T07:10:00.000Z');
|
||||
|
||||
const turnTime = resolveJoinTurnTime(
|
||||
rng,
|
||||
{ tickSeconds: 120 } as Parameters<typeof resolveJoinTurnTime>[1],
|
||||
acceptedAt,
|
||||
staleRuntimeTurnTime,
|
||||
undefined
|
||||
);
|
||||
|
||||
expect(turnTime.toISOString()).toBe('2026-08-15T17:58:05.087Z');
|
||||
expect(turnTime.getTime()).toBeGreaterThan(acceptedAt.getTime());
|
||||
expect(turnTime.getTime()).toBeLessThanOrEqual(acceptedAt.getTime() + 120_000);
|
||||
expect(calls).toEqual([
|
||||
[0, 119],
|
||||
[0, 999_999],
|
||||
]);
|
||||
});
|
||||
|
||||
it('uses the HiDCHe product name without the legacy PHP runtime label', () => {
|
||||
expect(JOIN_WELCOME_MESSAGE).toBe('삼국지 모의전투 HiDCHe의 세계에 오신 것을 환영합니다 ^o^');
|
||||
expect(JOIN_WELCOME_MESSAGE).not.toContain('PHP');
|
||||
|
||||
@@ -174,6 +174,8 @@ describe('InMemoryTurnProcessor ordering', () => {
|
||||
const tiedGeneralResult = await processor.run(new Date(addMinutes(baseTime, 10).getTime() + 1), budget);
|
||||
expect(tiedGeneralResult.processedTurns).toBe(0);
|
||||
expect(executed).toEqual([3, 2]);
|
||||
expect(world.peekDirtyState().accessScoreResetGeneralIds).toEqual([2, 3]);
|
||||
expect(world.getState().meta).toMatchObject({ refreshLimit: 350 });
|
||||
expect(world.getGeneralById(2)?.recentWarTime?.getTime()).toBe(baseTime.getTime());
|
||||
expect(world.getGeneralById(2)?.recentWarTick).not.toBeNull();
|
||||
expect(Number(world.getGeneralById(2)?.turnTick) % 10).toBe(4);
|
||||
|
||||
Reference in New Issue
Block a user