From ed276d3e50f367710ceb4b353e8d8e1881808c54 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 15 Feb 2026 21:18:52 +0000 Subject: [PATCH] perf(test): consolidate inbound reply suites --- src/auto-reply/reply/inbound-meta.test.ts | 24 -------- src/auto-reply/reply/inbound-text.test.ts | 35 ----------- ...iders-contract.test.ts => inbound.test.ts} | 59 ++++++++++++++++++- 3 files changed, 57 insertions(+), 61 deletions(-) delete mode 100644 src/auto-reply/reply/inbound-meta.test.ts delete mode 100644 src/auto-reply/reply/inbound-text.test.ts rename src/auto-reply/reply/{inbound-context.providers-contract.test.ts => inbound.test.ts} (65%) diff --git a/src/auto-reply/reply/inbound-meta.test.ts b/src/auto-reply/reply/inbound-meta.test.ts deleted file mode 100644 index f358aebc794..00000000000 --- a/src/auto-reply/reply/inbound-meta.test.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { describe, expect, it } from "vitest"; -import type { TemplateContext } from "../templating.js"; -import { buildInboundUserContextPrefix } from "./inbound-meta.js"; - -describe("buildInboundUserContextPrefix", () => { - it("omits conversation label block for direct chats", () => { - const text = buildInboundUserContextPrefix({ - ChatType: "direct", - ConversationLabel: "openclaw-tui", - } as TemplateContext); - - expect(text).toBe(""); - }); - - it("keeps conversation label for group chats", () => { - const text = buildInboundUserContextPrefix({ - ChatType: "group", - ConversationLabel: "ops-room", - } as TemplateContext); - - expect(text).toContain("Conversation info (untrusted metadata):"); - expect(text).toContain('"conversation_label": "ops-room"'); - }); -}); diff --git a/src/auto-reply/reply/inbound-text.test.ts b/src/auto-reply/reply/inbound-text.test.ts deleted file mode 100644 index 2b54a71299a..00000000000 --- a/src/auto-reply/reply/inbound-text.test.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { normalizeInboundTextNewlines } from "./inbound-text.js"; - -describe("normalizeInboundTextNewlines", () => { - it("converts CRLF to LF", () => { - expect(normalizeInboundTextNewlines("hello\r\nworld")).toBe("hello\nworld"); - }); - - it("converts CR to LF", () => { - expect(normalizeInboundTextNewlines("hello\rworld")).toBe("hello\nworld"); - }); - - it("preserves literal backslash-n sequences in Windows paths", () => { - // Windows paths like C:\Work\nxxx should NOT have \n converted to newlines - const windowsPath = "C:\\Work\\nxxx\\README.md"; - expect(normalizeInboundTextNewlines(windowsPath)).toBe("C:\\Work\\nxxx\\README.md"); - }); - - it("preserves backslash-n in messages containing Windows paths", () => { - const message = "Please read the file at C:\\Work\\nxxx\\README.md"; - expect(normalizeInboundTextNewlines(message)).toBe( - "Please read the file at C:\\Work\\nxxx\\README.md", - ); - }); - - it("preserves multiple backslash-n sequences", () => { - const message = "C:\\new\\notes\\nested"; - expect(normalizeInboundTextNewlines(message)).toBe("C:\\new\\notes\\nested"); - }); - - it("still normalizes actual CRLF while preserving backslash-n", () => { - const message = "Line 1\r\nC:\\Work\\nxxx"; - expect(normalizeInboundTextNewlines(message)).toBe("Line 1\nC:\\Work\\nxxx"); - }); -}); diff --git a/src/auto-reply/reply/inbound-context.providers-contract.test.ts b/src/auto-reply/reply/inbound.test.ts similarity index 65% rename from src/auto-reply/reply/inbound-context.providers-contract.test.ts rename to src/auto-reply/reply/inbound.test.ts index a75b2996c30..b92d7acf513 100644 --- a/src/auto-reply/reply/inbound-context.providers-contract.test.ts +++ b/src/auto-reply/reply/inbound.test.ts @@ -1,7 +1,62 @@ -import { describe, it } from "vitest"; -import type { MsgContext } from "../templating.js"; +import { describe, expect, it } from "vitest"; +import type { MsgContext, TemplateContext } from "../templating.js"; import { expectInboundContextContract } from "../../../test/helpers/inbound-contract.js"; import { finalizeInboundContext } from "./inbound-context.js"; +import { buildInboundUserContextPrefix } from "./inbound-meta.js"; +import { normalizeInboundTextNewlines } from "./inbound-text.js"; + +describe("buildInboundUserContextPrefix", () => { + it("omits conversation label block for direct chats", () => { + const text = buildInboundUserContextPrefix({ + ChatType: "direct", + ConversationLabel: "openclaw-tui", + } as TemplateContext); + + expect(text).toBe(""); + }); + + it("keeps conversation label for group chats", () => { + const text = buildInboundUserContextPrefix({ + ChatType: "group", + ConversationLabel: "ops-room", + } as TemplateContext); + + expect(text).toContain("Conversation info (untrusted metadata):"); + expect(text).toContain('"conversation_label": "ops-room"'); + }); +}); + +describe("normalizeInboundTextNewlines", () => { + it("converts CRLF to LF", () => { + expect(normalizeInboundTextNewlines("hello\r\nworld")).toBe("hello\nworld"); + }); + + it("converts CR to LF", () => { + expect(normalizeInboundTextNewlines("hello\rworld")).toBe("hello\nworld"); + }); + + it("preserves literal backslash-n sequences in Windows paths", () => { + const windowsPath = "C:\\Work\\nxxx\\README.md"; + expect(normalizeInboundTextNewlines(windowsPath)).toBe("C:\\Work\\nxxx\\README.md"); + }); + + it("preserves backslash-n in messages containing Windows paths", () => { + const message = "Please read the file at C:\\Work\\nxxx\\README.md"; + expect(normalizeInboundTextNewlines(message)).toBe( + "Please read the file at C:\\Work\\nxxx\\README.md", + ); + }); + + it("preserves multiple backslash-n sequences", () => { + const message = "C:\\new\\notes\\nested"; + expect(normalizeInboundTextNewlines(message)).toBe("C:\\new\\notes\\nested"); + }); + + it("still normalizes actual CRLF while preserving backslash-n", () => { + const message = "Line 1\r\nC:\\Work\\nxxx"; + expect(normalizeInboundTextNewlines(message)).toBe("Line 1\nC:\\Work\\nxxx"); + }); +}); describe("inbound context contract (providers + extensions)", () => { const cases: Array<{ name: string; ctx: MsgContext }> = [