auto-reply: handle empty stdout gracefully

This commit is contained in:
Peter Steinberger
2025-11-25 06:33:49 +01:00
parent 5b17aba4fc
commit 716f31f17a
2 changed files with 44 additions and 23 deletions

View File

@@ -274,6 +274,32 @@ describe("config and templating", () => {
expect(result?.mediaUrl).toBeUndefined();
});
it("injects fallback text when command returns nothing", async () => {
const runSpy = vi.spyOn(index, "runCommandWithTimeout").mockResolvedValue({
stdout: "",
stderr: "",
code: 0,
signal: null,
killed: false,
});
const cfg = {
inbound: {
reply: {
mode: "command" as const,
command: ["echo", "{{Body}}"],
},
},
};
const result = await index.getReplyFromConfig(
{ Body: "hi", From: "+1", To: "+2" },
undefined,
cfg,
runSpy,
);
expect(result?.text).toContain("command produced no output");
expect(result?.mediaUrl).toBeUndefined();
});
it("splitMediaFromOutput strips media token and preserves text", () => {
const { text, mediaUrl } = splitMediaFromOutput(
"line1\nMEDIA:https://x/y.png\nline2",