BREAKING API CHANGES IN v5.1.0: 1. VFS now a property (brain.vfs) not method (brain.vfs()) 2. VFS auto-initializes during brain.init() - no separate vfs.init() needed 3. Root directory (/) created automatically during brain.init() 4. Stricter UUID validation (32 hex chars required) 5. VFS readFile() returns Buffer (use .toString() for string) TEST FIXES (106 tests fixed, 86% → 96.7% pass rate): - Fixed brain.vfs() → brain.vfs in 17 test files - Updated VFS initialization tests for auto-init behavior - Fixed type-filtering test to account for VFS root directory - Fixed UUID validation tests to use valid UUID format - Updated VFS readFile expectations (Buffer → string conversion) FILES UPDATED (19 test files): - tests/unit/brainy-core.unit.test.ts (UUID validation) - tests/unit/type-filtering.unit.test.ts (VFS root count) - tests/unit/workshop-vfs-diagnostic.test.ts (VFS API) - tests/vfs/vfs-initialization.unit.test.ts (auto-init behavior) - tests/vfs/vfs.unit.test.ts (VFS API) - tests/vfs/vfs-bug-fixes.unit.test.ts (VFS API) - tests/integration/* (VFS API changes, 7 files) - tests/manual/* (VFS API changes, 5 files) TEST RESULTS: - Before: 906/1051 passing (86%), 120 failures - After: 1016/1051 passing (96.7%), 14 failures - Critical systems: VFS (✓ ALL PASS), COW (✓ ALL PASS), Batch Ops (✓ 25/26) Remaining 14 failures are edge cases (UUID validation) - will fix in patch.
106 lines
2.9 KiB
TypeScript
106 lines
2.9 KiB
TypeScript
/**
|
|
* VFS Initialization Tests
|
|
*
|
|
* Tests v5.1.0+ auto-initialization behavior
|
|
*/
|
|
|
|
import { describe, it, expect } from 'vitest'
|
|
import { VirtualFileSystem } from '../../src/vfs/index.js'
|
|
import { Brainy } from '../../src/brainy.js'
|
|
|
|
describe('VFS Initialization', () => {
|
|
|
|
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
|
|
|
|
// VFS is ready to use immediately after brain.init()
|
|
await vfs.writeFile('/test.txt', 'Hello World')
|
|
const content = await vfs.readFile('/test.txt')
|
|
expect(content.toString()).toBe('Hello World')
|
|
|
|
await brain.close()
|
|
})
|
|
|
|
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
|
|
|
|
// 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 root directory
|
|
const entries = await vfs.readdir('/')
|
|
expect(Array.isArray(entries)).toBe(true)
|
|
|
|
await brain.close()
|
|
})
|
|
|
|
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
|
|
|
|
// Create nested structure
|
|
await vfs.mkdir('/documents')
|
|
await vfs.writeFile('/documents/readme.txt', 'Important info')
|
|
await vfs.mkdir('/documents/reports')
|
|
await vfs.writeFile('/documents/reports/q1.txt', 'Q1 Report')
|
|
|
|
// Verify structure
|
|
const rootEntries = await vfs.readdir('/')
|
|
expect(rootEntries).toContain('documents')
|
|
|
|
const docEntries = await vfs.readdir('/documents')
|
|
expect(docEntries).toContain('readme.txt')
|
|
expect(docEntries).toContain('reports')
|
|
|
|
const reportEntries = await vfs.readdir('/documents/reports')
|
|
expect(reportEntries).toContain('q1.txt')
|
|
|
|
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()
|
|
})
|
|
})
|
|
})
|