@@ -16,7 +16,6 @@ const {
1616 mockExecuteKnowledgeSearch,
1717 mockRetrievalStatus,
1818 mockGenerateSearchEmbedding,
19- mockGetDocumentMetadataByIds,
2019 mockGetDocumentTagDefinitions,
2120 mockAuthenticateRequest,
2221 mockValidateWorkspaceAccess,
@@ -28,7 +27,6 @@ const {
2827 mockExecuteKnowledgeSearch : vi . fn ( ) ,
2928 mockRetrievalStatus : vi . fn ( ( ) => ( { status : 'complete' , timedOutLegs : [ ] } ) ) ,
3029 mockGenerateSearchEmbedding : vi . fn ( ) ,
31- mockGetDocumentMetadataByIds : vi . fn ( ) ,
3230 mockGetDocumentTagDefinitions : vi . fn ( ) ,
3331 mockAuthenticateRequest : vi . fn ( ) ,
3432 mockValidateWorkspaceAccess : vi . fn ( ) ,
@@ -60,9 +58,7 @@ vi.mock('@/lib/knowledge/search/queries', () => ({
6058 retrieveKnowledgeSearch : async ( params : { access : unknown } ) => ( {
6159 rows : await mockExecuteKnowledgeSearch ( params ) ,
6260 retrieval : mockRetrievalStatus ( ) ,
63- readAccess : params . access ,
6461 } ) ,
65- getDocumentMetadataByIds : mockGetDocumentMetadataByIds ,
6662} ) )
6763
6864vi . mock ( '@/app/api/knowledge/utils' , ( ) => knowledgeApiUtilsMock )
@@ -132,7 +128,6 @@ describe('v1 knowledge search route — per-KB embedding model', () => {
132128 isBYOK : false ,
133129 } )
134130 mockExecuteKnowledgeSearch . mockResolvedValue ( [ ] )
135- mockGetDocumentMetadataByIds . mockResolvedValue ( { } )
136131 mockGetDocumentTagDefinitions . mockResolvedValue ( [ ] )
137132 mockResolveBillingAttribution . mockImplementation (
138133 ( { actorUserId, workspaceId } : { actorUserId : string ; workspaceId : string } ) =>
@@ -164,7 +159,6 @@ describe('v1 knowledge search route — per-KB embedding model', () => {
164159 )
165160 expect ( mockExecuteKnowledgeSearch ) . toHaveBeenCalledOnce ( )
166161 expect ( response . status ) . toBe ( 500 )
167- expect ( mockGetDocumentMetadataByIds ) . not . toHaveBeenCalled ( )
168162 } )
169163
170164 it ( 'retains the reader provider for ranked results and returned document metadata' , async ( ) => {
@@ -193,17 +187,11 @@ describe('v1 knowledge search route — per-KB embedding model', () => {
193187 accessProvider : provider ,
194188 } )
195189 )
196- expect ( mockGetDocumentMetadataByIds ) . toHaveBeenCalledWith ( [ ] , access )
197190 } )
198191
199- it . each ( [
200- [ 'query' , false ] ,
201- [ 'query' , true ] ,
202- [ 'filters' , false ] ,
203- [ 'filters' , true ] ,
204- ] as const ) (
205- 'omits newly denied content from %s results and counts when all denied is %s' ,
206- async ( mode , allDenied ) => {
192+ it . each ( [ 'query' , 'filters' ] as const ) (
193+ 'renders the source card each %s result row carries' ,
194+ async ( mode ) => {
207195 const access = { kind : 'user' as const , userId : 'user-1' , tokens : [ 'reader-token' ] }
208196 const provider = {
209197 get : vi . fn ( ) . mockResolvedValue ( access ) ,
@@ -219,26 +207,17 @@ describe('v1 knowledge search route — per-KB embedding model', () => {
219207 { tagSlot : 'tag1' , displayName : 'category' , fieldType : 'text' } ,
220208 ] )
221209 mockExecuteKnowledgeSearch . mockResolvedValue ( [
222- {
223- documentId : 'revoked-document' ,
224- knowledgeBaseId : 'kb-1' ,
225- content : 'revoked page content' ,
226- tag1 : 'revoked tag' ,
227- chunkIndex : 0 ,
228- distance : 0.1 ,
229- } ,
230210 {
231211 documentId : 'allowed-document' ,
232212 knowledgeBaseId : 'kb-1' ,
233213 content : 'allowed page content' ,
214+ filename : 'Allowed page' ,
215+ sourceUrl : null ,
234216 tag1 : 'docs' ,
235217 chunkIndex : 0 ,
236218 distance : 0.2 ,
237219 } ,
238220 ] )
239- mockGetDocumentMetadataByIds . mockResolvedValue (
240- allDenied ? { } : { 'allowed-document' : { filename : 'Allowed page' , sourceUrl : null } }
241- )
242221 const response = await POST (
243222 createMockRequest ( 'POST' , {
244223 workspaceId : 'ws-1' ,
@@ -250,24 +229,19 @@ describe('v1 knowledge search route — per-KB embedding model', () => {
250229 )
251230 const body = await response . json ( )
252231 expect ( response . status ) . toBe ( 200 )
253- expect ( mockGetDocumentMetadataByIds ) . toHaveBeenCalledWith (
254- [ 'revoked-document' , 'allowed-document' ] ,
255- access
256- )
257- expect ( body . data . results ) . toEqual (
258- allDenied
259- ? [ ]
260- : [
261- expect . objectContaining ( {
262- documentId : 'allowed-document' ,
263- documentName : 'Allowed page' ,
264- content : 'allowed page content' ,
265- metadata : { category : 'docs' } ,
266- } ) ,
267- ]
232+ expect ( mockExecuteKnowledgeSearch ) . toHaveBeenCalledWith (
233+ expect . objectContaining ( { access, accessProvider : provider } )
268234 )
269- expect ( body . data . totalResults ) . toBe ( allDenied ? 0 : 1 )
270- expect ( JSON . stringify ( body ) ) . not . toContain ( 'revoked' )
235+ expect ( body . data . results ) . toEqual ( [
236+ expect . objectContaining ( {
237+ documentId : 'allowed-document' ,
238+ documentName : 'Allowed page' ,
239+ sourceUrl : null ,
240+ content : 'allowed page content' ,
241+ metadata : { category : 'docs' } ,
242+ } ) ,
243+ ] )
244+ expect ( body . data . totalResults ) . toBe ( 1 )
271245 }
272246 )
273247
@@ -372,7 +346,7 @@ describe('v1 knowledge search route — per-KB embedding model', () => {
372346 expect ( mockGenerateSearchEmbedding ) . not . toHaveBeenCalled ( )
373347 } )
374348
375- it ( 'surfaces sourceUrl from document metadata in search results ' , async ( ) => {
349+ it ( 'surfaces the sourceUrl a result row carries ' , async ( ) => {
376350 mockCheckKnowledgeBaseAccess . mockResolvedValueOnce ( {
377351 hasAccess : true ,
378352 knowledgeBase : baseKb ( 'kb-confluence' , 'text-embedding-3-small' ) ,
@@ -382,16 +356,12 @@ describe('v1 knowledge search route — per-KB embedding model', () => {
382356 documentId : 'doc-confluence' ,
383357 knowledgeBaseId : 'kb-confluence' ,
384358 content : 'page content' ,
359+ filename : 'Runbook.md' ,
360+ sourceUrl : 'https://example.atlassian.net/wiki/spaces/DOCS/pages/12345' ,
385361 chunkIndex : 0 ,
386362 distance : 0.1 ,
387363 } ,
388364 ] )
389- mockGetDocumentMetadataByIds . mockResolvedValue ( {
390- 'doc-confluence' : {
391- filename : 'Runbook.md' ,
392- sourceUrl : 'https://example.atlassian.net/wiki/spaces/DOCS/pages/12345' ,
393- } ,
394- } )
395365
396366 const req = createMockRequest ( 'POST' , {
397367 workspaceId : 'ws-1' ,
0 commit comments