Skip to content

Commit 3017a05

Browse files
committed
test(discord): isolate draft timer coverage
1 parent cb25ec4 commit 3017a05

6 files changed

Lines changed: 110 additions & 158 deletions

‎extensions/discord/src/monitor/message-handler.process.ack.test.ts‎

Lines changed: 17 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -244,24 +244,6 @@ describe("processDiscordMessage ack reactions", () => {
244244
}
245245
});
246246

247-
it("debounces intermediate phase reactions and jumps to done for short runs", async () => {
248-
dispatchInboundMessage.mockImplementationOnce(async (params?: DispatchInboundParams) => {
249-
await params?.replyOptions?.onReasoningStream?.();
250-
await params?.replyOptions?.onToolStart?.({ name: "exec", phase: "start" });
251-
return createNoQueuedDispatchResult();
252-
});
253-
254-
const ctx = await createAutomaticSourceDeliveryContext();
255-
256-
await runProcessDiscordMessage(ctx);
257-
258-
const emojis = getReactionEmojis();
259-
expect(emojis).toContain("👀");
260-
expect(emojis).toContain(DEFAULT_EMOJIS.done);
261-
expect(emojis).not.toContain(DEFAULT_EMOJIS.thinking);
262-
expect(emojis).not.toContain(DEFAULT_EMOJIS.coding);
263-
});
264-
265247
it("marks automatic visible replies as failed when final Discord delivery fails", async () => {
266248
dispatchInboundMessage.mockResolvedValueOnce({
267249
queuedFinal: false,
@@ -308,25 +290,28 @@ describe("processDiscordMessage ack reactions", () => {
308290
args: {
309291
action: "react",
310292
channelId: "c1",
311-
messageId: "m1",
293+
messageId: "tracked-m1",
312294
emoji: "📈",
313295
trackToolCalls: true,
314296
},
315297
});
316-
await vi.advanceTimersByTimeAsync(DEFAULT_TIMING.debounceMs);
298+
await new Promise<void>((resolve) => {
299+
setTimeout(resolve, DEFAULT_TIMING.debounceMs);
300+
});
317301
return createNoQueuedDispatchResult();
318302
});
319303

320304
const ctx = await createAutomaticSourceDeliveryContext({
321305
cfg: { messages: { ackReaction: "👀" } },
322306
});
323307

324-
await runProcessDiscordMessage(ctx);
308+
const runPromise = runProcessDiscordMessage(ctx);
309+
await vi.advanceTimersByTimeAsync(DEFAULT_TIMING.debounceMs);
325310
await vi.runAllTimersAsync();
311+
await runPromise;
326312

327-
expectReactionCallsContain("c1", "m1", "📈");
328-
expectReactionCallsContain("c1", "m1", "✉️");
329-
expectReactionCallsContain("c1", "m1", DEFAULT_EMOJIS.done);
313+
expectReactionCallsContain("c1", "tracked-m1", "📈");
314+
expectReactionCallsContain("c1", "tracked-m1", "✉️");
330315
});
331316

332317
it("resolves tracked reaction to targets like the Discord reaction action", async () => {
@@ -343,16 +328,20 @@ describe("processDiscordMessage ack reactions", () => {
343328
trackToolCalls: true,
344329
},
345330
});
346-
await vi.advanceTimersByTimeAsync(DEFAULT_TIMING.debounceMs);
331+
await new Promise<void>((resolve) => {
332+
setTimeout(resolve, DEFAULT_TIMING.debounceMs);
333+
});
347334
return createNoQueuedDispatchResult();
348335
});
349336

350337
const ctx = await createAutomaticSourceDeliveryContext({
351338
cfg: { messages: { ackReaction: "👀" } },
352339
});
353340

354-
await runProcessDiscordMessage(ctx);
341+
const runPromise = runProcessDiscordMessage(ctx);
342+
await vi.advanceTimersByTimeAsync(DEFAULT_TIMING.debounceMs);
355343
await vi.runAllTimersAsync();
344+
await runPromise;
356345

