diff --git a/tests/integration/all-apis-comprehensive.test.ts b/tests/integration/all-apis-comprehensive.test.ts index 5f793f37..d0390b56 100644 --- a/tests/integration/all-apis-comprehensive.test.ts +++ b/tests/integration/all-apis-comprehensive.test.ts @@ -224,7 +224,7 @@ describe('Comprehensive All-APIs Test', () => { let vfs: any it('vfs.init() - should initialize VFS', async () => { - vfs = brain.vfs() + vfs = brain.vfs await vfs.init() expect(vfs).toBeDefined() diff --git a/tests/integration/entity-confidence-weight.test.ts b/tests/integration/entity-confidence-weight.test.ts index f678389a..b902e589 100644 --- a/tests/integration/entity-confidence-weight.test.ts +++ b/tests/integration/entity-confidence-weight.test.ts @@ -308,7 +308,7 @@ describe('Entity Confidence & Weight Exposure', () => { describe('VFS integration', () => { it('should expose confidence/weight for VFS entities', async () => { - const vfs = brain.vfs() + const vfs = brain.vfs await vfs.init() await vfs.writeFile('/test.txt', 'VFS test content') diff --git a/tests/integration/remaining-apis.test.ts b/tests/integration/remaining-apis.test.ts index 5420c0d6..97637b3a 100644 --- a/tests/integration/remaining-apis.test.ts +++ b/tests/integration/remaining-apis.test.ts @@ -121,7 +121,7 @@ Carol,35,Manager` expect(result.stats.vfsFilesCreated).toBeGreaterThan(0) // Verify VFS file was created - const vfs = brain.vfs() + const vfs = brain.vfs await vfs.init() const exists = await vfs.exists('/imports/test-data.csv') expect(exists).toBe(true) @@ -173,7 +173,7 @@ Gadget,20` let vfs: any beforeAll(async () => { - vfs = brain.vfs() + vfs = brain.vfs await vfs.init() }) @@ -348,7 +348,7 @@ Gadget,20` console.log('\nšŸ“‹ Test: neural.clusters() VFS filtering') // Create VFS files - const vfs = brain.vfs() + const vfs = brain.vfs await vfs.writeFile('/cluster-test1.txt', 'VFS file content') await vfs.writeFile('/cluster-test2.txt', 'Another VFS file') @@ -416,7 +416,7 @@ Gadget,20` it('should handle VFS file operations at scale', async () => { console.log('\nšŸ“‹ Test: VFS operations at scale') - const vfs = brain.vfs() + const vfs = brain.vfs const start = Date.now() // Create 20 files diff --git a/tests/integration/vfs-and-graph-entities.test.ts b/tests/integration/vfs-and-graph-entities.test.ts index 9fb15c3b..0850f764 100644 --- a/tests/integration/vfs-and-graph-entities.test.ts +++ b/tests/integration/vfs-and-graph-entities.test.ts @@ -89,7 +89,7 @@ describe('VFS + Graph Entities Integration Test', () => { console.log('='.repeat(80)) // Initialize VFS - const vfs = brain.vfs() + const vfs = brain.vfs await vfs.init() // ASSERTION 4: VFS directory structure exists diff --git a/tests/integration/vfs-api-wiring.test.ts b/tests/integration/vfs-api-wiring.test.ts index 137f3bd9..9911b320 100644 --- a/tests/integration/vfs-api-wiring.test.ts +++ b/tests/integration/vfs-api-wiring.test.ts @@ -47,7 +47,7 @@ describe('VFS API Wiring Verification', () => { }) // Create VFS file - const vfs = brain.vfs() + const vfs = brain.vfs await vfs.init() await vfs.writeFile('/typescript.md', 'TypeScript programming guide') @@ -81,7 +81,7 @@ describe('VFS API Wiring Verification', () => { it('should verify vfs.search() finds VFS files', async () => { console.log('\nšŸ“‹ Test 2: vfs.search() finds VFS files') - const vfs = brain.vfs() + const vfs = brain.vfs await vfs.init() // Required before using VFS operations // Create test files @@ -111,7 +111,7 @@ describe('VFS API Wiring Verification', () => { it('should verify vfs.findSimilar() finds similar VFS files', async () => { console.log('\nšŸ“‹ Test 3: vfs.findSimilar() finds similar VFS files') - const vfs = brain.vfs() + const vfs = brain.vfs await vfs.init() // Required before using VFS operations // Create similar files @@ -143,7 +143,7 @@ describe('VFS API Wiring Verification', () => { it('should verify vfs.searchEntities() finds VFS entities', async () => { console.log('\nšŸ“‹ Test 4: vfs.searchEntities() finds VFS entities') - const vfs = brain.vfs() + const vfs = brain.vfs await vfs.init() // Required before using VFS operations // Create entity in VFS (if supported) @@ -164,7 +164,7 @@ describe('VFS API Wiring Verification', () => { it('should verify VFS semantic projections work', async () => { console.log('\nšŸ“‹ Test 5: VFS semantic projections') - const vfs = brain.vfs() + const vfs = brain.vfs await vfs.init() // Required before using VFS operations // Create files with metadata for projections @@ -282,7 +282,7 @@ describe('VFS API Wiring Verification', () => { it('should verify production scale performance', async () => { console.log('\nšŸ“‹ Test 8: Production scale performance') - const vfs = brain.vfs() + const vfs = brain.vfs await vfs.init() // Required before using VFS operations // Create batch of files diff --git a/tests/integration/vfs-debug.test.ts b/tests/integration/vfs-debug.test.ts index a5bf99b1..e0f0563b 100644 --- a/tests/integration/vfs-debug.test.ts +++ b/tests/integration/vfs-debug.test.ts @@ -14,7 +14,7 @@ describe('VFS Debug', () => { console.log('āœ… Brain initialized') // Get VFS and initialize - const vfs = brain.vfs() + const vfs = brain.vfs await vfs.init() console.log('āœ… VFS initialized') diff --git a/tests/integration/vfs-import-verification.test.ts b/tests/integration/vfs-import-verification.test.ts index 37688e75..3241be4e 100644 --- a/tests/integration/vfs-import-verification.test.ts +++ b/tests/integration/vfs-import-verification.test.ts @@ -100,7 +100,7 @@ describe('VFS Import Verification (Workshop Bug Investigation)', () => { console.log('\nšŸ“‚ Step 3: Initialize VFS and query...') // Get VFS instance - const vfs = brain.vfs() + const vfs = brain.vfs console.log(' - Got VFS instance') // Initialize VFS @@ -180,10 +180,10 @@ describe('VFS Import Verification (Workshop Bug Investigation)', () => { }) console.log('šŸ“‚ Get VFS (should be initialized by import)...') - const vfs = brain.vfs() + const vfs = brain.vfs // AFTER REFACTOR: This should work without calling vfs.init() - // Because VFSStructureGenerator uses brain.vfs() which caches the instance + // Because VFSStructureGenerator uses brain.vfs which caches the instance console.log('šŸ” Query root (without manual init)...') try { @@ -238,7 +238,7 @@ describe('VFS Import Verification (Workshop Bug Investigation)', () => { // Workshop team's check: Initialize VFS console.log('\nšŸ“‚ Initializing VFS (Workshop fix)...') - const vfs = brain.vfs() + const vfs = brain.vfs await vfs.init() // Workshop team's check: Query root diff --git a/tests/integration/vfs-knowledge-separation.test.ts b/tests/integration/vfs-knowledge-separation.test.ts index 1d6e8744..16882990 100644 --- a/tests/integration/vfs-knowledge-separation.test.ts +++ b/tests/integration/vfs-knowledge-separation.test.ts @@ -42,7 +42,7 @@ describe('VFS-Knowledge Separation (Option 3C)', () => { it('should exclude VFS entities from brain.find() by default', async () => { // Create VFS file entity - const vfs = brain.vfs() + const vfs = brain.vfs await vfs.init() await vfs.mkdir('/docs', { recursive: true }) await vfs.writeFile('/docs/readme.md', '# Hello World') diff --git a/tests/manual/simple-vfs-filter-test.test.ts b/tests/manual/simple-vfs-filter-test.test.ts index c70b7161..4b8065f7 100644 --- a/tests/manual/simple-vfs-filter-test.test.ts +++ b/tests/manual/simple-vfs-filter-test.test.ts @@ -47,7 +47,7 @@ describe('Simple VFS Filter Test', () => { // 2. Create VFS file console.log('\n2. Creating VFS file...') - const vfs = brain.vfs() + const vfs = brain.vfs await vfs.init() await vfs.writeFile('/test.txt', 'VFS file') console.log(' VFS file created') diff --git a/tests/manual/vfs-isvfs-diagnostic.test.ts b/tests/manual/vfs-isvfs-diagnostic.test.ts index b90667b9..41d6002f 100644 --- a/tests/manual/vfs-isvfs-diagnostic.test.ts +++ b/tests/manual/vfs-isvfs-diagnostic.test.ts @@ -35,7 +35,7 @@ describe('isVFS Flag Diagnostic', () => { it('should show what entities are created', async () => { // Create VFS file - const vfs = brain.vfs() + const vfs = brain.vfs await vfs.init() await vfs.writeFile('/test.txt', 'Hello World') diff --git a/tests/manual/vfs-multiple-init-diagnostic.test.ts b/tests/manual/vfs-multiple-init-diagnostic.test.ts index e07b8c5d..b6a589fb 100644 --- a/tests/manual/vfs-multiple-init-diagnostic.test.ts +++ b/tests/manual/vfs-multiple-init-diagnostic.test.ts @@ -44,7 +44,7 @@ describe('VFS Multiple Init Diagnostic', () => { }) it('should not create duplicate roots when calling vfs.init() multiple times on SAME instance', async () => { - const vfs = brain.vfs() + const vfs = brain.vfs // Call init multiple times await vfs.init() @@ -74,10 +74,10 @@ describe('VFS Multiple Init Diagnostic', () => { it('should not create duplicate roots when creating MULTIPLE VFS instances (Workshop scenario)', async () => { // Simulate Workshop's scenario: Getting VFS on multiple requests - // brain.vfs() returns cached instance, so this should be safe - const vfs1 = brain.vfs() - const vfs2 = brain.vfs() - const vfs3 = brain.vfs() + // brain.vfs returns cached instance, so this should be safe + const vfs1 = brain.vfs + const vfs2 = brain.vfs + const vfs3 = brain.vfs await vfs1.init() await vfs2.init() @@ -142,7 +142,7 @@ describe('VFS Multiple Init Diagnostic', () => { it('should verify readdir works after multiple inits', async () => { // Create a test directory - const vfs = brain.vfs() + const vfs = brain.vfs await vfs.mkdir('/test-dir', { recursive: true }) await vfs.writeFile('/test-dir/test.txt', 'Hello') @@ -170,7 +170,7 @@ describe('VFS Multiple Init Diagnostic', () => { }) it('should show if Contains relationships are created', async () => { - const vfs = brain.vfs() + const vfs = brain.vfs // Get root entity ID using workaround const collections = await brain.find({ diff --git a/tests/manual/vfs-search-debug.test.ts b/tests/manual/vfs-search-debug.test.ts index 59954e7c..e4423ad3 100644 --- a/tests/manual/vfs-search-debug.test.ts +++ b/tests/manual/vfs-search-debug.test.ts @@ -33,7 +33,7 @@ describe('VFS Search Debug', () => { }) it('should debug vfs.search() results', async () => { - const vfs = brain.vfs() + const vfs = brain.vfs await vfs.init() await vfs.writeFile('/test.txt', 'Hello world test content') diff --git a/tests/manual/vfs-where-clause-test.test.ts b/tests/manual/vfs-where-clause-test.test.ts index c75e7801..83ede49c 100644 --- a/tests/manual/vfs-where-clause-test.test.ts +++ b/tests/manual/vfs-where-clause-test.test.ts @@ -37,7 +37,7 @@ describe('VFS Where Clause Diagnostic', () => { }) it('should find root entity using where clause', async () => { - const vfs = brain.vfs() + const vfs = brain.vfs await vfs.init() // Method 1: Where clause (FIXED in v4.3.3!) @@ -84,7 +84,7 @@ describe('VFS Where Clause Diagnostic', () => { }) it('should find regular VFS files using where clause', async () => { - const vfs = brain.vfs() + const vfs = brain.vfs await vfs.mkdir('/test', { recursive: true }) await vfs.writeFile('/test/hello.txt', 'Hello World') diff --git a/tests/unit/brainy-core.unit.test.ts b/tests/unit/brainy-core.unit.test.ts index 9705846a..93754331 100644 --- a/tests/unit/brainy-core.unit.test.ts +++ b/tests/unit/brainy-core.unit.test.ts @@ -89,16 +89,17 @@ describe('Brainy 3.0 Core (Unit Tests)', () => { }) it('should handle non-existent IDs according to API contract', async () => { - const fakeId = 'non-existent-id' - + // Use valid UUID format (stricter validation in v5.1.0) + const fakeId = '00000000-0000-0000-0000-000000000000' + expect(await brain.get(fakeId)).toBeNull() - + // update should handle non-existent ID gracefully - await expect(brain.update({ - id: fakeId, - data: { test: 'data' } + await expect(brain.update({ + id: fakeId, + data: { test: 'data' } })).rejects.toThrow() - + // delete should not throw for non-existent ID await expect(brain.delete(fakeId)).resolves.not.toThrow() }) diff --git a/tests/unit/type-filtering.unit.test.ts b/tests/unit/type-filtering.unit.test.ts index 741ab41c..c24af8d6 100644 --- a/tests/unit/type-filtering.unit.test.ts +++ b/tests/unit/type-filtering.unit.test.ts @@ -96,9 +96,17 @@ describe('Type Filtering (Workshop Team Issue)', () => { await brain.add({ data: 'Location 1', type: NounType.Location }) await brain.add({ data: 'Concept 1', type: NounType.Concept }) + // v5.1.0: VFS auto-initialization creates root directory + // So we now have 4 entities: 3 added + 1 root directory const results = await brain.find({ limit: 100 }) - expect(results.length).toBe(3) + expect(results.length).toBeGreaterThanOrEqual(3) + + // Verify our entities are included + const types = results.map(r => r.type) + expect(types).toContain('person') + expect(types).toContain('location') + expect(types).toContain('concept') }) it('should verify entity type is set correctly', async () => { diff --git a/tests/unit/workshop-vfs-diagnostic.test.ts b/tests/unit/workshop-vfs-diagnostic.test.ts index f7171177..9edb5ff1 100644 --- a/tests/unit/workshop-vfs-diagnostic.test.ts +++ b/tests/unit/workshop-vfs-diagnostic.test.ts @@ -39,7 +39,7 @@ describe('Workshop VFS Diagnostic', () => { // Step 2: Use VFS to create files console.log('2ļøāƒ£ Creating VFS files...\n') - const vfs = brain.vfs() + const vfs = brain.vfs await vfs.init() await vfs.mkdir('/test', { recursive: true }) diff --git a/tests/vfs/vfs-bug-fixes.unit.test.ts b/tests/vfs/vfs-bug-fixes.unit.test.ts index 82d13468..66f02e05 100644 --- a/tests/vfs/vfs-bug-fixes.unit.test.ts +++ b/tests/vfs/vfs-bug-fixes.unit.test.ts @@ -21,7 +21,7 @@ describe('VFS Bug Fixes', () => { embeddingModel: 'Q8' }) await brain.init() - vfs = brain.vfs() + vfs = brain.vfs await vfs.init() }) diff --git a/tests/vfs/vfs-initialization.unit.test.ts b/tests/vfs/vfs-initialization.unit.test.ts index 22b60260..9e7e98be 100644 --- a/tests/vfs/vfs-initialization.unit.test.ts +++ b/tests/vfs/vfs-initialization.unit.test.ts @@ -1,7 +1,7 @@ /** * VFS Initialization Tests * - * Tests proper VFS initialization patterns to prevent common errors + * Tests v5.1.0+ auto-initialization behavior */ import { describe, it, expect } from 'vitest' @@ -10,97 +10,55 @@ import { Brainy } from '../../src/brainy.js' describe('VFS Initialization', () => { - describe('Common Initialization Errors', () => { - it('should fail if VFS is not initialized before use', async () => { + describe('Auto-Initialization (v5.1.0+)', () => { + it('should auto-initialize VFS during brain.init()', async () => { const brain = new Brainy({ storage: { type: 'memory' }, silent: true }) await brain.init() - const vfs = brain.vfs() - // Attempting to use VFS without calling init() + const vfs = brain.vfs - await expect(vfs.writeFile('/test.txt', 'Hello')) - .rejects.toThrow('VFS not initialized') - - await expect(vfs.readdir('/')) - .rejects.toThrow('VFS not initialized') - }) - }) - - describe('Correct Initialization Pattern', () => { - it('should work when VFS is properly initialized', async () => { - // Step 1: Initialize Brainy - const brain = new Brainy({ - storage: { type: 'memory' }, - silent: true - }) - await brain.init() - - // Step 2: Get VFS instance - const vfs = brain.vfs() - - // Step 3: Initialize VFS - this creates the root directory - await vfs.init() - - // Now VFS operations work correctly + // VFS is ready to use immediately after brain.init() await vfs.writeFile('/test.txt', 'Hello World') - await vfs.writeFile('/data.json', '{"key": "value"}') + const content = await vfs.readFile('/test.txt') + expect(content.toString()).toBe('Hello World') - // Root directory can be listed - const entries = await vfs.readdir('/') - expect(entries).toContain('test.txt') - expect(entries).toContain('data.json') - - // Root directory stats are available - const stats = await vfs.stat('/') - expect(stats.isDirectory()).toBe(true) - - // Cleanup - await vfs.close() await brain.close() }) - it('should automatically create root directory on init', async () => { + it('should automatically create root directory on brain.init()', async () => { const brain = new Brainy({ storage: { type: 'memory' }, silent: true }) await brain.init() - const vfs = brain.vfs() + const vfs = brain.vfs - // Before init, operations fail - await expect(vfs.exists('/')) - .rejects.toThrow('VFS not initialized') - - // After init, root exists - await vfs.init() + // Root directory exists after brain.init() expect(await vfs.exists('/')).toBe(true) // Root is a directory const stats = await vfs.stat('/') expect(stats.isDirectory()).toBe(true) - // Can list empty root + // Can list root directory const entries = await vfs.readdir('/') expect(Array.isArray(entries)).toBe(true) - expect(entries).toEqual([]) - await vfs.close() await brain.close() }) - it('should handle nested directories after initialization', async () => { + it('should handle nested directories after brain.init()', async () => { const brain = new Brainy({ storage: { type: 'memory' }, silent: true }) await brain.init() - const vfs = brain.vfs() - await vfs.init() + const vfs = brain.vfs // Create nested structure await vfs.mkdir('/documents') @@ -119,8 +77,30 @@ describe('VFS Initialization', () => { const reportEntries = await vfs.readdir('/documents/reports') expect(reportEntries).toContain('q1.txt') - await vfs.close() + await brain.close() + }) + + it('should work with VFS operations immediately', async () => { + const brain = new Brainy({ + storage: { type: 'memory' }, + silent: true + }) + await brain.init() + + const vfs = brain.vfs + + // All VFS operations work immediately + await vfs.writeFile('/test.txt', 'Hello') + await vfs.writeFile('/data.json', '{"key": "value"}') + + const entries = await vfs.readdir('/') + expect(entries).toContain('test.txt') + expect(entries).toContain('data.json') + + const testContent = await vfs.readFile('/test.txt') + expect(testContent.toString()).toBe('Hello') + await brain.close() }) }) -}) \ No newline at end of file +}) diff --git a/tests/vfs/vfs.unit.test.ts b/tests/vfs/vfs.unit.test.ts index 447ce0ff..8cdf4f5b 100644 --- a/tests/vfs/vfs.unit.test.ts +++ b/tests/vfs/vfs.unit.test.ts @@ -23,7 +23,7 @@ describe('VirtualFileSystem - Production Tests', () => { await brain.init() // Create VFS on top of Brainy - vfs = brain.vfs() + vfs = brain.vfs await vfs.init() })