Skip to content

Commit 48a45ba

Browse files
committed
fix: add flushAll to all mock debouncers and address review feedback
- Use Promise.all for parallel flush (keys are independent conversations) - Move detachConnectionUpdate before flushAll for cleaner shutdown boundary - Add flushAll to mock debouncers in feishu, slack, bluebubbles, and plugin-runtime-mock to fix TS2322 type errors - Add flushAll to BlueBubblesDebouncer type definition
1 parent ddc4032 commit 48a45ba

10 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎extensions/bluebubbles/src/monitor-debounce.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function sanitizeDebounceEntry(entry: BlueBubblesDebounceEntry): BlueBubblesDebo
3232
export type BlueBubblesDebouncer = {
3333
enqueue: (item: BlueBubblesDebounceEntry) => Promise<void>;
3434
flushKey: (key: string) => Promise<void>;
35+
flushAll: () => Promise<void>;
3536
};
3637

3738
export type BlueBubblesDebounceRegistry = {
@@ -218,6 +219,7 @@ export function createBlueBubblesDebounceRegistry(params: {
218219
await baseDebouncer.enqueue(sanitizeDebounceEntry(item));
219220
},
220221
flushKey: (key) => baseDebouncer.flushKey(key),
222+
flushAll: () => baseDebouncer.flushAll(),
221223
};
222224

223225
targetDebouncers.set(target, debouncer);

‎extensions/bluebubbles/src/monitor.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ function installTimingAwareInboundDebouncer(core: PluginRuntime) {
206206
flushKey: vi.fn(async (key: string) => {
207207
await flush(key);
208208
}),
209+
flushAll: vi.fn(async () => {}),
209210
};
210211
}) as unknown as PluginRuntime["channel"]["debounce"]["createInboundDebouncer"];
211212
}

‎extensions/feishu/src/monitor.reaction.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ describe("Feishu inbound debounce regressions", () => {
678678
params.onError?.(new Error("dispatch failed"), [item]);
679679
},
680680
flushKey: async () => {},
681+
flushAll: async () => {},
681682
}),
682683
}),
683684
);

‎extensions/feishu/src/monitor.test-mocks.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export function createFeishuRuntimeMockModule(): {
1818
createInboundDebouncer: () => {
1919
enqueue: () => Promise<void>;
2020
flushKey: () => Promise<void>;
21+
flushAll: () => Promise<void>;
2122
};
2223
};
2324
text: {
@@ -34,6 +35,7 @@ export function createFeishuRuntimeMockModule(): {
3435
createInboundDebouncer: () => ({
3536
enqueue: async () => {},
3637
flushKey: async () => {},
38+
flushAll: async () => {},
3739
}),
3840
},
3941
text: {

‎extensions/feishu/src/test-support/lifecycle-test-support.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export function createImmediateInboundDebounce() {
8686
}
8787
},
8888
flushKey: async () => {},
89+
flushAll: async () => {},
8990
}),
9091
};
9192
}

‎extensions/slack/src/monitor/message-handler.app-mention-race.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ vi.mock("../../../../src/channels/inbound-debounce-policy.js", () => ({
2727
await params.onFlush([entry]);
2828
},
2929
flushKey: async (_key: string) => {},
30+
flushAll: async () => {},
3031
},
3132
}),
3233
}));

‎extensions/slack/src/monitor/message-handler.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ vi.mock("openclaw/plugin-sdk/channel-inbound", async () => {
1818
debouncer: {
1919
enqueue: (entry: unknown) => enqueueMock(entry),
2020
flushKey: (key: string) => flushKeyMock(key),
21+
flushAll: async () => {},
2122
},
2223
}),
2324
shouldDebounceTextInbound: ({ hasMedia }: { hasMedia?: boolean }) => !hasMedia,

‎extensions/whatsapp/src/inbound/monitor.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,8 @@ export async function monitorWebInbox(options: {
559559
close: async () => {
560560
try {
561561
detachMessagesUpsert();
562-
await debouncer.flushAll();
563562
detachConnectionUpdate();
563+
await debouncer.flushAll();
564564
closeInboundMonitorSocket(sock);
565565
} catch (err) {
566566
logVerbose(`Socket close failed: ${String(err)}`);

‎src/auto-reply/inbound-debounce.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,7 @@ export function createInboundDebouncer<T>(params: InboundDebounceCreateParams<T>
233233

234234
const flushAll = async () => {
235235
const keys = Array.from(buffers.keys());
236-
for (const key of keys) {
237-
await flushKey(key);
238-
}
236+
await Promise.all(keys.map((key) => flushKey(key)));
239237
};
240238

241239
return { enqueue, flushKey, flushAll };

‎test/helpers/plugins/plugin-runtime-mock.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ export function createPluginRuntimeMock(overrides: DeepPartial<PluginRuntime> =
324324
await params.onFlush([item]);
325325
},
326326
flushKey: vi.fn(),
327+
flushAll: vi.fn(),
327328
}),
328329
) as unknown as PluginRuntime["channel"]["debounce"]["createInboundDebouncer"],
329330
resolveInboundDebounceMs: vi.fn(

0 commit comments

Comments
 (0)