@@ -525,66 +525,68 @@ describe('organization Search MCP with real ingestion and current access', () =>
525525 await db
526526 . delete ( organizationSearchMcpInvocation )
527527 . where ( eq ( organizationSearchMcpInvocation . organizationId , organizationId ) )
528+ const clientName = 'MCP fixture client' . repeat ( 20 )
528529 await db
529530 . update ( oauthClient )
530- . set ( { name : 'MCP fixture client' } )
531+ . set ( { name : clientName } )
531532 . where ( eq ( oauthClient . clientId , oauthClientId ) )
532- await aliceOAuth . listTools ( )
533- expect ( fixtures . afterResponse ) . toHaveLength ( 0 )
534- await search ( aliceOAuth )
535- await value ( aliceOAuth , 'read_document' , { documentId } )
536- expect ( ( await call ( bob , 'read_document' , { documentId } ) ) . isError ) . toBe ( true )
537- expect ( fixtures . afterResponse ) . toHaveLength ( 3 )
538- await flushAfterResponse ( )
539- const rows = await db
540- . select ( )
541- . from ( organizationSearchMcpInvocation )
542- . where ( eq ( organizationSearchMcpInvocation . organizationId , organizationId ) )
543- . orderBy ( organizationSearchMcpInvocation . createdAt )
544- . limit ( 10 )
545- expect ( rows ) . toHaveLength ( 3 )
546- expect ( rows ) . toMatchObject ( [
547- {
548- organizationId,
549- userId : aliceId ,
550- authKind : 'oauth_access_token' ,
551- oauthClientId,
552- clientName : 'MCP fixture client' ,
553- toolName : 'search' ,
554- outcome : 'success' ,
555- } ,
556- {
557- organizationId,
558- userId : aliceId ,
559- authKind : 'oauth_access_token' ,
560- oauthClientId,
561- clientName : 'MCP fixture client' ,
562- toolName : 'read_document' ,
563- outcome : 'success' ,
564- } ,
565- {
566- organizationId,
567- userId : bobId ,
568- authKind : 'personal_api_key' ,
569- oauthClientId : null ,
570- clientName : null ,
571- toolName : 'read_document' ,
572- outcome : 'error' ,
573- } ,
574- ] )
575- expect ( rows . every ( ( row ) => row . durationMs >= 0 ) ) . toBe ( true )
576- expect ( JSON . stringify ( rows ) ) . not . toContain ( documentId )
577- expect ( JSON . stringify ( rows ) ) . not . toContain ( oauthTokens . alice )
578- await db
579- . update ( oauthClient )
580- . set ( { name : 'Renamed client' } )
581- . where ( eq ( oauthClient . clientId , oauthClientId ) )
582- const [ historical ] = await db
583- . select ( )
584- . from ( organizationSearchMcpInvocation )
585- . where ( eq ( organizationSearchMcpInvocation . id , rows [ 0 ] . id ) )
586- . limit ( 1 )
587- expect ( historical . clientName ) . toBe ( 'MCP fixture client' )
533+ try {
534+ await aliceOAuth . listTools ( )
535+ expect ( fixtures . afterResponse ) . toHaveLength ( 0 )
536+ await search ( aliceOAuth )
537+ await value ( aliceOAuth , 'read_document' , { documentId } )
538+ expect ( ( await call ( bob , 'read_document' , { documentId } ) ) . isError ) . toBe ( true )
539+ expect ( fixtures . afterResponse ) . toHaveLength ( 3 )
540+ await db
541+ . update ( oauthClient )
542+ . set ( { name : 'Renamed client' } )
543+ . where ( eq ( oauthClient . clientId , oauthClientId ) )
544+ await flushAfterResponse ( )
545+ const rows = await db
546+ . select ( )
547+ . from ( organizationSearchMcpInvocation )
548+ . where ( eq ( organizationSearchMcpInvocation . organizationId , organizationId ) )
549+ . orderBy ( organizationSearchMcpInvocation . createdAt )
550+ . limit ( 10 )
551+ expect ( rows ) . toHaveLength ( 3 )
552+ expect ( rows ) . toMatchObject ( [
553+ {
554+ organizationId,
555+ userId : aliceId ,
556+ authKind : 'oauth_access_token' ,
557+ oauthClientId,
558+ clientName : clientName . slice ( 0 , 256 ) ,
559+ toolName : 'search' ,
560+ outcome : 'success' ,
561+ } ,
562+ {
563+ organizationId,
564+ userId : aliceId ,
565+ authKind : 'oauth_access_token' ,
566+ oauthClientId,
567+ clientName : clientName . slice ( 0 , 256 ) ,
568+ toolName : 'read_document' ,
569+ outcome : 'success' ,
570+ } ,
571+ {
572+ organizationId,
573+ userId : bobId ,
574+ authKind : 'personal_api_key' ,
575+ oauthClientId : null ,
576+ clientName : null ,
577+ toolName : 'read_document' ,
578+ outcome : 'error' ,
579+ } ,
580+ ] )
581+ expect ( rows . every ( ( row ) => row . durationMs >= 0 ) ) . toBe ( true )
582+ expect ( JSON . stringify ( rows ) ) . not . toContain ( documentId )
583+ expect ( JSON . stringify ( rows ) ) . not . toContain ( oauthTokens . alice )
584+ } finally {
585+ await db
586+ . update ( oauthClient )
587+ . set ( { name : 'Search MCP OAuth fixture' } )
588+ . where ( eq ( oauthClient . clientId , oauthClientId ) )
589+ }
588590 } )
589591
590592 it ( 'enforces current document and organization access on Search OAuth clients' , async ( ) => {
0 commit comments