chore: account for undefined arguments (#400)

This commit is contained in:
Pavel Feldman 2025-05-12 09:35:33 -07:00 committed by GitHub
parent 05dc5d915b
commit dd5b41f1d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 3 additions and 19 deletions

View File

@ -125,7 +125,7 @@ export class Context {
async run(tool: Tool, params: Record<string, unknown> | undefined) { async run(tool: Tool, params: Record<string, unknown> | undefined) {
// Tab management is done outside of the action() call. // Tab management is done outside of the action() call.
const toolResult = await tool.handle(this, tool.schema.inputSchema.parse(params)); const toolResult = await tool.handle(this, tool.schema.inputSchema.parse(params || {}));
const { code, action, waitForNetwork, captureSnapshot, resultOverride } = toolResult; const { code, action, waitForNetwork, captureSnapshot, resultOverride } = toolResult;
const racingAction = action ? () => this._raceAgainstModalDialogs(action) : undefined; const racingAction = action ? () => this._raceAgainstModalDialogs(action) : undefined;

View File

@ -37,7 +37,6 @@ test('cdp server reuse tab', async ({ cdpEndpoint, startClient }) => {
expect(await client.callTool({ expect(await client.callTool({
name: 'browser_snapshot', name: 'browser_snapshot',
arguments: {},
})).toHaveTextContent(` })).toHaveTextContent(`
- Ran Playwright code: - Ran Playwright code:
\`\`\`js \`\`\`js

View File

@ -36,7 +36,6 @@ test('browser_console_messages', async ({ client, server }) => {
const resource = await client.callTool({ const resource = await client.callTool({
name: 'browser_console_messages', name: 'browser_console_messages',
arguments: {},
}); });
expect(resource).toHaveTextContent([ expect(resource).toHaveTextContent([
'[LOG] Hello, world!', '[LOG] Hello, world!',

View File

@ -175,7 +175,6 @@ test('browser_type', async ({ client, server }) => {
}); });
expect(await client.callTool({ expect(await client.callTool({
name: 'browser_console_messages', name: 'browser_console_messages',
arguments: {},
})).toHaveTextContent('[LOG] Key pressed: Enter , Text: Hi!'); })).toHaveTextContent('[LOG] Key pressed: Enter , Text: Hi!');
}); });
@ -202,7 +201,6 @@ test('browser_type (slowly)', async ({ client, server }) => {
}); });
expect(await client.callTool({ expect(await client.callTool({
name: 'browser_console_messages', name: 'browser_console_messages',
arguments: {},
})).toHaveTextContent([ })).toHaveTextContent([
'[LOG] Key pressed: H Text: ', '[LOG] Key pressed: H Text: ',
'[LOG] Key pressed: i Text: H', '[LOG] Key pressed: i Text: H',
@ -237,5 +235,5 @@ test('browser_resize', async ({ client, server }) => {
// Resize browser window to 390x780 // Resize browser window to 390x780
await page.setViewportSize({ width: 390, height: 780 }); await page.setViewportSize({ width: 390, height: 780 });
\`\`\``); \`\`\``);
await expect.poll(() => client.callTool({ name: 'browser_snapshot', arguments: {} })).toContainTextContent('Window size: 390x780'); await expect.poll(() => client.callTool({ name: 'browser_snapshot' })).toContainTextContent('Window size: 390x780');
}); });

View File

@ -121,7 +121,7 @@ test('clicking on download link emits download', async ({ startClient, localOutp
ref: 'e2', ref: 'e2',
}, },
}); });
await expect.poll(() => client.callTool({ name: 'browser_snapshot', arguments: {} })).toContainTextContent(` await expect.poll(() => client.callTool({ name: 'browser_snapshot' })).toContainTextContent(`
### Downloads ### Downloads
- Downloaded file test.txt to ${path.join(outputDir, 'test.txt')}`); - Downloaded file test.txt to ${path.join(outputDir, 'test.txt')}`);
}); });

View File

@ -20,6 +20,5 @@ test('browser_install', async ({ client, mcpBrowser }) => {
test.skip(mcpBrowser !== 'chromium', 'Test only chromium'); test.skip(mcpBrowser !== 'chromium', 'Test only chromium');
expect(await client.callTool({ expect(await client.callTool({
name: 'browser_install', name: 'browser_install',
arguments: {},
})).toContainTextContent(`No open pages available.`); })).toContainTextContent(`No open pages available.`);
}); });

