mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 00:00:22 +00:00
perf(test): consolidate inbound reply suites
This commit is contained in:
@@ -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"');
|
||||
});
|
||||
});
|
||||
@@ -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");
|
||||
});
|
||||
});
|
||||
@@ -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 }> = [
|
||||
Reference in New Issue
Block a user