@@ -236,7 +236,7 @@ describe('Search source identity and concurrent creation', () => {
236236 ) . toHaveLength ( 0 )
237237 } )
238238
239- it ( 'adopts a legacy index only during admin setup and persists its canonical identity ' , async ( ) => {
239+ it ( 'preserves ordinary KB name collisions and creates one explicit Search configuration ' , async ( ) => {
240240 await db
241241 . update ( knowledgeBase )
242242 . set ( { name : 'Sim Search' } )
@@ -258,18 +258,40 @@ describe('Search source identity and concurrent creation', () => {
258258 principal : { kind : 'session' , userId : other . aliceId , sessionId : 'fixture-admin' } ,
259259 input,
260260 } )
261- const results = await Promise . all ( [ prepare ( ) , prepare ( ) ] )
262- expect ( results . map ( ( result ) => result . knowledgeBaseId ) ) . toEqual ( [
263- other . knowledgeBaseId ,
264- other . knowledgeBaseId ,
265- ] )
261+ await expect ( prepare ( ) ) . rejects . toMatchObject ( { code : 'conflict' } )
262+ expect (
263+ await db
264+ . select ( { name : knowledgeBase . name , isSearchIndex : knowledgeBase . isSearchIndex } )
265+ . from ( knowledgeBase )
266+ . where ( eq ( knowledgeBase . id , other . knowledgeBaseId ) )
267+ ) . toEqual ( [ { name : 'Sim Search' , isSearchIndex : false } ] )
266268 await db
267269 . update ( knowledgeBase )
268- . set ( { name : 'Renamed adopted index ' } )
270+ . set ( { name : 'Ordinary knowledge ' } )
269271 . where ( eq ( knowledgeBase . id , other . knowledgeBaseId ) )
272+ const results = await Promise . all ( [ prepare ( ) , prepare ( ) ] )
273+ const searchId = results [ 0 ] . knowledgeBaseId
274+ expect ( searchId ) . not . toBe ( other . knowledgeBaseId )
275+ expect ( results [ 1 ] . knowledgeBaseId ) . toBe ( searchId )
276+ expect (
277+ await db
278+ . select ( { id : knowledgeBase . id } )
279+ . from ( knowledgeBase )
280+ . where (
281+ and (
282+ eq ( knowledgeBase . workspaceId , other . workspaceId ) ,
283+ eq ( knowledgeBase . isSearchIndex , true )
284+ )
285+ )
286+ ) . toEqual ( [ { id : searchId } ] )
287+ await db
288+ . update ( knowledgeBase )
289+ . set ( { name : 'Renamed Search configuration' } )
290+ . where ( eq ( knowledgeBase . id , searchId ) )
270291 await expect ( readSearchIndex . execute ( { principal : reader , input } ) ) . resolves . toMatchObject ( {
271- knowledgeBaseId : other . knowledgeBaseId ,
292+ knowledgeBaseId : searchId ,
272293 } )
294+ await expect ( prepare ( ) ) . resolves . toMatchObject ( { knowledgeBaseId : searchId } )
273295 } )
274296
275297 it ( 'serializes matching creates across independent database transactions and keeps one grant' , async ( ) => {
0 commit comments