Skip to content

Commit 08c1cb2

Browse files
committed
fix(search): align typed metadata with full-mode payload
1 parent 31fa094 commit 08c1cb2

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

src/tools/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ export interface SearchResultItem {
8484
callers?: string[];
8585
tests?: string[];
8686
};
87+
imports?: string[];
88+
exports?: string[];
8789
snippet?: string;
8890
}
8991

tests/search-compact-mode.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)