fix(realtime): invalidate committed global activity logs

This commit is contained in:
2026-08-12 16:45:48 +00:00
parent 719c0c0e35
commit d1efa425eb
6 changed files with 286 additions and 13 deletions
@@ -271,6 +271,7 @@ integration('monthly nation betting persistence', () => {
durationMs: 0,
partial: false,
});
expect(hooks.takeCommittedReadModelChanges()?.worldHistoryChanged).toBe(true);
expect(await db.nationBetting.findUniqueOrThrow({ where: { id: bettingId } })).toMatchObject({
name: '천통국 예상',
@@ -320,6 +321,7 @@ integration('monthly nation betting persistence', () => {
})
).toBe(true);
await world.advanceMonth(new Date('0200-02-01T00:00:00.000Z'));
expect(world.peekDirtyState().logs).toEqual([]);
await hooks.hooks.flushChanges?.({
lastTurnTime: state.lastTurnTime.toISOString(),
processedGenerals: 0,
@@ -327,6 +329,7 @@ integration('monthly nation betting persistence', () => {
durationMs: 0,
partial: false,
});
expect(hooks.takeCommittedReadModelChanges()?.worldHistoryChanged).toBe(true);
expect(await db.nationBetting.findUniqueOrThrow({ where: { id: bettingId } })).toMatchObject({
finished: true,
@@ -1,9 +1,11 @@
import { describe, expect, it } from 'vitest';
import { createEmptyRealtimeReadModelChanges } from '@sammo-ts/common';
import { LogCategory, LogFormat, LogScope } from '@sammo-ts/logic';
import {
applyRealtimeReadModelBaseline,
createRealtimeReadModelBaseline,
mergePersistedVisibleLogChanges,
summarizeRealtimeReadModelChanges,
} from '../src/turn/databaseHooks.js';
import type { InMemoryTurnWorld } from '../src/turn/inMemoryWorld.js';
@@ -11,6 +13,35 @@ import type { TurnWorldChanges } from '../src/turn/inMemoryWorld.js';
import type { ReservedTurnChanges } from '../src/turn/reservedTurnStore.js';
describe('summarizeRealtimeReadModelChanges', () => {
it('classifies the committed log rows even when they bypass in-memory log drafts', () => {
expect(
mergePersistedVisibleLogChanges(createEmptyRealtimeReadModelChanges(), [
{
id: 10,
scope: LogScope.GENERAL,
category: LogCategory.ACTION,
generalId: 7,
},
{
id: 11,
scope: LogScope.SYSTEM,
category: LogCategory.SUMMARY,
generalId: null,
},
{
id: 12,
scope: LogScope.SYSTEM,
category: LogCategory.HISTORY,
generalId: null,
},
])
).toMatchObject({
recordGeneralIds: [7],
globalRecordsChanged: true,
worldHistoryChanged: true,
});
});
it('emits deterministic entity and record invalidations from committed changes', () => {
const worldChanges = {
generals: [{ id: 9 }, { id: 7 }],