refactor(8.0): remove dead, unreachable, and unwired modules
Pre-GA dead-code sweep. A deterministic import-reachability walk from the
package's real entry points (the exports map, the CLI bin, the conversation
surface) found 34 source modules that nothing reachable imports — they
compile and ship as dist output that no consumer or internal path can ever
reach. All were superseded duplicates, abandoned parallel implementations,
or built-but-never-wired features:
- superseded duplicates of live modules: an older "unified" entry, a
standalone neural-import variant, a static NLP processor + its matcher,
a parallel API-types module, a duplicate progress-types module
- an abandoned import path (orchestrator + entity deduplicator + barrels)
left behind when ingestion moved to the coordinator
- unwired feature modules (instance pool, import presets, cached
embeddings, relationship-confidence scorer) reachable only from tests
- dead leaf utilities (write buffer, deleted-items index, bounded
registry, two crypto shims, a cache manager, a structured logger, a
stale v5 type-migration helper, a browser-only FS type shim) and
several dead re-export barrels
- a CLI catalog command wired into no command
Also removed two tests that only exercised deleted modules, repointed two
VFS tests off a deleted barrel onto the implementation module, and deleted
one example that demoed removed features.
Verified: clean build (both tsc passes), unit 1505 + integration 607 green,
and a re-run of the reachability walk reports zero remaining orphans.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
03d654061f
commit
bf0afe8563
39 changed files with 2 additions and 10497 deletions
|
|
@ -1,317 +0,0 @@
|
|||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { Brainy } from '../../../src/brainy.js'
|
||||
import { InstancePool, createInstancePool } from '../../../src/import/InstancePool.js'
|
||||
|
||||
describe('InstancePool', () => {
|
||||
let brain: Brainy
|
||||
let pool: InstancePool
|
||||
|
||||
beforeEach(async () => {
|
||||
brain = new Brainy({ requireSubtype: false, storage: { type: 'memory' } })
|
||||
await brain.init()
|
||||
pool = new InstancePool(brain)
|
||||
})
|
||||
|
||||
describe('lazy initialization', () => {
|
||||
it('should not create instances until requested', () => {
|
||||
const stats = pool.getStats()
|
||||
expect(stats.nlpCreated).toBe(false)
|
||||
expect(stats.extractorCreated).toBe(false)
|
||||
})
|
||||
|
||||
it('should create NLP instance on first access', async () => {
|
||||
const nlp = await pool.getNLP()
|
||||
expect(nlp).toBeDefined()
|
||||
|
||||
const stats = pool.getStats()
|
||||
expect(stats.nlpCreated).toBe(true)
|
||||
expect(stats.nlpReuses).toBe(1)
|
||||
})
|
||||
|
||||
it('should create extractor instance on first access', () => {
|
||||
const extractor = pool.getExtractor()
|
||||
expect(extractor).toBeDefined()
|
||||
|
||||
const stats = pool.getStats()
|
||||
expect(stats.extractorCreated).toBe(true)
|
||||
expect(stats.extractorReuses).toBe(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('instance reuse', () => {
|
||||
it('should return same NLP instance on multiple calls', async () => {
|
||||
const nlp1 = await pool.getNLP()
|
||||
const nlp2 = await pool.getNLP()
|
||||
const nlp3 = await pool.getNLP()
|
||||
|
||||
expect(nlp1).toBe(nlp2)
|
||||
expect(nlp2).toBe(nlp3)
|
||||
|
||||
const stats = pool.getStats()
|
||||
expect(stats.nlpReuses).toBe(3)
|
||||
})
|
||||
|
||||
it('should return same extractor instance on multiple calls', () => {
|
||||
const extractor1 = pool.getExtractor()
|
||||
const extractor2 = pool.getExtractor()
|
||||
const extractor3 = pool.getExtractor()
|
||||
|
||||
expect(extractor1).toBe(extractor2)
|
||||
expect(extractor2).toBe(extractor3)
|
||||
|
||||
const stats = pool.getStats()
|
||||
expect(stats.extractorReuses).toBe(3)
|
||||
})
|
||||
|
||||
it('should track reuse counts correctly', async () => {
|
||||
await pool.getNLP()
|
||||
await pool.getNLP()
|
||||
pool.getExtractor()
|
||||
pool.getExtractor()
|
||||
pool.getExtractor()
|
||||
|
||||
const stats = pool.getStats()
|
||||
expect(stats.nlpReuses).toBe(2)
|
||||
expect(stats.extractorReuses).toBe(3)
|
||||
})
|
||||
})
|
||||
|
||||
describe('initialization', () => {
|
||||
it('should initialize all instances with init()', async () => {
|
||||
await pool.init()
|
||||
|
||||
expect(pool.isInitialized()).toBe(true)
|
||||
|
||||
const stats = pool.getStats()
|
||||
expect(stats.nlpCreated).toBe(true)
|
||||
expect(stats.extractorCreated).toBe(true)
|
||||
expect(stats.initialized).toBe(true)
|
||||
})
|
||||
|
||||
it('should handle concurrent init calls safely', async () => {
|
||||
// Call init multiple times concurrently
|
||||
const promises = [
|
||||
pool.init(),
|
||||
pool.init(),
|
||||
pool.init()
|
||||
]
|
||||
|
||||
await Promise.all(promises)
|
||||
|
||||
// Should only initialize once
|
||||
expect(pool.isInitialized()).toBe(true)
|
||||
})
|
||||
|
||||
it('should auto-initialize NLP when accessed', async () => {
|
||||
const nlp = await pool.getNLP()
|
||||
|
||||
// NLP is lazy-initialized but extractor might not be
|
||||
const stats = pool.getStats()
|
||||
expect(stats.nlpCreated).toBe(true)
|
||||
expect(stats.initialized).toBe(true)
|
||||
})
|
||||
|
||||
it('should provide sync access to NLP', () => {
|
||||
const nlp = pool.getNLPSync()
|
||||
expect(nlp).toBeDefined()
|
||||
|
||||
const stats = pool.getStats()
|
||||
expect(stats.nlpCreated).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('statistics', () => {
|
||||
it('should track creation time', async () => {
|
||||
await pool.init()
|
||||
|
||||
const stats = pool.getStats()
|
||||
expect(stats.creationTime).toBeGreaterThanOrEqual(0)
|
||||
})
|
||||
|
||||
it('should calculate memory saved', async () => {
|
||||
// Use instances multiple times
|
||||
await pool.getNLP()
|
||||
await pool.getNLP()
|
||||
await pool.getNLP()
|
||||
pool.getExtractor()
|
||||
pool.getExtractor()
|
||||
|
||||
const stats = pool.getStats()
|
||||
expect(stats.memorySaved).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('should reset statistics', async () => {
|
||||
await pool.getNLP()
|
||||
pool.getExtractor()
|
||||
|
||||
pool.resetStats()
|
||||
|
||||
const stats = pool.getStats()
|
||||
expect(stats.nlpReuses).toBe(0)
|
||||
expect(stats.extractorReuses).toBe(0)
|
||||
expect(stats.creationTime).toBe(0)
|
||||
})
|
||||
|
||||
it('should provide string representation', async () => {
|
||||
await pool.init()
|
||||
|
||||
const str = pool.toString()
|
||||
expect(str).toContain('InstancePool')
|
||||
expect(str).toContain('nlp=true')
|
||||
expect(str).toContain('extractor=true')
|
||||
})
|
||||
})
|
||||
|
||||
describe('memory efficiency', () => {
|
||||
it('should reuse instances in loop (no memory leak)', async () => {
|
||||
const initialStats = pool.getStats()
|
||||
|
||||
// Simulate import loop
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
const nlp = await pool.getNLP()
|
||||
const extractor = pool.getExtractor()
|
||||
|
||||
// All iterations should get same instances
|
||||
expect(nlp).toBeDefined()
|
||||
expect(extractor).toBeDefined()
|
||||
}
|
||||
|
||||
const finalStats = pool.getStats()
|
||||
expect(finalStats.nlpReuses).toBe(1000)
|
||||
expect(finalStats.extractorReuses).toBe(1000)
|
||||
|
||||
// Should have saved ~60GB of memory (1000 iterations × ~60MB)
|
||||
expect(finalStats.memorySaved).toBeGreaterThan(50 * 1024 * 1024 * 1000) // > 50GB
|
||||
})
|
||||
|
||||
it('should handle rapid concurrent access', async () => {
|
||||
// Simulate concurrent row processing
|
||||
const promises = []
|
||||
for (let i = 0; i < 100; i++) {
|
||||
promises.push(pool.getNLP())
|
||||
promises.push(Promise.resolve(pool.getExtractor()))
|
||||
}
|
||||
|
||||
await Promise.all(promises)
|
||||
|
||||
const stats = pool.getStats()
|
||||
expect(stats.nlpReuses).toBe(100)
|
||||
expect(stats.extractorReuses).toBe(100)
|
||||
})
|
||||
})
|
||||
|
||||
describe('cleanup', () => {
|
||||
it('should cleanup instances', async () => {
|
||||
await pool.init()
|
||||
expect(pool.isInitialized()).toBe(true)
|
||||
|
||||
pool.cleanup()
|
||||
|
||||
expect(pool.isInitialized()).toBe(false)
|
||||
const stats = pool.getStats()
|
||||
expect(stats.nlpCreated).toBe(false)
|
||||
expect(stats.extractorCreated).toBe(false)
|
||||
})
|
||||
|
||||
it('should allow reinitialization after cleanup', async () => {
|
||||
await pool.init()
|
||||
pool.cleanup()
|
||||
|
||||
await pool.init()
|
||||
expect(pool.isInitialized()).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('factory function', () => {
|
||||
it('should create pool with auto-init', async () => {
|
||||
const newPool = await createInstancePool(brain, true)
|
||||
|
||||
expect(newPool.isInitialized()).toBe(true)
|
||||
})
|
||||
|
||||
it('should create pool without auto-init', async () => {
|
||||
const newPool = await createInstancePool(brain, false)
|
||||
|
||||
expect(newPool.isInitialized()).toBe(false)
|
||||
})
|
||||
|
||||
it('should default to auto-init', async () => {
|
||||
const newPool = await createInstancePool(brain)
|
||||
|
||||
expect(newPool.isInitialized()).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('error handling', () => {
|
||||
it('should handle missing NLP instance gracefully', async () => {
|
||||
const emptyPool = new InstancePool(brain)
|
||||
|
||||
// Should create NLP on first access
|
||||
const nlp = await emptyPool.getNLP()
|
||||
expect(nlp).toBeDefined()
|
||||
})
|
||||
|
||||
it('should handle missing extractor instance gracefully', () => {
|
||||
const emptyPool = new InstancePool(brain)
|
||||
|
||||
// Should create extractor on first access
|
||||
const extractor = emptyPool.getExtractor()
|
||||
expect(extractor).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('real-world usage', () => {
|
||||
it('should work with actual NLP operations', async () => {
|
||||
const nlp = await pool.getNLP()
|
||||
|
||||
// Should be initialized and ready to use
|
||||
expect(nlp).toBeDefined()
|
||||
|
||||
// NLP should have init method
|
||||
expect(typeof nlp.init).toBe('function')
|
||||
})
|
||||
|
||||
it('should work with actual entity extraction', async () => {
|
||||
const extractor = pool.getExtractor()
|
||||
|
||||
// Should be ready to use
|
||||
expect(extractor).toBeDefined()
|
||||
|
||||
// Can call extractor methods
|
||||
const entities = await extractor.extract('Paris is a beautiful city', {
|
||||
confidence: 0.5
|
||||
})
|
||||
|
||||
expect(Array.isArray(entities)).toBe(true)
|
||||
})
|
||||
|
||||
it('should handle full import workflow', async () => {
|
||||
// Initialize pool
|
||||
await pool.init()
|
||||
|
||||
// Simulate processing multiple rows
|
||||
const rows = [
|
||||
{ text: 'Paris is beautiful' },
|
||||
{ text: 'London is historic' },
|
||||
{ text: 'Tokyo is modern' }
|
||||
]
|
||||
|
||||
for (const row of rows) {
|
||||
const nlp = await pool.getNLP()
|
||||
const extractor = pool.getExtractor()
|
||||
|
||||
// Process row - extract entities
|
||||
const entities = await extractor.extract(row.text, { confidence: 0.5 })
|
||||
|
||||
expect(nlp).toBeDefined()
|
||||
expect(extractor).toBeDefined()
|
||||
expect(entities).toBeDefined()
|
||||
}
|
||||
|
||||
// Verify instances were reused
|
||||
const stats = pool.getStats()
|
||||
expect(stats.nlpReuses).toBe(3)
|
||||
expect(stats.extractorReuses).toBe(3)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
@ -1,561 +0,0 @@
|
|||
import { describe, it, expect } from 'vitest'
|
||||
import {
|
||||
autoDetectPreset,
|
||||
getPreset,
|
||||
getPresetNames,
|
||||
explainPresetChoice,
|
||||
createCustomPreset,
|
||||
validatePreset,
|
||||
formatPreset,
|
||||
FAST_PRESET,
|
||||
BALANCED_PRESET,
|
||||
ACCURATE_PRESET,
|
||||
EXPLICIT_PRESET,
|
||||
PATTERN_PRESET,
|
||||
PRESETS,
|
||||
type ImportContext,
|
||||
type PresetConfig
|
||||
} from '../../../src/neural/presets.js'
|
||||
|
||||
describe('Presets', () => {
|
||||
describe('preset definitions', () => {
|
||||
it('should have all 5 presets defined', () => {
|
||||
expect(PRESETS).toBeDefined()
|
||||
expect(Object.keys(PRESETS)).toHaveLength(5)
|
||||
expect(PRESETS.fast).toBe(FAST_PRESET)
|
||||
expect(PRESETS.balanced).toBe(BALANCED_PRESET)
|
||||
expect(PRESETS.accurate).toBe(ACCURATE_PRESET)
|
||||
expect(PRESETS.explicit).toBe(EXPLICIT_PRESET)
|
||||
expect(PRESETS.pattern).toBe(PATTERN_PRESET)
|
||||
})
|
||||
|
||||
it('should have valid fast preset', () => {
|
||||
expect(FAST_PRESET.name).toBe('fast')
|
||||
expect(FAST_PRESET.signals.enabled).toEqual(['exact', 'pattern'])
|
||||
expect(FAST_PRESET.strategies.enabled).toEqual(['explicit'])
|
||||
expect(FAST_PRESET.streaming).toBe(true)
|
||||
expect(FAST_PRESET.strategies.earlyTermination).toBe(true)
|
||||
})
|
||||
|
||||
it('should have valid balanced preset', () => {
|
||||
expect(BALANCED_PRESET.name).toBe('balanced')
|
||||
expect(BALANCED_PRESET.signals.enabled).toEqual(['exact', 'embedding', 'pattern'])
|
||||
expect(BALANCED_PRESET.strategies.enabled).toEqual(['explicit', 'pattern', 'embedding'])
|
||||
expect(BALANCED_PRESET.streaming).toBe(false)
|
||||
})
|
||||
|
||||
it('should have valid accurate preset', () => {
|
||||
expect(ACCURATE_PRESET.name).toBe('accurate')
|
||||
expect(ACCURATE_PRESET.signals.enabled).toEqual(['exact', 'embedding', 'pattern', 'context'])
|
||||
expect(ACCURATE_PRESET.strategies.enabled).toEqual(['explicit', 'pattern', 'embedding'])
|
||||
expect(ACCURATE_PRESET.strategies.earlyTermination).toBe(false)
|
||||
})
|
||||
|
||||
it('should have valid explicit preset', () => {
|
||||
expect(EXPLICIT_PRESET.name).toBe('explicit')
|
||||
expect(EXPLICIT_PRESET.signals.enabled).toEqual(['exact', 'pattern'])
|
||||
expect(EXPLICIT_PRESET.strategies.enabled).toEqual(['explicit', 'pattern'])
|
||||
expect(EXPLICIT_PRESET.strategies.minConfidence).toBeGreaterThanOrEqual(0.80)
|
||||
})
|
||||
|
||||
it('should have valid pattern preset', () => {
|
||||
expect(PATTERN_PRESET.name).toBe('pattern')
|
||||
expect(PATTERN_PRESET.signals.enabled).toEqual(['embedding', 'pattern', 'context'])
|
||||
expect(PATTERN_PRESET.strategies.enabled).toEqual(['pattern', 'embedding'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('autoDetectPreset', () => {
|
||||
it('should return fast preset for large datasets', () => {
|
||||
const context: ImportContext = {
|
||||
rowCount: 15000,
|
||||
fileSize: 5_000_000
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('fast')
|
||||
})
|
||||
|
||||
it('should return fast preset for large files', () => {
|
||||
const context: ImportContext = {
|
||||
fileSize: 15_000_000
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('fast')
|
||||
})
|
||||
|
||||
it('should return accurate preset for small datasets', () => {
|
||||
const context: ImportContext = {
|
||||
rowCount: 50
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('accurate')
|
||||
})
|
||||
|
||||
it('should return explicit preset for Excel with explicit columns', () => {
|
||||
const context: ImportContext = {
|
||||
fileType: 'excel',
|
||||
hasExplicitColumns: true,
|
||||
rowCount: 500
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('explicit')
|
||||
})
|
||||
|
||||
it('should return explicit preset for CSV with explicit columns', () => {
|
||||
const context: ImportContext = {
|
||||
fileType: 'csv',
|
||||
hasExplicitColumns: true
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('explicit')
|
||||
})
|
||||
|
||||
it('should return pattern preset for PDF files', () => {
|
||||
const context: ImportContext = {
|
||||
fileType: 'pdf',
|
||||
rowCount: 200
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('pattern')
|
||||
})
|
||||
|
||||
it('should return pattern preset for Markdown files', () => {
|
||||
const context: ImportContext = {
|
||||
fileType: 'markdown'
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('pattern')
|
||||
})
|
||||
|
||||
it('should return pattern preset for narrative content', () => {
|
||||
const context: ImportContext = {
|
||||
hasNarrativeContent: true,
|
||||
rowCount: 300
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('pattern')
|
||||
})
|
||||
|
||||
it('should return pattern preset for long definitions', () => {
|
||||
const context: ImportContext = {
|
||||
avgDefinitionLength: 800,
|
||||
fileType: 'csv'
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('pattern')
|
||||
})
|
||||
|
||||
it('should return balanced preset for JSON', () => {
|
||||
const context: ImportContext = {
|
||||
fileType: 'json',
|
||||
rowCount: 500
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('balanced')
|
||||
})
|
||||
|
||||
it('should return balanced preset for medium datasets', () => {
|
||||
const context: ImportContext = {
|
||||
fileType: 'excel',
|
||||
rowCount: 2000
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('balanced')
|
||||
})
|
||||
|
||||
it('should return balanced preset for empty context', () => {
|
||||
const preset = autoDetectPreset()
|
||||
expect(preset.name).toBe('balanced')
|
||||
})
|
||||
|
||||
it('should return balanced preset for unknown file type', () => {
|
||||
const context: ImportContext = {
|
||||
fileType: 'unknown',
|
||||
rowCount: 500
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('balanced')
|
||||
})
|
||||
})
|
||||
|
||||
describe('getPreset', () => {
|
||||
it('should get preset by name', () => {
|
||||
expect(getPreset('fast')).toBe(FAST_PRESET)
|
||||
expect(getPreset('balanced')).toBe(BALANCED_PRESET)
|
||||
expect(getPreset('accurate')).toBe(ACCURATE_PRESET)
|
||||
expect(getPreset('explicit')).toBe(EXPLICIT_PRESET)
|
||||
expect(getPreset('pattern')).toBe(PATTERN_PRESET)
|
||||
})
|
||||
|
||||
it('should be case-insensitive', () => {
|
||||
expect(getPreset('FAST')).toBe(FAST_PRESET)
|
||||
expect(getPreset('Balanced')).toBe(BALANCED_PRESET)
|
||||
expect(getPreset('EXPLICIT')).toBe(EXPLICIT_PRESET)
|
||||
})
|
||||
|
||||
it('should throw error for unknown preset', () => {
|
||||
expect(() => getPreset('unknown')).toThrow('Unknown preset: unknown')
|
||||
})
|
||||
})
|
||||
|
||||
describe('getPresetNames', () => {
|
||||
it('should return all preset names', () => {
|
||||
const names = getPresetNames()
|
||||
expect(names).toHaveLength(5)
|
||||
expect(names).toContain('fast')
|
||||
expect(names).toContain('balanced')
|
||||
expect(names).toContain('accurate')
|
||||
expect(names).toContain('explicit')
|
||||
expect(names).toContain('pattern')
|
||||
})
|
||||
})
|
||||
|
||||
describe('explainPresetChoice', () => {
|
||||
it('should explain large dataset choice', () => {
|
||||
const context: ImportContext = {
|
||||
rowCount: 15000,
|
||||
fileSize: 12_000_000
|
||||
}
|
||||
|
||||
const explanation = explainPresetChoice(context)
|
||||
expect(explanation).toContain('Large dataset')
|
||||
expect(explanation).toContain('15000 rows')
|
||||
expect(explanation).toContain('fast preset')
|
||||
})
|
||||
|
||||
it('should explain small dataset choice', () => {
|
||||
const context: ImportContext = {
|
||||
rowCount: 50
|
||||
}
|
||||
|
||||
const explanation = explainPresetChoice(context)
|
||||
expect(explanation).toContain('Small critical dataset')
|
||||
expect(explanation).toContain('50 rows')
|
||||
expect(explanation).toContain('accurate preset')
|
||||
})
|
||||
|
||||
it('should explain explicit columns choice', () => {
|
||||
const context: ImportContext = {
|
||||
fileType: 'excel',
|
||||
hasExplicitColumns: true
|
||||
}
|
||||
|
||||
const explanation = explainPresetChoice(context)
|
||||
expect(explanation).toContain('EXCEL')
|
||||
expect(explanation).toContain('explicit relationship columns')
|
||||
expect(explanation).toContain('explicit preset')
|
||||
})
|
||||
|
||||
it('should explain narrative content choice', () => {
|
||||
const context: ImportContext = {
|
||||
fileType: 'pdf',
|
||||
hasNarrativeContent: true
|
||||
}
|
||||
|
||||
const explanation = explainPresetChoice(context)
|
||||
expect(explanation).toContain('Narrative content')
|
||||
expect(explanation).toContain('pattern preset')
|
||||
})
|
||||
|
||||
it('should explain default choice', () => {
|
||||
const context: ImportContext = {
|
||||
rowCount: 500
|
||||
}
|
||||
|
||||
const explanation = explainPresetChoice(context)
|
||||
expect(explanation).toContain('balanced preset')
|
||||
})
|
||||
})
|
||||
|
||||
describe('createCustomPreset', () => {
|
||||
it('should create custom preset from base', () => {
|
||||
const custom = createCustomPreset('balanced', {
|
||||
name: 'my-custom',
|
||||
batchSize: 2000
|
||||
})
|
||||
|
||||
expect(custom.name).toBe('my-custom')
|
||||
expect(custom.batchSize).toBe(2000)
|
||||
expect(custom.signals).toEqual(BALANCED_PRESET.signals)
|
||||
expect(custom.strategies).toEqual(BALANCED_PRESET.strategies)
|
||||
})
|
||||
|
||||
it('should override signals', () => {
|
||||
const custom = createCustomPreset('fast', {
|
||||
signals: {
|
||||
enabled: ['embedding'],
|
||||
weights: { embedding: 1.0, exact: 0, pattern: 0, context: 0 },
|
||||
timeout: 200
|
||||
}
|
||||
})
|
||||
|
||||
expect(custom.signals.enabled).toEqual(['embedding'])
|
||||
expect(custom.signals.timeout).toBe(200)
|
||||
})
|
||||
|
||||
it('should override strategies', () => {
|
||||
const custom = createCustomPreset('balanced', {
|
||||
strategies: {
|
||||
enabled: ['pattern'],
|
||||
timeout: 500,
|
||||
earlyTermination: false,
|
||||
minConfidence: 0.75
|
||||
}
|
||||
})
|
||||
|
||||
expect(custom.strategies.enabled).toEqual(['pattern'])
|
||||
expect(custom.strategies.timeout).toBe(500)
|
||||
expect(custom.strategies.earlyTermination).toBe(false)
|
||||
})
|
||||
|
||||
it('should merge partial signal overrides', () => {
|
||||
const custom = createCustomPreset('balanced', {
|
||||
signals: {
|
||||
timeout: 300
|
||||
} as any
|
||||
})
|
||||
|
||||
expect(custom.signals.enabled).toEqual(BALANCED_PRESET.signals.enabled)
|
||||
expect(custom.signals.timeout).toBe(300)
|
||||
})
|
||||
})
|
||||
|
||||
describe('validatePreset', () => {
|
||||
it('should validate all built-in presets', () => {
|
||||
expect(() => validatePreset(FAST_PRESET)).not.toThrow()
|
||||
expect(() => validatePreset(BALANCED_PRESET)).not.toThrow()
|
||||
expect(() => validatePreset(ACCURATE_PRESET)).not.toThrow()
|
||||
expect(() => validatePreset(EXPLICIT_PRESET)).not.toThrow()
|
||||
expect(() => validatePreset(PATTERN_PRESET)).not.toThrow()
|
||||
})
|
||||
|
||||
it('should reject preset with no signals', () => {
|
||||
const invalid: PresetConfig = {
|
||||
...BALANCED_PRESET,
|
||||
signals: {
|
||||
...BALANCED_PRESET.signals,
|
||||
enabled: []
|
||||
}
|
||||
}
|
||||
|
||||
expect(() => validatePreset(invalid)).toThrow('at least one enabled signal')
|
||||
})
|
||||
|
||||
it('should reject preset with no strategies', () => {
|
||||
const invalid: PresetConfig = {
|
||||
...BALANCED_PRESET,
|
||||
strategies: {
|
||||
...BALANCED_PRESET.strategies,
|
||||
enabled: []
|
||||
}
|
||||
}
|
||||
|
||||
expect(() => validatePreset(invalid)).toThrow('at least one enabled strategy')
|
||||
})
|
||||
|
||||
it('should reject preset with invalid weight sum', () => {
|
||||
const invalid: PresetConfig = {
|
||||
...BALANCED_PRESET,
|
||||
signals: {
|
||||
enabled: ['exact', 'embedding'],
|
||||
weights: {
|
||||
exact: 0.3,
|
||||
embedding: 0.5,
|
||||
pattern: 0,
|
||||
context: 0
|
||||
},
|
||||
timeout: 100
|
||||
}
|
||||
}
|
||||
|
||||
expect(() => validatePreset(invalid)).toThrow('weights must sum to 1.0')
|
||||
})
|
||||
|
||||
it('should reject preset with negative timeout', () => {
|
||||
const invalid: PresetConfig = {
|
||||
...BALANCED_PRESET,
|
||||
signals: {
|
||||
...BALANCED_PRESET.signals,
|
||||
timeout: -100
|
||||
}
|
||||
}
|
||||
|
||||
expect(() => validatePreset(invalid)).toThrow('Timeouts must be positive')
|
||||
})
|
||||
|
||||
it('should reject preset with invalid batch size', () => {
|
||||
const invalid: PresetConfig = {
|
||||
...BALANCED_PRESET,
|
||||
batchSize: 0
|
||||
}
|
||||
|
||||
expect(() => validatePreset(invalid)).toThrow('Batch size must be positive')
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatPreset', () => {
|
||||
it('should format preset for display', () => {
|
||||
const formatted = formatPreset(BALANCED_PRESET)
|
||||
|
||||
expect(formatted).toContain('Preset: balanced')
|
||||
expect(formatted).toContain('Description:')
|
||||
expect(formatted).toContain('Signals:')
|
||||
expect(formatted).toContain('exact: 40%')
|
||||
expect(formatted).toContain('embedding: 35%')
|
||||
expect(formatted).toContain('Strategies:')
|
||||
expect(formatted).toContain('explicit')
|
||||
expect(formatted).toContain('pattern')
|
||||
expect(formatted).toContain('embedding')
|
||||
expect(formatted).toContain('Streaming: false')
|
||||
expect(formatted).toContain('Batch size: 500')
|
||||
})
|
||||
|
||||
it('should format fast preset correctly', () => {
|
||||
const formatted = formatPreset(FAST_PRESET)
|
||||
|
||||
expect(formatted).toContain('fast')
|
||||
expect(formatted).toContain('Streaming: true')
|
||||
expect(formatted).toContain('Early termination: true')
|
||||
})
|
||||
})
|
||||
|
||||
describe('preset priorities', () => {
|
||||
it('should prioritize size over explicit columns for large datasets', () => {
|
||||
const context: ImportContext = {
|
||||
rowCount: 20000,
|
||||
fileType: 'excel',
|
||||
hasExplicitColumns: true
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('fast') // Size trumps explicit
|
||||
})
|
||||
|
||||
it('should prioritize small size over other factors', () => {
|
||||
const context: ImportContext = {
|
||||
rowCount: 50,
|
||||
fileType: 'pdf',
|
||||
hasNarrativeContent: true
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('accurate') // Small size trumps pattern
|
||||
})
|
||||
|
||||
it('should prioritize explicit columns over narrative for Excel', () => {
|
||||
const context: ImportContext = {
|
||||
rowCount: 500,
|
||||
fileType: 'excel',
|
||||
hasExplicitColumns: true,
|
||||
hasNarrativeContent: true
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('explicit') // Explicit trumps narrative
|
||||
})
|
||||
})
|
||||
|
||||
describe('edge cases', () => {
|
||||
it('should handle zero row count', () => {
|
||||
const context: ImportContext = {
|
||||
rowCount: 0,
|
||||
fileType: 'csv'
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('balanced')
|
||||
})
|
||||
|
||||
it('should handle boundary row count (exactly 100)', () => {
|
||||
const context: ImportContext = {
|
||||
rowCount: 100
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('balanced') // Not accurate (< 100)
|
||||
})
|
||||
|
||||
it('should handle boundary row count (exactly 10000)', () => {
|
||||
const context: ImportContext = {
|
||||
rowCount: 10000
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('balanced') // Not fast (> 10000)
|
||||
})
|
||||
|
||||
it('should handle missing hasExplicitColumns flag', () => {
|
||||
const context: ImportContext = {
|
||||
fileType: 'excel',
|
||||
rowCount: 500
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('balanced')
|
||||
})
|
||||
})
|
||||
|
||||
describe('real-world scenarios', () => {
|
||||
it('should handle glossary correctly', () => {
|
||||
const context: ImportContext = {
|
||||
fileType: 'excel',
|
||||
rowCount: 567,
|
||||
hasExplicitColumns: true, // Has "Related Terms" column
|
||||
fileSize: 50_000
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('explicit')
|
||||
|
||||
const explanation = explainPresetChoice(context)
|
||||
expect(explanation).toContain('explicit')
|
||||
})
|
||||
|
||||
it('should handle large CSV import', () => {
|
||||
const context: ImportContext = {
|
||||
fileType: 'csv',
|
||||
rowCount: 50000,
|
||||
fileSize: 25_000_000
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('fast')
|
||||
expect(preset.streaming).toBe(true)
|
||||
})
|
||||
|
||||
it('should handle PDF documentation', () => {
|
||||
const context: ImportContext = {
|
||||
fileType: 'pdf',
|
||||
rowCount: 150,
|
||||
hasNarrativeContent: true,
|
||||
avgDefinitionLength: 600
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('pattern')
|
||||
})
|
||||
|
||||
it('should handle JSON API import', () => {
|
||||
const context: ImportContext = {
|
||||
fileType: 'json',
|
||||
rowCount: 1000,
|
||||
fileSize: 500_000
|
||||
}
|
||||
|
||||
const preset = autoDetectPreset(context)
|
||||
expect(preset.name).toBe('balanced')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { VirtualFileSystem } from '../../src/vfs/index.js'
|
||||
import { VirtualFileSystem } from '../../src/vfs/VirtualFileSystem.js'
|
||||
import { Brainy } from '../../src/brainy.js'
|
||||
|
||||
describe('VFS Initialization', () => {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
||||
import { VirtualFileSystem } from '../../src/vfs/index.js'
|
||||
import { VirtualFileSystem } from '../../src/vfs/VirtualFileSystem.js'
|
||||
import { Brainy } from '../../src/brainy.js'
|
||||
import { VFSErrorCode } from '../../src/vfs/types.js'
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue