mirror of
https://github.com/davidkaya/aryx.git
synced 2026-08-06 19:58:43 +02:00
fix: improve streaming message merging
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -90,6 +90,41 @@ describe('session workspace helpers', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('keeps snapshot-like streamed updates readable while a message is pending', () => {
|
||||
const first = applySessionEventWorkspace(createWorkspace(), {
|
||||
sessionId: 'session-1',
|
||||
kind: 'message-delta',
|
||||
occurredAt: '2026-03-23T00:00:01.000Z',
|
||||
messageId: 'assistant-1',
|
||||
authorName: 'Writer',
|
||||
contentDelta: 'How about',
|
||||
} satisfies SessionEventRecord);
|
||||
|
||||
const second = applySessionEventWorkspace(first, {
|
||||
sessionId: 'session-1',
|
||||
kind: 'message-delta',
|
||||
occurredAt: '2026-03-23T00:00:02.000Z',
|
||||
messageId: 'assistant-1',
|
||||
authorName: 'Writer',
|
||||
contentDelta: 'The **Ashen Crown** feels',
|
||||
} satisfies SessionEventRecord);
|
||||
|
||||
const third = applySessionEventWorkspace(second, {
|
||||
sessionId: 'session-1',
|
||||
kind: 'message-delta',
|
||||
occurredAt: '2026-03-23T00:00:03.000Z',
|
||||
messageId: 'assistant-1',
|
||||
authorName: 'Writer',
|
||||
contentDelta: 'classic and timeless.',
|
||||
} satisfies SessionEventRecord);
|
||||
|
||||
expect(third?.sessions[0].messages[0]).toMatchObject({
|
||||
authorName: 'Writer',
|
||||
content: 'How about The **Ashen Crown** feels classic and timeless.',
|
||||
pending: true,
|
||||
});
|
||||
});
|
||||
|
||||
test('updates session status and error state from session events', () => {
|
||||
const running = applySessionEventWorkspace(createWorkspace(), {
|
||||
sessionId: 'session-1',
|
||||
|
||||
@@ -25,4 +25,19 @@ describe('streaming text merge', () => {
|
||||
|
||||
expect(mergeStreamingText(current, incoming)).toBe(incoming);
|
||||
});
|
||||
|
||||
test('inserts whitespace when snapshot-like updates would otherwise glue words together', () => {
|
||||
expect(mergeStreamingText('How about', 'The **Ashen Crown** feels')).toBe(
|
||||
'How about The **Ashen Crown** feels',
|
||||
);
|
||||
expect(mergeStreamingText('The **Ashen Crown** feels', 'classic and timeless.')).toBe(
|
||||
'The **Ashen Crown** feels classic and timeless.',
|
||||
);
|
||||
});
|
||||
|
||||
test('inserts a newline before streamed markdown block markers', () => {
|
||||
expect(mergeStreamingText('If you want, I can also give you', '- darker titles')).toBe(
|
||||
'If you want, I can also give you\n- darker titles',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user