fix: use local timestamps in agent envelope

This commit is contained in:
Peter Steinberger
2025-12-20 19:40:48 +01:00
parent 929a10e33d
commit 50e817f193
4 changed files with 149 additions and 94 deletions

View File

@@ -4,6 +4,9 @@ import { formatAgentEnvelope } from "./envelope.js";
describe("formatAgentEnvelope", () => {
it("includes surface, from, ip, host, and timestamp", () => {
const originalTz = process.env.TZ;
process.env.TZ = "UTC";
const ts = Date.UTC(2025, 0, 2, 3, 4); // 2025-01-02T03:04:00Z
const body = formatAgentEnvelope({
surface: "WebChat",
@@ -13,8 +16,29 @@ describe("formatAgentEnvelope", () => {
timestamp: ts,
body: "hello",
});
process.env.TZ = originalTz;
expect(body).toMatch(
/^\[WebChat user1 mac-mini 10\.0\.0\.5 2025-01-02T03:04\+00:00\{.+\}\] hello$/,
);
});
it("formats timestamps in local time (not UTC)", () => {
const originalTz = process.env.TZ;
process.env.TZ = "America/Los_Angeles";
const ts = Date.UTC(2025, 0, 2, 3, 4); // 2025-01-02T03:04:00Z
const body = formatAgentEnvelope({
surface: "WebChat",
timestamp: ts,
body: "hello",
});
process.env.TZ = originalTz;
expect(body).toBe(
"[WebChat user1 mac-mini 10.0.0.5 2025-01-02 03:04] hello",
"[WebChat 2025-01-01T19:04-08:00{America/Los_Angeles}] hello",
);
});