


























@@ -4,6 +4,9 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
44const { loadWebMedia } = vi.hoisted(() => ({
55loadWebMedia: vi.fn(),
66}));
7+const { probeVideoDimensions } = vi.hoisted(() => ({
8+probeVideoDimensions: vi.fn(),
9+}));
710const triggerInternalHook = vi.hoisted(() => vi.fn(async () => {}));
811const messageHookRunner = vi.hoisted(() => ({
912hasHooks: vi.fn<(name: string) => boolean>(() => false),
@@ -28,6 +31,14 @@ vi.mock("openclaw/plugin-sdk/web-media", () => ({
2831loadWebMedia: (...args: unknown[]) => loadWebMedia(...args),
2932}));
303334+vi.mock("openclaw/plugin-sdk/media-runtime", async (importOriginal) => {
35+const actual = await importOriginal<typeof import("openclaw/plugin-sdk/media-runtime")>();
36+return {
37+ ...actual,
38+ probeVideoDimensions,
39+};
40+});
41+3142vi.mock("openclaw/plugin-sdk/hook-runtime", async (importOriginal) => {
3243const actual = await importOriginal<typeof import("openclaw/plugin-sdk/hook-runtime")>();
3344return {
@@ -135,6 +146,8 @@ function createVoiceFailureHarness(params: {
135146describe("deliverReplies", () => {
136147beforeEach(() => {
137148loadWebMedia.mockClear();
149+probeVideoDimensions.mockReset();
150+probeVideoDimensions.mockResolvedValue(undefined);
138151triggerInternalHook.mockReset();
139152messageHookRunner.hasHooks.mockReset();
140153messageHookRunner.hasHooks.mockReturnValue(false);
@@ -489,6 +502,63 @@ describe("deliverReplies", () => {
489502);
490503});
491504505+it("passes probed dimensions to video reply sends", async () => {
506+const runtime = createRuntime();
507+const sendVideo = vi.fn().mockResolvedValue({
508+message_id: 22,
509+chat: { id: "123" },
510+});
511+const bot = createBot({ sendVideo });
512+probeVideoDimensions.mockResolvedValueOnce({ width: 720, height: 1280 });
513+514+mockMediaLoad("video.mp4", "video/mp4", "video");
515+516+await deliverWith({
517+replies: [{ mediaUrl: "https://example.com/video.mp4", text: "hi **boss**" }],
518+ runtime,
519+ bot,
520+});
521+522+expect(probeVideoDimensions).toHaveBeenCalledWith(Buffer.from("video"));
523+expect(sendVideo).toHaveBeenCalledWith(
524+"123",
525+expect.anything(),
526+expect.objectContaining({
527+caption: "hi <b>boss</b>",
528+parse_mode: "HTML",
529+width: 720,
530+height: 1280,
531+}),
532+);
533+});
534+535+it("does not probe GIF reply animations", async () => {
536+const runtime = createRuntime();
537+const sendAnimation = vi.fn().mockResolvedValue({
538+message_id: 23,
539+chat: { id: "123" },
540+});
541+const bot = createBot({ sendAnimation });
542+543+mockMediaLoad("fun.gif", "image/gif", "GIF89a");
544+545+await deliverWith({
546+replies: [{ mediaUrl: "https://example.com/fun.gif", text: "gif" }],
547+ runtime,
548+ bot,
549+});
550+551+expect(probeVideoDimensions).not.toHaveBeenCalled();
552+expect(sendAnimation).toHaveBeenCalledWith(
553+"123",
554+expect.anything(),
555+expect.not.objectContaining({
556+width: expect.any(Number),
557+height: expect.any(Number),
558+}),
559+);
560+});
561+492562it("passes mediaLocalRoots to media loading", async () => {
493563const runtime = createRuntime();
494564const sendPhoto = vi.fn().mockResolvedValue({
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。