Files
openclaw/src/auto-reply/reply/reply-inline.test.ts
scoootscooob 6200e242b2 fix(auto-reply): preserve newlines in stripInlineStatus and extractInlineSimpleCommand
The /\s+/g whitespace normalizer collapsed newlines along with spaces/tabs,
destroying paragraph structure in multi-line messages before they reached
the LLM. Use /[^\S\n]+/g to only collapse horizontal whitespace while
preserving line breaks.

Closes #32216

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 22:43:10 +00:00

55 lines
2.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { extractInlineSimpleCommand, stripInlineStatus } from "./reply-inline.js";
describe("stripInlineStatus", () => {
it("strips /status directive from message", () => {
const result = stripInlineStatus("/status hello world");
expect(result.cleaned).toBe("hello world");
expect(result.didStrip).toBe(true);
});
it("preserves newlines in multi-line messages", () => {
const result = stripInlineStatus("first line\nsecond line\nthird line");
expect(result.cleaned).toBe("first line\nsecond line\nthird line");
expect(result.didStrip).toBe(false);
});
it("preserves newlines when stripping /status", () => {
const result = stripInlineStatus("/status\nfirst paragraph\n\nsecond paragraph");
expect(result.cleaned).toBe("first paragraph\n\nsecond paragraph");
expect(result.didStrip).toBe(true);
});
it("collapses horizontal whitespace but keeps newlines", () => {
const result = stripInlineStatus("hello world\n indented line");
expect(result.cleaned).toBe("hello world\n indented line");
// didStrip is true because whitespace normalization changed the string
expect(result.didStrip).toBe(true);
});
it("returns empty string for whitespace-only input", () => {
const result = stripInlineStatus(" ");
expect(result.cleaned).toBe("");
expect(result.didStrip).toBe(false);
});
});
describe("extractInlineSimpleCommand", () => {
it("extracts /help command", () => {
const result = extractInlineSimpleCommand("/help some question");
expect(result?.command).toBe("/help");
expect(result?.cleaned).toBe("some question");
});
it("preserves newlines after extracting command", () => {
const result = extractInlineSimpleCommand("/help first line\nsecond line");
expect(result?.command).toBe("/help");
expect(result?.cleaned).toBe("first line\nsecond line");
});
it("returns null for empty body", () => {
expect(extractInlineSimpleCommand("")).toBeNull();
expect(extractInlineSimpleCommand(undefined)).toBeNull();
});
});