@@ -500,6 +500,66 @@ describe('search_codebase compact/full mode', () => {
500500 ] ) ;
501501 } ) ;
502502
503+ it ( 'real CodebaseSearcher preserves chunk imports and exports' , async ( ) => {
504+ if ( ! tempRoot ) throw new Error ( 'tempRoot not initialized' ) ;
505+
506+ const ctxDir = path . join ( tempRoot , CODEBASE_CONTEXT_DIRNAME ) ;
507+ const actualChunk = {
508+ id : 'auth-chunk' ,
509+ content :
510+ 'import { tokenStore } from "./token-store";\nexport class AuthService {\n getToken() { return tokenStore.read(); }\n}\nexport const AUTH_TOKEN = "auth";' ,
511+ filePath : path . join ( tempRoot , 'src' , 'auth' , 'auth.service.ts' ) ,
512+ relativePath : 'src/auth/auth.service.ts' ,
513+ startLine : 1 ,
514+ endLine : 5 ,
515+ language : 'ts' ,
516+ dependencies : [ ] ,
517+ imports : [
518+ 'src/auth/token-store.ts' ,
519+ 'src/auth/session.ts' ,
520+ 'src/shared/logger.ts' ,
521+ 'src/config/env.ts' ,
522+ 'src/http/client.ts'
523+ ] ,
524+ exports : [ 'AuthService' , 'AUTH_TOKEN' ] ,
525+ tags : [ 'service' ] ,
526+ metadata : {
527+ className : 'AuthService' ,
528+ symbolAware : true ,
529+ symbolName : 'AuthService' ,
530+ symbolKind : 'class'
531+ }
532+ } ;
533+
534+ await fs . writeFile (
535+ path . join ( ctxDir , KEYWORD_INDEX_FILENAME ) ,
536+ JSON . stringify (
537+ {
538+ header : { buildId : 'test-build-compact' , formatVersion : INDEX_FORMAT_VERSION } ,
539+ chunks : [ actualChunk ]
540+ } ,
541+ null ,
542+ 2
543+ ) ,
544+ 'utf-8'
545+ ) ;
546+
547+ const actualSearchModule = await vi . importActual < typeof import ( '../src/core/search.js' ) > (
548+ '../src/core/search.js'
549+ ) ;
550+ const searcher = new actualSearchModule . CodebaseSearcher ( tempRoot ) ;
551+ const results = await searcher . search ( 'AuthService token' , 5 , undefined , {
552+ useSemanticSearch : false ,
553+ useKeywordSearch : true ,
554+ enableReranker : false
555+ } ) ;
556+
557+ expect ( results ) . toHaveLength ( 1 ) ;
558+ expect ( results [ 0 ] . filePath ) . toBe ( actualChunk . filePath ) ;
559+ expect ( results [ 0 ] . imports ) . toEqual ( actualChunk . imports ) ;
560+ expect ( results [ 0 ] . exports ) . toEqual ( actualChunk . exports ) ;
561+ } ) ;
562+
503563 it ( 'adds a warning only when the final full payload exceeds the compact budget threshold' , async ( ) => {
504564 const oversizedSummary = 'Token-heavy summary ' . repeat ( 1200 ) ;
505565 const oversizedSnippet = 'const token = authService.getToken();\n' . repeat ( 600 ) ;
0 commit comments