Remove unused detectApiIntent and inferRouteDirectories
Both functions have zero callers — dead code on arrival. Remove them and their tests (9 tests) to keep the module focused on what's actually used: search term extraction, path relevance scoring, and kind bonuses.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Search Query Utilities Tests
|
||||
*
|
||||
* Tests multi-signal scoring, kind bonuses, path relevance, and API intent detection.
|
||||
* Tests multi-signal scoring, kind bonuses, and path relevance.
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
@@ -9,8 +9,6 @@ import {
|
||||
extractSearchTerms,
|
||||
scorePathRelevance,
|
||||
kindBonus,
|
||||
detectApiIntent,
|
||||
inferRouteDirectories,
|
||||
STOP_WORDS,
|
||||
} from '../src/search/query-utils';
|
||||
|
||||
@@ -114,83 +112,6 @@ describe('Search Query Utilities', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('detectApiIntent', () => {
|
||||
it('should detect API-related queries', () => {
|
||||
expect(detectApiIntent('find the API endpoint for users')).toBe(true);
|
||||
expect(detectApiIntent('where is the login route')).toBe(true);
|
||||
expect(detectApiIntent('show me the request handler')).toBe(true);
|
||||
});
|
||||
|
||||
it('should detect HTTP method patterns', () => {
|
||||
expect(detectApiIntent('GET /api/users')).toBe(true);
|
||||
expect(detectApiIntent('post /users/create')).toBe(true);
|
||||
});
|
||||
|
||||
it('should detect REST and GraphQL', () => {
|
||||
expect(detectApiIntent('REST API for payments')).toBe(true);
|
||||
expect(detectApiIntent('GraphQL resolver for orders')).toBe(true);
|
||||
});
|
||||
|
||||
it('should not detect non-API queries', () => {
|
||||
expect(detectApiIntent('fix the login bug')).toBe(false);
|
||||
expect(detectApiIntent('add dark mode support')).toBe(false);
|
||||
});
|
||||
|
||||
it('should detect controller and middleware mentions', () => {
|
||||
expect(detectApiIntent('find the auth controller')).toBe(true);
|
||||
expect(detectApiIntent('CORS middleware configuration')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('inferRouteDirectories', () => {
|
||||
it('should detect route directories', () => {
|
||||
const files = [
|
||||
'src/routes/auth.ts',
|
||||
'src/routes/users.ts',
|
||||
'src/utils/format.ts',
|
||||
];
|
||||
const dirs = inferRouteDirectories(files);
|
||||
expect(dirs).toBeDefined();
|
||||
if (dirs) {
|
||||
expect(dirs.some(d => d.includes('route'))).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('should detect controller directories', () => {
|
||||
const files = [
|
||||
'src/controllers/AuthController.ts',
|
||||
'src/models/User.ts',
|
||||
];
|
||||
const dirs = inferRouteDirectories(files);
|
||||
expect(dirs).toBeDefined();
|
||||
if (dirs) {
|
||||
expect(dirs.some(d => d.includes('controller'))).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('should detect api directories', () => {
|
||||
const files = [
|
||||
'src/api/v1/users.ts',
|
||||
'src/api/v1/orders.ts',
|
||||
];
|
||||
const dirs = inferRouteDirectories(files);
|
||||
expect(dirs).toBeDefined();
|
||||
if (dirs) {
|
||||
expect(dirs.some(d => d.includes('api'))).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('should return undefined when no route dirs found', () => {
|
||||
const files = [
|
||||
'src/utils/format.ts',
|
||||
'src/models/User.ts',
|
||||
'src/index.ts',
|
||||
];
|
||||
const dirs = inferRouteDirectories(files);
|
||||
expect(dirs).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('STOP_WORDS', () => {
|
||||
it('should contain common English stop words', () => {
|
||||
expect(STOP_WORDS.has('the')).toBe(true);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Search Query Utilities
|
||||
*
|
||||
* Shared module for search term extraction, scoring, and intent detection.
|
||||
* Shared module for search term extraction and scoring.
|
||||
*/
|
||||
|
||||
import * as path from 'path';
|
||||
@@ -87,43 +87,3 @@ export function kindBonus(kind: Node['kind']): number {
|
||||
};
|
||||
return bonuses[kind] ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect if a query has API/endpoint intent
|
||||
*/
|
||||
export function detectApiIntent(query: string): boolean {
|
||||
const apiPatterns = [
|
||||
/\bapi\b/i, /\bendpoint/i, /\broute/i, /\bhandler/i,
|
||||
/\bcontroller/i, /\bmiddleware/i, /\brest\b/i, /\bgraphql/i,
|
||||
/\bget\s+\//, /\bpost\s+\//, /\bput\s+\//, /\bdelete\s+\//,
|
||||
/\brequest/i, /\bresponse/i, /\bhttp/i,
|
||||
];
|
||||
return apiPatterns.some(p => p.test(query));
|
||||
}
|
||||
|
||||
/**
|
||||
* Infer route/controller directories from project structure
|
||||
* Returns undefined if no route directories are detected
|
||||
*/
|
||||
export function inferRouteDirectories(files: string[]): string[] | undefined {
|
||||
const routeDirs = new Set<string>();
|
||||
const routePatterns = [
|
||||
/routes?\//i, /controllers?\//i, /handlers?\//i,
|
||||
/api\//i, /endpoints?\//i,
|
||||
];
|
||||
|
||||
for (const file of files) {
|
||||
for (const pattern of routePatterns) {
|
||||
if (pattern.test(file)) {
|
||||
const match = file.match(pattern);
|
||||
if (match) {
|
||||
const idx = file.indexOf(match[0]);
|
||||
const dir = file.substring(0, idx + match[0].length - 1);
|
||||
routeDirs.add(dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return routeDirs.size > 0 ? Array.from(routeDirs) : undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user