fix(sync): keep deltas after initial part.updated coalescing
This commit is contained in:
@@ -336,6 +336,37 @@ describe('createEventPipeline', () => {
|
||||
expect(received[1].payload.type).toBe('message.part.updated');
|
||||
});
|
||||
|
||||
it('keeps text delta after an initial part.updated when no newer part.updated replaced it', async () => {
|
||||
const received = await runPipelineWithEvents([
|
||||
{
|
||||
directory: 'dir-a',
|
||||
payload: {
|
||||
type: 'message.part.updated',
|
||||
properties: {
|
||||
part: { id: 'part-1', type: 'text', messageID: 'msg-1' },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
directory: 'dir-a',
|
||||
payload: {
|
||||
type: 'message.part.delta',
|
||||
properties: {
|
||||
messageID: 'msg-1',
|
||||
partID: 'part-1',
|
||||
field: 'text',
|
||||
delta: 'hello',
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
expect(received).toHaveLength(2);
|
||||
expect(received[0].payload.type).toBe('message.part.updated');
|
||||
expect(received[1].payload.type).toBe('message.part.delta');
|
||||
expect(received[1].payload.properties.delta).toBe('hello');
|
||||
});
|
||||
|
||||
it('coalesces message.part.updated events for the same part', async () => {
|
||||
installDomStubs();
|
||||
|
||||
|
||||
@@ -80,4 +80,4 @@ export const syncDebug = {
|
||||
eventApplied: (eventType: string, sessionID?: string, messageID?: string) =>
|
||||
log("dispatch", "event → applied", { eventType, sessionID, messageID }),
|
||||
},
|
||||
} as const
|
||||
} as const
|
||||
|
||||
@@ -286,11 +286,6 @@ export function createEventPipeline(input: EventPipelineInput) {
|
||||
}
|
||||
d.coalesced.set(k, d.queue.length)
|
||||
}
|
||||
if (normalizedPayload.type === "message.part.updated") {
|
||||
const part = (normalizedPayload.properties as { part: { messageID: string; id: string } }).part
|
||||
d.staleDeltas.add(deltaKey(part.messageID, part.id, "text"))
|
||||
d.staleDeltas.add(deltaKey(part.messageID, part.id, "output"))
|
||||
}
|
||||
d.queue.push(normalizedPayload)
|
||||
scheduleDir(routedDirectory)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user