fix: harden MEDIA parsing and add tests

This commit is contained in:
Peter Steinberger
2025-11-25 05:25:57 +01:00
parent f4c5f2c193
commit 9bf35d3272
2 changed files with 64 additions and 5 deletions

View File

@@ -146,6 +146,32 @@ describe("config and templating", () => {
expect(result?.mediaUrl).toBe("https://example.com/img.jpg");
});
it("ignores invalid MEDIA lines with whitespace", async () => {
const runSpy = vi.spyOn(index, "runCommandWithTimeout").mockResolvedValue({
stdout: "hello\nMEDIA: not a url with spaces\nrest\n",
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).toBe("hello\nrest");
expect(result?.mediaUrl).toBeUndefined();
});
it("getReplyFromConfig runs command and manages session store", async () => {
const tmpStore = path.join(os.tmpdir(), `warelay-store-${Date.now()}.json`);
vi.spyOn(crypto, "randomUUID").mockReturnValue("session-123");