




























@@ -26,7 +26,6 @@ vi.mock("../media/store.js", async (importOriginal) => {
2626import { MAX_IMAGE_BYTES } from "@openclaw/media-core/constants";
2727import type { OpenClawConfig } from "../config/types.openclaw.js";
2828import {
29-buildMessageWithAttachments,
3029type ChatAttachment,
3130DEFAULT_CHAT_ATTACHMENT_MAX_MB,
3231parseMessageWithAttachments,
@@ -135,25 +134,6 @@ afterEach(() => {
135134vi.restoreAllMocks();
136135});
137136138-describe("buildMessageWithAttachments", () => {
139-it("embeds a single image as data URL", () => {
140-const msg = buildMessageWithAttachments("see this", [pngAttachment()]);
141-expect(msg).toContain("see this");
142-expect(msg).toContain(`data:image/png;base64,${PNG_1x1}`);
143-expect(msg).toContain("![dot.png]");
144-});
145-146-it("rejects non-image mime types", () => {
147-const bad: ChatAttachment = {
148-type: "file",
149-mimeType: "application/pdf",
150-fileName: "a.pdf",
151-content: "AAA",
152-};
153-expect(() => buildMessageWithAttachments("x", [bad])).toThrow(/image/);
154-});
155-});
156-157137describe("parseMessageWithAttachments", () => {
158138it("strips data URL prefix", async () => {
159139const parsed = await parseMessageWithAttachments(
@@ -508,22 +488,21 @@ describe("resolveChatAttachmentMaxBytes", () => {
508488});
509489});
510490511-describe("shared attachment validation", () => {
512-it("rejects invalid base64 content for both builder and parser", async () => {
491+describe("attachment validation", () => {
492+it("rejects invalid base64 content", async () => {
513493const bad: ChatAttachment = {
514494type: "image",
515495mimeType: "image/png",
516496fileName: "dot.png",
517497content: "%not-base64%",
518498};
519499520-expect(() => buildMessageWithAttachments("x", [bad])).toThrow(/base64/i);
521500await expect(
522501parseMessageWithAttachments("x", [bad], { log: { warn: () => {} } }),
523502).rejects.toThrow(/base64/i);
524503});
525504526-it("rejects images over limit for both builder and parser without decoding base64", async () => {
505+it("rejects images over limit without decoding base64", async () => {
527506const big = "A".repeat(10_000);
528507const att: ChatAttachment = {
529508type: "image",
@@ -534,9 +513,6 @@ describe("shared attachment validation", () => {
534513535514const fromSpy = vi.spyOn(Buffer, "from");
536515try {
537-expect(() => buildMessageWithAttachments("x", [att], { maxBytes: 16 })).toThrow(
538-/exceeds size limit/i,
539-);
540516await expect(
541517parseMessageWithAttachments("x", [att], { maxBytes: 16, log: { warn: () => {} } }),
542518).rejects.toThrow(/exceeds size limit/i);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。