codevault 1.8.4 → 1.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/chunking/token-counter.d.ts.map +1 -1
- package/dist/chunking/token-counter.js +16 -10
- package/dist/chunking/token-counter.js.map +1 -1
- package/dist/cli/commands/index-cmd.d.ts.map +1 -1
- package/dist/cli/commands/index-cmd.js +108 -97
- package/dist/cli/commands/index-cmd.js.map +1 -1
- package/dist/cli/commands/interactive-config.d.ts.map +1 -1
- package/dist/cli/commands/interactive-config.js +40 -3
- package/dist/cli/commands/interactive-config.js.map +1 -1
- package/dist/cli/commands/search-cmd.d.ts.map +1 -1
- package/dist/cli/commands/search-cmd.js +11 -7
- package/dist/cli/commands/search-cmd.js.map +1 -1
- package/dist/cli/commands/search-with-code-cmd.d.ts.map +1 -1
- package/dist/cli/commands/search-with-code-cmd.js +3 -1
- package/dist/cli/commands/search-with-code-cmd.js.map +1 -1
- package/dist/cli/utils.d.ts +56 -0
- package/dist/cli/utils.d.ts.map +1 -0
- package/dist/cli/utils.js +98 -0
- package/dist/cli/utils.js.map +1 -0
- package/dist/config/constants.d.ts +4 -0
- package/dist/config/constants.d.ts.map +1 -1
- package/dist/config/constants.js +2 -0
- package/dist/config/constants.js.map +1 -1
- package/dist/context/packs.d.ts.map +1 -1
- package/dist/context/packs.js +3 -1
- package/dist/context/packs.js.map +1 -1
- package/dist/core/IndexerEngine.d.ts +2 -0
- package/dist/core/IndexerEngine.d.ts.map +1 -1
- package/dist/core/IndexerEngine.js +34 -26
- package/dist/core/IndexerEngine.js.map +1 -1
- package/dist/core/SearchService.d.ts +1 -0
- package/dist/core/SearchService.d.ts.map +1 -1
- package/dist/core/SearchService.js +18 -12
- package/dist/core/SearchService.js.map +1 -1
- package/dist/core/batch-indexer.d.ts.map +1 -1
- package/dist/core/batch-indexer.js +5 -13
- package/dist/core/batch-indexer.js.map +1 -1
- package/dist/core/indexing/IndexFinalizationStage.d.ts.map +1 -1
- package/dist/core/indexing/IndexFinalizationStage.js +21 -2
- package/dist/core/indexing/IndexFinalizationStage.js.map +1 -1
- package/dist/core/indexing/IndexState.d.ts +3 -8
- package/dist/core/indexing/IndexState.d.ts.map +1 -1
- package/dist/core/indexing/IndexState.js.map +1 -1
- package/dist/core/indexing/PersistManager.d.ts +1 -1
- package/dist/core/indexing/PersistManager.d.ts.map +1 -1
- package/dist/core/indexing/PersistManager.js +17 -17
- package/dist/core/indexing/PersistManager.js.map +1 -1
- package/dist/core/search/HybridFusion.d.ts +0 -1
- package/dist/core/search/HybridFusion.d.ts.map +1 -1
- package/dist/core/search/HybridFusion.js +2 -14
- package/dist/core/search/HybridFusion.js.map +1 -1
- package/dist/core/search/ResultMapper.d.ts +0 -1
- package/dist/core/search/ResultMapper.d.ts.map +1 -1
- package/dist/core/search/ResultMapper.js +2 -13
- package/dist/core/search/ResultMapper.js.map +1 -1
- package/dist/core/search/SearchContextManager.d.ts +3 -0
- package/dist/core/search/SearchContextManager.d.ts.map +1 -1
- package/dist/core/search/SearchContextManager.js +15 -2
- package/dist/core/search/SearchContextManager.js.map +1 -1
- package/dist/core/search.d.ts.map +1 -1
- package/dist/core/search.js +9 -4
- package/dist/core/search.js.map +1 -1
- package/dist/languages/rules.d.ts.map +1 -1
- package/dist/languages/rules.js +14 -5
- package/dist/languages/rules.js.map +1 -1
- package/dist/mcp/schemas.d.ts +2 -2
- package/dist/mcp-server.d.ts +1 -0
- package/dist/mcp-server.d.ts.map +1 -1
- package/dist/mcp-server.js +32 -21
- package/dist/mcp-server.js.map +1 -1
- package/dist/providers/base.d.ts +3 -2
- package/dist/providers/base.d.ts.map +1 -1
- package/dist/providers/base.js +3 -1
- package/dist/providers/base.js.map +1 -1
- package/dist/providers/chat-llm.d.ts +2 -2
- package/dist/providers/chat-llm.d.ts.map +1 -1
- package/dist/providers/chat-llm.js +4 -1
- package/dist/providers/chat-llm.js.map +1 -1
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +4 -1
- package/dist/providers/openai.js.map +1 -1
- package/dist/ranking/api-reranker.d.ts.map +1 -1
- package/dist/ranking/api-reranker.js +27 -8
- package/dist/ranking/api-reranker.js.map +1 -1
- package/dist/ranking/symbol-boost.d.ts.map +1 -1
- package/dist/ranking/symbol-boost.js +4 -11
- package/dist/ranking/symbol-boost.js.map +1 -1
- package/dist/search/bm25.d.ts +10 -0
- package/dist/search/bm25.d.ts.map +1 -1
- package/dist/search/bm25.js +16 -0
- package/dist/search/bm25.js.map +1 -1
- package/dist/storage/encrypted-chunks.d.ts +3 -0
- package/dist/storage/encrypted-chunks.d.ts.map +1 -1
- package/dist/storage/encrypted-chunks.js +108 -16
- package/dist/storage/encrypted-chunks.js.map +1 -1
- package/dist/synthesis/conversational-synthesizer.d.ts +2 -1
- package/dist/synthesis/conversational-synthesizer.d.ts.map +1 -1
- package/dist/synthesis/conversational-synthesizer.js +6 -1
- package/dist/synthesis/conversational-synthesizer.js.map +1 -1
- package/dist/synthesis/prompt-builder.d.ts.map +1 -1
- package/dist/synthesis/prompt-builder.js +40 -13
- package/dist/synthesis/prompt-builder.js.map +1 -1
- package/dist/synthesis/synthesizer.d.ts.map +1 -1
- package/dist/synthesis/synthesizer.js +14 -2
- package/dist/synthesis/synthesizer.js.map +1 -1
- package/dist/tests/api-reranker.test.d.ts +2 -0
- package/dist/tests/api-reranker.test.d.ts.map +1 -0
- package/dist/tests/api-reranker.test.js +575 -0
- package/dist/tests/api-reranker.test.js.map +1 -0
- package/dist/tests/bm25.test.d.ts +2 -0
- package/dist/tests/bm25.test.d.ts.map +1 -0
- package/dist/tests/bm25.test.js +340 -0
- package/dist/tests/bm25.test.js.map +1 -0
- package/dist/tests/chunking/file-grouper.test.d.ts +2 -0
- package/dist/tests/chunking/file-grouper.test.d.ts.map +1 -0
- package/dist/tests/chunking/file-grouper.test.js +495 -0
- package/dist/tests/chunking/file-grouper.test.js.map +1 -0
- package/dist/tests/chunking/semantic-chunker.test.d.ts +2 -0
- package/dist/tests/chunking/semantic-chunker.test.d.ts.map +1 -0
- package/dist/tests/chunking/semantic-chunker.test.js +509 -0
- package/dist/tests/chunking/semantic-chunker.test.js.map +1 -0
- package/dist/tests/chunking/token-counter.test.d.ts +2 -0
- package/dist/tests/chunking/token-counter.test.d.ts.map +1 -0
- package/dist/tests/chunking/token-counter.test.js +441 -0
- package/dist/tests/chunking/token-counter.test.js.map +1 -0
- package/dist/tests/cli/ask-cmd.test.d.ts +2 -0
- package/dist/tests/cli/ask-cmd.test.d.ts.map +1 -0
- package/dist/tests/cli/ask-cmd.test.js +152 -0
- package/dist/tests/cli/ask-cmd.test.js.map +1 -0
- package/dist/tests/cli/chat-cmd.test.d.ts +2 -0
- package/dist/tests/cli/chat-cmd.test.d.ts.map +1 -0
- package/dist/tests/cli/chat-cmd.test.js +118 -0
- package/dist/tests/cli/chat-cmd.test.js.map +1 -0
- package/dist/tests/cli/config-cmd.test.d.ts +2 -0
- package/dist/tests/cli/config-cmd.test.d.ts.map +1 -0
- package/dist/tests/cli/config-cmd.test.js +226 -0
- package/dist/tests/cli/config-cmd.test.js.map +1 -0
- package/dist/tests/cli/context.test.d.ts +2 -0
- package/dist/tests/cli/context.test.d.ts.map +1 -0
- package/dist/tests/cli/context.test.js +158 -0
- package/dist/tests/cli/context.test.js.map +1 -0
- package/dist/tests/cli/index-cmd.test.d.ts +2 -0
- package/dist/tests/cli/index-cmd.test.d.ts.map +1 -0
- package/dist/tests/cli/index-cmd.test.js +89 -0
- package/dist/tests/cli/index-cmd.test.js.map +1 -0
- package/dist/tests/cli/index.test.d.ts +2 -0
- package/dist/tests/cli/index.test.d.ts.map +1 -0
- package/dist/tests/cli/index.test.js +167 -0
- package/dist/tests/cli/index.test.js.map +1 -0
- package/dist/tests/cli/info-cmd.test.d.ts +2 -0
- package/dist/tests/cli/info-cmd.test.d.ts.map +1 -0
- package/dist/tests/cli/info-cmd.test.js +47 -0
- package/dist/tests/cli/info-cmd.test.js.map +1 -0
- package/dist/tests/cli/interactive-config.test.d.ts +2 -0
- package/dist/tests/cli/interactive-config.test.d.ts.map +1 -0
- package/dist/tests/cli/interactive-config.test.js +30 -0
- package/dist/tests/cli/interactive-config.test.js.map +1 -0
- package/dist/tests/cli/mcp-cmd.test.d.ts +2 -0
- package/dist/tests/cli/mcp-cmd.test.d.ts.map +1 -0
- package/dist/tests/cli/mcp-cmd.test.js +47 -0
- package/dist/tests/cli/mcp-cmd.test.js.map +1 -0
- package/dist/tests/cli/search-cmd.test.d.ts +2 -0
- package/dist/tests/cli/search-cmd.test.d.ts.map +1 -0
- package/dist/tests/cli/search-cmd.test.js +120 -0
- package/dist/tests/cli/search-cmd.test.js.map +1 -0
- package/dist/tests/cli/search-with-code-cmd.test.d.ts +2 -0
- package/dist/tests/cli/search-with-code-cmd.test.d.ts.map +1 -0
- package/dist/tests/cli/search-with-code-cmd.test.js +140 -0
- package/dist/tests/cli/search-with-code-cmd.test.js.map +1 -0
- package/dist/tests/cli/update-cmd.test.d.ts +2 -0
- package/dist/tests/cli/update-cmd.test.d.ts.map +1 -0
- package/dist/tests/cli/update-cmd.test.js +75 -0
- package/dist/tests/cli/update-cmd.test.js.map +1 -0
- package/dist/tests/cli/utils.test.d.ts +2 -0
- package/dist/tests/cli/utils.test.d.ts.map +1 -0
- package/dist/tests/cli/utils.test.js +119 -0
- package/dist/tests/cli/utils.test.js.map +1 -0
- package/dist/tests/cli/watch-cmd.test.d.ts +2 -0
- package/dist/tests/cli/watch-cmd.test.d.ts.map +1 -0
- package/dist/tests/cli/watch-cmd.test.js +84 -0
- package/dist/tests/cli/watch-cmd.test.js.map +1 -0
- package/dist/tests/cli-ui.test.d.ts +2 -0
- package/dist/tests/cli-ui.test.d.ts.map +1 -0
- package/dist/tests/cli-ui.test.js +608 -0
- package/dist/tests/cli-ui.test.js.map +1 -0
- package/dist/tests/codemap-io.test.d.ts +2 -0
- package/dist/tests/codemap-io.test.d.ts.map +1 -0
- package/dist/tests/codemap-io.test.js +992 -0
- package/dist/tests/codemap-io.test.js.map +1 -0
- package/dist/tests/config/apply-env.test.d.ts +2 -0
- package/dist/tests/config/apply-env.test.d.ts.map +1 -0
- package/dist/tests/config/apply-env.test.js +717 -0
- package/dist/tests/config/apply-env.test.js.map +1 -0
- package/dist/tests/config/constants.test.d.ts +2 -0
- package/dist/tests/config/constants.test.d.ts.map +1 -0
- package/dist/tests/config/constants.test.js +406 -0
- package/dist/tests/config/constants.test.js.map +1 -0
- package/dist/tests/config/loader.test.d.ts +2 -0
- package/dist/tests/config/loader.test.d.ts.map +1 -0
- package/dist/tests/config/loader.test.js +716 -0
- package/dist/tests/config/loader.test.js.map +1 -0
- package/dist/tests/config/resolver.test.d.ts +2 -0
- package/dist/tests/config/resolver.test.d.ts.map +1 -0
- package/dist/tests/config/resolver.test.js +402 -0
- package/dist/tests/config/resolver.test.js.map +1 -0
- package/dist/tests/config/types.test.d.ts +2 -0
- package/dist/tests/config/types.test.d.ts.map +1 -0
- package/dist/tests/config/types.test.js +460 -0
- package/dist/tests/config/types.test.js.map +1 -0
- package/dist/tests/context-packs.test.d.ts +2 -0
- package/dist/tests/context-packs.test.d.ts.map +1 -0
- package/dist/tests/context-packs.test.js +826 -0
- package/dist/tests/context-packs.test.js.map +1 -0
- package/dist/tests/conversational-synthesizer.test.d.ts +2 -0
- package/dist/tests/conversational-synthesizer.test.d.ts.map +1 -0
- package/dist/tests/conversational-synthesizer.test.js +595 -0
- package/dist/tests/conversational-synthesizer.test.js.map +1 -0
- package/dist/tests/database.test.d.ts +2 -0
- package/dist/tests/database.test.d.ts.map +1 -0
- package/dist/tests/database.test.js +965 -0
- package/dist/tests/database.test.js.map +1 -0
- package/dist/tests/encrypted-chunks.test.d.ts +2 -0
- package/dist/tests/encrypted-chunks.test.d.ts.map +1 -0
- package/dist/tests/encrypted-chunks.test.js +1470 -0
- package/dist/tests/encrypted-chunks.test.js.map +1 -0
- package/dist/tests/hybrid.test.d.ts +2 -0
- package/dist/tests/hybrid.test.d.ts.map +1 -0
- package/dist/tests/hybrid.test.js +456 -0
- package/dist/tests/hybrid.test.js.map +1 -0
- package/dist/tests/indexer/ChangeQueue.test.d.ts +12 -0
- package/dist/tests/indexer/ChangeQueue.test.d.ts.map +1 -0
- package/dist/tests/indexer/ChangeQueue.test.js +441 -0
- package/dist/tests/indexer/ChangeQueue.test.js.map +1 -0
- package/dist/tests/indexer/ProviderManager.test.d.ts +12 -0
- package/dist/tests/indexer/ProviderManager.test.d.ts.map +1 -0
- package/dist/tests/indexer/ProviderManager.test.js +290 -0
- package/dist/tests/indexer/ProviderManager.test.js.map +1 -0
- package/dist/tests/indexer/WatchService.test.d.ts +14 -0
- package/dist/tests/indexer/WatchService.test.d.ts.map +1 -0
- package/dist/tests/indexer/WatchService.test.js +667 -0
- package/dist/tests/indexer/WatchService.test.js.map +1 -0
- package/dist/tests/indexer/merkle.test.d.ts +11 -0
- package/dist/tests/indexer/merkle.test.d.ts.map +1 -0
- package/dist/tests/indexer/merkle.test.js +497 -0
- package/dist/tests/indexer/merkle.test.js.map +1 -0
- package/dist/tests/indexer/update.test.d.ts +10 -0
- package/dist/tests/indexer/update.test.d.ts.map +1 -0
- package/dist/tests/indexer/update.test.js +317 -0
- package/dist/tests/indexer/update.test.js.map +1 -0
- package/dist/tests/indexer/watch.test.d.ts +8 -0
- package/dist/tests/indexer/watch.test.d.ts.map +1 -0
- package/dist/tests/indexer/watch.test.js +95 -0
- package/dist/tests/indexer/watch.test.js.map +1 -0
- package/dist/tests/integration/index-search.integration.test.js +1 -0
- package/dist/tests/integration/index-search.integration.test.js.map +1 -1
- package/dist/tests/languages.test.d.ts +2 -0
- package/dist/tests/languages.test.d.ts.map +1 -0
- package/dist/tests/languages.test.js +575 -0
- package/dist/tests/languages.test.js.map +1 -0
- package/dist/tests/logger-redaction.test.d.ts +2 -0
- package/dist/tests/logger-redaction.test.d.ts.map +1 -0
- package/dist/tests/logger-redaction.test.js +48 -0
- package/dist/tests/logger-redaction.test.js.map +1 -0
- package/dist/tests/logger.test.d.ts +2 -0
- package/dist/tests/logger.test.d.ts.map +1 -0
- package/dist/tests/logger.test.js +468 -0
- package/dist/tests/logger.test.js.map +1 -0
- package/dist/tests/markdown-formatter.test.d.ts +2 -0
- package/dist/tests/markdown-formatter.test.d.ts.map +1 -0
- package/dist/tests/markdown-formatter.test.js +453 -0
- package/dist/tests/markdown-formatter.test.js.map +1 -0
- package/dist/tests/mcp/tools/use-context-pack.test.d.ts +7 -0
- package/dist/tests/mcp/tools/use-context-pack.test.d.ts.map +1 -0
- package/dist/tests/mcp/tools/use-context-pack.test.js +505 -0
- package/dist/tests/mcp/tools/use-context-pack.test.js.map +1 -0
- package/dist/tests/mutex.test.d.ts +2 -0
- package/dist/tests/mutex.test.d.ts.map +1 -0
- package/dist/tests/mutex.test.js +489 -0
- package/dist/tests/mutex.test.js.map +1 -0
- package/dist/tests/path-helpers.test.d.ts +2 -0
- package/dist/tests/path-helpers.test.d.ts.map +1 -0
- package/dist/tests/path-helpers.test.js +332 -0
- package/dist/tests/path-helpers.test.js.map +1 -0
- package/dist/tests/prompt-builder.test.d.ts +2 -0
- package/dist/tests/prompt-builder.test.d.ts.map +1 -0
- package/dist/tests/prompt-builder.test.js +417 -0
- package/dist/tests/prompt-builder.test.js.map +1 -0
- package/dist/tests/providers/base.test.d.ts +2 -0
- package/dist/tests/providers/base.test.d.ts.map +1 -0
- package/dist/tests/providers/base.test.js +299 -0
- package/dist/tests/providers/base.test.js.map +1 -0
- package/dist/tests/providers/chat-llm.test.d.ts +2 -0
- package/dist/tests/providers/chat-llm.test.d.ts.map +1 -0
- package/dist/tests/providers/chat-llm.test.js +435 -0
- package/dist/tests/providers/chat-llm.test.js.map +1 -0
- package/dist/tests/providers/index.test.d.ts +2 -0
- package/dist/tests/providers/index.test.d.ts.map +1 -0
- package/dist/tests/providers/index.test.js +204 -0
- package/dist/tests/providers/index.test.js.map +1 -0
- package/dist/tests/providers/mock.test.d.ts +2 -0
- package/dist/tests/providers/mock.test.d.ts.map +1 -0
- package/dist/tests/providers/mock.test.js +225 -0
- package/dist/tests/providers/mock.test.js.map +1 -0
- package/dist/tests/providers/openai.test.d.ts +2 -0
- package/dist/tests/providers/openai.test.d.ts.map +1 -0
- package/dist/tests/providers/openai.test.js +408 -0
- package/dist/tests/providers/openai.test.js.map +1 -0
- package/dist/tests/providers/token-counter.test.d.ts +2 -0
- package/dist/tests/providers/token-counter.test.d.ts.map +1 -0
- package/dist/tests/providers/token-counter.test.js +247 -0
- package/dist/tests/providers/token-counter.test.js.map +1 -0
- package/dist/tests/rate-limiter.test.js +392 -1
- package/dist/tests/rate-limiter.test.js.map +1 -1
- package/dist/tests/scope.test.d.ts +2 -0
- package/dist/tests/scope.test.d.ts.map +1 -0
- package/dist/tests/scope.test.js +529 -0
- package/dist/tests/scope.test.js.map +1 -0
- package/dist/tests/simple-lru.test.js +377 -0
- package/dist/tests/simple-lru.test.js.map +1 -1
- package/dist/tests/symbol-boost.test.js +730 -10
- package/dist/tests/symbol-boost.test.js.map +1 -1
- package/dist/tests/symbols-extract.test.d.ts +2 -0
- package/dist/tests/symbols-extract.test.d.ts.map +1 -0
- package/dist/tests/symbols-extract.test.js +536 -0
- package/dist/tests/symbols-extract.test.js.map +1 -0
- package/dist/tests/symbols-graph.test.d.ts +2 -0
- package/dist/tests/symbols-graph.test.d.ts.map +1 -0
- package/dist/tests/symbols-graph.test.js +656 -0
- package/dist/tests/symbols-graph.test.js.map +1 -0
- package/dist/tests/synthesizer.test.d.ts +2 -0
- package/dist/tests/synthesizer.test.d.ts.map +1 -0
- package/dist/tests/synthesizer.test.js +381 -0
- package/dist/tests/synthesizer.test.js.map +1 -0
- package/dist/types/context-pack.d.ts +3 -3
- package/dist/utils/logger.d.ts +5 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +149 -4
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/mutex.d.ts +7 -2
- package/dist/utils/mutex.d.ts.map +1 -1
- package/dist/utils/mutex.js +31 -7
- package/dist/utils/mutex.js.map +1 -1
- package/dist/utils/path-helpers.d.ts.map +1 -1
- package/dist/utils/path-helpers.js +5 -2
- package/dist/utils/path-helpers.js.map +1 -1
- package/dist/utils/simple-lru.d.ts +6 -0
- package/dist/utils/simple-lru.d.ts.map +1 -1
- package/dist/utils/simple-lru.js +26 -0
- package/dist/utils/simple-lru.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,21 +1,741 @@
|
|
|
1
1
|
import test from 'node:test';
|
|
2
2
|
import assert from 'node:assert/strict';
|
|
3
3
|
import { applySymbolBoost } from '../ranking/symbol-boost.js';
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// Helper Functions
|
|
6
|
+
// ============================================================================
|
|
7
|
+
function createCodemap(entries) {
|
|
8
|
+
const codemap = {};
|
|
9
|
+
for (const [id, entry] of Object.entries(entries)) {
|
|
10
|
+
codemap[id] = {
|
|
11
|
+
file: entry.file || 'src/test.ts',
|
|
12
|
+
sha: entry.sha || `sha-${id}`,
|
|
13
|
+
lang: entry.lang || 'typescript',
|
|
14
|
+
symbol: entry.symbol || null,
|
|
15
|
+
symbol_neighbors: entry.symbol_neighbors || [],
|
|
16
|
+
symbol_signature: entry.symbol_signature,
|
|
17
|
+
symbol_parameters: entry.symbol_parameters,
|
|
18
|
+
...entry,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return codemap;
|
|
22
|
+
}
|
|
23
|
+
function createResults(items) {
|
|
24
|
+
return items.map((item) => ({
|
|
25
|
+
id: item.id,
|
|
26
|
+
score: item.score,
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
// ============================================================================
|
|
30
|
+
// applySymbolBoost - Empty/Invalid Input Handling
|
|
31
|
+
// ============================================================================
|
|
32
|
+
test('applySymbolBoost handles empty results array', () => {
|
|
33
|
+
const codemap = createCodemap({
|
|
34
|
+
chunk1: { symbol: 'testFunction' },
|
|
35
|
+
});
|
|
36
|
+
const results = [];
|
|
37
|
+
applySymbolBoost(results, { query: 'test', codemap });
|
|
38
|
+
assert.equal(results.length, 0);
|
|
39
|
+
});
|
|
40
|
+
test('applySymbolBoost handles null results', () => {
|
|
41
|
+
const codemap = createCodemap({
|
|
42
|
+
chunk1: { symbol: 'testFunction' },
|
|
43
|
+
});
|
|
44
|
+
// Should not throw
|
|
45
|
+
applySymbolBoost(null, { query: 'test', codemap });
|
|
46
|
+
});
|
|
47
|
+
test('applySymbolBoost handles undefined results', () => {
|
|
48
|
+
const codemap = createCodemap({
|
|
49
|
+
chunk1: { symbol: 'testFunction' },
|
|
50
|
+
});
|
|
51
|
+
// Should not throw
|
|
52
|
+
applySymbolBoost(undefined, { query: 'test', codemap });
|
|
53
|
+
});
|
|
54
|
+
test('applySymbolBoost handles non-array results', () => {
|
|
55
|
+
const codemap = createCodemap({
|
|
56
|
+
chunk1: { symbol: 'testFunction' },
|
|
57
|
+
});
|
|
58
|
+
// Should not throw
|
|
59
|
+
applySymbolBoost('not an array', { query: 'test', codemap });
|
|
60
|
+
});
|
|
61
|
+
test('applySymbolBoost handles null codemap', () => {
|
|
62
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
63
|
+
applySymbolBoost(results, { query: 'test', codemap: null });
|
|
64
|
+
// Score should remain unchanged
|
|
65
|
+
assert.equal(results[0].score, 0.5);
|
|
66
|
+
assert.equal(results[0].symbolBoost, undefined);
|
|
67
|
+
});
|
|
68
|
+
test('applySymbolBoost handles undefined codemap', () => {
|
|
69
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
70
|
+
applySymbolBoost(results, { query: 'test', codemap: undefined });
|
|
71
|
+
// Score should remain unchanged
|
|
72
|
+
assert.equal(results[0].score, 0.5);
|
|
73
|
+
});
|
|
74
|
+
test('applySymbolBoost handles empty codemap', () => {
|
|
75
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
76
|
+
const codemap = {};
|
|
77
|
+
applySymbolBoost(results, { query: 'test', codemap });
|
|
78
|
+
// Score should remain unchanged (no matching metadata)
|
|
79
|
+
assert.equal(results[0].score, 0.5);
|
|
80
|
+
assert.equal(results[0].symbolBoost, undefined);
|
|
81
|
+
});
|
|
82
|
+
test('applySymbolBoost handles result with no matching codemap entry', () => {
|
|
83
|
+
const codemap = createCodemap({
|
|
84
|
+
differentChunk: { symbol: 'testFunction' },
|
|
85
|
+
});
|
|
86
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
87
|
+
applySymbolBoost(results, { query: 'test', codemap });
|
|
88
|
+
// Score should remain unchanged
|
|
89
|
+
assert.equal(results[0].score, 0.5);
|
|
90
|
+
assert.equal(results[0].symbolBoost, undefined);
|
|
91
|
+
});
|
|
92
|
+
// ============================================================================
|
|
93
|
+
// applySymbolBoost - Score Capping (MAX_SYMBOL_BOOST = 0.45)
|
|
94
|
+
// ============================================================================
|
|
4
95
|
test('applySymbolBoost caps total score at or below 1.0', () => {
|
|
5
|
-
const codemap = {
|
|
96
|
+
const codemap = createCodemap({
|
|
6
97
|
chunk1: {
|
|
7
|
-
file: 'src/example.ts',
|
|
8
98
|
symbol: 'processPayment',
|
|
9
99
|
sha: 'sha-1',
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
const results = [
|
|
15
|
-
{ id: 'chunk1', score: 0.9, symbol: 'processPayment', symbolBoost: 0 }
|
|
16
|
-
];
|
|
100
|
+
symbol_neighbors: [],
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
const results = createResults([{ id: 'chunk1', score: 0.9 }]);
|
|
17
104
|
applySymbolBoost(results, { query: 'process payment', codemap });
|
|
18
105
|
assert.ok(results[0].score <= 1, 'score should not exceed 1.0');
|
|
19
|
-
assert.ok(results[0].symbolBoost <= 0.45, 'boost should respect cap');
|
|
106
|
+
assert.ok(results[0].symbolBoost <= 0.45, 'boost should respect cap of 0.45');
|
|
107
|
+
});
|
|
108
|
+
test('applySymbolBoost caps symbolBoost at 0.45 even with high match strength', () => {
|
|
109
|
+
const codemap = createCodemap({
|
|
110
|
+
chunk1: {
|
|
111
|
+
symbol: 'processPaymentTransaction',
|
|
112
|
+
symbol_signature: 'processPaymentTransaction(amount, currency, recipient)',
|
|
113
|
+
symbol_parameters: ['amount', 'currency', 'recipient'],
|
|
114
|
+
sha: 'sha-1',
|
|
115
|
+
// Add neighbors that also match query
|
|
116
|
+
symbol_neighbors: ['sha-2'],
|
|
117
|
+
},
|
|
118
|
+
chunk2: {
|
|
119
|
+
symbol: 'validatePayment',
|
|
120
|
+
sha: 'sha-2',
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
124
|
+
applySymbolBoost(results, {
|
|
125
|
+
query: 'process payment transaction amount currency recipient validate',
|
|
126
|
+
codemap,
|
|
127
|
+
});
|
|
128
|
+
assert.ok(results[0].symbolBoost <= 0.45, 'symbolBoost must be capped at 0.45');
|
|
129
|
+
assert.ok(results[0].score <= 1.0, 'total score must not exceed 1.0');
|
|
130
|
+
});
|
|
131
|
+
test('applySymbolBoost ensures total score never exceeds 1.0 even with base score of 1.0', () => {
|
|
132
|
+
const codemap = createCodemap({
|
|
133
|
+
chunk1: {
|
|
134
|
+
symbol: 'testFunction',
|
|
135
|
+
sha: 'sha-1',
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
const results = createResults([{ id: 'chunk1', score: 1.0 }]);
|
|
139
|
+
applySymbolBoost(results, { query: 'test function', codemap });
|
|
140
|
+
assert.equal(results[0].score, 1.0, 'score should be capped at 1.0');
|
|
141
|
+
});
|
|
142
|
+
test('applySymbolBoost handles base score greater than 1.0 (normalizes to 1.0)', () => {
|
|
143
|
+
const codemap = createCodemap({
|
|
144
|
+
chunk1: {
|
|
145
|
+
symbol: 'testFunction',
|
|
146
|
+
sha: 'sha-1',
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
const results = createResults([{ id: 'chunk1', score: 1.5 }]);
|
|
150
|
+
applySymbolBoost(results, { query: 'test function', codemap });
|
|
151
|
+
// Base score should be clamped to 1.0, then boost added (capped at 1.0)
|
|
152
|
+
assert.ok(results[0].score <= 1.0, 'score should never exceed 1.0');
|
|
153
|
+
});
|
|
154
|
+
test('applySymbolBoost handles negative base score (normalizes to 0)', () => {
|
|
155
|
+
const codemap = createCodemap({
|
|
156
|
+
chunk1: {
|
|
157
|
+
symbol: 'testFunction',
|
|
158
|
+
sha: 'sha-1',
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
const results = createResults([{ id: 'chunk1', score: -0.5 }]);
|
|
162
|
+
applySymbolBoost(results, { query: 'test function', codemap });
|
|
163
|
+
// Base score should be clamped to 0, then boost added
|
|
164
|
+
assert.ok(results[0].score >= 0, 'score should never be negative');
|
|
165
|
+
});
|
|
166
|
+
// ============================================================================
|
|
167
|
+
// applySymbolBoost - Signature Matching
|
|
168
|
+
// ============================================================================
|
|
169
|
+
test('applySymbolBoost boosts when query contains exact symbol name', () => {
|
|
170
|
+
const codemap = createCodemap({
|
|
171
|
+
chunk1: {
|
|
172
|
+
symbol: 'calculateTotal',
|
|
173
|
+
sha: 'sha-1',
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
177
|
+
applySymbolBoost(results, { query: 'calculatetotal function', codemap });
|
|
178
|
+
assert.ok(results[0].symbolBoost > 0, 'should receive boost for exact symbol match');
|
|
179
|
+
assert.ok(results[0].symbolBoostSources.includes('signature'), 'source should include signature');
|
|
180
|
+
});
|
|
181
|
+
test('applySymbolBoost boosts for case-insensitive symbol match', () => {
|
|
182
|
+
const codemap = createCodemap({
|
|
183
|
+
chunk1: {
|
|
184
|
+
symbol: 'ProcessData',
|
|
185
|
+
sha: 'sha-1',
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
189
|
+
applySymbolBoost(results, { query: 'PROCESSDATA function', codemap });
|
|
190
|
+
assert.ok(results[0].symbolBoost > 0, 'should boost for case-insensitive match');
|
|
191
|
+
});
|
|
192
|
+
test('applySymbolBoost boosts when query matches symbol signature', () => {
|
|
193
|
+
const codemap = createCodemap({
|
|
194
|
+
chunk1: {
|
|
195
|
+
symbol: 'foo',
|
|
196
|
+
symbol_signature: 'calculateDiscount(price, rate)',
|
|
197
|
+
sha: 'sha-1',
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
201
|
+
applySymbolBoost(results, { query: 'calculatediscount(price, rate)', codemap });
|
|
202
|
+
assert.ok(results[0].symbolBoost > 0, 'should boost for signature match');
|
|
203
|
+
});
|
|
204
|
+
test('applySymbolBoost boosts for camelCase token matching', () => {
|
|
205
|
+
const codemap = createCodemap({
|
|
206
|
+
chunk1: {
|
|
207
|
+
symbol: 'getUserAccountDetails',
|
|
208
|
+
sha: 'sha-1',
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
212
|
+
applySymbolBoost(results, { query: 'user account details', codemap });
|
|
213
|
+
assert.ok(results[0].symbolBoost > 0, 'should boost for camelCase token matches');
|
|
214
|
+
assert.ok(results[0].symbolMatchStrength > 0, 'should set symbolMatchStrength');
|
|
215
|
+
});
|
|
216
|
+
test('applySymbolBoost boosts for underscore_separated token matching', () => {
|
|
217
|
+
const codemap = createCodemap({
|
|
218
|
+
chunk1: {
|
|
219
|
+
symbol: 'get_user_profile',
|
|
220
|
+
sha: 'sha-1',
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
224
|
+
applySymbolBoost(results, { query: 'user profile function', codemap });
|
|
225
|
+
assert.ok(results[0].symbolBoost > 0, 'should boost for underscore token matches');
|
|
226
|
+
});
|
|
227
|
+
test('applySymbolBoost does not boost for token-only matching when tokens are shorter than MIN_TOKEN_LENGTH (3)', () => {
|
|
228
|
+
// Note: The MIN_TOKEN_LENGTH check only applies to token-based regex matching,
|
|
229
|
+
// NOT to the direct symbol substring check. If the query contains the exact symbol
|
|
230
|
+
// (e.g., 'ab' in 'ab function'), it will still match via the substring check.
|
|
231
|
+
// This test verifies that short tokens from symbol splitting are skipped.
|
|
232
|
+
const codemap = createCodemap({
|
|
233
|
+
chunk1: {
|
|
234
|
+
symbol: 'XY', // 2 chars - when split, tokens are too short for regex matching
|
|
235
|
+
sha: 'sha-1',
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
239
|
+
// Query does NOT contain 'xy' as a substring, so substring check fails
|
|
240
|
+
// Token 'xy' is too short (< 3) so token-based regex matching is also skipped
|
|
241
|
+
applySymbolBoost(results, { query: 'different query here', codemap });
|
|
242
|
+
// Should not boost because neither substring nor token match works
|
|
243
|
+
assert.equal(results[0].symbolBoost, undefined, 'should not boost when no match');
|
|
244
|
+
});
|
|
245
|
+
test('applySymbolBoost boosts short symbol via substring match even if token too short', () => {
|
|
246
|
+
// This test verifies that the substring check bypasses the MIN_TOKEN_LENGTH restriction
|
|
247
|
+
const codemap = createCodemap({
|
|
248
|
+
chunk1: {
|
|
249
|
+
symbol: 'ab', // 2 chars - too short for token matching, but works for substring
|
|
250
|
+
sha: 'sha-1',
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
254
|
+
// Query contains 'ab' as substring, so it matches via substring check
|
|
255
|
+
applySymbolBoost(results, { query: 'ab function', codemap });
|
|
256
|
+
// Should boost because queryLower.includes('ab') is true
|
|
257
|
+
assert.ok(results[0].symbolBoost > 0, 'should boost via substring match');
|
|
258
|
+
});
|
|
259
|
+
test('applySymbolBoost handles symbol with null value', () => {
|
|
260
|
+
const codemap = createCodemap({
|
|
261
|
+
chunk1: {
|
|
262
|
+
symbol: null,
|
|
263
|
+
sha: 'sha-1',
|
|
264
|
+
},
|
|
265
|
+
});
|
|
266
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
267
|
+
applySymbolBoost(results, { query: 'test function', codemap });
|
|
268
|
+
// Should not throw and should not boost
|
|
269
|
+
assert.equal(results[0].symbolBoost, undefined);
|
|
270
|
+
});
|
|
271
|
+
test('applySymbolBoost handles empty symbol string', () => {
|
|
272
|
+
const codemap = createCodemap({
|
|
273
|
+
chunk1: {
|
|
274
|
+
symbol: '',
|
|
275
|
+
sha: 'sha-1',
|
|
276
|
+
},
|
|
277
|
+
});
|
|
278
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
279
|
+
applySymbolBoost(results, { query: 'test', codemap });
|
|
280
|
+
assert.equal(results[0].symbolBoost, undefined);
|
|
281
|
+
});
|
|
282
|
+
// ============================================================================
|
|
283
|
+
// applySymbolBoost - Parameter Matching
|
|
284
|
+
// ============================================================================
|
|
285
|
+
test('applySymbolBoost boosts when query matches function parameters', () => {
|
|
286
|
+
const codemap = createCodemap({
|
|
287
|
+
chunk1: {
|
|
288
|
+
symbol: 'calculateTax',
|
|
289
|
+
symbol_parameters: ['income', 'taxRate', 'deductions'],
|
|
290
|
+
sha: 'sha-1',
|
|
291
|
+
},
|
|
292
|
+
});
|
|
293
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
294
|
+
applySymbolBoost(results, { query: 'calculate income deductions', codemap });
|
|
295
|
+
assert.ok(results[0].symbolBoost > 0, 'should boost for parameter matches');
|
|
296
|
+
});
|
|
297
|
+
test('applySymbolBoost handles parameter with type annotations', () => {
|
|
298
|
+
const codemap = createCodemap({
|
|
299
|
+
chunk1: {
|
|
300
|
+
symbol: 'processOrder',
|
|
301
|
+
symbol_parameters: ['orderId: string', 'quantity: number', 'price: number'],
|
|
302
|
+
sha: 'sha-1',
|
|
303
|
+
},
|
|
304
|
+
});
|
|
305
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
306
|
+
applySymbolBoost(results, { query: 'order quantity price', codemap });
|
|
307
|
+
assert.ok(results[0].symbolBoost > 0, 'should boost for parameter name matches with types');
|
|
308
|
+
});
|
|
309
|
+
test('applySymbolBoost handles empty symbol_parameters array', () => {
|
|
310
|
+
const codemap = createCodemap({
|
|
311
|
+
chunk1: {
|
|
312
|
+
symbol: 'noParams',
|
|
313
|
+
symbol_parameters: [],
|
|
314
|
+
sha: 'sha-1',
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
318
|
+
applySymbolBoost(results, { query: 'noparams function', codemap });
|
|
319
|
+
// Should still boost for symbol match
|
|
320
|
+
assert.ok(results[0].symbolBoost > 0);
|
|
321
|
+
});
|
|
322
|
+
test('applySymbolBoost handles undefined symbol_parameters', () => {
|
|
323
|
+
const codemap = createCodemap({
|
|
324
|
+
chunk1: {
|
|
325
|
+
symbol: 'noParams',
|
|
326
|
+
sha: 'sha-1',
|
|
327
|
+
},
|
|
328
|
+
});
|
|
329
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
330
|
+
applySymbolBoost(results, { query: 'noparams', codemap });
|
|
331
|
+
// Should not throw
|
|
332
|
+
assert.ok(results[0].symbolBoost > 0 || results[0].symbolBoost === undefined);
|
|
333
|
+
});
|
|
334
|
+
test('applySymbolBoost ignores non-string parameters', () => {
|
|
335
|
+
const codemap = createCodemap({
|
|
336
|
+
chunk1: {
|
|
337
|
+
symbol: 'mixedParams',
|
|
338
|
+
symbol_parameters: ['validParam', 123, null, 'anotherValid'],
|
|
339
|
+
sha: 'sha-1',
|
|
340
|
+
},
|
|
341
|
+
});
|
|
342
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
343
|
+
// Should not throw
|
|
344
|
+
applySymbolBoost(results, { query: 'validparam anothervalid', codemap });
|
|
345
|
+
assert.ok(results[0].symbolBoost > 0);
|
|
346
|
+
});
|
|
347
|
+
// ============================================================================
|
|
348
|
+
// applySymbolBoost - Neighbor Matching
|
|
349
|
+
// ============================================================================
|
|
350
|
+
test('applySymbolBoost boosts when neighbor symbol matches query', () => {
|
|
351
|
+
const codemap = createCodemap({
|
|
352
|
+
chunk1: {
|
|
353
|
+
symbol: 'mainFunction',
|
|
354
|
+
sha: 'sha-1',
|
|
355
|
+
symbol_neighbors: ['sha-2'],
|
|
356
|
+
},
|
|
357
|
+
chunk2: {
|
|
358
|
+
symbol: 'helperUtility',
|
|
359
|
+
sha: 'sha-2',
|
|
360
|
+
},
|
|
361
|
+
});
|
|
362
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
363
|
+
applySymbolBoost(results, { query: 'helper utility', codemap });
|
|
364
|
+
assert.ok(results[0].symbolBoost > 0, 'should boost for neighbor match');
|
|
365
|
+
assert.ok(results[0].symbolBoostSources.includes('neighbor'), 'source should include neighbor');
|
|
366
|
+
assert.ok(results[0].symbolNeighborStrength > 0, 'should set symbolNeighborStrength');
|
|
367
|
+
});
|
|
368
|
+
test('applySymbolBoost finds best neighbor match among multiple neighbors', () => {
|
|
369
|
+
const codemap = createCodemap({
|
|
370
|
+
chunk1: {
|
|
371
|
+
symbol: 'mainFunction',
|
|
372
|
+
sha: 'sha-1',
|
|
373
|
+
symbol_neighbors: ['sha-2', 'sha-3', 'sha-4'],
|
|
374
|
+
},
|
|
375
|
+
chunk2: {
|
|
376
|
+
symbol: 'weakMatch',
|
|
377
|
+
sha: 'sha-2',
|
|
378
|
+
},
|
|
379
|
+
chunk3: {
|
|
380
|
+
symbol: 'strongMatchQueryTerms',
|
|
381
|
+
sha: 'sha-3',
|
|
382
|
+
},
|
|
383
|
+
chunk4: {
|
|
384
|
+
symbol: 'anotherWeak',
|
|
385
|
+
sha: 'sha-4',
|
|
386
|
+
},
|
|
387
|
+
});
|
|
388
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
389
|
+
applySymbolBoost(results, { query: 'strong match query terms', codemap });
|
|
390
|
+
assert.ok(results[0].symbolNeighborStrength > 0, 'should find best neighbor match');
|
|
391
|
+
});
|
|
392
|
+
test('applySymbolBoost handles empty symbol_neighbors array', () => {
|
|
393
|
+
const codemap = createCodemap({
|
|
394
|
+
chunk1: {
|
|
395
|
+
symbol: 'isolatedFunction',
|
|
396
|
+
sha: 'sha-1',
|
|
397
|
+
symbol_neighbors: [],
|
|
398
|
+
},
|
|
399
|
+
});
|
|
400
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
401
|
+
applySymbolBoost(results, { query: 'isolated', codemap });
|
|
402
|
+
// Should still work, just no neighbor boost
|
|
403
|
+
assert.equal(results[0].symbolNeighborStrength, undefined);
|
|
404
|
+
});
|
|
405
|
+
test('applySymbolBoost handles neighbor SHA not found in codemap', () => {
|
|
406
|
+
const codemap = createCodemap({
|
|
407
|
+
chunk1: {
|
|
408
|
+
symbol: 'mainFunction',
|
|
409
|
+
sha: 'sha-1',
|
|
410
|
+
symbol_neighbors: ['non-existent-sha'],
|
|
411
|
+
},
|
|
412
|
+
});
|
|
413
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
414
|
+
// Should not throw
|
|
415
|
+
applySymbolBoost(results, { query: 'main function', codemap });
|
|
416
|
+
assert.ok(results[0].symbolBoost >= 0 || results[0].symbolBoost === undefined);
|
|
417
|
+
});
|
|
418
|
+
test('applySymbolBoost handles undefined symbol_neighbors', () => {
|
|
419
|
+
const codemap = {
|
|
420
|
+
chunk1: {
|
|
421
|
+
file: 'test.ts',
|
|
422
|
+
sha: 'sha-1',
|
|
423
|
+
symbol: 'testSymbol',
|
|
424
|
+
},
|
|
425
|
+
};
|
|
426
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
427
|
+
// Should not throw
|
|
428
|
+
applySymbolBoost(results, { query: 'testsymbol', codemap });
|
|
429
|
+
assert.ok(typeof results[0].score === 'number');
|
|
430
|
+
});
|
|
431
|
+
// ============================================================================
|
|
432
|
+
// applySymbolBoost - Combined Signature and Neighbor Boost
|
|
433
|
+
// ============================================================================
|
|
434
|
+
test('applySymbolBoost combines signature and neighbor boosts', () => {
|
|
435
|
+
const codemap = createCodemap({
|
|
436
|
+
chunk1: {
|
|
437
|
+
symbol: 'processOrder',
|
|
438
|
+
sha: 'sha-1',
|
|
439
|
+
symbol_neighbors: ['sha-2'],
|
|
440
|
+
},
|
|
441
|
+
chunk2: {
|
|
442
|
+
symbol: 'validatePayment',
|
|
443
|
+
sha: 'sha-2',
|
|
444
|
+
},
|
|
445
|
+
});
|
|
446
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
447
|
+
applySymbolBoost(results, { query: 'process order validate payment', codemap });
|
|
448
|
+
// Should have both sources
|
|
449
|
+
assert.ok(results[0].symbolBoostSources.includes('signature'), 'should include signature');
|
|
450
|
+
assert.ok(results[0].symbolBoostSources.includes('neighbor'), 'should include neighbor');
|
|
451
|
+
assert.ok(results[0].symbolBoost > 0, 'combined boost should be positive');
|
|
452
|
+
assert.ok(results[0].symbolBoost <= 0.45, 'combined boost should still be capped');
|
|
453
|
+
});
|
|
454
|
+
// ============================================================================
|
|
455
|
+
// applySymbolBoost - Multiple Results Processing
|
|
456
|
+
// ============================================================================
|
|
457
|
+
test('applySymbolBoost processes multiple results independently', () => {
|
|
458
|
+
const codemap = createCodemap({
|
|
459
|
+
chunk1: { symbol: 'functionOne', sha: 'sha-1' },
|
|
460
|
+
chunk2: { symbol: 'functionTwo', sha: 'sha-2' },
|
|
461
|
+
chunk3: { symbol: 'noMatch', sha: 'sha-3' },
|
|
462
|
+
});
|
|
463
|
+
const results = createResults([
|
|
464
|
+
{ id: 'chunk1', score: 0.6 },
|
|
465
|
+
{ id: 'chunk2', score: 0.5 },
|
|
466
|
+
{ id: 'chunk3', score: 0.4 },
|
|
467
|
+
]);
|
|
468
|
+
applySymbolBoost(results, { query: 'function one two', codemap });
|
|
469
|
+
// chunk1 and chunk2 should be boosted, chunk3 should not
|
|
470
|
+
assert.ok(results[0].symbolBoost > 0, 'chunk1 should be boosted');
|
|
471
|
+
assert.ok(results[1].symbolBoost > 0, 'chunk2 should be boosted');
|
|
472
|
+
assert.equal(results[2].symbolBoost, undefined, 'chunk3 should not be boosted');
|
|
473
|
+
});
|
|
474
|
+
test('applySymbolBoost handles results with undefined score', () => {
|
|
475
|
+
const codemap = createCodemap({
|
|
476
|
+
chunk1: { symbol: 'testFunction', sha: 'sha-1' },
|
|
477
|
+
});
|
|
478
|
+
const results = [{ id: 'chunk1' }]; // score is undefined
|
|
479
|
+
applySymbolBoost(results, { query: 'testfunction', codemap });
|
|
480
|
+
// Should treat undefined score as 0
|
|
481
|
+
assert.ok(results[0].score >= 0, 'score should be >= 0');
|
|
482
|
+
assert.ok(results[0].score <= 1, 'score should be <= 1');
|
|
483
|
+
});
|
|
484
|
+
// ============================================================================
|
|
485
|
+
// applySymbolBoost - Regex Special Character Handling
|
|
486
|
+
// ============================================================================
|
|
487
|
+
test('applySymbolBoost handles symbols with regex special characters', () => {
|
|
488
|
+
const codemap = createCodemap({
|
|
489
|
+
chunk1: {
|
|
490
|
+
symbol: 'process$Value',
|
|
491
|
+
sha: 'sha-1',
|
|
492
|
+
},
|
|
493
|
+
});
|
|
494
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
495
|
+
// Should not throw due to unescaped regex special chars
|
|
496
|
+
applySymbolBoost(results, { query: 'process value', codemap });
|
|
497
|
+
// May or may not boost depending on token matching
|
|
498
|
+
assert.ok(typeof results[0].score === 'number');
|
|
499
|
+
});
|
|
500
|
+
test('applySymbolBoost handles query with regex special characters', () => {
|
|
501
|
+
const codemap = createCodemap({
|
|
502
|
+
chunk1: {
|
|
503
|
+
symbol: 'testFunction',
|
|
504
|
+
sha: 'sha-1',
|
|
505
|
+
},
|
|
506
|
+
});
|
|
507
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
508
|
+
// Should not throw
|
|
509
|
+
applySymbolBoost(results, { query: 'test.*function [regex]', codemap });
|
|
510
|
+
assert.ok(typeof results[0].score === 'number');
|
|
511
|
+
});
|
|
512
|
+
test('applySymbolBoost handles symbols with parentheses and brackets', () => {
|
|
513
|
+
const codemap = createCodemap({
|
|
514
|
+
chunk1: {
|
|
515
|
+
symbol: 'array[index]',
|
|
516
|
+
sha: 'sha-1',
|
|
517
|
+
},
|
|
518
|
+
});
|
|
519
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
520
|
+
// Should not throw
|
|
521
|
+
applySymbolBoost(results, { query: 'array index', codemap });
|
|
522
|
+
assert.ok(typeof results[0].score === 'number');
|
|
523
|
+
});
|
|
524
|
+
// ============================================================================
|
|
525
|
+
// applySymbolBoost - Edge Cases for Match Strength Calculation
|
|
526
|
+
// ============================================================================
|
|
527
|
+
test('applySymbolBoost gives higher weight to exact symbol match vs token match', () => {
|
|
528
|
+
const codemap = createCodemap({
|
|
529
|
+
exact: {
|
|
530
|
+
symbol: 'calculateTotal',
|
|
531
|
+
sha: 'sha-exact',
|
|
532
|
+
},
|
|
533
|
+
partial: {
|
|
534
|
+
symbol: 'calculateSomethingElse',
|
|
535
|
+
sha: 'sha-partial',
|
|
536
|
+
},
|
|
537
|
+
});
|
|
538
|
+
const resultsExact = createResults([{ id: 'exact', score: 0.5 }]);
|
|
539
|
+
const resultsPartial = createResults([{ id: 'partial', score: 0.5 }]);
|
|
540
|
+
applySymbolBoost(resultsExact, { query: 'calculatetotal', codemap });
|
|
541
|
+
applySymbolBoost(resultsPartial, { query: 'calculatetotal', codemap });
|
|
542
|
+
// Exact match should have higher or equal boost
|
|
543
|
+
const exactBoost = resultsExact[0].symbolBoost ?? 0;
|
|
544
|
+
const partialBoost = resultsPartial[0].symbolBoost ?? 0;
|
|
545
|
+
assert.ok(exactBoost >= partialBoost, 'exact match should have higher boost');
|
|
546
|
+
});
|
|
547
|
+
test('applySymbolBoost accumulates boost for multiple token matches', () => {
|
|
548
|
+
const codemap = createCodemap({
|
|
549
|
+
chunk1: {
|
|
550
|
+
symbol: 'getUserAccountBalanceHistory',
|
|
551
|
+
sha: 'sha-1',
|
|
552
|
+
},
|
|
553
|
+
});
|
|
554
|
+
const resultsSingle = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
555
|
+
const resultsMultiple = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
556
|
+
applySymbolBoost(resultsSingle, { query: 'user', codemap });
|
|
557
|
+
applySymbolBoost(resultsMultiple, { query: 'user account balance history', codemap });
|
|
558
|
+
const singleBoost = resultsSingle[0].symbolBoost ?? 0;
|
|
559
|
+
const multipleBoost = resultsMultiple[0].symbolBoost ?? 0;
|
|
560
|
+
assert.ok(multipleBoost >= singleBoost, 'multiple token matches should boost more');
|
|
561
|
+
});
|
|
562
|
+
// ============================================================================
|
|
563
|
+
// applySymbolBoost - Unicode and International Characters
|
|
564
|
+
// ============================================================================
|
|
565
|
+
test('applySymbolBoost handles unicode characters in symbol names', () => {
|
|
566
|
+
const codemap = createCodemap({
|
|
567
|
+
chunk1: {
|
|
568
|
+
symbol: 'getUsuarioNome',
|
|
569
|
+
sha: 'sha-1',
|
|
570
|
+
},
|
|
571
|
+
});
|
|
572
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
573
|
+
// Should not throw
|
|
574
|
+
applySymbolBoost(results, { query: 'usuario nome', codemap });
|
|
575
|
+
assert.ok(typeof results[0].score === 'number');
|
|
576
|
+
});
|
|
577
|
+
// ============================================================================
|
|
578
|
+
// applySymbolBoost - Very Long Symbols and Queries
|
|
579
|
+
// ============================================================================
|
|
580
|
+
test('applySymbolBoost handles very long symbol names', () => {
|
|
581
|
+
const longSymbol = 'a'.repeat(1000) + 'TestFunction';
|
|
582
|
+
const codemap = createCodemap({
|
|
583
|
+
chunk1: {
|
|
584
|
+
symbol: longSymbol,
|
|
585
|
+
sha: 'sha-1',
|
|
586
|
+
},
|
|
587
|
+
});
|
|
588
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
589
|
+
// Should not throw or hang
|
|
590
|
+
applySymbolBoost(results, { query: 'test function', codemap });
|
|
591
|
+
assert.ok(typeof results[0].score === 'number');
|
|
592
|
+
});
|
|
593
|
+
test('applySymbolBoost handles very long queries', () => {
|
|
594
|
+
const codemap = createCodemap({
|
|
595
|
+
chunk1: {
|
|
596
|
+
symbol: 'simpleFunction',
|
|
597
|
+
sha: 'sha-1',
|
|
598
|
+
},
|
|
599
|
+
});
|
|
600
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
601
|
+
const longQuery = 'simple function ' + 'extra '.repeat(500);
|
|
602
|
+
// Should not throw or hang
|
|
603
|
+
applySymbolBoost(results, { query: longQuery, codemap });
|
|
604
|
+
assert.ok(typeof results[0].score === 'number');
|
|
605
|
+
});
|
|
606
|
+
// ============================================================================
|
|
607
|
+
// applySymbolBoost - Mutation Verification
|
|
608
|
+
// ============================================================================
|
|
609
|
+
test('applySymbolBoost mutates results in place', () => {
|
|
610
|
+
const codemap = createCodemap({
|
|
611
|
+
chunk1: {
|
|
612
|
+
symbol: 'testFunction',
|
|
613
|
+
sha: 'sha-1',
|
|
614
|
+
},
|
|
615
|
+
});
|
|
616
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
617
|
+
const originalReference = results[0];
|
|
618
|
+
applySymbolBoost(results, { query: 'testfunction', codemap });
|
|
619
|
+
// Should be same reference, mutated
|
|
620
|
+
assert.strictEqual(results[0], originalReference, 'should mutate in place');
|
|
621
|
+
assert.ok(results[0].symbolBoost > 0, 'should have boost applied');
|
|
622
|
+
});
|
|
623
|
+
test('applySymbolBoost does not add properties when no boost applied', () => {
|
|
624
|
+
const codemap = createCodemap({
|
|
625
|
+
chunk1: {
|
|
626
|
+
symbol: 'completelyDifferent',
|
|
627
|
+
sha: 'sha-1',
|
|
628
|
+
},
|
|
629
|
+
});
|
|
630
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
631
|
+
applySymbolBoost(results, { query: 'xyz abc', codemap });
|
|
632
|
+
assert.equal(results[0].symbolBoost, undefined, 'should not add symbolBoost when no match');
|
|
633
|
+
assert.equal(results[0].symbolBoostSources, undefined, 'should not add symbolBoostSources');
|
|
634
|
+
});
|
|
635
|
+
// ============================================================================
|
|
636
|
+
// applySymbolBoost - Zero Score Handling
|
|
637
|
+
// ============================================================================
|
|
638
|
+
test('applySymbolBoost handles base score of exactly 0', () => {
|
|
639
|
+
const codemap = createCodemap({
|
|
640
|
+
chunk1: {
|
|
641
|
+
symbol: 'testFunction',
|
|
642
|
+
sha: 'sha-1',
|
|
643
|
+
},
|
|
644
|
+
});
|
|
645
|
+
const results = createResults([{ id: 'chunk1', score: 0 }]);
|
|
646
|
+
applySymbolBoost(results, { query: 'testfunction', codemap });
|
|
647
|
+
assert.ok(results[0].score >= 0, 'score should be >= 0');
|
|
648
|
+
assert.ok(results[0].score <= 0.45, 'score should be <= 0.45 (max boost)');
|
|
649
|
+
});
|
|
650
|
+
// ============================================================================
|
|
651
|
+
// applySymbolBoost - Large Codemap Performance
|
|
652
|
+
// ============================================================================
|
|
653
|
+
test('applySymbolBoost handles large codemap efficiently', () => {
|
|
654
|
+
// Create a large codemap
|
|
655
|
+
const entries = {};
|
|
656
|
+
for (let i = 0; i < 1000; i++) {
|
|
657
|
+
entries[`chunk${i}`] = {
|
|
658
|
+
symbol: `function${i}`,
|
|
659
|
+
sha: `sha-${i}`,
|
|
660
|
+
symbol_neighbors: i > 0 ? [`sha-${i - 1}`] : [],
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
const codemap = createCodemap(entries);
|
|
664
|
+
const results = createResults([
|
|
665
|
+
{ id: 'chunk500', score: 0.5 },
|
|
666
|
+
{ id: 'chunk999', score: 0.4 },
|
|
667
|
+
]);
|
|
668
|
+
const start = Date.now();
|
|
669
|
+
applySymbolBoost(results, { query: 'function500 function999', codemap });
|
|
670
|
+
const elapsed = Date.now() - start;
|
|
671
|
+
assert.ok(elapsed < 1000, 'should complete in reasonable time');
|
|
672
|
+
assert.ok(results[0].symbolBoost > 0 || results[1].symbolBoost > 0, 'should find matches');
|
|
673
|
+
});
|
|
674
|
+
// ============================================================================
|
|
675
|
+
// applySymbolBoost - Regex Cache Behavior (buildQueryTokenRegex)
|
|
676
|
+
// ============================================================================
|
|
677
|
+
test('applySymbolBoost benefits from regex cache on repeated queries', () => {
|
|
678
|
+
const codemap = createCodemap({
|
|
679
|
+
chunk1: { symbol: 'processData', sha: 'sha-1' },
|
|
680
|
+
chunk2: { symbol: 'processInfo', sha: 'sha-2' },
|
|
681
|
+
});
|
|
682
|
+
// First call
|
|
683
|
+
const results1 = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
684
|
+
applySymbolBoost(results1, { query: 'process data', codemap });
|
|
685
|
+
// Second call with same tokens (should use cached regexes)
|
|
686
|
+
const results2 = createResults([{ id: 'chunk2', score: 0.5 }]);
|
|
687
|
+
applySymbolBoost(results2, { query: 'process info', codemap });
|
|
688
|
+
// Both should work correctly
|
|
689
|
+
assert.ok(results1[0].symbolBoost > 0);
|
|
690
|
+
assert.ok(results2[0].symbolBoost > 0);
|
|
691
|
+
});
|
|
692
|
+
// ============================================================================
|
|
693
|
+
// applySymbolBoost - Signature Weight Calculation Details
|
|
694
|
+
// ============================================================================
|
|
695
|
+
test('applySymbolBoost signature match gives weight 4 for exact symbol in query', () => {
|
|
696
|
+
const codemap = createCodemap({
|
|
697
|
+
chunk1: {
|
|
698
|
+
symbol: 'abc',
|
|
699
|
+
sha: 'sha-1',
|
|
700
|
+
},
|
|
701
|
+
});
|
|
702
|
+
const results = createResults([{ id: 'chunk1', score: 0.3 }]);
|
|
703
|
+
applySymbolBoost(results, { query: 'abc function call', codemap });
|
|
704
|
+
// Weight 4 / 4 = 1.0 strength, * 0.3 signature boost = 0.3
|
|
705
|
+
assert.ok(results[0].symbolMatchStrength === 1, 'full match should give strength 1');
|
|
706
|
+
});
|
|
707
|
+
test('applySymbolBoost handles signature with normalized whitespace', () => {
|
|
708
|
+
const codemap = createCodemap({
|
|
709
|
+
chunk1: {
|
|
710
|
+
symbol: 'foo',
|
|
711
|
+
symbol_signature: 'processData( input, output )',
|
|
712
|
+
sha: 'sha-1',
|
|
713
|
+
},
|
|
714
|
+
});
|
|
715
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
716
|
+
applySymbolBoost(results, { query: 'processdata( input, output )', codemap });
|
|
717
|
+
assert.ok(results[0].symbolBoost !== undefined || results[0].score === 0.5);
|
|
718
|
+
});
|
|
719
|
+
// ============================================================================
|
|
720
|
+
// applySymbolBoost - Non-Object Codemap Entry Handling
|
|
721
|
+
// ============================================================================
|
|
722
|
+
test('applySymbolBoost skips codemap entries without sha', () => {
|
|
723
|
+
const codemap = {
|
|
724
|
+
chunk1: {
|
|
725
|
+
file: 'test.ts',
|
|
726
|
+
sha: 'sha-1',
|
|
727
|
+
symbol: 'validSymbol',
|
|
728
|
+
symbol_neighbors: ['sha-invalid'],
|
|
729
|
+
},
|
|
730
|
+
chunk2: {
|
|
731
|
+
file: 'test.ts',
|
|
732
|
+
sha: undefined, // Invalid sha
|
|
733
|
+
symbol: 'invalidEntry',
|
|
734
|
+
},
|
|
735
|
+
};
|
|
736
|
+
const results = createResults([{ id: 'chunk1', score: 0.5 }]);
|
|
737
|
+
// Should not throw
|
|
738
|
+
applySymbolBoost(results, { query: 'valid symbol', codemap });
|
|
739
|
+
assert.ok(typeof results[0].score === 'number');
|
|
20
740
|
});
|
|
21
741
|
//# sourceMappingURL=symbol-boost.test.js.map
|