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 <zeng.lingbiao@xydigit.com>

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
zengLingbiao
2026-07-16 16:50:08 +08:00
committed by GitHub
parent 0b7f4ccb72
commit c2b73a0a01
2 changed files with 11 additions and 1 deletions

View File

@@ -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", () => {

View File

@@ -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);