fix(FEEDBACK-0001): complete iteration 0 - harden context search

This commit is contained in:
Giancarmine Salucci
2026-03-27 01:25:46 +01:00
parent e7a2a83cdb
commit 16436bfab2
15 changed files with 1469 additions and 44 deletions

View File

@@ -177,6 +177,85 @@ describe('preprocessQuery', () => {
it('handles single short token without wildcard', () => {
expect(preprocessQuery('ab')).toBe('ab');
});
// Punctuation-heavy and code-like queries
it('normalizes code-like queries with slashes', () => {
// "foo/bar/baz" should extract searchable terms
const result = preprocessQuery('foo/bar/baz');
expect(result).toContain('foo');
expect(result).toContain('bar');
expect(result).toContain('baz');
});
it('extracts terms from dot-notation queries', () => {
// "object.method.name" should extract searchable parts
const result = preprocessQuery('object.method.name');
expect(result).toContain('object');
expect(result).toContain('method');
expect(result).toContain('name');
});
it('handles snake_case identifiers', () => {
// "my_function_name" should be preserved
const result = preprocessQuery('my_function_name');
expect(result).toContain('my_function_name');
});
it('removes punctuation from parenthesized expressions', () => {
// "(hello world)" → "hello world*"
const result = preprocessQuery('(hello world)');
expect(result).toContain('hello');
expect(result).toContain('world');
});
it('handles bracket-enclosed content', () => {
// "[foo bar]" → "foo bar*"
const result = preprocessQuery('[foo bar]');
expect(result).toContain('foo');
expect(result).toContain('bar');
});
it('returns empty string for pure punctuation', () => {
expect(preprocessQuery('!@#$%^&*()')).toBe('');
});
it('returns empty string for punctuation with operators only', () => {
expect(preprocessQuery('!!! AND *** OR ((()))')).toBe('');
});
it('normalizes C++ style template syntax', () => {
// "vector<int>" → "vector int*"
const result = preprocessQuery('vector<int>');
expect(result).toContain('vector');
expect(result).toContain('int');
});
it('handles colons and semicolons in code snippets', () => {
// "http://example.com; function()" → extracts searchable terms
const result = preprocessQuery('http://example.com; function()');
expect(result).toContain('http');
expect(result).toContain('example');
expect(result).toContain('com');
expect(result).toContain('function');
});
it('normalizes arithmetic operators', () => {
// "a + b * c" → "a b c*"
const result = preprocessQuery('a + b * c');
// Should extract terms, but skip operators
const terms = result.split(/\s+/).filter((t) => !['AND', 'OR', 'NOT'].includes(t));
expect(terms.length).toBeGreaterThan(0);
});
it('returns single searchable term with wildcard when >=3 chars', () => {
const result = preprocessQuery('!!!hello!!!');
expect(result).toBe('hello*');
});
it('returns single short term without wildcard', () => {
const result = preprocessQuery('!!!ab!!!');
expect(result).toBe('ab');
});
});
// ---------------------------------------------------------------------------