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

推荐订阅源

IT之家
IT之家
T
Tailwind CSS Blog
V
V2EX
阮一峰的网络日志
阮一峰的网络日志
H
Help Net Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
腾讯CDC
GbyAI
GbyAI
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Last Week in AI
Last Week in AI
A
About on SuperTechFans
L
LangChain Blog
Engineering at Meta
Engineering at Meta
F
Fortinet All Blogs
G
Google Developers Blog
The Cloudflare Blog
云风的 BLOG
云风的 BLOG
D
Docker
博客园 - 聂微东
博客园 - 司徒正美
Recent Announcements
Recent Announcements
MyScale Blog
MyScale Blog
U
Unit 42

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: tighten media reference assertions · openclaw/openc...
steipete · 2026-05-09 · via Recent Commits to openclaw:main

@@ -10,33 +10,77 @@ import {

1010

resolveMediaReferenceLocalPath,

1111

} from "./media-reference.js";

121213+

async function expectMediaReferenceError(

14+

run: () => Promise<unknown>,

15+

expectedCode: MediaReferenceError["code"],

16+

) {

17+

let mediaError: unknown;

18+

try {

19+

await run();

20+

} catch (error) {

21+

mediaError = error;

22+

}

23+

expect(mediaError).toBeInstanceOf(MediaReferenceError);

24+

if (!(mediaError instanceof MediaReferenceError)) {

25+

throw new Error("expected MediaReferenceError");

26+

}

27+

expect(mediaError.name).toBe("MediaReferenceError");

28+

expect(mediaError.code).toBe(expectedCode);

29+

}

30+1331

