**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.
This commit is contained in:
David Snelling 2025-07-28 10:04:45 -07:00
parent 5d607068a8
commit 7f082df6a3
11 changed files with 1418 additions and 85 deletions

View file

@ -4,6 +4,7 @@
import { EmbeddingFunction, EmbeddingModel, Vector } from '../coreTypes.js'
import { executeInThread } from './workerUtils.js'
import { isBrowser } from './environment.js'
/**
* TensorFlow Universal Sentence Encoder embedding model
@ -40,9 +41,7 @@ export class UniversalSentenceEncoder implements EmbeddingModel {
*/
private addServerCompatibilityPolyfills(): void {
// Apply in all non-browser environments (Node.js, serverless, server environments)
const isBrowserEnv =
typeof window !== 'undefined' && typeof document !== 'undefined'
if (isBrowserEnv) {
if (isBrowser()) {
return // Browser environments don't need these polyfills
}
@ -270,7 +269,7 @@ export class UniversalSentenceEncoder implements EmbeddingModel {
// Try to import WebGL backend for GPU acceleration in browser environments
try {
if (typeof window !== 'undefined') {
if (isBrowser()) {
await import('@tensorflow/tfjs-backend-webgl')
// Check if WebGL is available
try {
@ -577,8 +576,10 @@ function findUSELoadFunction(
/**
* Check if we're running in a test environment (standalone version)
* Uses the same logic as the class method to avoid duplication
*/
function isTestEnvironment(): boolean {
// Use the same implementation as the class method
// Safely check for Node.js environment first
if (typeof process === 'undefined') {
return false