feat: Add per-file and non-production diversity caps to context building
Addresses single files monopolizing the node budget when BFS traverses from multiple entry points in the same class. Caps each file to ~20% of maxNodes and limits test/sample/integration files to 15% to ensure cross-file diversity in context results. Expands isTestFile detection to include integration, sample, example, and other non-production directories.
This commit is contained in:
@@ -231,10 +231,31 @@ export function isTestFile(filePath: string): boolean {
|
||||
lower.includes('/__tests__/') ||
|
||||
lower.includes('/spec/') ||
|
||||
lower.includes('/testlib/') ||
|
||||
lower.includes('/testing/')
|
||||
lower.includes('/testing/') ||
|
||||
// Non-production directories: examples, samples, benchmarks, fixtures, demos.
|
||||
// Check both mid-path (/integration/) and start-of-path (integration/) since
|
||||
// file paths may be stored as relative paths without a leading slash.
|
||||
matchesNonProductionDir(lower)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a path is in a non-production directory (integration, sample, example, etc.)
|
||||
* Handles both absolute paths (/foo/integration/bar) and relative paths (integration/bar).
|
||||
*/
|
||||
function matchesNonProductionDir(lowerPath: string): boolean {
|
||||
const dirs = [
|
||||
'integration', 'sample', 'samples', 'example', 'examples',
|
||||
'fixture', 'fixtures', 'benchmark', 'benchmarks', 'demo', 'demos',
|
||||
];
|
||||
for (const dir of dirs) {
|
||||
if (lowerPath.includes('/' + dir + '/') || lowerPath.startsWith(dir + '/')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bonus when a node's name matches the search query.
|
||||
* Exact matches get the largest boost; prefix matches get smaller boosts.
|
||||
|
||||
Reference in New Issue
Block a user