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

推荐订阅源

奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Blog — PlanetScale
Blog — PlanetScale
小众软件
小众软件
F
Fortinet All Blogs
博客园 - 叶小钗
博客园_首页
D
DataBreaches.Net
Apple Machine Learning Research
Apple Machine Learning Research
U
Unit 42
爱范儿
爱范儿
aimingoo的专栏
aimingoo的专栏
博客园 - Franky
Martin Fowler
Martin Fowler
酷 壳 – CoolShell
酷 壳 – CoolShell
The Cloudflare Blog
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
IT之家
IT之家
M
MIT News - Artificial intelligence
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - 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
test: tighten before tool approval assertions · openclaw/...
steipete · 2026-05-10 · via Recent Commits to openclaw:main

@@ -24,6 +24,41 @@ vi.mock("./tools/gateway.js", () => ({

2424

const mockGetGlobalHookRunner = vi.mocked(getGlobalHookRunner);

2525

const mockCallGatewayTool = vi.mocked(callGatewayTool);

262627+

function requireRecord(value: unknown, label: string): Record<string, unknown> {

28+

if (!value || typeof value !== "object" || Array.isArray(value)) {

29+

throw new Error(`expected ${label}`);

30+

}

31+

return value as Record<string, unknown>;

32+

}

33+34+

function requireApprovalRequestCall(label: string): {

35+

timeoutParams: Record<string, unknown>;

36+

request: Record<string, unknown>;

37+

options: Record<string, unknown>;

38+

} {

39+

const call = mockCallGatewayTool.mock.calls[0];

40+

if (!call) {

41+

throw new Error(`expected ${label}`);

42+

}

43+

expect(call[0]).toBe("plugin.approval.request");

44+

return {

45+

timeoutParams: requireRecord(call[1], `${label} timeout params`),

46+

request: requireRecord(call[2], `${label} request`),

47+

options: requireRecord(call[3], `${label} options`),

48+

};

49+

}

50+51+

function requireBeforeToolCall(

52+

mock: ReturnType<typeof vi.fn<HookRunner["runBeforeToolCall"]>>,

53+

label: string,

54+

): Parameters<HookRunner["runBeforeToolCall"]> {

55+

const call = mock.mock.calls[0];

56+

if (!call) {

57+

throw new Error(`expected ${label}`);

58+

}

59+

return call;

60+

}

61+2762

describe("runBeforeToolCallHook — embedded mode approvals", () => {

2863

let hookRunner: Pick<HookRunner, "hasHooks" | "runBeforeToolCall">;

2964

let runBeforeToolCallMock: ReturnType<typeof vi.fn<HookRunner["runBeforeToolCall"]>>;

@@ -75,9 +110,23 @@ describe("runBeforeToolCallHook — embedded mode approvals", () => {

75110

});

76111

expect(mockCallGatewayTool).toHaveBeenCalledWith(

77112

"plugin.approval.request",

78-

expect.any(Object),

79-

expect.any(Object),

80-

expect.any(Object),

113+

{

114+

timeoutMs: 130_000,

115+

},

116+

{

117+

agentId: undefined,

118+

allowedDecisions: undefined,

119+

description: "Test approval request",

120+

pluginId: "test-plugin",

121+

sessionKey: undefined,

122+

severity: "info",

123+

timeoutMs: 120_000,

124+

title: "Needs approval",

125+

toolCallId: "call-1",

126+

toolName: "exec",

127+

twoPhase: true,

128+

},

129+

{ expectFinal: false },

81130

);

82131

expect(onResolution).toHaveBeenCalledTimes(1);

83132

expect(onResolution).toHaveBeenCalledWith(PluginApprovalResolutions.CANCELLED);

@@ -133,12 +182,17 @@ describe("runBeforeToolCallHook — embedded mode approvals", () => {

133182

});

134183135184

expect(result.blocked).toBe(true);

136-

expect(mockCallGatewayTool).toHaveBeenCalledWith(

137-

"plugin.approval.request",

138-

expect.any(Object),

139-

expect.any(Object),

140-

expect.any(Object),

141-

);

185+

const approvalCall = requireApprovalRequestCall("non-embedded approval request");

186+

expect(approvalCall.timeoutParams.timeoutMs).toBe(15_000);

187+

expect(approvalCall.request.pluginId).toBe("test-plugin");

188+

expect(approvalCall.request.title).toBe("Needs approval");

189+

expect(approvalCall.request.description).toBe("Test approval request");

190+

expect(approvalCall.request.severity).toBe("info");

191+

expect(approvalCall.request.toolName).toBe("exec");

192+

expect(approvalCall.request.toolCallId).toBe("call-2");

193+

expect(approvalCall.request.timeoutMs).toBe(5_000);

194+

expect(approvalCall.request.twoPhase).toBe(true);

195+

expect(approvalCall.options.expectFinal).toBe(false);

142196

});

143197144198

it("preserves hook params override after an approval allow decision", async () => {

@@ -210,15 +264,17 @@ describe("runBeforeToolCallHook — embedded mode approvals", () => {

210264

});

211265212266

expect(result).toEqual({ blocked: false, params: { command: "deploy" } });

213-

expect(mockCallGatewayTool).toHaveBeenCalledWith(

214-

"plugin.approval.request",

215-

expect.any(Object),

216-

expect.objectContaining({

217-

pluginId: "trusted-policy",

218-

title: "Policy approval",

219-

}),

220-

{ expectFinal: false },

221-

);

267+

const approvalCall = requireApprovalRequestCall("trusted policy approval request");

268+

expect(approvalCall.timeoutParams.timeoutMs).toBe(130_000);

269+

expect(approvalCall.request.pluginId).toBe("trusted-policy");

270+

expect(approvalCall.request.title).toBe("Policy approval");

271+

expect(approvalCall.request.description).toBe("Policy requested approval");

272+

expect(approvalCall.request.toolName).toBe("exec");

273+

expect(approvalCall.request.toolCallId).toBe("call-policy");

274+

expect(approvalCall.request.agentId).toBe("main");

275+

expect(approvalCall.request.sessionKey).toBe("main");

276+

expect(approvalCall.request.twoPhase).toBe(true);

277+

expect(approvalCall.options.expectFinal).toBe(false);

222278

expect(runBeforeToolCallMock).not.toHaveBeenCalled();

223279

});

224280

@@ -247,12 +303,14 @@ describe("runBeforeToolCallHook — embedded mode approvals", () => {

247303

});

248304249305

expect(result).toEqual({ blocked: false, params: { command: "patched" } });

250-

expect(runBeforeToolCallMock).toHaveBeenCalledWith(

251-

expect.objectContaining({

252-

params: { command: "patched" },

253-

}),

254-

expect.any(Object),

306+

const [hookParams, hookContext] = requireBeforeToolCall(

307+

runBeforeToolCallMock,

308+

"before_tool_call invocation",

255309

);

310+

expect(hookParams.params).toEqual({ command: "patched" });

311+

expect(hookParams.toolName).toBe("exec");

312+

expect(hookParams.toolCallId).toBe("call-policy-params");

313+

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

256314

});

257315258316

it("keeps original params after an approval allow decision without overrides", async () => {