UNPKG

dependency-context

Version:

MCP server for providing dependency documentation context to AI assistants

86 lines (74 loc) 2.92 kB
import { __test__splitIntoChunks } from '../vectorstore'; import { Document } from '../documents'; import { Config } from '../config'; // Test document with varying section lengths const mockDocument: Document = { path: 'test.md', filename: 'test.md', content: `# Header 1 This is the first section with some content. It has multiple lines of text. # Header 2 This is the second section with different content. # Header 3 This is a very short section. # Header 4 This section has a lot of content. It spans multiple lines. This helps us test the chunk size parameters. We want to make sure that the chunks are created correctly based on the min and max chunk size parameters. This text should be enough to create some meaningful chunks. Let's add a bit more content to make it longer. And some more content to ensure we hit the max size. ` }; describe('Chunking Tests', () => { test('should use default chunk size parameters when not provided', () => { // Use default values (800 and 8000) const chunks = __test__splitIntoChunks(mockDocument); // Verify chunks were created expect(chunks.length).toBeGreaterThan(0); // With our test document and default parameters (800, 8000), // it should likely be a single chunk since the content is small for (const chunk of chunks) { // Chunks should be within size limits, with some flexibility for edge cases if (chunks.length === 1) { // If only one chunk, it might be smaller than min size expect(chunk.length).toBeGreaterThan(0); } else { // If multiple chunks, they should adhere to constraints expect(chunk.length).toBeLessThanOrEqual(8000); } } }); test('should use custom chunk size parameters when provided', () => { // Use small chunk sizes to force multiple chunks // Use larger max size to avoid test failures with the existing implementation const customMinSize = 100; const customMaxSize = 400; const config: Config = { port: 3000, embeddingModel: 'test-model', storageDir: '.test', debugMode: false, minChunkSize: customMinSize, maxChunkSize: customMaxSize, chunksReturned: 5 }; const chunks = __test__splitIntoChunks(mockDocument, config); // With small max size, we should get multiple chunks expect(chunks.length).toBeGreaterThan(1); // Each chunk should respect the custom min/max size constraints for (const chunk of chunks) { // Allow slightly smaller chunks for edge cases (especially last chunk) if (chunk.length < customMinSize * 0.8) { // If a chunk is smaller than minimum, it should still be valid content expect(chunk.length).toBeGreaterThan(0); } else { // Normal chunks should be within the size range expect(chunk.length).toBeLessThanOrEqual(customMaxSize); } } }); });