@@ -10,6 +10,7 @@ import {afterEach, describe, it} from 'node:test';
1010
1111import sinon from 'sinon' ;
1212
13+ import type { ParsedArguments } from '../../src/cli.js' ;
1314import type { McpResponse } from '../../src/McpResponse.js' ;
1415import {
1516 installExtension ,
@@ -18,8 +19,13 @@ import {
1819 reloadExtension ,
1920 triggerExtensionAction ,
2021} from '../../src/tools/extensions.js' ;
22+ import { listPages } from '../../src/tools/pages.js' ;
2123import { withMcpContext } from '../utils.js' ;
2224
25+ const EXTENSION_WITH_SW_PATH = path . join (
26+ import . meta. dirname ,
27+ '../../../tests/tools/fixtures/extension-sw' ,
28+ ) ;
2329const EXTENSION_PATH = path . join (
2430 import . meta. dirname ,
2531 '../../../tests/tools/fixtures/extension' ,
@@ -129,39 +135,74 @@ describe('extension', () => {
129135 assert . ok ( reinstalled , 'Extension should be present after reload' ) ;
130136 } ) ;
131137 } ) ;
132-
133138 it ( 'triggers an extension action' , async ( ) => {
134139 await withMcpContext (
135140 async ( response , context ) => {
136- const triggerSpy = sinon . spy ( context , 'triggerExtensionAction' ) ;
137-
138141 await installExtension . handler (
139- { params : { path : EXTENSION_PATH } } ,
142+ { params : { path : EXTENSION_WITH_SW_PATH } } ,
140143 response ,
141144 context ,
142145 ) ;
143146
144147 const extensionId = extractId ( response ) ;
148+
145149 response . resetResponseLineForTesting ( ) ;
150+ const listPageDef = listPages ( {
151+ categoryExtensions : true ,
152+ } as ParsedArguments ) ;
153+ await listPageDef . handler (
154+ { params : { } , page : context . getSelectedMcpPage ( ) } ,
155+ response ,
156+ context ,
157+ ) ;
158+ let result = await response . handle ( listPageDef . name , context ) ;
159+ let textContent = result . content . find ( c => c . type === 'text' ) as {
160+ type : 'text' ;
161+ text : string ;
162+ } ;
163+ assert . ok (
164+ ! textContent . text . includes ( extensionId ) ,
165+ 'Response should not contain extension service worker id' ,
166+ ) ;
146167
147168 await triggerExtensionAction . handler (
148169 { params : { id : extensionId } } ,
149170 response ,
150171 context ,
151172 ) ;
173+
174+ const swTarget = await context . browser . waitForTarget (
175+ t =>
176+ t . type ( ) === 'service_worker' &&
177+ t . url ( ) . includes ( extensionId ) ,
178+ ) ;
179+ const swUrl = swTarget . url ( ) ;
152180
153- assert . ok (
154- triggerSpy . calledOnceWithExactly ( extensionId ) ,
155- 'triggerExtensionAction should be called with correct params' ,
181+ response . resetResponseLineForTesting ( ) ;
182+ await listPageDef . handler (
183+ { params : { } , page : context . getSelectedMcpPage ( ) } ,
184+ response ,
185+ context ,
156186 ) ;
187+ result = await response . handle ( listPageDef . name , context ) ;
188+ textContent = result . content . find ( c => c . type === 'text' ) as {
189+ type : 'text' ;
190+ text : string ;
191+ } ;
157192 assert . ok (
158- response . responseLines [ 0 ] . includes (
159- `Extension action triggered. Id: ${ extensionId } ` ,
160- ) ,
161- 'Response should indicate action triggered' ,
193+ textContent . text . includes ( swUrl ) ,
194+ 'Response should contain extension service worker url' ,
162195 ) ;
163196 } ,
164- { channel : 'chrome-canary' } ,
197+ {
198+ channel : process . env . CANARY_EXECUTABLE_PATH
199+ ? undefined
200+ : 'chrome-canary' ,
201+ executablePath : process . env . CANARY_EXECUTABLE_PATH ,
202+ } ,
203+ {
204+ categoryExtensions : true ,
205+ } as ParsedArguments
165206 ) ;
166207 } ) ;
167208} ) ;
0 commit comments