feat(browser): add sensitive action controls and read-only noise reduction (#22867)

This commit is contained in:
cynthialong0-0
2026-03-20 15:34:04 -07:00
committed by GitHub
parent 11ec4ac2f8
commit e8fe43bd69
11 changed files with 342 additions and 1 deletions
@@ -301,4 +301,55 @@ describe('mcpToolWrapper', () => {
expect(mockBrowserManager.callTool).toHaveBeenCalledTimes(3);
});
});
describe('Hard Block: upload_file', () => {
beforeEach(() => {
mockMcpTools.push({
name: 'upload_file',
description: 'Upload a file',
inputSchema: {
type: 'object',
properties: { path: { type: 'string' } },
},
});
});
it('should block upload_file when blockFileUploads is true', async () => {
const tools = await createMcpDeclarativeTools(
mockBrowserManager,
mockMessageBus,
false,
true, // blockFileUploads
);
const uploadTool = tools.find((t) => t.name === 'upload_file')!;
const invocation = uploadTool.build({ path: 'test.txt' });
const result = await invocation.execute(new AbortController().signal);
expect(result.error).toBeDefined();
expect(result.llmContent).toContain('File uploads are blocked');
expect(mockBrowserManager.callTool).not.toHaveBeenCalled();
});
it('should NOT block upload_file when blockFileUploads is false', async () => {
const tools = await createMcpDeclarativeTools(
mockBrowserManager,
mockMessageBus,
false,
false, // blockFileUploads
);
const uploadTool = tools.find((t) => t.name === 'upload_file')!;
const invocation = uploadTool.build({ path: 'test.txt' });
const result = await invocation.execute(new AbortController().signal);
expect(result.error).toBeUndefined();
expect(result.llmContent).toBe('Tool result');
expect(mockBrowserManager.callTool).toHaveBeenCalledWith(
'upload_file',
expect.anything(),
expect.anything(),
);
});
});
});