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

推荐订阅源

J
Java Code Geeks
Martin Fowler
Martin Fowler
B
Blog RSS Feed
D
DataBreaches.Net
L
LangChain Blog
月光博客
月光博客
S
SegmentFault 最新的问题
阮一峰的网络日志
阮一峰的网络日志
V
Visual Studio Blog
美团技术团队
Jina AI
Jina AI
博客园 - 司徒正美
雷峰网
雷峰网
Last Week in AI
Last Week in AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
IT之家
IT之家
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
小众软件
小众软件
罗磊的独立博客
博客园_首页
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta

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: clear file-transfer policy broad matchers · opencla...
steipete · 2026-05-10 · via Recent Commits to openclaw:main

@@ -50,23 +50,35 @@ function withConfig(fileTransfer: Record<string, unknown> | undefined) {

5050

}

5151

}

525253+

function expectResultFields(result: unknown, fields: Record<string, unknown>) {

54+

expect(typeof result).toBe("object");

55+

expect(result).not.toBeNull();

56+

if (typeof result !== "object" || result === null) {

57+

throw new Error("policy result was not an object");

58+

}

59+

const record = result as Record<string, unknown>;

60+

for (const [key, value] of Object.entries(fields)) {

61+

expect(record[key]).toEqual(value);

62+

}

63+

}

64+5365

describe("evaluateFilePolicy — default deny", () => {

5466

it("returns NO_POLICY when no plugin config block is present", () => {

5567

getRuntimeConfigMock.mockReturnValue({});

5668

const r = evaluateFilePolicy({ nodeId: "n1", kind: "read", path: "/tmp/x" });

57-

expect(r).toMatchObject({ ok: false, code: "NO_POLICY", askable: false });

69+

expectResultFields(r, { ok: false, code: "NO_POLICY", askable: false });

5870

});

59716072

it("returns NO_POLICY when plugin policy block is missing", () => {

6173

getRuntimeConfigMock.mockReturnValue({ plugins: { entries: { "file-transfer": {} } } });

6274

const r = evaluateFilePolicy({ nodeId: "n1", kind: "read", path: "/tmp/x" });

63-

expect(r).toMatchObject({ ok: false, code: "NO_POLICY" });

75+

expectResultFields(r, { ok: false, code: "NO_POLICY" });

6476

});

65776678

it("returns NO_POLICY when no entry exists for the node and no '*' fallback", () => {

6779

withConfig({ "other-node": { allowReadPaths: ["/tmp/**"] } });

6880

const r = evaluateFilePolicy({ nodeId: "n1", kind: "read", path: "/tmp/x" });

69-

expect(r).toMatchObject({ ok: false, code: "NO_POLICY" });

81+

expectResultFields(r, { ok: false, code: "NO_POLICY" });

7082

});

71837284

it("prefers the current runtime config over a stale passed plugin config", () => {

@@ -93,7 +105,7 @@ describe("evaluateFilePolicy — default deny", () => {

93105

},

94106

},

95107

});

96-

expect(r).toMatchObject({ ok: true, reason: "matched-allow" });

108+

expectResultFields(r, { ok: true, reason: "matched-allow" });

97109

});

98110

});

99111

@@ -107,7 +119,7 @@ describe("evaluateFilePolicy — '..' traversal short-circuit", () => {

107119

kind: "read",

108120

path: "/allowed/../etc/passwd",

109121

});

110-

expect(r).toMatchObject({ ok: false, code: "POLICY_DENIED", askable: false });

122+

expectResultFields(r, { ok: false, code: "POLICY_DENIED", askable: false });

111123

expect(r.ok ? "" : r.reason).toMatch(/\.\./);

112124

});

113125

@@ -120,15 +132,15 @@ describe("evaluateFilePolicy — '..' traversal short-circuit", () => {

120132

kind: "read",

121133

path: "/tmp/foo/..",

122134

});

123-

expect(r).toMatchObject({ ok: false, code: "POLICY_DENIED" });

135+

expectResultFields(r, { ok: false, code: "POLICY_DENIED" });

124136

});

125137126138

it("rejects bare '..'", () => {

127139

withConfig({

128140

n1: { allowReadPaths: ["/**"] },

129141

});

130142

const r = evaluateFilePolicy({ nodeId: "n1", kind: "read", path: ".." });

131-

expect(r).toMatchObject({ ok: false, code: "POLICY_DENIED" });

143+

expectResultFields(r, { ok: false, code: "POLICY_DENIED" });

132144

});

