mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-02 05:01:35 +00:00
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:
@@ -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", () => {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user