Files
core2026/app/game-api/test/idempotentTransport.test.ts
T
Hide_D 5040691d7c feat: implement input event system with durable command handling
- Introduced InputEvent model with status tracking (PENDING, PROCESSING, SUCCEEDED, FAILED) and unique request IDs.
- Added DatabaseTurnDaemonTransport for sending commands and handling idempotency.
- Implemented executeInputEvent function to manage input event lifecycle and error handling.
- Created DatabaseTurnDaemonCommandQueue for managing command processing and lease recovery.
- Enhanced turn daemon lifecycle to support atomic command execution and error recovery.
- Added tests for input event atomicity, command queuing, and error handling scenarios.
2026-07-25 05:36:34 +00:00

23 lines
1.0 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { IdempotentTurnDaemonTransport } from '../src/daemon/idempotentTransport.js';
import { InMemoryTurnDaemonTransport } from '../src/daemon/inMemoryTransport.js';
describe('IdempotentTurnDaemonTransport', () => {
it('derives stable ordered engine request IDs from the API input event', async () => {
const inner = new InMemoryTurnDaemonTransport();
const firstAttempt = new IdempotentTurnDaemonTransport(inner, 'api-event');
const retry = new IdempotentTurnDaemonTransport(inner, 'api-event');
await firstAttempt.sendCommand({ type: 'vacation', generalId: 7 });
await firstAttempt.sendCommand({ type: 'dropItem', generalId: 7, itemType: 'weapon' });
await retry.sendCommand({ type: 'vacation', generalId: 7 });
expect(inner.commands.map((entry) => entry.requestId)).toEqual([
'api-event:engine:0:vacation',
'api-event:engine:1:dropItem',
'api-event:engine:0:vacation',
]);
});
});