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

推荐订阅源

J
Java Code Geeks
月光博客
月光博客
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
F
Fortinet All Blogs
T
The Blog of Author Tim Ferriss
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
aimingoo的专栏
aimingoo的专栏
U
Unit 42
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MyScale Blog
MyScale Blog
T
Tailwind CSS Blog
N
Netflix TechBlog - Medium
B
Blog
博客园_首页
G
Google Developers Blog
Recent Announcements
Recent Announcements
博客园 - 【当耐特】
P
Proofpoint News Feed
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
MongoDB | Blog
MongoDB | Blog
Last Week in AI
Last Week in AI

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 mcp loopback assertions · openclaw/openclaw...
steipete · 2026-05-11 · via Recent Commits to openclaw:main

@@ -18,6 +18,25 @@ type MockBeforeToolCallHookResult =

1818

| { blocked: true; reason: string }

1919

| { blocked: false; params: unknown };

202021+

type ScopedToolsCall = {

22+

sessionKey?: string;

23+

accountId?: string;

24+

messageProvider?: string;

25+

senderIsOwner?: boolean;

26+

surface?: string;

27+

};

28+29+

type BeforeToolCallHookInput = {

30+

toolName?: string;

31+

params?: unknown;

32+

ctx?: {

33+

agentId?: string;

34+

config?: unknown;

35+

sessionKey?: string;

36+

};

37+

signal?: unknown;

38+

};

39+2140

