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

推荐订阅源

GbyAI
GbyAI
Martin Fowler
Martin Fowler
I
InfoQ
腾讯CDC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
爱范儿
爱范儿
Microsoft Security Blog
Microsoft Security Blog
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
博客园 - 聂微东
Microsoft Azure Blog
Microsoft Azure Blog
D
Docker
博客园 - 三生石上(FineUI控件)
Y
Y Combinator Blog
博客园 - Franky
Engineering at Meta
Engineering at Meta
B
Blog
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
Jina AI
Jina AI
V
Visual Studio Blog

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(imessage): make inbound image attachments readable by...
homer-byte · 2026-05-13 · via Recent Commits to openclaw:main

@@ -0,0 +1,120 @@

1+

import fs from "node:fs/promises";

2+

import os from "node:os";

3+

import path from "node:path";

4+

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

5+

import { stageIMessageAttachments } from "./media-staging.js";

6+7+

let tempDir: string;

8+9+

async function writeTempFile(name: string, contents: Buffer | string): Promise<string> {

10+

const filePath = path.join(tempDir, name);

11+

await fs.writeFile(filePath, contents);

12+

return filePath;

13+

}

14+15+

describe("stageIMessageAttachments", () => {

16+

beforeEach(async () => {

17+

tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-imessage-media-"));

18+

});

19+20+

afterEach(async () => {

21+

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

22+

});

23+24+

it("copies allowed iMessage attachments into the inbound media store", async () => {

25+

const sourcePath = await writeTempFile("photo.png", Buffer.from("png-bytes"));

26+

const saveMediaBuffer = vi.fn(async () => ({

27+

id: "saved.png",

28+

path: "/state/media/inbound/saved.png",

29+

size: 9,

30+

contentType: "image/png",

31+

}));

32+33+

await expect(

34+

stageIMessageAttachments(

35+

[{ original_path: sourcePath, mime_type: "image/png", missing: false }],

36+

{ maxBytes: 1024, allowedRoots: [tempDir], deps: { saveMediaBuffer } },

37+

),

38+

).resolves.toEqual([{ path: "/state/media/inbound/saved.png", contentType: "image/png" }]);

39+40+

expect(saveMediaBuffer).toHaveBeenCalledWith(

41+

Buffer.from("png-bytes"),

42+

"image/png",

43+

"inbound",

44+

1024,

45+

"photo.png",

46+

);

47+

});

48+49+

it("drops attachments whose canonical path escapes the allowed root", async () => {

50+

const allowedRoot = path.join(tempDir, "allowed");

51+

const outsideRoot = path.join(tempDir, "outside");

52+

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

53+

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

54+

const outsidePath = path.join(outsideRoot, "secret.png");

55+

await fs.writeFile(outsidePath, Buffer.from("secret-bytes"));

56+

await fs.symlink(outsideRoot, path.join(allowedRoot, "link"), "dir");

57+58+

const saveMediaBuffer = vi.fn();

59+

const logVerbose = vi.fn();

60+61+

await expect(

62+

stageIMessageAttachments(

63+

[

64+

{

65+

original_path: path.join(allowedRoot, "link", "secret.png"),

66+

mime_type: "image/png",

67+

missing: false,

68+

},

69+

],

70+

{ maxBytes: 1024, allowedRoots: [allowedRoot], deps: { saveMediaBuffer, logVerbose } },

71+

),

72+

).resolves.toEqual([]);

73+74+

expect(saveMediaBuffer).not.toHaveBeenCalled();

75+

expect(logVerbose).toHaveBeenCalledWith(

76+

expect.stringContaining("attachment path resolves outside allowed roots"),

77+

);

78+

});

79+80+

it("converts HEIC iMessage attachments to JPEG before staging", async () => {

81+

const sourcePath = await writeTempFile("IMG_0001.HEIC", Buffer.from("heic-bytes"));

82+

const saveMediaBuffer = vi.fn(async () => ({

83+

id: "saved.jpg",

84+

path: "/state/media/inbound/saved.jpg",

85+

size: 10,

86+

contentType: "image/jpeg",

87+

}));

88+

const convertHeicToJpeg = vi.fn(async () => Buffer.from("jpeg-bytes"));

89+90+

await stageIMessageAttachments(

91+

[{ original_path: sourcePath, mime_type: "image/heic", missing: false }],

92+

{ maxBytes: 1024, deps: { saveMediaBuffer, convertHeicToJpeg } },

93+

);

94+95+

expect(convertHeicToJpeg).toHaveBeenCalledWith(sourcePath, 1024);

96+

expect(saveMediaBuffer).toHaveBeenCalledWith(

97+

Buffer.from("jpeg-bytes"),

98+

"image/jpeg",

99+

"inbound",

100+

1024,

101+

"IMG_0001.jpg",

102+

);

103+

});

104+105+

it("drops attachments over the inbound media limit", async () => {

106+

const sourcePath = await writeTempFile("huge.png", Buffer.from("too large"));

107+

const saveMediaBuffer = vi.fn();

108+

const logVerbose = vi.fn();

109+110+

await expect(

111+

stageIMessageAttachments(

112+

[{ original_path: sourcePath, mime_type: "image/png", missing: false }],

113+

{ maxBytes: 4, deps: { saveMediaBuffer, logVerbose } },

114+

),

115+

).resolves.toEqual([]);

116+117+

expect(saveMediaBuffer).not.toHaveBeenCalled();

118+

expect(logVerbose).toHaveBeenCalledWith(expect.stringContaining("failed to stage"));

119+

});

120+

});