fix: stabilize telegram draft boundary previews (#33842) (thanks @ngutman)

This commit is contained in:
Ayaan Zaidi
2026-03-04 08:55:13 +05:30
committed by Ayaan Zaidi
parent 5ce53095c5
commit 575bd77196
8 changed files with 463 additions and 73 deletions

View File

@@ -43,7 +43,11 @@ function createHarness(params?: {
const log = vi.fn();
const markDelivered = vi.fn();
const finalizedPreviewByLane: Record<LaneName, boolean> = { answer: false, reasoning: false };
const archivedAnswerPreviews: Array<{ messageId: number; textSnapshot: string }> = [];
const archivedAnswerPreviews: Array<{
messageId: number;
textSnapshot: string;
deleteIfUnused?: boolean;
}> = [];
const deliverLaneText = createLaneTextDeliverer({
lanes,
@@ -71,8 +75,10 @@ function createHarness(params?: {
flushDraftLane,
stopDraftLane,
editPreview,
deletePreviewMessage,
log,
markDelivered,
archivedAnswerPreviews,
};
}
@@ -306,4 +312,26 @@ describe("createLaneTextDeliverer", () => {
);
expect(harness.markDelivered).not.toHaveBeenCalled();
});
it("deletes consumed boundary previews after fallback final send", async () => {
const harness = createHarness();
harness.archivedAnswerPreviews.push({
messageId: 4444,
textSnapshot: "Boundary preview",
deleteIfUnused: false,
});
const result = await harness.deliverLaneText({
laneName: "answer",
text: "Final with media",
payload: { text: "Final with media", mediaUrl: "file:///tmp/example.png" },
infoKind: "final",
});
expect(result).toBe("sent");
expect(harness.sendPayload).toHaveBeenCalledWith(
expect.objectContaining({ text: "Final with media", mediaUrl: "file:///tmp/example.png" }),
);
expect(harness.deletePreviewMessage).toHaveBeenCalledWith(4444);
});
});