From c228584de1568444d3e75fbef31f01d129787b36 Mon Sep 17 00:00:00 2001 From: Suraj Anand Date: Wed, 28 Jan 2026 22:01:49 +0530 Subject: [PATCH] test: add agentId field validation tests --- test/hooks.agentId.test.ts | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 test/hooks.agentId.test.ts diff --git a/test/hooks.agentId.test.ts b/test/hooks.agentId.test.ts new file mode 100644 index 000000000..7684a9b08 --- /dev/null +++ b/test/hooks.agentId.test.ts @@ -0,0 +1,68 @@ +import { describe, it, expect } from "vitest"; +import { normalizeAgentPayload } from "../src/gateway/hooks.js"; + +describe("normalizeAgentPayload agentId support", () => { + it("should accept agentId as a string", () => { + const payload = { + message: "test message", + channel: "last", + agentId: "agent-123", + }; + const result = normalizeAgentPayload(payload); + expect(result.ok).toBe(true); + if (result.ok) { + expect(result.value.agentId).toBe("agent-123"); + } + }); + + it("should trim agentId whitespace", () => { + const payload = { + message: "test message", + channel: "last", + agentId: " agent-456 ", + }; + const result = normalizeAgentPayload(payload); + expect(result.ok).toBe(true); + if (result.ok) { + expect(result.value.agentId).toBe("agent-456"); + } + }); + + it("should handle missing agentId as undefined", () => { + const payload = { + message: "test message", + channel: "last", + }; + const result = normalizeAgentPayload(payload); + expect(result.ok).toBe(true); + if (result.ok) { + expect(result.value.agentId).toBeUndefined(); + } + }); + + it("should ignore empty agentId strings", () => { + const payload = { + message: "test message", + channel: "last", + agentId: " ", + }; + const result = normalizeAgentPayload(payload); + expect(result.ok).toBe(true); + if (result.ok) { + expect(result.value.agentId).toBeUndefined(); + } + }); + + it("should handle non-string agentId as undefined", () => { + const payload = { + message: "test message", + channel: "last", + agentId: 123, + } as any; + const result = normalizeAgentPayload(payload); + expect(result.ok).toBe(true); + if (result.ok) { + expect(result.value.agentId).toBeUndefined(); + } + }); +});