ai-chatbot/tests/routes/openclaw-video-attachments.test.ts

93 lines
2.7 KiB
TypeScript

import { expect, test } from "@playwright/test";
import {
buildOpenClawVideoDisplayText,
buildOpenClawVideoReferenceText,
getOpenClawChatVideoContentType,
isOpenClawChatVideoFile,
normalizeOpenClawChatMediaAttachments,
OPENCLAW_CHAT_VIDEO_MAX_FILES,
} from "@/lib/openclaw-chat/media-attachments";
test.describe("OpenClaw video attachments", () => {
test("accepts the supported browser video formats by MIME type or extension", () => {
expect(
isOpenClawChatVideoFile({
name: "市场分析.mp4",
type: "video/mp4",
})
).toBe(true);
expect(
isOpenClawChatVideoFile({
name: "素材.MOV",
type: "application/octet-stream",
})
).toBe(true);
expect(
getOpenClawChatVideoContentType({
name: "演示.m4v",
type: "",
})
).toBe("video/x-m4v");
expect(
isOpenClawChatVideoFile({
name: "说明.pdf",
type: "application/pdf",
})
).toBe(false);
});
test("normalizes public video URLs to the OpenClaw attachment contract", () => {
expect(
normalizeOpenClawChatMediaAttachments([
{
type: "video",
url: "https://cdn.example.com/demo.mp4",
name: "demo.mp4",
contentType: "video/mp4",
},
])
).toEqual([
{
type: "video",
url: "https://cdn.example.com/demo.mp4",
name: "demo.mp4",
content_type: "video/mp4",
},
]);
});
test("rejects private schemes, duplicates, and videos beyond the gateway limit", () => {
const attachments = normalizeOpenClawChatMediaAttachments([
{ type: "video", url: "https://cdn.example.com/one.mp4" },
{ type: "video", url: "https://cdn.example.com/two.mov" },
{ type: "video", url: "https://cdn.example.com/three.webm" },
{ type: "video", url: "file:///tmp/private.mp4" },
{ type: "video", url: "https://cdn.example.com/one.mp4" },
]);
expect(attachments).toHaveLength(OPENCLAW_CHAT_VIDEO_MAX_FILES);
expect(attachments.map((attachment) => attachment.url)).toEqual([
"https://cdn.example.com/one.mp4",
"https://cdn.example.com/two.mov",
]);
});
test("builds a readable fallback message without exposing storage credentials", () => {
const attachments = normalizeOpenClawChatMediaAttachments([
{
type: "video",
url: "https://cdn.example.com/review.mp4",
name: "review.mp4",
},
]);
expect(buildOpenClawVideoDisplayText(attachments)).toContain("review.mp4");
expect(buildOpenClawVideoReferenceText(attachments)).toContain(
"https://cdn.example.com/review.mp4"
);
expect(buildOpenClawVideoReferenceText(attachments)).not.toContain(
"Authorization"
);
});
});