View File

@ -24,7 +24,6 @@ test('test reopen browser', async ({ client, server }) => {
expect(await client.callTool({ expect(await client.callTool({
name: 'browser_close', name: 'browser_close',
arguments: {},
})).toContainTextContent('No open pages available'); })).toContainTextContent('No open pages available');
expect(await client.callTool({ expect(await client.callTool({

View File

@ -40,7 +40,6 @@ test('browser_network_requests', async ({ client, server }) => {
await expect.poll(() => client.callTool({ await expect.poll(() => client.callTool({
name: 'browser_network_requests', name: 'browser_network_requests',
arguments: {},
})).toHaveTextContent(`[GET] ${`${server.PREFIX}`} => [200] OK })).toHaveTextContent(`[GET] ${`${server.PREFIX}`} => [200] OK
[GET] ${`${server.PREFIX}json`} => [200] OK`); [GET] ${`${server.PREFIX}json`} => [200] OK`);
}); });

View File

@ -40,7 +40,6 @@ test('save as pdf', async ({ client, mcpBrowser, server }) => {
const response = await client.callTool({ const response = await client.callTool({
name: 'browser_pdf_save', name: 'browser_pdf_save',
arguments: {},
}); });
expect(response).toHaveTextContent(/Save page as.*page-[^:]+.pdf/); expect(response).toHaveTextContent(/Save page as.*page-[^:]+.pdf/);
}); });

View File

@ -26,7 +26,6 @@ test('browser_take_screenshot (viewport)', async ({ client, server }) => {
expect(await client.callTool({ expect(await client.callTool({
name: 'browser_take_screenshot', name: 'browser_take_screenshot',
arguments: {},
})).toEqual({ })).toEqual({
content: [ content: [
{ {
@ -81,7 +80,6 @@ test('--output-dir should work', async ({ startClient, localOutputPath, server }
await client.callTool({ await client.callTool({
name: 'browser_take_screenshot', name: 'browser_take_screenshot',
arguments: {},
}); });
expect(fs.existsSync(outputDir)).toBeTruthy(); expect(fs.existsSync(outputDir)).toBeTruthy();
@ -180,12 +178,10 @@ test('browser_take_screenshot (noImageResponses)', async ({ startClient, server
await client.callTool({ await client.callTool({
name: 'browser_take_screenshot', name: 'browser_take_screenshot',
arguments: {},
}); });
expect(await client.callTool({ expect(await client.callTool({
name: 'browser_take_screenshot', name: 'browser_take_screenshot',
arguments: {},
})).toEqual({ })).toEqual({
content: [ content: [
{ {
@ -206,12 +202,10 @@ test('browser_take_screenshot (cursor)', async ({ startClient, server }) => {
await client.callTool({ await client.callTool({
name: 'browser_take_screenshot', name: 'browser_take_screenshot',
arguments: {},
}); });
expect(await client.callTool({ expect(await client.callTool({
name: 'browser_take_screenshot', name: 'browser_take_screenshot',
arguments: {},
})).toEqual({ })).toEqual({
content: [ content: [
{ {

View File

@ -32,7 +32,6 @@ async function createTab(client: Client, title: string, body: string) {
test('list initial tabs', async ({ client }) => { test('list initial tabs', async ({ client }) => {
expect(await client.callTool({ expect(await client.callTool({
name: 'browser_tab_list', name: 'browser_tab_list',
arguments: {},
})).toHaveTextContent(`### Open tabs })).toHaveTextContent(`### Open tabs
- 1: (current) [] (about:blank)`); - 1: (current) [] (about:blank)`);
}); });
@ -41,7 +40,6 @@ test('list first tab', async ({ client }) => {
await createTab(client, 'Tab one', 'Body one'); await createTab(client, 'Tab one', 'Body one');
expect(await client.callTool({ expect(await client.callTool({
name: 'browser_tab_list', name: 'browser_tab_list',
arguments: {},
})).toHaveTextContent(`### Open tabs })).toHaveTextContent(`### Open tabs
- 1: [] (about:blank) - 1: [] (about:blank)
- 2: (current) [Tab one] (data:text/html,<title>Tab one</title><body>Body one</body>)`); - 2: (current) [Tab one] (data:text/html,<title>Tab one</title><body>Body one</body>)`);