brainy/CHANGES.md
David Snelling 7f082df6a3 **test(api): add integration tests for API endpoints and core functionality**
- **Integration Tests**:
  - Introduced `api-integration.test.ts` to validate API functionality:
    - Verifies text insertion, vector embedding generation, and search operations.
    - Confirms HNSW index correctness for vector similarity search.
    - Ensures no dimensional mismatches in embeddings.

- **Test Server**:
  - Added test server utilizing Express for endpoint simulation (`/insert` and `/search/text`).

- **Dependencies**:
  - Introduced `express` and `node-fetch` as new dependencies for testing purposes.

- **Vitest Fix**:
  - Updated `vitest.config.ts` to resolve the `process.memoryUsage` error by setting `logHeapUsage: false`.

- **Package Updates**:
  - Modified `package-lock.json` to include newly added dependencies and updates.

**Purpose**: Guarantees the stability of core API endpoints and vector-related functionality, ensuring reliable behavior for end-to-end scenarios.
2025-07-28 10:04:45 -07:00

1.7 KiB

Changes

2025-07-28

Bug Fixes

  • Fixed an issue in FileSystemStorage constructor where path operations were performed before the path module was fully loaded. The fix defers path operations until the init() method is called, when the path module is guaranteed to be loaded.

Details

The issue was in the FileSystemStorage constructor where it was using the path module synchronously:

constructor(rootDirectory: string) {
  super()
  this.rootDir = rootDirectory
  this.nounsDir = path.join(this.rootDir, NOUNS_DIR)  // Error here - path could be undefined
  this.verbsDir = path.join(this.rootDir, VERBS_DIR)
  this.metadataDir = path.join(this.rootDir, METADATA_DIR)
  this.indexDir = path.join(this.rootDir, INDEX_DIR)
}

However, the path module was being loaded asynchronously via dynamic imports:

try {
  // Using dynamic imports to avoid issues in browser environments
  const fsPromise = import('fs')
  const pathPromise = import('path')

  Promise.all([fsPromise, pathPromise]).then(([fsModule, pathModule]) => {
    fs = fsModule
    path = pathModule.default
  }).catch(error => {
    console.error('Failed to load Node.js modules:', error)
  })
} catch (error) {
  console.error(
    'FileSystemStorage: Failed to load Node.js modules. This adapter is not supported in this environment.',
    error
  )
}

The fix:

  1. Modified the constructor to only store the rootDirectory and defer path operations
  2. Updated the init() method to initialize directory paths when the path module is guaranteed to be loaded

This ensures that path operations are only performed when the path module is available, preventing the "Cannot read properties of undefined (reading 'join')" error.