Skip to content

Commit 07e4a91

Browse files
committed
test: replace Go-specific test with generic MIN_BLOCK_CHARS test
- Remove go-indexing-fix.spec.ts as requested in PR feedback - Add generic test in parser.spec.ts to verify 50-character threshold - Test ensures content under 50 chars is filtered, 50+ chars is indexed - Applies to all languages, not just Go
1 parent def262f commit 07e4a91

File tree

2 files changed

+44
-211
lines changed

2 files changed

+44
-211
lines changed

src/services/code-index/__tests__/go-indexing-fix.spec.ts

Lines changed: 0 additions & 211 deletions
This file was deleted.

src/services/code-index/processors/__tests__/parser.spec.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,50 @@ describe("CodeParser", () => {
186186
const result = await parser["_performFallbackChunking"]("test.js", shortContent, "hash", new Set())
187187
expect(result).toEqual([])
188188
})
189+
190+
it("should respect 50-character minimum threshold for all languages", async () => {
191+
// Test content that is exactly 49 characters (should be filtered)
192+
const shortContent = "function f() { return 1; } // Exactly 49 chars!!!"
193+
expect(shortContent.length).toBe(49)
194+
195+
// Test content that is exactly 50 characters (should be included)
196+
const minContent = "function g() { return 42; } // Exactly 50 chars!!!"
197+
expect(minContent.length).toBe(50)
198+
199+
// Test content that is longer than 50 characters (should be included)
200+
const longContent = "function calculate() { return 1 + 2 + 3; } // This is longer than 50 characters"
201+
expect(longContent.length).toBeGreaterThan(50)
202+
203+
// Mock the language parser to return captures for our test content
204+
const mockCapture = (content: string, startLine: number = 0) => ({
205+
node: {
206+
text: content,
207+
startPosition: { row: startLine },
208+
endPosition: { row: startLine },
209+
type: "function_declaration",
210+
childForFieldName: vi.fn().mockReturnValue(null),
211+
children: [],
212+
},
213+
name: "definition.function",
214+
})
215+
216+
// Test short content (49 chars) - should be filtered out
217+
mockLanguageParser.js.query.captures.mockReturnValue([mockCapture(shortContent)])
218+
const shortResult = await parser["parseContent"]("test.js", shortContent, "hash1")
219+
expect(shortResult).toEqual([])
220+
221+
// Test minimum content (50 chars) - should be included
222+
mockLanguageParser.js.query.captures.mockReturnValue([mockCapture(minContent)])
223+
const minResult = await parser["parseContent"]("test.js", minContent, "hash2")
224+
expect(minResult.length).toBe(1)
225+
expect(minResult[0].content).toBe(minContent)
226+
227+
// Test longer content - should be included
228+
mockLanguageParser.js.query.captures.mockReturnValue([mockCapture(longContent)])
229+
const longResult = await parser["parseContent"]("test.js", longContent, "hash3")
230+
expect(longResult.length).toBe(1)
231+
expect(longResult[0].content).toBe(longContent)
232+
})
189233
})
190234

191235
describe("_chunkLeafNodeByLines", () => {

0 commit comments

Comments
 (0)