133145

});

134146

@@ -145,7 +157,7 @@ describe("evaluateFilePolicy — denyPaths always wins", () => {

145157

kind: "read",

146158

path: "/tmp/.ssh/id_rsa",

147159

});

148-

expect(r).toMatchObject({ ok: false, code: "POLICY_DENIED", askable: false });

160+

expectResultFields(r, { ok: false, code: "POLICY_DENIED", askable: false });

149161

expect(r.ok ? "" : r.reason).toMatch(/deny/);

150162

});

151163

@@ -161,7 +173,7 @@ describe("evaluateFilePolicy — denyPaths always wins", () => {

161173

kind: "read",

162174

path: "/var/secrets/api.key",

163175

});

164-

expect(r).toMatchObject({ ok: false, code: "POLICY_DENIED", askable: false });

176+

expectResultFields(r, { ok: false, code: "POLICY_DENIED", askable: false });

165177

});

166178

});

167179

@@ -183,34 +195,35 @@ describe("evaluateFilePolicy — allow matching", () => {

183195

n1: { allowReadPaths: ["/tmp/**"], maxBytes: 1024 },

184196

});

185197

const r = evaluateFilePolicy({ nodeId: "n1", kind: "read", path: "/tmp/x" });

186-

expect(r).toMatchObject({ ok: true, maxBytes: 1024 });

198+

expectResultFields(r, { ok: true, maxBytes: 1024 });

187199

});

188200189201

it("uses kind=write to consult allowWritePaths, not allowReadPaths", () => {

190202

withConfig({

191203

n1: { allowReadPaths: ["/tmp/**"], allowWritePaths: ["/srv/**"] },

192204

});

193-

expect(evaluateFilePolicy({ nodeId: "n1", kind: "write", path: "/srv/out.txt" })).toMatchObject(

194-

{ ok: true },

195-

);

196-

expect(evaluateFilePolicy({ nodeId: "n1", kind: "write", path: "/tmp/out.txt" })).toMatchObject(

197-

{ ok: false, code: "POLICY_DENIED" },

198-

);

205+

expectResultFields(evaluateFilePolicy({ nodeId: "n1", kind: "write", path: "/srv/out.txt" }), {

206+

ok: true,

207+

});

208+

expectResultFields(evaluateFilePolicy({ nodeId: "n1", kind: "write", path: "/tmp/out.txt" }), {

209+

ok: false,

210+

code: "POLICY_DENIED",

211+

});

199212

});

200213201214

