2025-07-23 18:25:15 +00:00
import { expect , test } from 'vitest'
2025-08-22 18:48:29 +00:00
import { renderHook } from '@testing-library/react' ;
2025-07-23 18:25:15 +00:00
import { useExtractReferences } from './useExtractReferences' ;
import { getFileReferenceId } from './utils' ;
2025-07-26 01:34:33 +00:00
import { TextUIPart } from 'ai' ;
2025-07-23 18:25:15 +00:00
test ( 'useExtractReferences extracts file references from text content' , ( ) = > {
2025-07-26 01:34:33 +00:00
const part : TextUIPart = {
type : 'text' ,
text : 'The auth flow is implemented in @file:{github.com/sourcebot-dev/sourcebot::auth.ts} and uses sessions @file:{github.com/sourcebot-dev/sourcebot::auth.ts:45-60}.'
}
2025-07-23 18:25:15 +00:00
2025-07-26 01:34:33 +00:00
const { result } = renderHook ( ( ) = > useExtractReferences ( part ) ) ;
2025-07-23 18:25:15 +00:00
expect ( result . current ) . toHaveLength ( 2 ) ;
expect ( result . current [ 0 ] ) . toMatchObject ( {
2025-07-24 17:21:00 +00:00
repo : 'github.com/sourcebot-dev/sourcebot' ,
path : 'auth.ts' ,
id : getFileReferenceId ( { repo : 'github.com/sourcebot-dev/sourcebot' , path : 'auth.ts' } ) ,
2025-07-23 18:25:15 +00:00
type : 'file' ,
} ) ;
expect ( result . current [ 1 ] ) . toMatchObject ( {
2025-07-24 17:21:00 +00:00
repo : 'github.com/sourcebot-dev/sourcebot' ,
path : 'auth.ts' ,
2025-07-23 18:25:15 +00:00
id : getFileReferenceId ( {
2025-07-24 17:21:00 +00:00
repo : 'github.com/sourcebot-dev/sourcebot' ,
path : 'auth.ts' ,
2025-07-23 18:25:15 +00:00
range : {
startLine : 45 ,
endLine : 60 ,
}
} ) ,
type : 'file' ,
range : {
startLine : 45 ,
endLine : 60 ,
}
} ) ;
} ) ;