Skip to content

Commit fb78d21

Browse files
kalvinnchauam
andauthored
test(mcp): allow protection checks in bundled help fixture (#2061)
Signed-off-by: Kalvin Chau <[email protected]> Co-authored-by: am <6e30cd56c30e030cd31bb0939b94a7c257c9a09d5ba2d92cf2735da45629f248@buzz.block.builderlab.xyz>
1 parent 0944c1d commit fb78d21

1 file changed

Lines changed: 45 additions & 35 deletions

File tree

‎src/buzz-mcp/tools.test.ts‎

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -131,41 +131,51 @@ function fake(
131131
return { client, published };
132132
}
133133

134-
it("serves product help through MCP without channel access or host I/O", async () => {
135-
const client = new Proxy({} as BuzzClient, {
136-
get(_target, property) {
137-
throw new Error(`Help must not access the host: ${String(property)}`);
138-
},
139-
});
140-
const list = await respond(client, {}, { id: 1, method: "tools/list" });
141-
expect(list).toMatchObject({
142-
result: {
143-
tools: expect.arrayContaining([
144-
expect.objectContaining({ name: "buzz_help" }),
145-
]),
146-
},
147-
});
148-
const reply = await respond(
149-
client,
150-
{},
151-
{
152-
id: 2,
153-
method: "tools/call",
154-
params: { name: "buzz_help", arguments: {} },
155-
},
156-
);
157-
expect(reply).toMatchObject({
158-
result: {
159-
content: [
160-
{
161-
type: "text",
162-
text: expect.stringContaining("# Buzz quick guide"),
163-
},
164-
],
165-
},
166-
});
167-
expect(reply).not.toHaveProperty("result.isError");
168-
});
134+
it.each([false, true])(
135+
"serves product help through MCP without channel access or host I/O (protected: %s)",
136+
async (protectedSession) => {
137+
const protect = vi.fn<NonNullable<BuzzClient["protect"]>>(async () => {});
138+
const client = new Proxy({} as BuzzClient, {
139+
get(_target, property) {
140+
// The shared session gate checks this optional hook before dispatch.
141+
if (property === "protect")
142+
return protectedSession ? protect : undefined;
143+
throw new Error(`Help must not access the host: ${String(property)}`);
144+
},
145+
});
146+
const list = await respond(client, {}, { id: 1, method: "tools/list" });
147+
expect(list).toMatchObject({
148+
result: {
149+
tools: expect.arrayContaining([
150+
expect.objectContaining({ name: "buzz_help" }),
151+
]),
152+
},
153+
});
154+
const reply = await respond(
155+
client,
156+
{},
157+
{
158+
id: 2,
159+
method: "tools/call",
160+
params: { name: "buzz_help", arguments: {} },
161+
},
162+
);
163+
expect(reply).toMatchObject({
164+
result: {
165+
content: [
166+
{
167+
type: "text",
168+
text: expect.stringContaining("# Buzz quick guide"),
169+
},
170+
],
171+
},
172+
});
173+
expect(reply).not.toHaveProperty("result.isError");
174+
expect(protect.mock.calls.map(([action]) => action.kind)).toEqual(
175+
protectedSession ? ["tool", "tool-result"] : [],
176+
);
177+
},
178+
);
169179

170180
const members = event({
171181
kind: 39002,

0 commit comments

Comments
 (0)