357346
const resolveCall = firstMockCall(
358347
discordTargetMocks.resolveDiscordTargetChannelId,
@@ -364,37 +353,6 @@ describe("processDiscordMessage ack reactions", () => {
364353
);
365354
expectReactionCallsContain("dm-u1", "m1", "📈");
366355
expectReactionCallsContain("dm-u1", "m1", "✉️");
367-
expectReactionCallsContain("dm-u1", "m1", DEFAULT_EMOJIS.done);
368-
});
369-
370-
it("shows stall emojis for long no-progress runs", async () => {
371-
vi.useFakeTimers();
372-
let releaseDispatch: (() => void) | undefined;
373-
const dispatchGate = new Promise<void>((resolve) => {
374-
releaseDispatch = () => resolve();
375-
});
376-
dispatchInboundMessage.mockImplementationOnce(async () => {
377-
await dispatchGate;
378-
return createNoQueuedDispatchResult();
379-
});
380-
381-
const ctx = await createAutomaticSourceDeliveryContext();
382-
const runPromise = runProcessDiscordMessage(ctx);
383-
384-
await vi.advanceTimersByTimeAsync(30_001);
385-
if (!releaseDispatch) {
386-
throw new Error("Expected Discord dispatch release callback to be initialized");
387-
}
388-
releaseDispatch();
389-
await vi.runAllTimersAsync();
390-
391-
await runPromise;
392-
const emojis = (
393-
sendMocks.reactMessageDiscord.mock.calls as unknown as Array<[unknown, unknown, string]>
394-
).map((call) => call[2]);
395-
expect(emojis).toContain(DEFAULT_EMOJIS.stallSoft);
396-
expect(emojis).toContain(DEFAULT_EMOJIS.stallHard);
397-
expect(emojis).toContain(DEFAULT_EMOJIS.done);
398356
});
399357

