GitNexus/gitnexus/test/integration/bm25-symbol-hydration.test.ts
Gergő Magyar 62f86ea068
feat(mcp): reduce response size and query overhead (#3621)
* docs(mcp): document focused response filters

* feat(mcp): add opt-in response section and relation filters

* test(mcp): verify response filters and compatibility

* test(mcp): add deterministic response-size benchmark

* docs(skills): teach focused MCP calls and safe filter use

* docs(skills): update debugging response-filter guidance

* docs(skills): update exploration response-filter guidance

* docs(skills): explain focused MCP response options

* docs(plugin): mirror focused debugging guidance

* docs(plugin): mirror focused exploration guidance

* docs(plugin): mirror focused MCP tool guide

* docs(cursor): mirror focused debugging guidance

* docs(cursor): mirror focused exploration guidance

* test(mcp): give filter cases unique identities

Use named cases to keep array inputs intact and let the CI execution audit distinguish every malformed-filter test.

* perf(mcp): batch BM25 symbol hydration

* test(mcp): serialize native hydration coverage

* test(eval): publish child PID atomically

* test(mcp): cover hydration on native platforms

---------

Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
Co-authored-by: Abhigyan Patwari <126312502+abhigyanpatwari@users.noreply.github.com>
2026-10-18 17:32:09 +01:00

65 lines
2.4 KiB
TypeScript

import { expect, it, vi } from 'vitest';
import { LocalBackend } from '../../src/mcp/local/local-backend.js';
import { searchFTSFromLbug } from '../../src/core/search/bm25-index.js';
import { executeParameterized } from '../../src/core/lbug/pool-adapter.js';
import { withTestLbugDB } from '../helpers/test-indexed-db.js';
import { LOCAL_BACKEND_SEED_DATA } from '../fixtures/local-backend-seed.js';
// Supply ranked FTS hits; exercise hydration with the real native graph and pool.
vi.mock('../../src/core/search/bm25-index.js', () => ({ searchFTSFromLbug: vi.fn() }));
withTestLbugDB(
'bm25-symbol-hydration',
(handle) => {
it('matches individual native reads across files and node tables', async () => {
const hits = [
{
filePath: 'src/auth.ts',
score: 8,
rank: 1,
nodeIds: ['method:AuthService.authenticate', 'func:validate', 'func:login'],
},
{ filePath: 'src/utils.ts', score: 4, rank: 2, nodeIds: ['func:hash'] },
{ filePath: 'src/deleted.ts', score: 2, rank: 3, nodeIds: ['func:deleted'] },
];
vi.mocked(searchFTSFromLbug).mockResolvedValue({ results: hits, ftsAvailable: true });
const expected = [];
for (const hit of hits) {
const symbols = await executeParameterized(
handle.repoId,
`MATCH (n) WHERE n.id IN $nodeIds
RETURN n.id AS id, n.name AS name, labels(n)[0] AS type,
n.filePath AS filePath, n.startLine AS startLine, n.endLine AS endLine
ORDER BY startLine, id`,
{ nodeIds: hit.nodeIds },
);
if (symbols.length) {
expected.push(
...symbols.map(({ id, ...symbol }) => ({
nodeId: id,
...symbol,
type: symbol.type || undefined,
bm25Score: hit.score,
})),
);
} else {
expected.push({
name: 'deleted.ts',
type: 'File',
filePath: hit.filePath,
bm25Score: hit.score,
});
}
}
const backend = new LocalBackend() as unknown as {
bm25Search: (repo: { lbugPath: string }, query: string, limit: number) => Promise<unknown>;
};
expect(await backend.bm25Search({ lbugPath: handle.repoId }, 'authentication', 20)).toEqual({
results: expected,
ftsUsed: true,
});
});
},
{ seed: LOCAL_BACKEND_SEED_DATA, poolAdapter: true },
);