it("propagates followSymlinks=false by default and =true when configured", () => {

202215

withConfig({

203216

n1: { allowReadPaths: ["/tmp/**"] },

204217

});

205-

expect(evaluateFilePolicy({ nodeId: "n1", kind: "read", path: "/tmp/x" })).toMatchObject({

218+

expectResultFields(evaluateFilePolicy({ nodeId: "n1", kind: "read", path: "/tmp/x" }), {

206219

ok: true,

207220

followSymlinks: false,

208221

});

209222210223

withConfig({

211224

n2: { allowReadPaths: ["/tmp/**"], followSymlinks: true },

212225

});

213-

expect(evaluateFilePolicy({ nodeId: "n2", kind: "read", path: "/tmp/x" })).toMatchObject({

226+

expectResultFields(evaluateFilePolicy({ nodeId: "n2", kind: "read", path: "/tmp/x" }), {

214227

ok: true,

215228

followSymlinks: true,

216229

});

@@ -221,26 +234,28 @@ describe("evaluateFilePolicy — allow matching", () => {

221234

withConfig({

222235

n1: { allowReadPaths: ["~/Screenshots/**"] },

223236

});

224-

expect(

237+

expectResultFields(

225238

evaluateFilePolicy({

226239

nodeId: "n1",

227240

kind: "read",

228241

path: path.join(home, "Screenshots", "shot.png"),

229242

}),

230-

).toMatchObject({ ok: true });

243+

{ ok: true },

244+

);

231245

});

232246233247

it("matches Windows node paths without gateway-local path semantics", () => {

234248

withConfig({

235249

n1: { allowReadPaths: ["C:/Users/me/**"] },

236250

});

237-

expect(

251+

expectResultFields(

238252

evaluateFilePolicy({

239253

nodeId: "n1",

240254

kind: "read",

241255

path: "C:\\Users\\me\\file.txt",

242256

}),

243-

).toMatchObject({ ok: true });

257+

{ ok: true },

258+

);

244259

});

245260

});

246261

@@ -250,7 +265,7 @@ describe("evaluateFilePolicy — ask modes", () => {

250265

n1: { ask: "on-miss", allowReadPaths: ["/var/log/**"] },

251266

});

252267

const r = evaluateFilePolicy({ nodeId: "n1", kind: "read", path: "/tmp/x" });

253-

expect(r).toMatchObject({

268+

expectResultFields(r, {

254269

ok: false,

255270

code: "POLICY_DENIED",

256271

askable: true,

@@ -268,7 +283,7 @@ describe("evaluateFilePolicy — ask modes", () => {

268283

},

269284

});

270285

const r = evaluateFilePolicy({ nodeId: "n1", kind: "read", path: "/tmp/x" });

271-

expect(r).toMatchObject({

286+

expectResultFields(r, {

272287

ok: false,

273288

code: "POLICY_DENIED",

274289

askable: true,

@@ -283,31 +298,31 @@ describe("evaluateFilePolicy — ask modes", () => {

283298

n1: { ask: "on-miss", allowReadPaths: ["/tmp/**"] },

284299

});

285300

const r = evaluateFilePolicy({ nodeId: "n1", kind: "read", path: "/tmp/x" });

286-

expect(r).toMatchObject({ ok: true, reason: "matched-allow" });

301+

expectResultFields(r, { ok: true, reason: "matched-allow" });

287302

});

288303289304

it("ask=always always returns ask-always (prompt on every call)", () => {

290305

withConfig({

291306

n1: { ask: "always", allowReadPaths: ["/tmp/**"] },

292307

});

293308

const r = evaluateFilePolicy({ nodeId: "n1", kind: "read", path: "/tmp/x" });

294-

expect(r).toMatchObject({ ok: true, reason: "ask-always", askMode: "always" });

309+

expectResultFields(r, { ok: true, reason: "ask-always", askMode: "always" });

295310

});

296311297312

it("ask=off returns non-askable POLICY_DENIED on miss", () => {

298313

withConfig({

299314

n1: { ask: "off", allowReadPaths: ["/var/log/**"] },

300315

});

301316

const r = evaluateFilePolicy({ nodeId: "n1", kind: "read", path: "/tmp/x" });

302-

expect(r).toMatchObject({ ok: false, code: "POLICY_DENIED", askable: false });

317+

expectResultFields(r, { ok: false, code: "POLICY_DENIED", askable: false });

303318

});

304319305320

it("invalid ask values normalize to off", () => {

306321

withConfig({

307322

n1: { ask: "sometimes", allowReadPaths: ["/var/log/**"] },

308323

});

309324

const r = evaluateFilePolicy({ nodeId: "n1", kind: "read", path: "/tmp/x" });

310-

expect(r).toMatchObject({ ok: false, askable: false });

325+

expectResultFields(r, { ok: false, askable: false });

311326

});

312327

});

313328

@@ -316,28 +331,30 @@ describe("evaluateFilePolicy — node-id resolution", () => {

316331

withConfig({

317332

"Lobster MacBook": { allowReadPaths: ["/tmp/**"] },

318333

});

319-

expect(

334+

expectResultFields(

320335

evaluateFilePolicy({

321336

nodeId: "node-abc-123",

322337

nodeDisplayName: "Lobster MacBook",

323338

kind: "read",

324339

path: "/tmp/x",

325340

}),

326-

).toMatchObject({ ok: true });

341+

{ ok: true },

342+

);

327343

});

328344329345

it("falls back to '*' wildcard when neither id nor displayName matches", () => {

330346

withConfig({

331347

"*": { allowReadPaths: ["/tmp/**"] },

332348

});

333-

expect(

349+

expectResultFields(

334350

evaluateFilePolicy({

335351

nodeId: "n1",

336352

nodeDisplayName: "anything",

337353

kind: "read",

338354

path: "/tmp/x",

339355

}),

340-

).toMatchObject({ ok: true });

356+

{ ok: true },

357+

);

341358

});

342359

});

343360