From c2b73a0a01202d261ec5e7112f8dbe8d5ec384d8 Mon Sep 17 00:00:00 2001 From: zengLingbiao Date: Thu, 16 Jul 2026 16:50:08 +0800 Subject: [PATCH] fix(envelope): accept timestamp 0 in formatEnvelopeTimestamp (#106407) * fix(envelope): accept timestamp 0 in formatEnvelopeTimestamp formatEnvelopeTimestamp used if (!ts) to check for missing timestamps, which incorrectly rejected the valid numeric timestamp 0 (Unix epoch). Replace the falsy check with an explicit undefined/null check so 0 is treated as a valid timestamp value. * refactor(auto-reply): tighten epoch timestamp fix Exercise the public envelope path with an exact epoch result and keep the missing-value guard aligned with its declared input type. Co-authored-by: zenglingbiao --------- Co-authored-by: Peter Steinberger --- src/auto-reply/envelope.test.ts | 10 ++++++++++ src/auto-reply/envelope.ts | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/auto-reply/envelope.test.ts b/src/auto-reply/envelope.test.ts index 972dc06ff10d..2c2f059f17da 100644 --- a/src/auto-reply/envelope.test.ts +++ b/src/auto-reply/envelope.test.ts @@ -79,6 +79,16 @@ describe("formatAgentEnvelope", () => { const body = formatAgentEnvelope({ channel: "Telegram", body: "hi" }); expect(body).toBe("[Telegram] hi"); }); + + it("formats the Unix epoch timestamp", () => { + const body = formatAgentEnvelope({ + channel: "WebChat", + timestamp: 0, + envelope: { timezone: "utc" }, + body: "hello", + }); + expect(body).toBe("[WebChat Thu 1970-01-01T00:00:00Z] hello"); + }); }); describe("formatInboundEnvelope", () => { diff --git a/src/auto-reply/envelope.ts b/src/auto-reply/envelope.ts index 188fa9051b0b..43c2d0623d95 100644 --- a/src/auto-reply/envelope.ts +++ b/src/auto-reply/envelope.ts @@ -114,7 +114,7 @@ export function formatEnvelopeTimestamp( ts: number | Date | undefined, options?: EnvelopeFormatOptions, ): string | undefined { - if (!ts) { + if (ts === undefined) { return undefined; } const resolved = normalizeEnvelopeOptions(options);