const runBeforeToolCallHookMock = vi.hoisted(() =>

2241

vi.fn(

2342

async (args: { params: unknown }): Promise<MockBeforeToolCallHookResult> => ({

@@ -88,6 +107,22 @@ async function sendRaw(params: {

88107

});

89108

}

90109110+

function getScopedToolsCall(index: number): ScopedToolsCall {

111+

const call = resolveGatewayScopedToolsMock.mock.calls[index]?.[0];

112+

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

113+

throw new Error(`Expected scoped tools call ${index} to receive an options object`);

114+

}

115+

return call as ScopedToolsCall;

116+

}

117+118+

function getBeforeToolCallHookInput(index: number): BeforeToolCallHookInput {

119+

const call = runBeforeToolCallHookMock.mock.calls[index]?.[0];

120+

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

121+

throw new Error(`Expected before-tool-call hook ${index} to receive an input object`);

122+

}

123+

return call as BeforeToolCallHookInput;

124+

}

125+91126

beforeEach(() => {

92127

resolveGatewayScopedToolsMock.mockClear();

93128

runBeforeToolCallHookMock.mockClear();

@@ -139,15 +174,12 @@ describe("mcp loopback server", () => {

139174

});

140175141176

expect(response.status).toBe(200);

142-

expect(resolveGatewayScopedToolsMock).toHaveBeenCalledWith(

143-

expect.objectContaining({

144-

sessionKey: "agent:main:telegram:group:chat123",

145-

accountId: "work",

146-

messageProvider: "telegram",

147-

senderIsOwner: false,

148-

surface: "loopback",

149-

}),

150-

);

177+

const call = getScopedToolsCall(0);

178+

expect(call.sessionKey).toBe("agent:main:telegram:group:chat123");

179+

expect(call.accountId).toBe("work");

180+

expect(call.messageProvider).toBe("telegram");

181+

expect(call.senderIsOwner).toBe(false);

182+

expect(call.surface).toBe("loopback");

151183

});

152184153185

it("adds empty properties for object schemas that omit properties", async () => {

@@ -210,24 +242,17 @@ describe("mcp loopback server", () => {

210242

expect((await sendToolsList("false")).status).toBe(200);

211243212244

expect(resolveGatewayScopedToolsMock).toHaveBeenCalledTimes(2);

213-

expect(resolveGatewayScopedToolsMock).toHaveBeenNthCalledWith(

214-

1,

215-

expect.objectContaining({

216-

sessionKey: "agent:main:matrix:dm:test",

217-

messageProvider: "matrix",

218-

senderIsOwner: true,

219-

surface: "loopback",

220-

}),

221-

);

222-

expect(resolveGatewayScopedToolsMock).toHaveBeenNthCalledWith(

223-

2,

224-

expect.objectContaining({

225-

sessionKey: "agent:main:matrix:dm:test",

226-

messageProvider: "matrix",

227-

senderIsOwner: false,

228-

surface: "loopback",

229-

}),

230-

);

245+

const ownerCall = getScopedToolsCall(0);

246+

expect(ownerCall.sessionKey).toBe("agent:main:matrix:dm:test");

247+

expect(ownerCall.messageProvider).toBe("matrix");

248+

expect(ownerCall.senderIsOwner).toBe(true);

249+

expect(ownerCall.surface).toBe("loopback");

250+251+

const nonOwnerCall = getScopedToolsCall(1);

252+

expect(nonOwnerCall.sessionKey).toBe("agent:main:matrix:dm:test");

253+

expect(nonOwnerCall.messageProvider).toBe("matrix");

254+

expect(nonOwnerCall.senderIsOwner).toBe(false);

255+

expect(nonOwnerCall.surface).toBe("loopback");

231256

});

232257233258

it("ignores spoofed owner headers when the bearer token is non-owner scoped", async () => {

@@ -247,14 +272,11 @@ describe("mcp loopback server", () => {

247272

});

248273249274

expect(response.status).toBe(200);

250-

expect(resolveGatewayScopedToolsMock).toHaveBeenCalledWith(

251-

expect.objectContaining({

252-

sessionKey: "agent:main:matrix:dm:test",

253-

messageProvider: "matrix",

254-

senderIsOwner: false,

255-

surface: "loopback",

256-

}),

257-

);

275+

const call = getScopedToolsCall(0);

276+

expect(call.sessionKey).toBe("agent:main:matrix:dm:test");

277+

expect(call.messageProvider).toBe("matrix");

278+

expect(call.senderIsOwner).toBe(false);

279+

expect(call.surface).toBe("loopback");

258280

});

259281260282

it("filters owner-only tools from non-owner tool lists", async () => {

@@ -406,7 +428,7 @@ describe("mcp loopback server", () => {

406428

});

407429408430

it("honors before-tool-call hook blocks before loopback tool execution", async () => {

409-

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

431+

const execute = vi.fn<MockGatewayTool["execute"]>(async () => ({

410432

content: [{ type: "text", text: "EXECUTED" }],

411433

}));

412434

runBeforeToolCallHookMock.mockResolvedValueOnce({

@@ -446,25 +468,20 @@ describe("mcp loopback server", () => {

446468

};

447469448470

expect(response.status).toBe(200);

449-

expect(runBeforeToolCallHookMock).toHaveBeenCalledWith(

450-

expect.objectContaining({

451-

toolName: "message",

452-

params: { body: "hello" },

453-

ctx: expect.objectContaining({

454-

agentId: "main",

455-

config: { session: { mainKey: "main" } },

456-

sessionKey: "agent:main:main",

457-

}),

458-

signal: expect.any(AbortSignal),

459-

}),

460-

);

471+

const hookInput = getBeforeToolCallHookInput(0);

472+

expect(hookInput.toolName).toBe("message");

473+

expect(hookInput.params).toEqual({ body: "hello" });

474+

expect(hookInput.ctx?.agentId).toBe("main");

475+

expect(hookInput.ctx?.config).toEqual({ session: { mainKey: "main" } });

476+

expect(hookInput.ctx?.sessionKey).toBe("agent:main:main");

477+

expect(hookInput.signal).toBeInstanceOf(AbortSignal);

461478

expect(execute).not.toHaveBeenCalled();

462479

expect(payload.result?.isError).toBe(true);

463480

expect(payload.result?.content?.[0]?.text).toBe("blocked by hook");

464481

});

465482466483

it("forwards the request abort signal to loopback tool execution", async () => {

467-

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

484+

const execute = vi.fn<MockGatewayTool["execute"]>(async () => ({

468485

content: [{ type: "text", text: "EXECUTED" }],

469486

}));

470487

resolveGatewayScopedToolsMock.mockReturnValue({

@@ -501,11 +518,11 @@ describe("mcp loopback server", () => {

501518502519

expect(response.status).toBe(200);

503520

expect(payload.result?.isError).toBe(false);

504-

expect(execute).toHaveBeenCalledWith(

505-

expect.stringMatching(/^mcp-/),

506-

{ body: "hello" },

507-

expect.any(AbortSignal),

508-

);

521+

expect(execute).toHaveBeenCalledTimes(1);

522+

const [callId, params, signal] = execute.mock.calls[0] ?? [];

523+

expect(callId).toMatch(/^mcp-/);

524+

expect(params).toEqual({ body: "hello" });

525+

expect(signal).toBeInstanceOf(AbortSignal);

509526

});

510527511528

it("tracks the active runtime only while the server is running", async () => {