fix: make session resume atomic across restarts

This commit is contained in:
User
2026-07-15 00:42:35 +02:00
parent 2b4797f133
commit 08b1f4909e
12 changed files with 1082 additions and 107 deletions
+11
View File
@@ -5,6 +5,10 @@ export class FakeEventSource {
onerror: (() => void) | null = null;
closed = false;
private listeners = new Map<string, Set<(e: { data: string; lastEventId: string }) => void>>();
private historicalListeners = new Map<
string,
Set<(e: { data: string; lastEventId: string }) => void>
>();
constructor(public url: string) {
FakeEventSource.instances.push(this);
}
@@ -17,9 +21,16 @@ export class FakeEventSource {
const data = JSON.stringify(obj);
for (const h of this.listeners.get(type) ?? []) h({ data, lastEventId });
}
/** Simulate an event already queued before removeEventListener/close completed. */
emitQueuedNamed(type: string, obj: unknown, lastEventId = "") {
const data = JSON.stringify(obj);
for (const h of this.historicalListeners.get(type) ?? []) h({ data, lastEventId });
}
addEventListener(type: string, handler: (e: { data: string; lastEventId: string }) => void) {
if (!this.listeners.has(type)) this.listeners.set(type, new Set());
if (!this.historicalListeners.has(type)) this.historicalListeners.set(type, new Set());
this.listeners.get(type)!.add(handler);
this.historicalListeners.get(type)!.add(handler);
}
removeEventListener(type: string, handler: (e: { data: string; lastEventId: string }) => void) {
this.listeners.get(type)?.delete(handler);