@@ -21,7 +21,6 @@ const mocks = vi.hoisted(() => ({
2121 generateEmbedding : vi . fn ( ) ,
2222 executeSearch : vi . fn ( ) ,
2323 retrieval : vi . fn ( ) ,
24- getDocumentMetadata : vi . fn ( ) ,
2524 getTagDefinitions : vi . fn ( ) ,
2625 getTagDefinitionsBatch : vi . fn ( ) ,
2726 recordEmbeddingUsage : vi . fn ( ) ,
@@ -100,7 +99,6 @@ vi.mock('@/lib/knowledge/search/queries', () => ({
10099 retrieval : mocks . retrieval ( ) ,
101100 readAccess : ( args [ 0 ] as { access : unknown } ) . access ,
102101 } ) ,
103- getDocumentMetadataByIds : mocks . getDocumentMetadata ,
104102} ) )
105103
106104vi . mock ( '@/lib/knowledge/tags/service' , ( ) => ( {
@@ -170,6 +168,9 @@ describe('knowledge search application use case', () => {
170168 content : 'answer' ,
171169 chunkIndex : 0 ,
172170 distance : 0.2 ,
171+ filename : 'guide.pdf' ,
172+ sourceUrl : null ,
173+ connectorType : null ,
173174 tag1 : null ,
174175 tag2 : null ,
175176 tag3 : null ,
@@ -189,29 +190,11 @@ describe('knowledge search application use case', () => {
189190 boolean3 : null ,
190191 } ,
191192 ] )
192- mocks . getDocumentMetadata . mockResolvedValue ( {
193- 'document-1' : { filename : 'guide.pdf' , sourceUrl : null } ,
194- } )
195193 mocks . getTagDefinitions . mockResolvedValue ( [ ] )
196194 mocks . recordEmbeddingUsage . mockResolvedValue ( undefined )
197195 mocks . importProvenance . mockResolvedValue ( { imported : true , documentMetadata : { } } )
198196 } )
199197
200- it ( 'drops passages whose access was revoked before the final document metadata read' , async ( ) => {
201- mocks . getDocumentMetadata . mockResolvedValue ( { } )
202- const result = await searchKnowledge . execute ( {
203- principal : { kind : 'session' , userId : 'user-1' , sessionId : 'session-1' } ,
204- input : {
205- workspaceId : 'workspace-1' ,
206- knowledgeBaseIds : [ 'knowledge-1' ] ,
207- query : 'orion' ,
208- topK : 20 ,
209- } ,
210- } )
211- expect ( result . results ) . toEqual ( [ ] )
212- expect ( result . totalResults ) . toBe ( 0 )
213- } )
214-
215198 it . each ( [ false , true ] ) (
216199 'requires explicit partial-result support for empty incomplete searches (allowPartialResults=%s)' ,
217200 async ( allowPartialResults ) => {
@@ -512,7 +495,6 @@ describe('knowledge search application use case', () => {
512495 } )
513496 ) . rejects . toThrow ( 'Search superseded during embedding' )
514497 expect ( mocks . executeSearch ) . not . toHaveBeenCalled ( )
515- expect ( mocks . getDocumentMetadata ) . not . toHaveBeenCalled ( )
516498 } )
517499
518500 it ( 'does not start reranking or metadata reads after retrieval is cancelled' , async ( ) => {
@@ -536,7 +518,6 @@ describe('knowledge search application use case', () => {
536518 } )
537519 ) . rejects . toThrow ( 'Search superseded during retrieval' )
538520 expect ( mocks . rerank ) . not . toHaveBeenCalled ( )
539- expect ( mocks . getDocumentMetadata ) . not . toHaveBeenCalled ( )
540521 expect ( mocks . searched ) . not . toHaveBeenCalled ( )
541522 } )
542523
@@ -550,6 +531,9 @@ describe('knowledge search application use case', () => {
550531 content : 'first' ,
551532 chunkIndex : 0 ,
552533 distance : 0.1 ,
534+ filename : 'thread' ,
535+ sourceUrl : null ,
536+ connectorType : 'slack' ,
553537 } ,
554538 {
555539 id : 'chunk-2' ,
@@ -558,6 +542,9 @@ describe('knowledge search application use case', () => {
558542 content : 'second' ,
559543 chunkIndex : 1 ,
560544 distance : 0.2 ,
545+ filename : 'thread' ,
546+ sourceUrl : null ,
547+ connectorType : 'slack' ,
561548 } ,
562549 {
563550 id : 'chunk-3' ,
@@ -566,12 +553,11 @@ describe('knowledge search application use case', () => {
566553 content : 'third' ,
567554 chunkIndex : 0 ,
568555 distance : 0.3 ,
556+ filename : 'page' ,
557+ sourceUrl : null ,
558+ connectorType : 'gitlab' ,
569559 } ,
570560 ] )
571- mocks . getDocumentMetadata . mockResolvedValue ( {
572- 'document-1' : { filename : 'thread' , connectorType : 'slack' } ,
573- 'document-2' : { filename : 'page' , connectorType : 'gitlab' } ,
574- } )
575561 await searchKnowledge . execute ( {
576562 principal : { kind : 'personal_api_key' , userId : 'user-1' , keyId : 'key-1' } ,
577563 input : {
@@ -808,14 +794,20 @@ describe('knowledge search application use case', () => {
808794 it ( 'keeps the source card metadata when a provenance registry is present' , async ( ) => {
809795 const registry = { markIncomplete : vi . fn ( ) }
810796 const sourceModifiedAt = new Date ( '2026-08-20T12:00:00Z' )
811- mocks . getDocumentMetadata . mockResolvedValueOnce ( {
812- 'document-1' : {
797+ mocks . executeSearch . mockResolvedValueOnce ( [
798+ {
799+ id : 'embedding-1' ,
800+ documentId : 'document-1' ,
801+ knowledgeBaseId : 'knowledge-1' ,
802+ content : 'answer' ,
803+ chunkIndex : 0 ,
804+ distance : 0.2 ,
805+ sourceModifiedAt,
813806 filename : 'guide.pdf' ,
814807 sourceUrl : 'https://example.com/guide' ,
815- sourceModifiedAt,
816808 connectorType : 'google_drive' ,
817809 } ,
818- } )
810+ ] )
819811
820812 const result = await searchKnowledge . execute ( {
821813 principal : { kind : 'session' , userId : 'user-1' , sessionId : 'session-1' } ,
@@ -828,7 +820,6 @@ describe('knowledge search application use case', () => {
828820 } ,
829821 } )
830822
831- expect ( mocks . getDocumentMetadata ) . toHaveBeenCalledWith ( [ 'document-1' ] , expect . anything ( ) )
832823 expect ( result . results [ 0 ] ) . toMatchObject ( {
833824 documentName : 'guide.pdf' ,
834825 sourceUrl : 'https://example.com/guide' ,
0 commit comments