merge: 최신 main을 유산 경매 종류 정렬에 반영

This commit is contained in:
2026-08-20 16:17:47 +00:00
11 changed files with 206 additions and 12 deletions
+41 -1
View File
@@ -135,7 +135,16 @@ describe('buildTurnCommandTable', () => {
'che_정착장려', 'che_정착장려',
'che_주민선정', 'che_주민선정',
], ],
: ['che_징병', 'che_모병', 'che_훈련', 'che_사기진작', 'che_출병', 'che_집합', 'che_소집해제'], : [
'che_징병',
'che_모병',
'che_훈련',
'che_사기진작',
'che_출병',
'che_집합',
'che_소집해제',
'che_첩보',
],
: ['che_이동', 'che_강행', 'che_인재탐색', 'che_귀환', 'che_임관', 'che_랜덤임관'], : ['che_이동', 'che_강행', 'che_인재탐색', 'che_귀환', 'che_임관', 'che_랜덤임관'],
: ['che_선동', 'che_탈취', 'che_파괴', 'che_화계'], : ['che_선동', 'che_탈취', 'che_파괴', 'che_화계'],
: ['che_증여', 'che_헌납', 'che_물자조달', 'che_하야', 'che_거병', 'che_건국', 'che_선양', 'che_해산'], : ['che_증여', 'che_헌납', 'che_물자조달', 'che_하야', 'che_거병', 'che_건국', 'che_선양', 'che_해산'],
@@ -221,6 +230,37 @@ describe('buildTurnCommandTable', () => {
}); });
}); });
it('exposes the user-only spy command with a city target when the actor can pay the Ref cost', async () => {
const general = { ...buildGeneral(), gold: 300, rice: 300 } as GeneralRow;
const table = await buildTurnCommandTable({
worldState: buildWorldState(),
general,
city: buildCity(),
nation: buildNation(),
nationGenerals: null,
});
const spy = table.general
.find(({ category }) => category === '군사')
?.values.find(({ key }) => key === 'che_첩보');
expect(spy).toMatchObject({
name: '첩보',
reqArg: true,
possible: true,
status: 'available',
inputFields: [
{
key: 'destCityId',
label: '대상 도시',
kind: 'select',
required: true,
optionSource: 'cities',
},
],
});
});
it('uses min-condition constraints for availability', async () => { it('uses min-condition constraints for availability', async () => {
const table = await buildTurnCommandTable({ const table = await buildTurnCommandTable({
worldState: buildWorldState(), worldState: buildWorldState(),
+11 -2
View File
@@ -814,7 +814,11 @@ export class InMemoryTurnWorld {
}; };
} }
pushLog(entry: LogEntryDraft): void { pushLog(entry: LogEntryDraft, occurredAt?: Date): void {
if (occurredAt && !entry.occurredAt) {
this.logs.push({ ...entry, occurredAt: new Date(occurredAt.getTime()) });
return;
}
this.logs.push(entry); this.logs.push(entry);
} }
@@ -1382,7 +1386,12 @@ export class InMemoryTurnWorld {
this.dirtyNationIds.add(result.nation.id); this.dirtyNationIds.add(result.nation.id);
} }
if (result.logs && result.logs.length > 0) { if (result.logs && result.logs.length > 0) {
this.logs.push(...result.logs); // Ref command logs use the executing general's pre-advance turntime.
// Preserve that per-entry occurrence time instead of replacing every
// log in the transaction with the shared completion cursor at flush.
for (const log of result.logs) {
this.pushLog(log, currentGeneral.turnTime);
}
} }
if (result.messages && result.messages.length > 0) { if (result.messages && result.messages.length > 0) {
this.messages.push(...result.messages); this.messages.push(...result.messages);
@@ -2245,10 +2245,13 @@ export const createImmediateGeneralActionExecutor = async (options: {
definition.formatConstraintFailure?.(reason, constraintCtx, args, view) ?? definition.formatConstraintFailure?.(reason, constraintCtx, args, view) ??
`${reason} ${definition.name} 실패.`; `${reason} ${definition.name} 실패.`;
if (input.actionKey === 'che_접경귀환' || input.actionKey === 'che_등용수락') { if (input.actionKey === 'che_접경귀환' || input.actionKey === 'che_등용수락') {
options.world.pushLog({ options.world.pushLog(
...createActionLog(failureText), {
generalId: general.id, ...createActionLog(failureText),
}); generalId: general.id,
},
general.turnTime
);
} }
return { ok: false, reason: failureText }; return { ok: false, reason: failureText };
} }
@@ -2325,7 +2328,7 @@ export const createImmediateGeneralActionExecutor = async (options: {
if (input.actionKey === 'che_접경귀환' && (resolution.general as TurnGeneral).cityId === general.cityId) { if (input.actionKey === 'che_접경귀환' && (resolution.general as TurnGeneral).cityId === general.cityId) {
for (const log of resolution.logs) { for (const log of resolution.logs) {
options.world.pushLog(log); options.world.pushLog(log, general.turnTime);
} }
return { ok: false, reason: '가까운 아국 도시가 없습니다.' }; return { ok: false, reason: '가까운 아국 도시가 없습니다.' };
} }
@@ -2409,7 +2412,7 @@ export const createImmediateGeneralActionExecutor = async (options: {
options.world.removeTroop(troopId); options.world.removeTroop(troopId);
} }
for (const log of [...resolution.logs, ...progressionLogs]) { for (const log of [...resolution.logs, ...progressionLogs]) {
options.world.pushLog(log); options.world.pushLog(log, general.turnTime);
} }
options.world.updateGeneral(input.generalId, nextGeneral); options.world.updateGeneral(input.generalId, nextGeneral);
return { ok: true }; return { ok: true };
@@ -1,5 +1,6 @@
import { afterAll, beforeAll, describe, expect, it } from 'vitest'; import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { createGamePostgresConnector, type GamePrismaClient } from '@sammo-ts/infra'; import { createGamePostgresConnector, type GamePrismaClient } from '@sammo-ts/infra';
import { LogCategory, LogScope } 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';
@@ -15,6 +16,7 @@ integration('general access score reset persistence', () => {
let closeDb: (() => Promise<void>) | undefined; let closeDb: (() => Promise<void>) | undefined;
const cleanup = async () => { const cleanup = async () => {
await db.logEntry.deleteMany({ where: { generalId } });
await db.generalAccessLog.deleteMany({ where: { generalId } }); await db.generalAccessLog.deleteMany({ where: { generalId } });
await db.general.deleteMany({ where: { id: generalId } }); await db.general.deleteMany({ where: { id: generalId } });
await db.worldState.deleteMany({ where: { scenarioCode } }); await db.worldState.deleteMany({ where: { scenarioCode } });
@@ -33,8 +35,9 @@ integration('general access score reset persistence', () => {
await closeDb?.(); await closeDb?.();
}); });
it('commits the own-turn reset marker in the same world flush', async () => { it('commits the own-turn reset marker and per-entry log occurrence time in the same world flush', async () => {
const turnTime = new Date('2026-08-15T00:10:00.000Z'); const turnTime = new Date('2026-08-15T00:10:00.000Z');
const occurredAt = new Date('2026-08-15T00:07:43.000Z');
await db.general.create({ await db.general.create({
data: { data: {
id: generalId, id: generalId,
@@ -95,6 +98,13 @@ integration('general access score reset persistence', () => {
{ schedule: { entries: [{ startMinute: 0, tickMinutes: 10 }] } } { schedule: { entries: [{ startMinute: 0, tickMinutes: 10 }] } }
); );
world.markGeneralAccessScoreReset(generalId); world.markGeneralAccessScoreReset(generalId);
world.pushLog({
scope: LogScope.GENERAL,
category: LogCategory.ACTION,
text: '<C>●</>1월:아무것도 실행하지 않았습니다.',
generalId,
occurredAt,
});
const hooks = await createDatabaseTurnHooks(databaseUrl!, world); const hooks = await createDatabaseTurnHooks(databaseUrl!, world);
try { try {
@@ -113,6 +123,12 @@ integration('general access score reset persistence', () => {
refreshScoreTotal: 999, refreshScoreTotal: 999,
}); });
expect(world.peekDirtyState().accessScoreResetGeneralIds).toEqual([]); expect(world.peekDirtyState().accessScoreResetGeneralIds).toEqual([]);
expect(
await db.logEntry.findFirstOrThrow({
where: { generalId, category: LogCategory.ACTION },
select: { createdAt: true },
})
).toEqual({ createdAt: occurredAt });
} finally { } finally {
await hooks.close(); await hooks.close();
} }
@@ -159,6 +159,25 @@ const makeState = (meta: Record<string, unknown> = {}): TurnWorldState => ({
}); });
describe('legacy general turn lifecycle', () => { describe('legacy general turn lifecycle', () => {
it('timestamps action logs with the executing general turn instead of the shared flush cursor', async () => {
const flushCursor = new Date('0200-01-01T00:35:00.000Z');
const generalTurnTime = new Date('0200-01-01T00:37:43.000Z');
const harness = await createTurnTestHarness({
snapshot: makeSnapshot([makeGeneral({ turnTime: generalTurnTime })]),
state: { ...makeState(), lastTurnTime: flushCursor },
schedule,
map,
});
harness.reservedTurnStore.getGeneralTurns(1)[0] = { action: '휴식', args: {} };
await harness.runOneTick();
const actionLog = harness.world
.peekDirtyState()
.logs.find((log) => log.text.includes('아무것도 실행하지 않았습니다.'));
expect(actionLog?.occurredAt).toEqual(generalTurnTime);
});
it('emits legacy plain logs when command gains cross experience and dedication levels', async () => { it('emits legacy plain logs when command gains cross experience and dedication levels', async () => {
const harness = await createTurnTestHarness({ const harness = await createTurnTestHarness({
snapshot: makeSnapshot([ snapshot: makeSnapshot([
@@ -224,4 +224,31 @@ describe('레거시 사령부 턴 실행 호환성', () => {
}, },
]); ]);
}); });
it('첩보 도시는 실행 월부터 세 달 보이고 각 월 시작에 감소한 뒤 만료된다', async () => {
const nation = {
id: 1,
meta: {
rate: 20,
spy: { 2: 3 },
},
};
const handler = createNationTurnMonthlyHandler({
getWorld: () =>
({
listNations: () => [nation],
updateNation: (_id: number, patch: { meta?: typeof nation.meta }) => {
if (patch.meta) nation.meta = patch.meta;
},
}) as never,
});
expect(nation.meta.spy).toEqual({ 2: 3 });
await handler.beforeMonthChanged?.({} as never);
expect(nation.meta.spy).toEqual({ 2: 2 });
await handler.beforeMonthChanged?.({} as never);
expect(nation.meta.spy).toEqual({ 2: 1 });
await handler.beforeMonthChanged?.({} as never);
expect(nation.meta.spy).toEqual({});
});
}); });
@@ -416,6 +416,22 @@ const commandTable = {
}, },
], ],
}, },
{
key: 'che_첩보',
name: '첩보',
reqArg: true,
possible: true,
status: 'needsInput',
inputFields: [
{
key: 'destCityId',
label: '대상 도시',
kind: 'select',
required: true,
optionSource: 'cities',
},
],
},
], ],
}, },
], ],
@@ -921,6 +937,48 @@ test('renders and accepts every Ref strategy command at mobile width', async ({
await picker.screenshot({ path: test.info().outputPath('all-strategy-commands-mobile.png') }); await picker.screenshot({ path: test.info().outputPath('all-strategy-commands-mobile.png') });
}); });
test('shows and reserves the Ref spy command for a user on desktop and mobile', async ({ page }) => {
const requests = await install(page);
await page.setViewportSize({ width: 1200, height: 900 });
await page.goto('/');
const editor = page.locator('[data-command-scope="general"]');
await editor.getByRole('button', { name: '1턴 명령 입력', exact: true }).click();
let picker = page.getByTestId('command-picker');
await picker.getByRole('button', { name: '군사', exact: true }).click();
const spy = picker.getByRole('button', { name: '첩보', exact: true });
await expect(spy).toBeVisible();
await spy.hover();
await spy.focus();
await expect(spy).toBeFocused();
await spy.click();
const form = picker.getByTestId('command-argument-form');
await expect(form.getByTestId('command-argument-guidance')).toContainText(
'선택한 도시에 첩보를 실행합니다.'
);
await expect(form.getByTestId('command-argument-guidance')).toContainText(
'인접 도시에서는 더 많은 정보를 얻습니다.'
);
await form.locator('select').selectOption('2');
await picker.screenshot({ path: test.info().outputPath('spy-command-desktop-1200.png') });
await picker.getByRole('button', { name: '입력', exact: true }).click();
await expect(editor.locator('.action-column > div').first()).toHaveText('【허창】에 첩보 실행');
expect(JSON.stringify(requests)).toContain('"action":"che_첩보","args":{"destCityId":2}');
await page.setViewportSize({ width: 500, height: 900 });
await editor.getByRole('button', { name: '2턴 명령 입력', exact: true }).click();
picker = page.getByTestId('command-picker');
await picker.getByRole('button', { name: '군사', exact: true }).click();
await expect(picker.getByRole('button', { name: '첩보', exact: true })).toBeVisible();
const geometry = await picker.evaluate((element) => ({
width: element.getBoundingClientRect().width,
horizontalOverflow: element.scrollWidth - element.clientWidth,
}));
expect(geometry.width).toBeLessThanOrEqual(500);
expect(geometry.horizontalOverflow).toBeLessThanOrEqual(0);
await picker.screenshot({ path: test.info().outputPath('spy-command-mobile-500.png') });
});
test('defaults founding to a Ref-selectable nation trait and paints color option labels', async ({ test('defaults founding to a Ref-selectable nation trait and paints color option labels', async ({
page, page,
}) => { }) => {
+3 -2
View File
@@ -47,8 +47,9 @@ export const finalizeLogEntry = (entry: LogEntryDraft, context: LogContext): Log
if (entry.meta !== undefined) { if (entry.meta !== undefined) {
record.meta = entry.meta; record.meta = entry.meta;
} }
if (context.at !== undefined) { const createdAt = entry.occurredAt ?? context.at;
record.createdAt = context.at; if (createdAt !== undefined) {
record.createdAt = createdAt;
} }
return record; return record;
+2
View File
@@ -31,6 +31,8 @@ export interface LogEntryDraft {
/** 월 경계 전 action처럼 flush 시점과 다른 달에 귀속되는 로그의 명시적 날짜. */ /** 월 경계 전 action처럼 flush 시점과 다른 달에 귀속되는 로그의 명시적 날짜. */
year?: number; year?: number;
month?: number; month?: number;
/** 로그를 만든 논리 게임 시각. 생략하면 flush context의 시각을 사용한다. */
occurredAt?: Date;
} }
export interface LogEntryRecord { export interface LogEntryRecord {
@@ -22,4 +22,22 @@ describe('finalizeLogEntry', () => {
text: '<C>●</>193년 12월:이전 달 사건', text: '<C>●</>193년 12월:이전 달 사건',
}); });
}); });
it('keeps an explicit occurrence time instead of replacing it with the flush time', () => {
const occurredAt = new Date('0200-01-01T00:37:43.000Z');
const flushAt = new Date('0200-01-01T00:40:00.000Z');
expect(
finalizeLogEntry(
{
scope: LogScope.GENERAL,
category: LogCategory.ACTION,
text: '상업 투자를 실행했습니다.',
generalId: 1,
occurredAt,
},
{ year: 200, month: 1, at: flushAt }
)?.createdAt
).toEqual(occurredAt);
});
}); });
+1
View File
@@ -33,6 +33,7 @@
"che_징병", "che_징병",
"che_모병", "che_모병",
"che_소집해제", "che_소집해제",
"che_첩보",
"che_군량매매", "che_군량매매",
"che_물자조달", "che_물자조달",
"che_증여", "che_증여",