From 6d642bb759d9c900da85735adb43921210122078 Mon Sep 17 00:00:00 2001 From: hided62 Date: Sun, 26 Jul 2026 13:13:15 +0000 Subject: [PATCH] test live sortie full log parity --- .../src/turn-differential/canonical.ts | 3 ++ .../src/turn-differential/coreCommandTrace.ts | 9 ++-- ...rnCommandCoreReference.integration.test.ts | 43 ++++++++++++++++++- .../test/turnSnapshotComparator.test.ts | 2 +- 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/tools/integration-tests/src/turn-differential/canonical.ts b/tools/integration-tests/src/turn-differential/canonical.ts index afc6ea2..6bba61e 100644 --- a/tools/integration-tests/src/turn-differential/canonical.ts +++ b/tools/integration-tests/src/turn-differential/canonical.ts @@ -7,6 +7,7 @@ export interface TurnSnapshotSelector { logAfterId?: number; messageAfterId?: number; includeNationHistoryLogs?: boolean; + includeGlobalHistoryLogs?: boolean; } export interface CanonicalTurnSnapshot { @@ -24,6 +25,7 @@ export interface CanonicalTurnSnapshot { messages: Array>; watermarks: { logId: number; + historyLogId: number; messageId: number; }; } @@ -259,6 +261,7 @@ export const projectCoreDatabaseSnapshot = (rows: { messages: [], watermarks: { logId: logs.reduce((max, row) => Math.max(max, Number(row.id) || 0), 0), + historyLogId: logs.reduce((max, row) => Math.max(max, Number(row.id) || 0), 0), messageId: 0, }, }; diff --git a/tools/integration-tests/src/turn-differential/coreCommandTrace.ts b/tools/integration-tests/src/turn-differential/coreCommandTrace.ts index 1e48123..324f848 100644 --- a/tools/integration-tests/src/turn-differential/coreCommandTrace.ts +++ b/tools/integration-tests/src/turn-differential/coreCommandTrace.ts @@ -68,6 +68,7 @@ export interface TurnCommandFixtureRequest { logAfterId?: number; messageAfterId?: number; includeNationHistoryLogs?: boolean; + includeGlobalHistoryLogs?: boolean; generalCooldowns?: GeneralCooldownSelector[]; nationCooldowns?: NationCooldownSelector[]; diplomacyPairs?: Array<{ fromNationId: number; toNationId: number }>; @@ -469,7 +470,7 @@ const buildWorldInput = ( lastTurnTime: turnTime, meta: { hiddenSeed: request.setup?.world?.hiddenSeed ?? 'turn-command-differential-seed', - killturn: 24, + killturn: readNumber(referenceBefore.world, 'killTurn', 24), isUnited: readNumber(referenceBefore.world, 'isUnited'), scenarioId: readNumber(referenceBefore.world, 'scenarioId'), initYear: readNumber( @@ -661,7 +662,7 @@ const projectWorld = ( ), logs, messages, - watermarks: { logId: logs.length, messageId: messages.length }, + watermarks: { logId: logs.length, historyLogId: logs.length, messageId: messages.length }, }; }; @@ -785,8 +786,8 @@ export const runCoreTurnCommandTrace = async ( id: index + 1, scope: log.scope, category: log.category, - generalId: log.generalId ?? actor.id, - nationId: log.nationId ?? actor.nationId, + generalId: log.generalId ?? (log.scope === 'GENERAL' ? actor.id : undefined), + nationId: log.nationId ?? (log.scope === 'NATION' ? actor.nationId : undefined), year: state.currentYear, month: state.currentMonth, text: log.text, diff --git a/tools/integration-tests/test/turnCommandCoreReference.integration.test.ts b/tools/integration-tests/test/turnCommandCoreReference.integration.test.ts index 5371b27..33a8d6b 100644 --- a/tools/integration-tests/test/turnCommandCoreReference.integration.test.ts +++ b/tools/integration-tests/test/turnCommandCoreReference.integration.test.ts @@ -20,11 +20,30 @@ const ignoredLifecyclePaths = [ /^logs/, /^messages/, /^world\.turnTime$/, - /^generals\[[^\]]+\]\.(?:turnTime|recentWarTime|lastTurn|killTurn|mySet)(?:\.|$)/, + /^generals\[[^\]]+\]\.(?:turnTime|recentWarTime|lastTurn|mySet)(?:\.|$)/, /^generals\[[^\]]+\]\.meta(?:\.|$)/, /^nations\[[^\]]+\]\.meta(?:\.|$)/, ]; +const normalizeStoredLogText = (value: unknown): string => + String(value) + .replace(/^(?:●<\/>|◆<\/>|★<\/>)(?:(?:\d+년 )?\d+월:|\d+년:)?/, '') + .replace(/(.*?)<\/span>/g, '$1') + .replace(/ <1>\d{2}:\d{2}<\/>$/, ''); + +const semanticLogSignatures = (logs: Array>): string[] => + logs + .map((entry) => + JSON.stringify({ + scope: String(entry.scope).toLowerCase(), + category: String(entry.category).toLowerCase(), + generalId: Number(entry.generalId) || null, + nationId: Number(entry.nationId) || null, + text: normalizeStoredLogText(entry.text), + }) + ) + .sort(); + const readFixture = (relativePath: string): TurnCommandFixtureRequest => { const stackRoot = path.join(workspaceRoot!, 'docker_compose_files/reference'); const fixture = JSON.parse( @@ -34,6 +53,7 @@ const readFixture = (relativePath: string): TurnCommandFixtureRequest => { ...fixture, setup: { ...fixture.setup, + isolateWorld: true, world: { ...fixture.setup?.world, hiddenSeed: 'turn-command-differential-seed', @@ -60,6 +80,10 @@ integration('core ↔ legacy command-boundary differential', () => { '%s matches command RNG and canonical state delta', async (_label, fixturePath) => { const request = readFixture(fixturePath); + if (request.action === 'che_출병') { + request.observe!.includeNationHistoryLogs = true; + request.observe!.includeGlobalHistoryLogs = true; + } const reference = runReferenceTurnCommandTraceRequest( workspaceRoot!, request as unknown as Record @@ -73,9 +97,24 @@ integration('core ↔ legacy command-boundary differential', () => { }); expect(reference.execution.outcome).toMatchObject({ completed: true }); expect(core.rng).toEqual(reference.rng); + if (request.action === 'che_출병') { + const generalLogWatermark = reference.before.watermarks.logId; + const historyLogWatermark = reference.before.watermarks.historyLogId; + const referenceAddedLogs = reference.after.logs.filter((entry) => + String(entry.scope).toLowerCase() === 'nation' || + (String(entry.scope).toLowerCase() === 'system' && + String(entry.category).toLowerCase() === 'history') + ? (Number(entry.id) || 0) > historyLogWatermark + : (Number(entry.id) || 0) > generalLogWatermark + ); + expect(semanticLogSignatures(core.after.logs)).toEqual(semanticLogSignatures(referenceAddedLogs)); + } expect( compareTurnSnapshotDeltas(reference.before, reference.after, core.before, core.after, { - ignoredPathPatterns: ignoredLifecyclePaths, + ignoredPathPatterns: + request.action === 'che_출병' + ? ignoredLifecyclePaths + : [...ignoredLifecyclePaths, /^generals\[[^\]]+\]\.killTurn(?:\.|$)/], }) ).toEqual([]); }, diff --git a/tools/integration-tests/test/turnSnapshotComparator.test.ts b/tools/integration-tests/test/turnSnapshotComparator.test.ts index 60973ba..5d3a6f0 100644 --- a/tools/integration-tests/test/turnSnapshotComparator.test.ts +++ b/tools/integration-tests/test/turnSnapshotComparator.test.ts @@ -23,7 +23,7 @@ const snapshot = ( nationTurns: [], logs: [], messages: [], - watermarks: { logId: 0, messageId: 0 }, + watermarks: { logId: 0, historyLogId: 0, messageId: 0 }, ...overrides, });