@@ -1517,6 +1517,42 @@ describe('OAuth provider context propagation', () => {
15171517 expect ( fetchMock ) . toHaveBeenCalledTimes ( 2 )
15181518 } )
15191519
1520+ it ( 'rejects a stale QuickBooks realm when the credential response omits its binding' , async ( ) => {
1521+ mockGenerateInternalToken . mockResolvedValue ( 'internal-token' )
1522+ const fetchMock = vi . fn ( ) . mockImplementation ( async ( url : string ) => {
1523+ if ( url . includes ( '/api/auth/oauth/token' ) ) {
1524+ return new Response ( JSON . stringify ( { accessToken : 'fresh-access-token' } ) , {
1525+ headers : { 'Content-Type' : 'application/json' } ,
1526+ } )
1527+ }
1528+
1529+ throw new Error ( 'QuickBooks API must not be called with an unbound realm' )
1530+ } )
1531+ global . fetch = Object . assign ( fetchMock , { preconnect : vi . fn ( ) } ) as typeof fetch
1532+
1533+ const result = await executeTool (
1534+ 'test_quickbooks_context' ,
1535+ {
1536+ credential : 'quickbooks-credential' ,
1537+ realmId : 'workflow-supplied-company' ,
1538+ } ,
1539+ {
1540+ executionContext : createToolExecutionContext ( {
1541+ userId : 'user-123' ,
1542+ workflowId : 'workflow-123' ,
1543+ } ) ,
1544+ }
1545+ )
1546+
1547+ expect ( result ) . toMatchObject ( {
1548+ success : false ,
1549+ error : expect . stringContaining (
1550+ 'QuickBooks company identity is missing. Reconnect the QuickBooks credential.'
1551+ ) ,
1552+ } )
1553+ expect ( fetchMock ) . toHaveBeenCalledTimes ( 1 )
1554+ } )
1555+
15201556 it ( 'does not expose a non-JSON QuickBooks failure body in tool output' , async ( ) => {
15211557 mockGenerateInternalToken . mockResolvedValue ( 'internal-token' )
15221558 const fetchMock = vi . fn ( ) . mockImplementation ( async ( url : string ) => {
0 commit comments