400358
it("falls back to plain ack when status reactions are disabled", async () => {
@@ -407,10 +365,7 @@ describe("processDiscordMessage ack reactions", () => {
407365
cfg: {
408366
messages: {
409367
ackReaction: "👀",
410-
statusReactions: {
411-
enabled: false,
412-
timing: { debounceMs: 0 },
413-
},
368+
statusReactions: { enabled: false },
414369
},
415370
session: { store: "/tmp/openclaw-discord-process-test-sessions.json" },
416371
},
@@ -437,12 +392,7 @@ describe("processDiscordMessage ack reactions", () => {
437392

438393
const ctx = await createAutomaticSourceDeliveryContext({
439394
cfg: {
440-
messages: {
441-
ackReaction: "👀",
442-
statusReactions: {
443-
timing: { debounceMs: 0 },
444-
},
445-
},
395+
messages: { ackReaction: "👀" },
446396
session: { store: "/tmp/openclaw-discord-process-test-sessions.json" },
447397
},
448398
});
@@ -456,23 +406,4 @@ describe("processDiscordMessage ack reactions", () => {
456406
expect(emojis).toContain(DEFAULT_EMOJIS.compacting);
457407
expect(emojis).toContain(DEFAULT_EMOJIS.thinking);
458408
});
459-
460-
it("keeps the plain ack reaction when status reactions are disabled", async () => {
461-
const ctx = await createAutomaticSourceDeliveryContext({
462-
cfg: {
463-
messages: {
464-
ackReaction: "👀",
465-
statusReactions: {
466-
enabled: false,
467-
},
468-
},
469-
session: { store: "/tmp/openclaw-discord-process-test-sessions.json" },
470-
},
471-
});
472-
473-
await runProcessDiscordMessage(ctx);
474-
475-
expect(getReactionEmojis()).toEqual(["👀"]);
476-
expect(sendMocks.removeReactionDiscord).not.toHaveBeenCalled();
477-
});
478409
});

‎extensions/discord/src/monitor/message-handler.process.draft-final.test.ts‎

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { describe, expect, it, vi } from "vitest";
33
import {
44
BASE_CHANNEL_ROUTE,
5-
createAutomaticSourceDeliveryContext,
65
createBaseContext,
76
createDiscordDraftStream,
87
createMockDraftStream,
@@ -19,6 +18,7 @@ import {
1918
} from "./message-handler.process.test-harness.js";
2019
import type { DispatchInboundParams } from "./message-handler.process.test-harness.js";
2120
import {
21+
createAutomaticDraftContext,
2222
createMockDraftStreamForTest,
2323
expectFinalWithProgressReceipt,
2424
expectFreshFinalText,
@@ -45,7 +45,7 @@ async function runHookSafetyFinalReply(mode: (typeof PREVIEW_MODES)[number]) {
4545
await params?.dispatcher.waitForIdle();
4646
return { queuedFinal: true, counts: { final: 1, tool: 0, block: 0 } };
4747
});
48-
const ctx = await createAutomaticSourceDeliveryContext({
48+
const ctx = await createAutomaticDraftContext({
4949
discordConfig: { streaming: { mode } },
5050
});
5151
await runProcessDiscordMessage(ctx);
@@ -88,7 +88,7 @@ describe("processDiscordMessage provider preview hook safety", () => {
8888
});
8989

9090
it("keeps explicitly disabled previews off without hooks", async () => {
91-
const ctx = await createAutomaticSourceDeliveryContext({
91+
const ctx = await createAutomaticDraftContext({
9292
discordConfig: { streaming: { mode: "off" } },
9393
});
9494

@@ -104,7 +104,7 @@ describe("processDiscordMessage provider preview hook safety", () => {
104104
await params?.dispatcher.sendFinalReply({ text: "Hello" });
105105
return { queuedFinal: true, counts: { final: 1, tool: 0, block: 0 } };
106106
});
107-
const ctx = await createAutomaticSourceDeliveryContext({
107+
const ctx = await createAutomaticDraftContext({
108108
cfg: { agents: { defaults: { blockStreamingDefault: "on" } } },
109109
discordConfig: { streaming: { mode: "partial" } },
110110
});
@@ -153,7 +153,7 @@ describe("processDiscordMessage draft streaming final delivery", () => {
153153
return { queuedFinal: true, counts: { final: 1, tool: 0, block: 0 } };
154154
});
155155

156-
const ctx = await createAutomaticSourceDeliveryContext({
156+
const ctx = await createAutomaticDraftContext({
157157
discordConfig: { streaming: { mode: "partial" }, maxLinesPerMessage: 5 },
158158
cfg: {
159159
channels: { discord: { mentionAliases: { Sentinel: "1485891428809707651" } } },
@@ -172,7 +172,7 @@ describe("processDiscordMessage draft streaming final delivery", () => {
172172
return { queuedFinal: true, counts: { final: 1, tool: 0, block: 0 } };
173173
});
174174

175-
const ctx = await createAutomaticSourceDeliveryContext({
175+
const ctx = await createAutomaticDraftContext({
176176
discordConfig: { streaming: { mode: "partial" }, maxLinesPerMessage: 5 },
177177
});
178178

@@ -188,7 +188,7 @@ describe("processDiscordMessage draft streaming final delivery", () => {
188188
return { queuedFinal: true, counts: { final: 1, tool: 0, block: 0 } };
189189
});
190190

191-
const ctx = await createAutomaticSourceDeliveryContext({
191+
const ctx = await createAutomaticDraftContext({
192192
discordConfig: { streaming: { mode: "partial" }, maxLinesPerMessage: 5 },
193193
});
194194

@@ -205,7 +205,7 @@ describe("processDiscordMessage draft streaming final delivery", () => {
205205
return { queuedFinal: true, counts: { final: 1, tool: 0, block: 0 } };
206206
});
207207

208-
const ctx = await createAutomaticSourceDeliveryContext({
208+
const ctx = await createAutomaticDraftContext({
209209
discordConfig: { streaming: { mode: "partial" }, maxLinesPerMessage: 5 },
210210
});
211211

@@ -224,7 +224,7 @@ describe("processDiscordMessage draft streaming final delivery", () => {
224224
return { queuedFinal: true, counts: { final: 1, tool: 0, block: 0 } };
225225
});
226226

227-
const ctx = await createAutomaticSourceDeliveryContext({
227+
const ctx = await createAutomaticDraftContext({
228228
discordConfig: { streaming: { mode: "partial" }, maxLinesPerMessage: 5 },
229229
cfg: {
230230
channels: { discord: { mentionAliases: { Sentinel: "1485891428809707651" } } },
@@ -258,7 +258,7 @@ describe("processDiscordMessage draft streaming final delivery", () => {
258258
return { queuedFinal: true, counts: { final: 1, tool: 0, block: 0 } };
259259
});
260260

261-
const ctx = await createAutomaticSourceDeliveryContext({
261+
const ctx = await createAutomaticDraftContext({
262262
discordConfig: { streaming: { mode: "progress" }, maxLinesPerMessage: 5 },
263263
});
264264

@@ -301,7 +301,7 @@ describe("processDiscordMessage draft streaming final delivery", () => {
301301
return { queuedFinal: true, counts: { final: 1, tool: 0, block: 0 } };
302302
});
303303

304-
const ctx = await createAutomaticSourceDeliveryContext({
304+
const ctx = await createAutomaticDraftContext({
305305
baseSessionKey: BASE_CHANNEL_ROUTE.sessionKey,
306306
discordConfig: { streaming: { mode: "progress" }, maxLinesPerMessage: 5 },
307307
route: BASE_CHANNEL_ROUTE,
@@ -326,7 +326,7 @@ describe("processDiscordMessage draft streaming final delivery", () => {
326326
return { queuedFinal: true, counts: { final: 1, tool: 0, block: 0 } };
327327
});
328328

329-
const ctx = await createAutomaticSourceDeliveryContext({
329+
const ctx = await createAutomaticDraftContext({
330330
discordConfig: {
331331
maxLinesPerMessage: 5,
332332
streaming: {
@@ -365,7 +365,7 @@ describe("processDiscordMessage draft streaming final delivery", () => {
365365
return { queuedFinal: true, counts: { final: 1, tool: 0, block: 0 } };
366366
});
367367

368-
const ctx = await createAutomaticSourceDeliveryContext({
368+
const ctx = await createAutomaticDraftContext({
369369
discordConfig: { streaming: { mode: "progress" }, maxLinesPerMessage: 5 },
370370
});
371371

@@ -391,7 +391,7 @@ describe("processDiscordMessage draft streaming final delivery", () => {
391391
return { queuedFinal: true, counts: { final: 1, tool: 0, block: 0 } };
392392
});
393393

394-
const ctx = await createAutomaticSourceDeliveryContext({
394+
const ctx = await createAutomaticDraftContext({
395395
discordConfig: { streaming: { mode: "progress" } },
396396
});
397397
await runProcessDiscordMessage(ctx);
@@ -401,7 +401,7 @@ describe("processDiscordMessage draft streaming final delivery", () => {
401401
createMockDraftStreamForTest();
402402
dispatchInboundMessage.mockImplementationOnce(async () => createNoQueuedDispatchResult());
403403

404-
const ctx = await createAutomaticSourceDeliveryContext({
404+
const ctx = await createAutomaticDraftContext({
405405
discordConfig: {
406406
streaming: { mode: "progress", progress: { label: "Shelling", narration: false } },
407407
},
@@ -417,7 +417,7 @@ describe("processDiscordMessage draft streaming final delivery", () => {
417417
createMockDraftStreamForTest();
418418
dispatchInboundMessage.mockImplementationOnce(async () => createNoQueuedDispatchResult());
419419

420-
const ctx = await createAutomaticSourceDeliveryContext({
420+
const ctx = await createAutomaticDraftContext({
421421
discordConfig: {
422422
streaming: { mode: "progress", progress: { label: "Shelling", commandText: "status" } },
423423
},
@@ -447,7 +447,7 @@ describe("processDiscordMessage draft streaming final delivery", () => {
447447
return createNoQueuedDispatchResult();
448448
});
449449

450-
const ctx = await createAutomaticSourceDeliveryContext({
450+
const ctx = await createAutomaticDraftContext({
451451
discordConfig: { streaming: { mode: "progress" }, maxLinesPerMessage: 5 },
452452
});
453453

@@ -472,7 +472,7 @@ describe("processDiscordMessage draft streaming final delivery", () => {
472472
return createNoQueuedDispatchResult();
473473
});
474474

475-
const ctx = await createAutomaticSourceDeliveryContext({
475+
const ctx = await createAutomaticDraftContext({
476476
discordConfig: { streaming: { mode: "progress" }, maxLinesPerMessage: 5 },
477477
});
478478

@@ -492,7 +492,7 @@ describe("processDiscordMessage draft streaming final delivery", () => {
492492
return createNoQueuedDispatchResult();
493493
});
494494

495-
const ctx = await createAutomaticSourceDeliveryContext({
495+
const ctx = await createAutomaticDraftContext({
496496
discordConfig: { streaming: { mode: "progress" } },
497497
});
498498

@@ -518,7 +518,7 @@ describe("processDiscordMessage draft streaming final delivery", () => {
518518
return { queuedFinal: true, counts: { final: 1, tool: 0, block: 0 } };
519519
});
520520

521-
const ctx = await createAutomaticSourceDeliveryContext({
521+
const ctx = await createAutomaticDraftContext({
522522
discordConfig: {
523523
streaming: { mode: "progress", progress: { label: "Shelling", thinking: true } },
524524
},
@@ -547,7 +547,7 @@ describe("processDiscordMessage draft streaming final delivery", () => {
547547
return { queuedFinal: true, counts: { final: 1, tool: 0, block: 0 } };
548548
});
549549

550-
const ctx = await createAutomaticSourceDeliveryContext({
550+
const ctx = await createAutomaticDraftContext({
551551
discordConfig: {
552552
streaming: { mode: "progress", progress: { label: "Shelling", thinking: true } },
553553
},
@@ -585,7 +585,7 @@ describe("processDiscordMessage draft streaming final delivery", () => {
585585
return { queuedFinal: true, counts: { final: 1, tool: 0, block: 0 } };
586586
});
587587

588-
const ctx = await createAutomaticSourceDeliveryContext({
588+
const ctx = await createAutomaticDraftContext({
589589
discordConfig: {
590590
streaming: { mode: "progress", progress: { label: "Shelling", commentary: true } },
591591
},
@@ -615,7 +615,7 @@ describe("processDiscordMessage draft streaming final delivery", () => {
615615
return { queuedFinal: true, counts: { final: 1, tool: 0, block: 0 } };
616616
});
617617

618-
const ctx = await createAutomaticSourceDeliveryContext({
618+
const ctx = await createAutomaticDraftContext({
619619
discordConfig: {
620620
maxLinesPerMessage: 5,
621621
streaming: { mode: "progress", progress: { label: "Shelling" } },
@@ -648,7 +648,7 @@ describe("processDiscordMessage draft streaming final delivery", () => {
648648
return { queuedFinal: true, counts: { final: 1, tool: 0, block: 0 } };
649649
});
650650

651-
const ctx = await createAutomaticSourceDeliveryContext({
651+
const ctx = await createAutomaticDraftContext({
652652
discordConfig: {
653653
maxLinesPerMessage: 5,
654654
streaming: { mode: "progress", progress: { label: "Shelling" } },

0 commit comments

Comments
 (0)