@@ -45,7 +45,7 @@ describe('Privileged context state consistency', () => {
4545 } ) ) ;
4646 } ) ;
4747
48- it ( 'select_privileged_context should update currentContextId (BUG: it does not) ' , async ( ) => {
48+ it ( 'select_privileged_context should update currentContextId' , async ( ) => {
4949 const { handleSelectPrivilegedContext } = await import (
5050 '../../src/tools/privileged-context.js'
5151 ) ;
@@ -55,12 +55,12 @@ describe('Privileged context state consistency', () => {
5555 expect ( mockSwitchToWindow ) . toHaveBeenCalledWith ( 'chrome-context-id' ) ;
5656 expect ( mockSetContext ) . toHaveBeenCalledWith ( 'chrome' ) ;
5757
58- // BUG: select_privileged_context does NOT call setCurrentContextId
59- // so currentContextId stays as 'original-content- context'
58+ // select_privileged_context should call setCurrentContextId and update
59+ // currentContextId to 'chrome- context-id '
6060 expect ( mockSetCurrentContextId ) . toHaveBeenCalledWith ( 'chrome-context-id' ) ;
6161 } ) ;
6262
63- it ( 'set_firefox_prefs after select_privileged_context should not revert to old context (BUG: it does) ' , async ( ) => {
63+ it ( 'set_firefox_prefs after select_privileged_context should not revert to old context' , async ( ) => {
6464 const { handleSelectPrivilegedContext } = await import (
6565 '../../src/tools/privileged-context.js'
6666 ) ;
@@ -71,24 +71,17 @@ describe('Privileged context state consistency', () => {
7171 // User selects privileged context
7272 await handleSelectPrivilegedContext ( { contextId : 'chrome-context-id' } ) ;
7373
74- // BUG: currentContextId is still 'original-content-context' because
75- // select_privileged_context never called setCurrentContextId.
76- // So when set_firefox_prefs saves originalContextId, it gets the wrong value.
7774 mockExecuteScript . mockResolvedValue ( undefined ) ;
7875 mockSwitchToWindow . mockClear ( ) ;
7976 mockSetContext . mockClear ( ) ;
8077
78+ // Call set_firefox_prefs which requires privileged context.
8179 await handleSetFirefoxPrefs ( { prefs : { 'browser.ml.enable' : true } } ) ;
8280
83- // The finally block in set_firefox_prefs restores to originalContextId.
84- // Because currentContextId was never updated, it restores to
85- // 'original-content-context' — silently undoing the privileged context selection.
8681 const setContextCalls = mockSetContext . mock . calls ;
8782 const lastSetContext = setContextCalls [ setContextCalls . length - 1 ] ;
8883
89- // BUG: last setContext call is 'content' — it reverted the privileged context
90- // After fix: the tool should detect we're already in a privileged context
91- // and restore back to it (or at minimum, currentContextId should be correct)
84+ // Check that the context has not switched to content unexpectedly.
9285 expect ( lastSetContext [ 0 ] ) . not . toBe ( 'content' ) ;
9386 } ) ;
9487} ) ;
0 commit comments