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.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
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',
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user