




















@@ -76,7 +76,10 @@ describe("telegram bot message processor", () => {
7676sendMessage: ReturnType<typeof vi.fn>,
7777) {
7878const runtimeError = vi.fn();
79-buildTelegramMessageContext.mockResolvedValue(context);
79+buildTelegramMessageContext.mockResolvedValue({
80+sendTyping: vi.fn().mockResolvedValue(undefined),
81+ ...context,
82+});
8083dispatchTelegramMessage.mockRejectedValue(new Error("dispatch exploded"));
8184const processMessage = createTelegramMessageProcessor({
8285 ...baseDeps,
@@ -87,12 +90,21 @@ describe("telegram bot message processor", () => {
8790}
88918992it("dispatches when context is available", async () => {
90-buildTelegramMessageContext.mockResolvedValue({ route: { sessionKey: "agent:main:main" } });
93+const sendTyping = vi.fn().mockResolvedValue(undefined);
94+buildTelegramMessageContext.mockResolvedValue({
95+chatId: 123,
96+route: { sessionKey: "agent:main:main" },
97+ sendTyping,
98+});
919992100const processMessage = createTelegramMessageProcessor(baseDeps);
93101await processSampleMessage(processMessage);
94102103+expect(sendTyping).toHaveBeenCalledTimes(1);
95104expect(dispatchTelegramMessage).toHaveBeenCalledTimes(1);
105+expect(sendTyping.mock.invocationCallOrder[0]).toBeLessThan(
106+dispatchTelegramMessage.mock.invocationCallOrder[0],
107+);
96108});
9710998110it("skips dispatch when no context is produced", async () => {
@@ -102,6 +114,21 @@ describe("telegram bot message processor", () => {
102114expect(dispatchTelegramMessage).not.toHaveBeenCalled();
103115});
104116117+it("keeps dispatch running when the early typing cue fails", async () => {
118+const sendTyping = vi.fn().mockRejectedValue(new Error("typing failed"));
119+buildTelegramMessageContext.mockResolvedValue({
120+chatId: 123,
121+route: { sessionKey: "agent:main:main" },
122+ sendTyping,
123+});
124+125+const processMessage = createTelegramMessageProcessor(baseDeps);
126+await processSampleMessage(processMessage);
127+128+expect(sendTyping).toHaveBeenCalledTimes(1);
129+expect(dispatchTelegramMessage).toHaveBeenCalledTimes(1);
130+});
131+105132it("sends user-visible fallback when dispatch throws", async () => {
106133const sendMessage = vi.fn().mockResolvedValue(undefined);
107134const { processMessage, runtimeError } = createDispatchFailureHarness(
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。