mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-24 07:01:49 +00:00
fix: mark buffered reply typing runs complete
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { dispatchInboundMessage, withReplyDispatcher } from "./dispatch.js";
|
||||
import {
|
||||
dispatchInboundMessage,
|
||||
dispatchInboundMessageWithBufferedDispatcher,
|
||||
withReplyDispatcher,
|
||||
} from "./dispatch.js";
|
||||
import type { ReplyDispatcher } from "./reply/reply-dispatcher.js";
|
||||
import { buildTestCtx } from "./reply/test-ctx.js";
|
||||
|
||||
@@ -90,4 +94,32 @@ describe("withReplyDispatcher", () => {
|
||||
|
||||
expect(order).toEqual(["sendFinalReply", "markComplete", "waitForIdle"]);
|
||||
});
|
||||
|
||||
it("dispatchInboundMessageWithBufferedDispatcher cleans up typing after a resolver starts it", async () => {
|
||||
const typing = {
|
||||
onReplyStart: vi.fn(async () => {}),
|
||||
startTypingLoop: vi.fn(async () => {}),
|
||||
startTypingOnText: vi.fn(async () => {}),
|
||||
refreshTypingTtl: vi.fn(),
|
||||
isActive: vi.fn(() => true),
|
||||
markRunComplete: vi.fn(),
|
||||
markDispatchIdle: vi.fn(),
|
||||
cleanup: vi.fn(),
|
||||
};
|
||||
|
||||
await dispatchInboundMessageWithBufferedDispatcher({
|
||||
ctx: buildTestCtx(),
|
||||
cfg: {} as OpenClawConfig,
|
||||
dispatcherOptions: {
|
||||
deliver: async () => undefined,
|
||||
},
|
||||
replyResolver: async (_ctx, opts) => {
|
||||
opts?.onTypingController?.(typing);
|
||||
return { text: "ok" };
|
||||
},
|
||||
});
|
||||
|
||||
expect(typing.markRunComplete).toHaveBeenCalledTimes(1);
|
||||
expect(typing.markDispatchIdle).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -60,9 +60,8 @@ export async function dispatchInboundMessageWithBufferedDispatcher(params: {
|
||||
replyOptions?: Omit<GetReplyOptions, "onToolResult" | "onBlockReply">;
|
||||
replyResolver?: typeof import("./reply.js").getReplyFromConfig;
|
||||
}): Promise<DispatchInboundResult> {
|
||||
const { dispatcher, replyOptions, markDispatchIdle } = createReplyDispatcherWithTyping(
|
||||
params.dispatcherOptions,
|
||||
);
|
||||
const { dispatcher, replyOptions, markDispatchIdle, markRunComplete } =
|
||||
createReplyDispatcherWithTyping(params.dispatcherOptions);
|
||||
try {
|
||||
return await dispatchInboundMessage({
|
||||
ctx: params.ctx,
|
||||
@@ -75,6 +74,7 @@ export async function dispatchInboundMessageWithBufferedDispatcher(params: {
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
markRunComplete();
|
||||
markDispatchIdle();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user