Chrome DevTools for coding agents
test: migrate third-party tool handler tests to mocks (#2776)
elizabethbrunette21c4312f9399dd
diff --git a/tests/tools/thirdPartyDeveloper.test.ts b/tests/tools/thirdPartyDeveloper.test.tsindex 408cffda..7c4b94ce 100644--- a/tests/tools/thirdPartyDeveloper.test.ts+++ b/tests/tools/thirdPartyDeveloper.test.ts@@ -315,85 +315,79 @@ describe('thirdPartyDeveloperTools', () => {}it('executes a tool', async () => {- await withMcpContext(- async (response, context, args) => {- await setupThirdPartyDeveloperTools(response, context, args, () => {- const mockToolGroup = {- name: 'test-group',- description: 'test description',- tools: [- {- name: 'test-tool',- description: 'test tool description',- inputSchema: {- type: 'object',- properties: {- arg: {type: 'string'},- },- required: ['arg'],- },- execute: () => 'result',+ const {page, context, response, args} = createHandlerMocks({+ categoryExperimentalThirdParty: true,+ });+ page.getThirdPartyDeveloperTools.returns([+ {+ name: 'test-group',+ description: 'test description',+ tools: [+ {+ name: 'test-tool',+ description: 'test tool description',+ inputSchema: {+ type: 'object',+ properties: {+ arg: {type: 'string'},},- ],- };- window.addEventListener('devtoolstooldiscovery', (e: Event) => {- // @ts-expect-error Event has `respondWith`- e.respondWith(mockToolGroup);- });- });+ required: ['arg'],+ },+ },+ ],+ },+ ]);++ await executeThirdPartyDeveloperTool(args).handler(+ {+ params: {+ toolName: 'test-tool',+ params: JSON.stringify({arg: 'value'}),+ },+ page,+ },+ response,+ context,+ );++ sinon.assert.calledOnceWithExactly(+ page.executeThirdPartyDeveloperTool,+ 'test-tool',+ {arg: 'value'},+ response,+ );+ });++ it('throws if tool not found in list', async () => {+ const {page, context, response, args} = createHandlerMocks({+ categoryExperimentalThirdParty: true,+ });+ page.getThirdPartyDeveloperTools.returns([+ {+ name: 'test-group',+ description: 'test description',+ tools: [],+ },+ ]);+ await assert.rejects(+ async () => {await executeThirdPartyDeveloperTool(args).handler({params: {- toolName: 'test-tool',- params: JSON.stringify({arg: 'value'}),+ toolName: 'missing-tool',+ params: JSON.stringify({}),},- page: context.getSelectedMcpPage(),+ page,},response,context,);- assert.strictEqual(- response.responseLines[0],- JSON.stringify('result', null, 2),- );},- undefined,- {categoryExperimentalThirdParty: true},+ {message: /Tool missing-tool not found/},);- });-- it('throws if tool not found in list', async () => {- await withMcpContext(async (response, context, args) => {- await setupThirdPartyDeveloperTools(response, context, args, () => {- const mockToolGroup = {- name: 'test-group',- description: 'test description',- tools: [],- };- window.addEventListener('devtoolstooldiscovery', (e: Event) => {- // @ts-expect-error Event has `respondWith`- e.respondWith(mockToolGroup);- });- });- await assert.rejects(- async () => {- await executeThirdPartyDeveloperTool(args).handler(- {- params: {- toolName: 'missing-tool',- params: JSON.stringify({}),- },- page: context.getSelectedMcpPage(),- },- response,- context,- );- },- {message: /Tool missing-tool not found/},- );- });+ sinon.assert.notCalled(page.executeThirdPartyDeveloperTool);});it('rejects JSON array params', async () => {@@ -415,53 +409,47 @@ describe('thirdPartyDeveloperTools', () => {});it('throws if parameters are invalid', async () => {- await withMcpContext(- async (response, context, args) => {- await setupThirdPartyDeveloperTools(response, context, args, () => {- const mockToolGroup = {- name: 'test-group',- description: 'test description',- tools: [- {- name: 'test-tool',- description: 'test tool description',- inputSchema: {- type: 'object',- properties: {- arg: {type: 'string'},- },- required: ['arg'],- },- execute: () => 'result',+ const {page, context, response, args} = createHandlerMocks({+ categoryExperimentalThirdParty: true,+ });+ page.getThirdPartyDeveloperTools.returns([+ {+ name: 'test-group',+ description: 'test description',+ tools: [+ {+ name: 'test-tool',+ description: 'test tool description',+ inputSchema: {+ type: 'object',+ properties: {+ arg: {type: 'string'},},- ],- };- window.addEventListener('devtoolstooldiscovery', (e: Event) => {- // @ts-expect-error Event has `respondWith`- e.respondWith(mockToolGroup);- });- });+ required: ['arg'],+ },+ },+ ],+ },+ ]);- await assert.rejects(- async () => {- await executeThirdPartyDeveloperTool(args).handler(- {- params: {- toolName: 'test-tool',- params: JSON.stringify({}), // Missing required 'arg'- },- page: context.getSelectedMcpPage(),- },- response,- context,- );+ await assert.rejects(+ async () => {+ await executeThirdPartyDeveloperTool(args).handler(+ {+ params: {+ toolName: 'test-tool',+ params: JSON.stringify({}), // Missing required 'arg'+ },+ page,},- {message: /Invalid parameters for tool test-tool/},+ response,+ context,);},- undefined,- {categoryExperimentalThirdParty: true},+ {message: /Invalid parameters for tool test-tool/},);++ sinon.assert.notCalled(page.executeThirdPartyDeveloperTool);});it('handles JSON result', async () => {