describe("media reference helpers", () => {

1432

it("normalizes outbound MEDIA tags without changing canonical media URIs", () => {

1533

expect(normalizeMediaReferenceSource(" MEDIA: ./out.png")).toBe("./out.png");

1634

expect(normalizeMediaReferenceSource("media://inbound/a.png")).toBe("media://inbound/a.png");

1735

});

18361937

it("classifies supported and unsupported media reference schemes", () => {

20-

expect(classifyMediaReferenceSource("media://inbound/a.png")).toMatchObject({

21-

isMediaStoreUrl: true,

38+

expect(classifyMediaReferenceSource("media://inbound/a.png")).toStrictEqual({

39+

hasScheme: true,

2240

hasUnsupportedScheme: false,

41+

isDataUrl: false,

42+

isFileUrl: false,

43+

isHttpUrl: false,

44+

isMediaStoreUrl: true,

45+

looksLikeWindowsDrivePath: false,

2346

});

24-

expect(classifyMediaReferenceSource("data:image/png;base64,cG5n")).toMatchObject({

25-

isDataUrl: true,

47+

expect(classifyMediaReferenceSource("data:image/png;base64,cG5n")).toStrictEqual({

48+

hasScheme: true,

2649

hasUnsupportedScheme: false,

50+

isDataUrl: true,

51+

isFileUrl: false,

52+

isHttpUrl: false,

53+

isMediaStoreUrl: false,

54+

looksLikeWindowsDrivePath: false,

2755

});

2856

expect(

2957

classifyMediaReferenceSource("data:image/png;base64,cG5n", { allowDataUrl: false }),

30-

).toMatchObject({

31-

isDataUrl: true,

58+

).toStrictEqual({

59+

hasScheme: true,

3260

hasUnsupportedScheme: true,

61+

isDataUrl: true,

62+

isFileUrl: false,

63+

isHttpUrl: false,

64+

isMediaStoreUrl: false,

65+

looksLikeWindowsDrivePath: false,

3366

});

34-

expect(classifyMediaReferenceSource("ftp://example.test/a.png")).toMatchObject({

67+

expect(classifyMediaReferenceSource("ftp://example.test/a.png")).toStrictEqual({

68+

hasScheme: true,

3569

hasUnsupportedScheme: true,

70+

isDataUrl: false,

71+

isFileUrl: false,

72+

isHttpUrl: false,

73+

isMediaStoreUrl: false,

74+

looksLikeWindowsDrivePath: false,

3675

});

37-

expect(classifyMediaReferenceSource("C:\\Users\\pete\\image.png")).toMatchObject({

38-

looksLikeWindowsDrivePath: true,

76+

expect(classifyMediaReferenceSource("C:\\Users\\pete\\image.png")).toStrictEqual({

77+

hasScheme: true,

3978

hasUnsupportedScheme: false,

79+

isDataUrl: false,

80+

isFileUrl: false,

81+

isHttpUrl: false,

82+

isMediaStoreUrl: false,

83+

looksLikeWindowsDrivePath: true,

4084

});

4185

});

4286

@@ -49,7 +93,7 @@ describe("media reference helpers", () => {

4993

const realFilePath = await fs.realpath(filePath);

50945195

try {

52-

await expect(resolveInboundMediaReference(`media://inbound/${id}`)).resolves.toMatchObject({

96+

await expect(resolveInboundMediaReference(`media://inbound/${id}`)).resolves.toStrictEqual({

5397

id,

5498

normalizedSource: `media://inbound/${id}`,

5599

physicalPath: realFilePath,

@@ -87,8 +131,9 @@ describe("media reference helpers", () => {

87131

const realFilePath = await fs.realpath(filePath);

8813289133

try {

90-

await expect(resolveInboundMediaReference(filePath)).resolves.toMatchObject({

134+

await expect(resolveInboundMediaReference(filePath)).resolves.toStrictEqual({

91135

id,

136+

normalizedSource: filePath,

92137

physicalPath: realFilePath,

93138

sourceType: "path",

94139

});

@@ -104,21 +149,22 @@ describe("media reference helpers", () => {

104149

});

105150106151

it("rejects inbound media URIs with unsupported locations or unsafe ids", async () => {

107-

await expect(resolveInboundMediaReference("media://outbound/a.png")).rejects.toMatchObject({

108-

code: "path-not-allowed",

109-

});

110-

await expect(

111-

resolveInboundMediaReference("media://inbound/nested%2Fa.png"),

112-

).rejects.toBeInstanceOf(MediaReferenceError);

113-

await expect(

114-

resolveInboundMediaReference("media://inbound/nested%2Fa.png"),

115-

).rejects.toMatchObject({ code: "invalid-path" });

116-

await expect(resolveInboundMediaReference("media://inbound/")).rejects.toMatchObject({

117-

code: "invalid-path",

118-

});

119-

await expect(resolveInboundMediaReference("media://inbound/%00.png")).rejects.toMatchObject({

120-

code: "invalid-path",

121-

});

152+

await expectMediaReferenceError(

153+

() => resolveInboundMediaReference("media://outbound/a.png"),

154+

"path-not-allowed",

155+

);

156+

await expectMediaReferenceError(

157+

() => resolveInboundMediaReference("media://inbound/nested%2Fa.png"),

158+

"invalid-path",

159+

);

160+

await expectMediaReferenceError(

161+

() => resolveInboundMediaReference("media://inbound/"),

162+

"invalid-path",

163+

);

164+

await expectMediaReferenceError(

165+

() => resolveInboundMediaReference("media://inbound/%00.png"),

166+

"invalid-path",

167+

);

122168

});

123169124170

it("rejects symlinked inbound media files", async () => {

@@ -133,12 +179,11 @@ describe("media reference helpers", () => {

133179

await fs.symlink(targetPath, linkPath);

134180135181

try {

136-

await expect(resolveInboundMediaReference(`media://inbound/${id}`)).rejects.toMatchObject({

137-

code: "invalid-path",

138-

});

139-

await expect(resolveInboundMediaReference(linkPath)).rejects.toMatchObject({

140-

code: "invalid-path",

141-

});

182+

await expectMediaReferenceError(

183+

() => resolveInboundMediaReference(`media://inbound/${id}`),

184+

"invalid-path",

185+

);

186+

await expectMediaReferenceError(() => resolveInboundMediaReference(linkPath), "invalid-path");

142187

} finally {

143188

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

144189

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