|
1 | 1 | // Qa Channel tests cover inbound plugin behavior. |
2 | 2 | import path from "node:path"; |
3 | 3 | import { createPluginRuntimeMock } from "openclaw/plugin-sdk/channel-test-helpers"; |
| 4 | +import { saveMediaBuffer } from "openclaw/plugin-sdk/media-runtime"; |
4 | 5 | import { loadOutboundMediaFromUrl } from "openclaw/plugin-sdk/outbound-media"; |
5 | 6 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
6 | 7 | import { setQaChannelRuntime } from "../api.js"; |
@@ -33,6 +34,15 @@ vi.mock("openclaw/plugin-sdk/outbound-media", async (importOriginal) => { |
33 | 34 | }; |
34 | 35 | }); |
35 | 36 |
|
| 37 | +vi.mock("openclaw/plugin-sdk/media-runtime", async (importOriginal) => ({ |
| 38 | + ...(await importOriginal<typeof import("openclaw/plugin-sdk/media-runtime")>()), |
| 39 | + saveMediaBuffer: vi.fn(async () => ({ |
| 40 | + id: "stored-audio.ogg", |
| 41 | + path: "/tmp/openclaw-media/stored-audio.ogg", |
| 42 | + contentType: "audio/ogg", |
| 43 | + })), |
| 44 | +})); |
| 45 | + |
36 | 46 | type HandleQaInboundParams = Parameters<typeof handleQaInbound>[0]; |
37 | 47 |
|
38 | 48 | function createQaInboundParams( |
@@ -510,6 +520,37 @@ describe("handleQaInbound", () => { |
510 | 520 | expect(ctxPayload.media?.every((fact) => fact.path === undefined)).toBe(true); |
511 | 521 | }); |
512 | 522 |
|
| 523 | + it("projects saved inline attachments through a media-store URL", async () => { |
| 524 | + const runtime = createPluginRuntimeMock(); |
| 525 | + setQaChannelRuntime(runtime); |
| 526 | + |
| 527 | + await handleQaInbound( |
| 528 | + createQaInboundParams({ |
| 529 | + message: { |
| 530 | + attachments: [ |
| 531 | + { |
| 532 | + id: "audio-1", |
| 533 | + kind: "audio", |
| 534 | + mimeType: "audio/ogg", |
| 535 | + fileName: "voice-note.ogg", |
| 536 | + contentBase64: Buffer.alloc(2048, 0x52).toString("base64"), |
| 537 | + mediaFactCarrier: "media-store-url", |
| 538 | + }, |
| 539 | + ], |
| 540 | + }, |
| 541 | + }), |
| 542 | + ); |
| 543 | + |
| 544 | + expect(saveMediaBuffer).toHaveBeenCalledOnce(); |
| 545 | + const media = firstRunAssembledParams(runtime).ctxPayload.media; |
| 546 | + expect(media).toHaveLength(1); |
| 547 | + expect(media?.[0]).toMatchObject({ |
| 548 | + path: undefined, |
| 549 | + url: "media://inbound/stored-audio.ogg", |
| 550 | + contentType: "audio/ogg", |
| 551 | + }); |
| 552 | + }); |
| 553 | + |
513 | 554 | it("rejects non-http attachment URLs without dropping the message", async () => { |
514 | 555 | const runtime = createPluginRuntimeMock(); |
515 | 556 | const warn = vi.spyOn(console, "warn").mockImplementation(() => undefined); |
|
0 commit comments