test(telegram): cover visible error fresh final

This commit is contained in:
Peter Steinberger
2026-05-03 16:23:51 +01:00
parent 2b38345c8a
commit 6becfcb275
2 changed files with 18 additions and 12 deletions

View File

@@ -307,7 +307,8 @@ curl "https://api.telegram.org/bot<bot_token>/getUpdates"
For text-only replies:
- short DM/group/topic previews: OpenClaw keeps the same preview message and performs a final edit in place
- short DM/group/topic previews: OpenClaw keeps the same preview message and performs a final edit in place, unless a visible non-preview message was sent after the preview appeared
- previews followed by visible non-preview output: OpenClaw sends the completed reply as a fresh final message and cleans up the older preview, so the final answer appears after intermediate output
- previews older than about one minute: OpenClaw sends the completed reply as a fresh final message and then cleans up the preview, so Telegram's visible timestamp reflects completion time instead of the preview creation time
For complex replies (for example media payloads), OpenClaw falls back to normal final delivery and then cleans up the preview message.

View File

@@ -3179,8 +3179,11 @@ describe("dispatchTelegramMessage draft streaming", () => {
);
});
it("handles error block + response final — error delivered, response finalizes preview", async () => {
const draftStream = createDraftStream(999);
it("sends a fresh final after a visible error block bubble pushes the preview up", async () => {
const draftStream = createTestDraftStream({
messageId: 999,
visibleSinceMs: Date.now() - 1_000,
});
createTelegramDraftStream.mockReturnValue(draftStream);
editMessageTelegram.mockResolvedValue({ ok: true });
dispatchReplyWithBufferedBlockDispatcher.mockImplementation(
@@ -3201,16 +3204,18 @@ describe("dispatchTelegramMessage draft streaming", () => {
await dispatchWithContext({ context: createContext() });
// Block error went through deliverReplies
expect(deliverReplies).toHaveBeenCalledTimes(1);
// Final was finalized via preview edit
expect(editMessageTelegram).toHaveBeenCalledWith(
123,
999,
"The command timed out. Here's what I found...",
expect.any(Object),
// Error block + fresh final both went through deliverReplies; preview was
// not edited in place and the stale preview was cleared.
expect(deliverReplies).toHaveBeenCalledTimes(2);
expect(editMessageTelegram).not.toHaveBeenCalled();
expect(deliverReplies).toHaveBeenLastCalledWith(
expect.objectContaining({
replies: [
expect.objectContaining({ text: "The command timed out. Here's what I found..." }),
],
}),
);
expect(draftStream.clear).not.toHaveBeenCalled();
expect(draftStream.clear).toHaveBeenCalled();
});
// #76529: when a visible non-final message is delivered after the answer