mirror of
https://github.com/davidkaya/aryx.git
synced 2026-08-26 21:03:58 +02:00
fix: harden activity event handling
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
|
||||
import {
|
||||
markRunTurnPendingErrored,
|
||||
shouldHandleRunTurnEvent,
|
||||
type RunTurnPendingCommand,
|
||||
} from '@main/sidecar/runTurnPending';
|
||||
|
||||
describe('run turn pending helpers', () => {
|
||||
test('marks a run-turn pending command as errored and rejects it once', () => {
|
||||
const rejected: Error[] = [];
|
||||
const pending: RunTurnPendingCommand = {
|
||||
kind: 'run-turn',
|
||||
resolve: () => undefined,
|
||||
reject: (error) => rejected.push(error),
|
||||
onDelta: () => undefined,
|
||||
onActivity: () => undefined,
|
||||
errored: false,
|
||||
};
|
||||
|
||||
const first = markRunTurnPendingErrored(pending, 'boom');
|
||||
const second = markRunTurnPendingErrored(pending, new Error('later'));
|
||||
|
||||
expect(first).toBeInstanceOf(Error);
|
||||
expect(first.message).toBe('boom');
|
||||
expect(second.message).toBe('later');
|
||||
expect(pending.errored).toBe(true);
|
||||
expect(rejected).toHaveLength(1);
|
||||
expect(rejected[0].message).toBe('boom');
|
||||
});
|
||||
|
||||
test('stops handling turn events after the pending command has errored', () => {
|
||||
const pending: RunTurnPendingCommand = {
|
||||
kind: 'run-turn',
|
||||
resolve: () => undefined,
|
||||
reject: () => undefined,
|
||||
onDelta: () => undefined,
|
||||
onActivity: () => undefined,
|
||||
errored: false,
|
||||
};
|
||||
|
||||
expect(shouldHandleRunTurnEvent(pending)).toBe(true);
|
||||
|
||||
markRunTurnPendingErrored(pending, new Error('boom'));
|
||||
|
||||
expect(shouldHandleRunTurnEvent(pending)).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user