test: add URL-only audio skip test for tiny remote attachments

This commit is contained in:
Glucksberg
2026-02-04 14:41:02 +00:00
committed by Peter Steinberger
parent 43f94e3ab8
commit 8039ef7dba

View File

@@ -360,6 +360,50 @@ describe("applyMediaUnderstanding", () => {
expect(ctx.Body).toBe("[Audio]\nTranscript:\nremote transcript");
});
it("skips URL-only audio when remote file is too small", async () => {
const { applyMediaUnderstanding } = await loadApply();
// Override the default mock to return a tiny buffer (below MIN_AUDIO_FILE_BYTES)
mockedFetchRemoteMedia.mockResolvedValueOnce({
buffer: Buffer.alloc(100),
contentType: "audio/ogg",
fileName: "tiny.ogg",
});
const ctx: MsgContext = {
Body: "<media:audio>",
MediaUrl: "https://example.com/tiny.ogg",
MediaType: "audio/ogg",
ChatType: "dm",
};
const transcribeAudio = vi.fn(async () => ({ text: "should-not-run" }));
const cfg: OpenClawConfig = {
tools: {
media: {
audio: {
enabled: true,
maxBytes: 1024 * 1024,
scope: {
default: "deny",
rules: [{ action: "allow", match: { chatType: "direct" } }],
},
models: [{ provider: "groq" }],
},
},
},
};
const result = await applyMediaUnderstanding({
ctx,
cfg,
providers: {
groq: { id: "groq", transcribeAudio },
},
});
expect(transcribeAudio).not.toHaveBeenCalled();
expect(result.appliedAudio).toBe(false);
});
it("skips audio transcription when attachment exceeds maxBytes", async () => {
const ctx = await createAudioCtx({
fileName: "large.wav",