惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
C
Check Point Blog
I
InfoQ
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta
月光博客
月光博客
Recent Announcements
Recent Announcements
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tailwind CSS Blog
Y
Y Combinator Blog
博客园 - Franky
博客园_首页
罗磊的独立博客
量子位
美团技术团队
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
大猫的无限游戏
大猫的无限游戏
爱范儿
爱范儿
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Martin Fowler
Martin Fowler
博客园 - 叶小钗
aimingoo的专栏
aimingoo的专栏

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix: route rich menu images through media loader · opencl...
jesse-merhi · 2026-04-29 · via Recent Commits to openclaw:main

@@ -1,13 +1,30 @@

1-

import { describe, expect, it } from "vitest";

1+

import fs from "node:fs/promises";

2+

import os from "node:os";

3+

import path from "node:path";

4+

import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";

5+

import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";

26

import {

7+

createDefaultMenuConfig,

38

createGridLayout,

9+

datetimePickerAction,

410

messageAction,

5-

uriAction,

611

postbackAction,

7-

datetimePickerAction,

8-

createDefaultMenuConfig,

12+

uploadRichMenuImage,

13+

uriAction,

914

} from "./rich-menu.js";

101516+

const { setRichMenuImageMock, MessagingApiBlobClientMock } = vi.hoisted(() => {

17+

const setRichMenuImageMock = vi.fn();

18+

const MessagingApiBlobClientMock = vi.fn(function () {

19+

return { setRichMenuImage: setRichMenuImageMock };

20+

});

21+

return { setRichMenuImageMock, MessagingApiBlobClientMock };

22+

});

23+24+

vi.mock("@line/bot-sdk", () => ({

25+

messagingApi: { MessagingApiBlobClient: MessagingApiBlobClientMock },

26+

}));

27+1128

describe("messageAction", () => {

1229

it("creates message actions with explicit or default text", () => {

1330

const cases = [

@@ -205,3 +222,89 @@ describe("createDefaultMenuConfig", () => {

205222

expect(commands).toContain("/settings");

206223

});

207224

});

225+226+

const richMenuUploadCfg: OpenClawConfig = {

227+

channels: {

228+

line: {

229+

channelAccessToken: "line-token",

230+

channelSecret: "line-secret",

231+

},

232+

},

233+

};

234+235+

describe("uploadRichMenuImage", () => {

236+

let tempRoot: string;

237+238+

beforeEach(async () => {

239+

tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-line-rich-menu-"));

240+

setRichMenuImageMock.mockReset();

241+

MessagingApiBlobClientMock.mockClear();

242+

});

243+244+

afterEach(async () => {

245+

await fs.rm(tempRoot, { recursive: true, force: true });

246+

});

247+248+

it("loads local image paths through approved media localRoots", async () => {

249+

const workspaceDir = path.join(tempRoot, "workspace");

250+

await fs.mkdir(workspaceDir, { recursive: true });

251+

const imagePath = path.join(workspaceDir, "menu.png");

252+

const imageBytes = Buffer.from([

253+

0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x00,

254+

]);

255+

await fs.writeFile(imagePath, imageBytes);

256+257+

await uploadRichMenuImage("rich-menu-1", imagePath, {

258+

cfg: richMenuUploadCfg,

259+

mediaLocalRoots: [workspaceDir],

260+

});

261+262+

expect(MessagingApiBlobClientMock).toHaveBeenCalledWith({ channelAccessToken: "line-token" });

263+

expect(setRichMenuImageMock).toHaveBeenCalledOnce();

264+

const [richMenuId, blob] = setRichMenuImageMock.mock.calls[0] ?? [];

265+

expect(richMenuId).toBe("rich-menu-1");

266+

expect(blob).toBeInstanceOf(Blob);

267+

expect((blob as Blob).type).toBe("image/png");

268+

await expect((blob as Blob).arrayBuffer()).resolves.toEqual(

269+

imageBytes.buffer.slice(imageBytes.byteOffset, imageBytes.byteOffset + imageBytes.byteLength),

270+

);

271+

});

272+273+

it("rejects local image paths outside approved media localRoots before uploading", async () => {

274+

const workspaceDir = path.join(tempRoot, "workspace");

275+

const outsideDir = path.join(tempRoot, "outside");

276+

await fs.mkdir(workspaceDir, { recursive: true });

277+

await fs.mkdir(outsideDir, { recursive: true });

278+

const outsideImagePath = path.join(outsideDir, "menu.jpg");

279+

await fs.writeFile(outsideImagePath, Buffer.from([0xff, 0xd8, 0xff, 0xd9]));

280+281+

await expect(

282+

uploadRichMenuImage("rich-menu-1", outsideImagePath, {

283+

cfg: richMenuUploadCfg,

284+

mediaLocalRoots: [workspaceDir],

285+

}),

286+

).rejects.toThrow(/Local media path is not under an allowed directory/i);

287+288+

expect(setRichMenuImageMock).not.toHaveBeenCalled();

289+

});

290+291+

it("preserves extension-based content-type fallback for approved local paths", async () => {

292+

const workspaceDir = path.join(tempRoot, "workspace");

293+

await fs.mkdir(workspaceDir, { recursive: true });

294+

const imagePath = path.join(workspaceDir, "menu.jpg");

295+

const imageBytes = Buffer.from("placeholder image bytes");

296+

await fs.writeFile(imagePath, imageBytes);

297+298+

await uploadRichMenuImage("rich-menu-2", imagePath, {

299+

cfg: richMenuUploadCfg,

300+

mediaLocalRoots: [workspaceDir],

301+

});

302+303+

expect(setRichMenuImageMock).toHaveBeenCalledOnce();

304+

const blob = setRichMenuImageMock.mock.calls[0]?.[1] as Blob;

305+

expect(blob.type).toBe("image/jpeg");

306+

await expect(blob.arrayBuffer()).resolves.toEqual(

307+

imageBytes.buffer.slice(imageBytes.byteOffset, imageBytes.byteOffset + imageBytes.byteLength),

308+

);

309+

});

310+

});