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

推荐订阅源

月光博客
月光博客
V
Visual Studio Blog
C
Check Point Blog
Google DeepMind News
Google DeepMind News
S
SegmentFault 最新的问题
博客园 - 聂微东
量子位
T
Tailwind CSS Blog
罗磊的独立博客
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Y
Y Combinator Blog
L
LangChain Blog
小众软件
小众软件
Engineering at Meta
Engineering at Meta
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Security Latest
Security Latest
M
MIT News - Artificial intelligence
Know Your Adversary
Know Your Adversary
MongoDB | Blog
MongoDB | Blog
Google DeepMind News
Google DeepMind News
大猫的无限游戏
大猫的无限游戏
H
Help Net Security
爱范儿
爱范儿
T
The Exploit Database - CXSecurity.com
有赞技术团队
有赞技术团队
V
Vulnerabilities – Threatpost
Martin Fowler
Martin Fowler
A
Arctic Wolf
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 司徒正美
Cyberwarzone
Cyberwarzone
阮一峰的网络日志
阮一峰的网络日志
The Hacker News
The Hacker News
Apple Machine Learning Research
Apple Machine Learning Research
宝玉的分享
宝玉的分享
GbyAI
GbyAI
Latest news
Latest news
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
腾讯CDC
AWS News Blog
AWS News Blog
aimingoo的专栏
aimingoo的专栏
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
L
Lohrmann on Cybersecurity
博客园 - Franky
S
Securelist
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Threatpost
美团技术团队

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 test: trim doctor command hotspots · openclaw/openclaw@c66f16a test: isolate agent auth and spawn hotspots · openclaw/openclaw@9285935 test: stabilize MCP startup disposal race · openclaw/openclaw@dd9d2eb test: merge browser contract server suites · openclaw/openclaw@5817a76 test: narrow ollama provider discovery setup · openclaw/openclaw@a0d9598 build: declare qa-lab aimock runtime dependency · openclaw/openclaw@24431e5 test: speed up safe-bins exec harness · openclaw/openclaw@ee856ab test: preserve tool helpers in embedded runner mocks · openclaw/openclaw@acd86a0 refactor: move memory embeddings into provider plugins · openclaw/openclaw@77e6e4c test: reuse system-run temp fixtures · openclaw/openclaw@7e9ff0f test: trim hotspot wait overhead · openclaw/openclaw@12a59b0 Check: avoid duplicate boundary prep · openclaw/openclaw@baf11b8 test: reduce hotspot fixture overhead · openclaw/openclaw@3a59edd feat(ui): overhaul settings and slash command UX (#67819) thanks @Bun… · openclaw/openclaw@2cfb660 QA Matrix: exit cleanly on failure · openclaw/openclaw@42805d2 QA Matrix: isolate scenario coverage · openclaw/openclaw@7e659e1 Matrix: refresh crypto bootstrap state · openclaw/openclaw@94081d8 QA Lab: add provider registry · openclaw/openclaw@bb7e982 Matrix: add plugin changelog · openclaw/openclaw@4acab55 test: trim more hotspot overhead · openclaw/openclaw@f485311 test: trim remaining hotspot tests · openclaw/openclaw@6ba8626 test: narrow hotspot mocks · openclaw/openclaw@dbc8179 test: isolate gemini embedding request helpers · openclaw/openclaw@cd330f5 test: trim memory and mcp hotspots · openclaw/openclaw@fd48dfa test: slim provider registry mocks · openclaw/openclaw@2e08c77 test: harden Parallels update smoke · openclaw/openclaw@1a98090 feat: default Anthropic to Opus 4.7 · openclaw/openclaw@628b454 fix: harden node-host shell payload mutability checks · openclaw/openclaw@75c551e fix: land node-host approval binding for native binaries (#66731) (th… · openclaw/openclaw@29919bb CI: add daily schedule to CodeQL workflow (#67645) · openclaw/openclaw@69d25f5 fix(gateway): capture config hash after plugin auto-enable to prevent… · openclaw/openclaw@8c11210 fix: repair sanitized replay tool results before send (#67620) (thank… · openclaw/openclaw@c3c7a99 fix: restrict HTML timeout short-circuit to transient statuses · openclaw/openclaw@de129a6 fix: keep TUI watchdog bound to active run (#67401) (thanks @xantorres) · openclaw/openclaw@3525273 Gateway/skills: dedupe skills prefix-match + drop dead fallback on log · openclaw/openclaw@d7f489f Extensions/lmstudio: back off inference preload after consecutive fai… · openclaw/openclaw@b555214 TUI/streaming: add watchdog that resets the activity indicator after … · openclaw/openclaw@f44ab20 Agents/tool-loop: enable unknown-tool stream guard by default · openclaw/openclaw@36ed367 Gateway/skills: invalidate session skills snapshot on config write · openclaw/openclaw@b23d59a fix: classify HTML provider error pages correctly (#67642) (thanks @s… · openclaw/openclaw@e588e90 fix(skills): remove unused model-usage import (#67641) · openclaw/openclaw@55f05df docs(changelog): credit codex fix superseded PRs · openclaw/openclaw@e485f24 fix(openai-codex): normalize stale transport metadata in resolution a… · openclaw/openclaw@90801ba CI: pin Docker-related GitHub Actions (#67632) · openclaw/openclaw@f697b01 Android: modernize WebView and discovery API usage (#67627) · openclaw/openclaw@44a6e50 fix(deps): bump hono to 4.12.14 and @hono/node-server to 1.19.14 (GHS… · openclaw/openclaw@fbccc18 fix(deps): bump dompurify to 3.4.0 (#67614) · openclaw/openclaw@2c2dc00 CI: add explicit permissions to all workflow jobs (fixes code-scannin… · openclaw/openclaw@01b7516 fix: register bundled TTS providers and route overrides correctly (#6… · openclaw/openclaw@6ea3cdd fix: align host tilde paths with OS home (#62804) (thanks @stainlu) · openclaw/openclaw@ecfaf64 fix: flush creds queue before reconnect socket open (#67464) (thanks … · openclaw/openclaw@405c63f fix: strip standalone <function> tool call tags from visible text (#6… · openclaw/openclaw@78df859 fix(agents): preserve cli session metadata before transcript persist … · openclaw/openclaw@898fd04 docs(changelog): move cli transcript entry · openclaw/openclaw@c1817c6 fix(agents): normalize cli transcript api field · openclaw/openclaw@3a3fae0 docs(changelog): note cli transcript persistence · openclaw/openclaw@6c343f1 fix(agents): persist cli transcript turns · openclaw/openclaw@b8ef507 fix(msteams): harden security-sensitive flows (#65841) · openclaw/openclaw@c56b56e [Dashboard] Fix exec approval modal overflow for long command content… · openclaw/openclaw@053c5b0 Docs: remove QA changelog entry · openclaw/openclaw@7fd5771 QA: fix private runtime source loading (#67428) · openclaw/openclaw@d5933af docs(gateway): correct protocol.md schema path, hello-ok example, aut… · openclaw/openclaw@489404d CI: pin Node 22 runners to 22.18.0 · openclaw/openclaw@4ffa621 models.authStatus: normalize provider ids + tighten env-backed escape… · openclaw/openclaw@f2fdb9d Update CHANGELOG.md · openclaw/openclaw@7694a92 test(parallels): clean up npm update guard jobs · openclaw/openclaw@045ea7b Plugins: prefer scanDir override paths · openclaw/openclaw@b2974da fix(dreaming): default storage.mode to "separate" so phase blocks sto… · openclaw/openclaw@8c392f0 fix(memory-core): skip dreaming transcript ingestion via session stor… · openclaw/openclaw@a1b01f0 fix: dedupe replayed exec.finished node events (#67281) · openclaw/openclaw@5dcf526
refactor: share chat attachment test helpers · openclaw/openclaw@dacd18a
vincentkoc · 2026-06-02 · via Recent Commits to openclaw:main

@@ -35,6 +35,28 @@ import {

3535

const PNG_1x1 =

3636

"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/woAAn8B9FD5fHAAAAAASUVORK5CYII=";

373738+

type ParsedAttachments = Awaited<ReturnType<typeof parseMessageWithAttachments>>;

39+40+

function pngAttachment(overrides: Partial<ChatAttachment> = {}): ChatAttachment {

41+

return {

42+

type: "image",

43+

mimeType: "image/png",

44+

fileName: "dot.png",

45+

content: PNG_1x1,

46+

...overrides,

47+

};

48+

}

49+50+

function pdfAttachment(overrides: Partial<ChatAttachment> = {}): ChatAttachment {

51+

return {

52+

type: "file",

53+

mimeType: "application/pdf",

54+

fileName: "report.pdf",

55+

content: Buffer.from("%PDF-1.4\n").toString("base64"),

56+

...overrides,

57+

};

58+

}

59+3860

async function parseWithWarnings(

3961

message: string,

4062

attachments: ChatAttachment[],

@@ -48,6 +70,21 @@ async function parseWithWarnings(

4870

return { parsed, logs };

4971

}

507273+

async function parseTextOnlyAttachments(

74+

message: string,

75+

attachments: ChatAttachment[],

76+

logs: string[],

77+

infos?: string[],

78+

) {

79+

const log: NonNullable<Parameters<typeof parseMessageWithAttachments>[2]>["log"] = {

80+

warn: (warning) => logs.push(warning),

81+

};

82+

if (infos) {

83+

log.info = (info) => infos.push(info);

84+

}

85+

return parseMessageWithAttachments(message, attachments, { log, supportsImages: false });

86+

}

87+5188

async function cleanupOffloadedRefs(refs: { id: string }[]) {

5289

await Promise.allSettled(refs.map((ref) => deleteMediaBufferMock(ref.id, "inbound")));

5390

}

@@ -56,6 +93,30 @@ function savedMime() {

5693

return saveMediaBufferMock.mock.calls[0]?.[1];

5794

}

589596+

function expectSingleInlinePng(parsed: ParsedAttachments) {

97+

expect(parsed.images).toHaveLength(1);

98+

expect(parsed.images[0]?.mimeType).toBe("image/png");

99+

}

100+101+

async function expectUnsupportedAttachmentReason(

102+

attachments: ChatAttachment[],

103+

opts: Parameters<typeof parseMessageWithAttachments>[2],

104+

reason: UnsupportedAttachmentError["reason"],

105+

) {

106+

let caught: unknown;

107+

try {

108+

await parseMessageWithAttachments("x", attachments, {

109+

log: { warn: () => {} },

110+

...opts,

111+

});

112+

} catch (err) {

113+

caught = err;

114+

}

115+

expect(caught).toBeInstanceOf(UnsupportedAttachmentError);

116+

expect((caught as UnsupportedAttachmentError).reason).toBe(reason);

117+

expect(saveMediaBufferMock).not.toHaveBeenCalled();

118+

}

119+59120

beforeEach(() => {

60121

saveMediaBufferMock.mockClear();

61122

deleteMediaBufferMock.mockClear();

@@ -67,14 +128,7 @@ afterEach(() => {

6712868129

describe("buildMessageWithAttachments", () => {

69130

it("embeds a single image as data URL", () => {

70-

const msg = buildMessageWithAttachments("see this", [

71-

{

72-

type: "image",

73-

mimeType: "image/png",

74-

fileName: "dot.png",

75-

content: PNG_1x1,

76-

},

77-

]);

131+

const msg = buildMessageWithAttachments("see this", [pngAttachment()]);

78132

expect(msg).toContain("see this");

79133

expect(msg).toContain(`data:image/png;base64,${PNG_1x1}`);

80134

expect(msg).toContain("![dot.png]");

@@ -95,46 +149,25 @@ describe("parseMessageWithAttachments", () => {

95149

it("strips data URL prefix", async () => {

96150

const parsed = await parseMessageWithAttachments(

97151

"see this",

98-

[

99-

{

100-

type: "image",

101-

mimeType: "image/png",

102-

fileName: "dot.png",

103-

content: `data:image/png;base64,${PNG_1x1}`,

104-

},

105-

],

152+

[pngAttachment({ content: `data:image/png;base64,${PNG_1x1}` })],

106153

{ log: { warn: () => {} } },

107154

);

108-

expect(parsed.images).toHaveLength(1);

109-

expect(parsed.images[0]?.mimeType).toBe("image/png");

155+

expectSingleInlinePng(parsed);

110156

expect(parsed.images[0]?.data).toBe(PNG_1x1);

111157

});

112158113159

it("sniffs mime when missing", async () => {

114160

const { parsed, logs } = await parseWithWarnings("see this", [

115-

{

116-

type: "image",

117-

fileName: "dot.png",

118-

content: PNG_1x1,

119-

},

161+

pngAttachment({ mimeType: undefined }),

120162

]);

121163

expect(parsed.message).toBe("see this");

122-

expect(parsed.images).toHaveLength(1);

123-

expect(parsed.images[0]?.mimeType).toBe("image/png");

164+

expectSingleInlinePng(parsed);

124165

expect(parsed.images[0]?.data).toBe(PNG_1x1);

125166

expect(logs).toHaveLength(0);

126167

});

127168128169

it("accepts non-image payloads and offloads them via the media store", async () => {

129-

const pdf = Buffer.from("%PDF-1.4\n%µ¶\n1 0 obj\n<<>>\nendobj\n").toString("base64");

130-

const { parsed, logs } = await parseWithWarnings("read this", [

131-

{

132-

type: "file",

133-

mimeType: "application/pdf",

134-

fileName: "report.pdf",

135-

content: pdf,

136-

},

137-

]);

170+

const { parsed, logs } = await parseWithWarnings("read this", [pdfAttachment()]);

138171

expect(parsed.images).toHaveLength(0);

139172

expect(parsed.offloadedRefs).toHaveLength(1);

140173

const ref = parsed.offloadedRefs[0];

@@ -166,37 +199,16 @@ describe("parseMessageWithAttachments", () => {

166199167200

it("prefers sniffed mime type and logs mismatch", async () => {

168201

const { parsed, logs } = await parseWithWarnings("x", [

169-

{

170-

type: "image",

171-

mimeType: "image/jpeg",

172-

fileName: "dot.png",

173-

content: PNG_1x1,

174-

},

202+

pngAttachment({ mimeType: "image/jpeg" }),

175203

]);

176-

expect(parsed.images).toHaveLength(1);

177-

expect(parsed.images[0]?.mimeType).toBe("image/png");

204+

expectSingleInlinePng(parsed);

178205

expect(logs).toHaveLength(1);

179206

expect(logs[0]).toMatch(/mime mismatch/i);

180207

});

181208182209

it("keeps image inline and offloads non-image side by side", async () => {

183-

const pdf = Buffer.from("%PDF-1.4\n").toString("base64");

184-

const { parsed } = await parseWithWarnings("x", [

185-

{

186-

type: "image",

187-

mimeType: "image/png",

188-

fileName: "dot.png",

189-

content: PNG_1x1,

190-

},

191-

{

192-

type: "file",

193-

mimeType: "application/pdf",

194-

fileName: "report.pdf",

195-

content: pdf,

196-

},

197-

]);

198-

expect(parsed.images).toHaveLength(1);

199-

expect(parsed.images[0]?.mimeType).toBe("image/png");

210+

const { parsed } = await parseWithWarnings("x", [pngAttachment(), pdfAttachment()]);

211+

expectSingleInlinePng(parsed);

200212

expect(parsed.offloadedRefs).toHaveLength(1);

201213

expect(parsed.offloadedRefs[0]?.mimeType).toBe("application/pdf");

202214

expect(parsed.imageOrder).toEqual(["inline"]);

@@ -215,14 +227,9 @@ describe("parseMessageWithAttachments", () => {

215227

const bigPng = Buffer.alloc(2_100_000);

216228

bigPng.set([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a], 0);

217229

const { parsed } = await parseWithWarnings("x", [

218-

{ type: "file", mimeType: "application/pdf", fileName: "report.pdf", content: pdf },

219-

{ type: "image", mimeType: "image/png", fileName: "dot.png", content: PNG_1x1 },

220-

{

221-

type: "image",

222-

mimeType: "image/png",

223-

fileName: "big.png",

224-

content: bigPng.toString("base64"),

225-

},

230+

pdfAttachment({ content: pdf }),

231+

pngAttachment(),

232+

pngAttachment({ fileName: "big.png", content: bigPng.toString("base64") }),

226233

]);

227234

expect(parsed.images).toHaveLength(1);

228235

expect(parsed.offloadedRefs.map((ref) => ref.mimeType)).toEqual([

@@ -333,79 +340,43 @@ describe("parseMessageWithAttachments validation errors", () => {

333340

});

334341335342

it("throws UnsupportedAttachmentError on non-image when acceptNonImage is false", async () => {

336-

const pdf = Buffer.from("%PDF-1.4\n").toString("base64");

337-

let caught: unknown;

338-

try {

339-

await parseMessageWithAttachments(

340-

"x",

341-

[{ type: "file", mimeType: "application/pdf", fileName: "a.pdf", content: pdf }],

342-

{ log: { warn: () => {} }, acceptNonImage: false },

343-

);

344-

} catch (err) {

345-

caught = err;

346-

}

347-

expect(caught).toBeInstanceOf(UnsupportedAttachmentError);

348-

expect((caught as UnsupportedAttachmentError).reason).toBe("unsupported-non-image");

349-

expect(saveMediaBufferMock).not.toHaveBeenCalled();

343+

await expectUnsupportedAttachmentReason(

344+

[pdfAttachment({ fileName: "a.pdf" })],

345+

{ acceptNonImage: false },

346+

"unsupported-non-image",

347+

);

350348

});

351349352350

it("rejects generic-container payloads mislabeled as images when acceptNonImage is false", async () => {

353351

const docx = Buffer.from("PK\u0003\u0004fake-docx-content").toString("base64");

354-

let caught: unknown;

355-

try {

356-

await parseMessageWithAttachments(

357-

"x",

358-

[{ type: "file", mimeType: "image/png", fileName: "report.docx", content: docx }],

359-

{ log: { warn: () => {} }, acceptNonImage: false },

360-

);

361-

} catch (err) {

362-

caught = err;

363-

}

364-

expect(caught).toBeInstanceOf(UnsupportedAttachmentError);

365-

expect((caught as UnsupportedAttachmentError).reason).toBe("unsupported-non-image");

366-

expect(saveMediaBufferMock).not.toHaveBeenCalled();

352+

await expectUnsupportedAttachmentReason(

353+

[pdfAttachment({ mimeType: "image/png", fileName: "report.docx", content: docx })],

354+

{ acceptNonImage: false },

355+

"unsupported-non-image",

356+

);

367357

});

368358369359

it("rejects generic-container payloads with image mime and image filename when acceptNonImage is false", async () => {

370360

const zip = Buffer.from("PK\u0003\u0004zip-archive-bytes").toString("base64");

371-

let caught: unknown;

372-

try {

373-

await parseMessageWithAttachments(

374-

"x",

375-

[{ type: "image", mimeType: "image/png", fileName: "fake.png", content: zip }],

376-

{ log: { warn: () => {} }, acceptNonImage: false },

377-

);

378-

} catch (err) {

379-

caught = err;

380-

}

381-

expect(caught).toBeInstanceOf(UnsupportedAttachmentError);

382-

expect((caught as UnsupportedAttachmentError).reason).toBe("unsupported-non-image");

383-

expect(saveMediaBufferMock).not.toHaveBeenCalled();

361+

await expectUnsupportedAttachmentReason(

362+

[pngAttachment({ fileName: "fake.png", content: zip })],

363+

{ acceptNonImage: false },

364+

"unsupported-non-image",

365+

);

384366

});

385367386368

it("throws UnsupportedAttachmentError on image when supportsInlineImages is false", async () => {

387-

let caught: unknown;

388-

try {

389-

await parseMessageWithAttachments(

390-

"x",

391-

[{ type: "image", mimeType: "image/png", fileName: "dot.png", content: PNG_1x1 }],

392-

{ log: { warn: () => {} }, supportsInlineImages: false },

393-

);

394-

} catch (err) {

395-

caught = err;

396-

}

397-

expect(caught).toBeInstanceOf(UnsupportedAttachmentError);

398-

expect((caught as UnsupportedAttachmentError).reason).toBe("text-only-image");

399-

expect(saveMediaBufferMock).not.toHaveBeenCalled();

369+

await expectUnsupportedAttachmentReason(

370+

[pngAttachment()],

371+

{ supportsInlineImages: false },

372+

"text-only-image",

373+

);

400374

});

401375402376

it("still offloads non-image attachments when supportsInlineImages is false", async () => {

403-

const pdf = Buffer.from("%PDF-1.4\n").toString("base64");

404-

const { parsed } = await parseWithWarnings(

405-

"x",

406-

[{ type: "file", mimeType: "application/pdf", fileName: "a.pdf", content: pdf }],

407-

{ supportsInlineImages: false },

408-

);

377+

const { parsed } = await parseWithWarnings("x", [pdfAttachment({ fileName: "a.pdf" })], {

378+

supportsInlineImages: false,

379+

});

409380

expect(parsed.offloadedRefs).toHaveLength(1);

410381

expect(parsed.offloadedRefs[0]?.mimeType).toBe("application/pdf");

411382

expect(saveMediaBufferMock).toHaveBeenCalledOnce();

@@ -447,37 +418,17 @@ describe("parseMessageWithAttachments validation errors", () => {

447418448419

it("keeps image sniff fallback for generic image attachments", async () => {

449420

const { parsed, logs } = await parseWithWarnings("see this", [

450-

{

451-

type: "file",

452-

mimeType: "application/octet-stream",

453-

fileName: "dot",

454-

content: PNG_1x1,

455-

},

421+

pngAttachment({ type: "file", mimeType: "application/octet-stream", fileName: "dot" }),

456422

]);

457-

expect(parsed.images).toHaveLength(1);

458-

expect(parsed.images[0]?.mimeType).toBe("image/png");

423+

expectSingleInlinePng(parsed);

459424

expect(parsed.offloadedRefs).toHaveLength(0);

460425

expect(logs).toHaveLength(0);

461426

});

462427463428

it("offloads images for text-only models instead of dropping them", async () => {

464429

const logs: string[] = [];

465430

const infos: string[] = [];

466-

const parsed = await parseMessageWithAttachments(

467-

"see this",

468-

[

469-

{

470-

type: "image",

471-

mimeType: "image/png",

472-

fileName: "dot.png",

473-

content: PNG_1x1,

474-

},

475-

],

476-

{

477-

log: { info: (message) => infos.push(message), warn: (warning) => logs.push(warning) },

478-

supportsImages: false,

479-

},

480-

);

431+

const parsed = await parseTextOnlyAttachments("see this", [pngAttachment()], logs, infos);

481432482433

try {

483434

expect(parsed.images).toHaveLength(0);

@@ -503,10 +454,7 @@ describe("parseMessageWithAttachments validation errors", () => {

503454

content: PNG_1x1,

504455

}),

505456

);

506-

const parsed = await parseMessageWithAttachments("see these", attachments, {

507-

log: { warn: (warning) => logs.push(warning) },

508-

supportsImages: false,

509-

});

457+

const parsed = await parseTextOnlyAttachments("see these", attachments, logs);

510458511459

try {

512460

expect(parsed.images).toHaveLength(0);