2025-08-26 12:32:21 -07:00
/ * *
2025-09-11 16:23:32 -07:00
* Unit Tests for Brainy 3.0 Core Functionality
2025-08-26 12:32:21 -07:00
*
2025-09-11 16:23:32 -07:00
* Tests business logic with real embeddings - production ready
* No mocks , no fakes , real implementation
2025-08-26 12:32:21 -07:00
* /
import { describe , it , expect , beforeEach } from 'vitest'
2025-09-11 16:23:32 -07:00
import { Brainy } from '../../src/brainy.js'
import { NounType } from '../../src/types/graphTypes.js'
2025-08-26 12:32:21 -07:00
2025-09-11 16:23:32 -07:00
describe ( 'Brainy 3.0 Core (Unit Tests)' , ( ) = > {
let brain : Brainy
2025-08-26 12:32:21 -07:00
beforeEach ( async ( ) = > {
2025-09-11 16:23:32 -07:00
// Create instance with real embeddings for production-ready tests
brain = new Brainy ( {
refactor: remove augmentation system and semantic type matching
Remove the entire augmentation pipeline infrastructure (52 files,
~15,000 lines) and the semantic type matching system. These were
unused middleware layers adding complexity without value.
What was removed:
- src/augmentations/ directory (all augmentation implementations)
- src/augmentationManager.ts (pipeline orchestrator)
- src/types/augmentations.ts, src/types/pipelineTypes.ts
- src/shared/default-augmentations.ts
- Semantic type suggestion (BrainyTypes.suggestNoun/suggestVerb)
- src/utils/typeMatching/ (embedding-based type matcher)
What was preserved by relocating:
- Import handlers (CSV, PDF, Excel) -> src/importers/handlers/
- NeuralImportAugmentation -> src/cortex/neuralImportAugmentation.ts
- Type matching utilities -> heuristic inference in consumers
What was simplified:
- brainy.ts: operations call storage directly (no execute() wrapper)
- IntegrationBase: standalone class (no BaseAugmentation parent)
- BrainyTypes: validation-only (nouns, verbs, isValid*, get*)
- Pipeline: direct execution (no augmentation interception)
- index.ts: removed TypeSuggestion, suggestType exports
- package.json: removed stale types/augmentations export
Build passes, 1176 tests pass, 0 failures.
2026-02-01 10:48:56 -08:00
storage : { type : 'memory' }
2025-08-26 12:32:21 -07:00
} )
await brain . init ( )
} )
describe ( 'CRUD Operations' , ( ) = > {
2025-09-11 16:23:32 -07:00
it ( 'should create items with add' , async ( ) = > {
const id = await brain . add ( {
data : { name : 'JavaScript' , type : 'language' } ,
type : NounType . Concept ,
metadata : { category : 'programming' }
2025-08-26 12:32:21 -07:00
} )
expect ( id ) . toBeTypeOf ( 'string' )
expect ( id . length ) . toBeGreaterThan ( 0 )
} )
2025-09-11 16:23:32 -07:00
it ( 'should retrieve items with get' , async ( ) = > {
const id = await brain . add ( {
feat: enforce data/metadata separation, numeric range queries, improved docs
- Store data opaquely in add() and update() instead of spreading object
properties into top-level metadata. data is for semantic search (HNSW),
metadata is for structured where-filter queries (MetadataIndex).
- Fix numeric range queries in MetadataIndex — use numeric-aware comparison
instead of lexicographic string comparison for normalized values.
- Add data field to RelateParams and Relation types for relationship content.
- Add where.type → where.noun alias in metadata-only find() path.
- Rewrite README: focused ~350 lines from 791, quick start first, feature
showcase with mini-snippets, organized doc links, no version callouts.
- Add DATA_MODEL.md and QUERY_OPERATORS.md reference docs.
- Remove 10 outdated/redundant doc files consolidated into API reference.
- Improve JSDoc on Entity, Relation, AddParams, FindParams, and core methods.
- Fix tests asserting data properties appear in metadata (data model violation).
- Deprecate verb.source/target in favor of from/to (public) and sourceId/targetId (storage).
2026-02-09 12:06:59 -08:00
data : 'Python is a programming language created in 1991' ,
2025-09-11 16:23:32 -07:00
type : NounType . Concept ,
feat: enforce data/metadata separation, numeric range queries, improved docs
- Store data opaquely in add() and update() instead of spreading object
properties into top-level metadata. data is for semantic search (HNSW),
metadata is for structured where-filter queries (MetadataIndex).
- Fix numeric range queries in MetadataIndex — use numeric-aware comparison
instead of lexicographic string comparison for normalized values.
- Add data field to RelateParams and Relation types for relationship content.
- Add where.type → where.noun alias in metadata-only find() path.
- Rewrite README: focused ~350 lines from 791, quick start first, feature
showcase with mini-snippets, organized doc links, no version callouts.
- Add DATA_MODEL.md and QUERY_OPERATORS.md reference docs.
- Remove 10 outdated/redundant doc files consolidated into API reference.
- Improve JSDoc on Entity, Relation, AddParams, FindParams, and core methods.
- Fix tests asserting data properties appear in metadata (data model violation).
- Deprecate verb.source/target in favor of from/to (public) and sourceId/targetId (storage).
2026-02-09 12:06:59 -08:00
metadata : { name : 'Python' , category : 'programming' , year : 1991 }
2025-09-11 16:23:32 -07:00
} )
feat: enforce data/metadata separation, numeric range queries, improved docs
- Store data opaquely in add() and update() instead of spreading object
properties into top-level metadata. data is for semantic search (HNSW),
metadata is for structured where-filter queries (MetadataIndex).
- Fix numeric range queries in MetadataIndex — use numeric-aware comparison
instead of lexicographic string comparison for normalized values.
- Add data field to RelateParams and Relation types for relationship content.
- Add where.type → where.noun alias in metadata-only find() path.
- Rewrite README: focused ~350 lines from 791, quick start first, feature
showcase with mini-snippets, organized doc links, no version callouts.
- Add DATA_MODEL.md and QUERY_OPERATORS.md reference docs.
- Remove 10 outdated/redundant doc files consolidated into API reference.
- Improve JSDoc on Entity, Relation, AddParams, FindParams, and core methods.
- Fix tests asserting data properties appear in metadata (data model violation).
- Deprecate verb.source/target in favor of from/to (public) and sourceId/targetId (storage).
2026-02-09 12:06:59 -08:00
2025-09-11 16:23:32 -07:00
const retrieved = await brain . get ( id )
feat: enforce data/metadata separation, numeric range queries, improved docs
- Store data opaquely in add() and update() instead of spreading object
properties into top-level metadata. data is for semantic search (HNSW),
metadata is for structured where-filter queries (MetadataIndex).
- Fix numeric range queries in MetadataIndex — use numeric-aware comparison
instead of lexicographic string comparison for normalized values.
- Add data field to RelateParams and Relation types for relationship content.
- Add where.type → where.noun alias in metadata-only find() path.
- Rewrite README: focused ~350 lines from 791, quick start first, feature
showcase with mini-snippets, organized doc links, no version callouts.
- Add DATA_MODEL.md and QUERY_OPERATORS.md reference docs.
- Remove 10 outdated/redundant doc files consolidated into API reference.
- Improve JSDoc on Entity, Relation, AddParams, FindParams, and core methods.
- Fix tests asserting data properties appear in metadata (data model violation).
- Deprecate verb.source/target in favor of from/to (public) and sourceId/targetId (storage).
2026-02-09 12:06:59 -08:00
2025-08-26 12:32:21 -07:00
expect ( retrieved ) . toBeTruthy ( )
expect ( retrieved ? . metadata ? . name ) . toBe ( 'Python' )
feat: enforce data/metadata separation, numeric range queries, improved docs
- Store data opaquely in add() and update() instead of spreading object
properties into top-level metadata. data is for semantic search (HNSW),
metadata is for structured where-filter queries (MetadataIndex).
- Fix numeric range queries in MetadataIndex — use numeric-aware comparison
instead of lexicographic string comparison for normalized values.
- Add data field to RelateParams and Relation types for relationship content.
- Add where.type → where.noun alias in metadata-only find() path.
- Rewrite README: focused ~350 lines from 791, quick start first, feature
showcase with mini-snippets, organized doc links, no version callouts.
- Add DATA_MODEL.md and QUERY_OPERATORS.md reference docs.
- Remove 10 outdated/redundant doc files consolidated into API reference.
- Improve JSDoc on Entity, Relation, AddParams, FindParams, and core methods.
- Fix tests asserting data properties appear in metadata (data model violation).
- Deprecate verb.source/target in favor of from/to (public) and sourceId/targetId (storage).
2026-02-09 12:06:59 -08:00
expect ( retrieved ? . metadata ? . category ) . toBe ( 'programming' )
2025-08-26 12:32:21 -07:00
expect ( retrieved ? . metadata ? . year ) . toBe ( 1991 )
} )
2025-09-11 16:23:32 -07:00
it ( 'should update items with update' , async ( ) = > {
const id = await brain . add ( {
feat: enforce data/metadata separation, numeric range queries, improved docs
- Store data opaquely in add() and update() instead of spreading object
properties into top-level metadata. data is for semantic search (HNSW),
metadata is for structured where-filter queries (MetadataIndex).
- Fix numeric range queries in MetadataIndex — use numeric-aware comparison
instead of lexicographic string comparison for normalized values.
- Add data field to RelateParams and Relation types for relationship content.
- Add where.type → where.noun alias in metadata-only find() path.
- Rewrite README: focused ~350 lines from 791, quick start first, feature
showcase with mini-snippets, organized doc links, no version callouts.
- Add DATA_MODEL.md and QUERY_OPERATORS.md reference docs.
- Remove 10 outdated/redundant doc files consolidated into API reference.
- Improve JSDoc on Entity, Relation, AddParams, FindParams, and core methods.
- Fix tests asserting data properties appear in metadata (data model violation).
- Deprecate verb.source/target in favor of from/to (public) and sourceId/targetId (storage).
2026-02-09 12:06:59 -08:00
data : 'TypeScript is a typed JavaScript superset' ,
2025-09-11 16:23:32 -07:00
type : NounType . Concept ,
feat: enforce data/metadata separation, numeric range queries, improved docs
- Store data opaquely in add() and update() instead of spreading object
properties into top-level metadata. data is for semantic search (HNSW),
metadata is for structured where-filter queries (MetadataIndex).
- Fix numeric range queries in MetadataIndex — use numeric-aware comparison
instead of lexicographic string comparison for normalized values.
- Add data field to RelateParams and Relation types for relationship content.
- Add where.type → where.noun alias in metadata-only find() path.
- Rewrite README: focused ~350 lines from 791, quick start first, feature
showcase with mini-snippets, organized doc links, no version callouts.
- Add DATA_MODEL.md and QUERY_OPERATORS.md reference docs.
- Remove 10 outdated/redundant doc files consolidated into API reference.
- Improve JSDoc on Entity, Relation, AddParams, FindParams, and core methods.
- Fix tests asserting data properties appear in metadata (data model violation).
- Deprecate verb.source/target in favor of from/to (public) and sourceId/targetId (storage).
2026-02-09 12:06:59 -08:00
metadata : { name : 'TypeScript' , version : '4.0' , category : 'programming' }
2025-09-11 16:23:32 -07:00
} )
feat: enforce data/metadata separation, numeric range queries, improved docs
- Store data opaquely in add() and update() instead of spreading object
properties into top-level metadata. data is for semantic search (HNSW),
metadata is for structured where-filter queries (MetadataIndex).
- Fix numeric range queries in MetadataIndex — use numeric-aware comparison
instead of lexicographic string comparison for normalized values.
- Add data field to RelateParams and Relation types for relationship content.
- Add where.type → where.noun alias in metadata-only find() path.
- Rewrite README: focused ~350 lines from 791, quick start first, feature
showcase with mini-snippets, organized doc links, no version callouts.
- Add DATA_MODEL.md and QUERY_OPERATORS.md reference docs.
- Remove 10 outdated/redundant doc files consolidated into API reference.
- Improve JSDoc on Entity, Relation, AddParams, FindParams, and core methods.
- Fix tests asserting data properties appear in metadata (data model violation).
- Deprecate verb.source/target in favor of from/to (public) and sourceId/targetId (storage).
2026-02-09 12:06:59 -08:00
2025-09-11 16:23:32 -07:00
await brain . update ( {
id ,
feat: enforce data/metadata separation, numeric range queries, improved docs
- Store data opaquely in add() and update() instead of spreading object
properties into top-level metadata. data is for semantic search (HNSW),
metadata is for structured where-filter queries (MetadataIndex).
- Fix numeric range queries in MetadataIndex — use numeric-aware comparison
instead of lexicographic string comparison for normalized values.
- Add data field to RelateParams and Relation types for relationship content.
- Add where.type → where.noun alias in metadata-only find() path.
- Rewrite README: focused ~350 lines from 791, quick start first, feature
showcase with mini-snippets, organized doc links, no version callouts.
- Add DATA_MODEL.md and QUERY_OPERATORS.md reference docs.
- Remove 10 outdated/redundant doc files consolidated into API reference.
- Improve JSDoc on Entity, Relation, AddParams, FindParams, and core methods.
- Fix tests asserting data properties appear in metadata (data model violation).
- Deprecate verb.source/target in favor of from/to (public) and sourceId/targetId (storage).
2026-02-09 12:06:59 -08:00
metadata : { version : '5.0' , popularity : 'high' }
2025-09-11 16:23:32 -07:00
} )
feat: enforce data/metadata separation, numeric range queries, improved docs
- Store data opaquely in add() and update() instead of spreading object
properties into top-level metadata. data is for semantic search (HNSW),
metadata is for structured where-filter queries (MetadataIndex).
- Fix numeric range queries in MetadataIndex — use numeric-aware comparison
instead of lexicographic string comparison for normalized values.
- Add data field to RelateParams and Relation types for relationship content.
- Add where.type → where.noun alias in metadata-only find() path.
- Rewrite README: focused ~350 lines from 791, quick start first, feature
showcase with mini-snippets, organized doc links, no version callouts.
- Add DATA_MODEL.md and QUERY_OPERATORS.md reference docs.
- Remove 10 outdated/redundant doc files consolidated into API reference.
- Improve JSDoc on Entity, Relation, AddParams, FindParams, and core methods.
- Fix tests asserting data properties appear in metadata (data model violation).
- Deprecate verb.source/target in favor of from/to (public) and sourceId/targetId (storage).
2026-02-09 12:06:59 -08:00
2025-09-11 16:23:32 -07:00
const updated = await brain . get ( id )
2025-08-26 12:32:21 -07:00
expect ( updated ? . metadata ? . version ) . toBe ( '5.0' )
expect ( updated ? . metadata ? . popularity ) . toBe ( 'high' )
feat: enforce data/metadata separation, numeric range queries, improved docs
- Store data opaquely in add() and update() instead of spreading object
properties into top-level metadata. data is for semantic search (HNSW),
metadata is for structured where-filter queries (MetadataIndex).
- Fix numeric range queries in MetadataIndex — use numeric-aware comparison
instead of lexicographic string comparison for normalized values.
- Add data field to RelateParams and Relation types for relationship content.
- Add where.type → where.noun alias in metadata-only find() path.
- Rewrite README: focused ~350 lines from 791, quick start first, feature
showcase with mini-snippets, organized doc links, no version callouts.
- Add DATA_MODEL.md and QUERY_OPERATORS.md reference docs.
- Remove 10 outdated/redundant doc files consolidated into API reference.
- Improve JSDoc on Entity, Relation, AddParams, FindParams, and core methods.
- Fix tests asserting data properties appear in metadata (data model violation).
- Deprecate verb.source/target in favor of from/to (public) and sourceId/targetId (storage).
2026-02-09 12:06:59 -08:00
expect ( updated ? . metadata ? . name ) . toBe ( 'TypeScript' ) // Original metadata preserved
2025-08-26 12:32:21 -07:00
} )
2025-09-11 16:23:32 -07:00
it ( 'should delete items with delete' , async ( ) = > {
const id = await brain . add ( {
data : { name : 'ToDelete' , temp : true } ,
type : NounType . Concept
} )
2025-08-26 12:32:21 -07:00
// Verify it exists
2025-09-11 16:23:32 -07:00
expect ( await brain . get ( id ) ) . toBeTruthy ( )
2025-08-26 12:32:21 -07:00
// Delete it
2025-09-11 16:23:32 -07:00
await brain . delete ( id )
2025-08-26 12:32:21 -07:00
// Verify it's gone
2025-09-11 16:23:32 -07:00
expect ( await brain . get ( id ) ) . toBeNull ( )
2025-08-26 12:32:21 -07:00
} )
it ( 'should handle non-existent IDs according to API contract' , async ( ) = > {
2025-11-02 11:38:12 -08:00
// Use valid UUID format (stricter validation in v5.1.0)
2025-11-14 12:56:29 -08:00
// v5.10.0: Can't use 00000000... anymore (it's the VFS root)
const fakeId = '11111111-1111-1111-1111-111111111111'
2025-11-02 11:38:12 -08:00
2025-09-11 16:23:32 -07:00
expect ( await brain . get ( fakeId ) ) . toBeNull ( )
2025-11-02 11:38:12 -08:00
2025-09-11 16:23:32 -07:00
// update should handle non-existent ID gracefully
2025-11-02 11:38:12 -08:00
await expect ( brain . update ( {
id : fakeId ,
data : { test : 'data' }
2025-09-11 16:23:32 -07:00
} ) ) . rejects . toThrow ( )
2025-11-02 11:38:12 -08:00
2025-09-11 16:23:32 -07:00
// delete should not throw for non-existent ID
await expect ( brain . delete ( fakeId ) ) . resolves . not . toThrow ( )
2025-08-26 12:32:21 -07:00
} )
} )
2025-09-11 16:23:32 -07:00
describe ( 'Search Operations' , ( ) = > {
2025-08-26 12:32:21 -07:00
beforeEach ( async ( ) = > {
2025-09-11 16:23:32 -07:00
// Add test data with real embeddings
await brain . add ( {
data : { name : 'React' , type : 'framework' , category : 'frontend' } ,
type : NounType . Concept ,
metadata : { tags : [ 'ui' , 'javascript' ] }
} )
await brain . add ( {
data : { name : 'Vue' , type : 'framework' , category : 'frontend' } ,
type : NounType . Concept ,
metadata : { tags : [ 'ui' , 'javascript' ] }
} )
await brain . add ( {
data : { name : 'Express' , type : 'framework' , category : 'backend' } ,
type : NounType . Concept ,
metadata : { tags : [ 'server' , 'nodejs' ] }
} )
await brain . add ( {
data : { name : 'Java' , type : 'language' , category : 'backend' } ,
type : NounType . Concept ,
metadata : { tags : [ 'jvm' , 'enterprise' ] }
} )
2025-08-26 12:32:21 -07:00
} )
2025-09-11 16:23:32 -07:00
it ( 'should return search results with real embeddings' , async ( ) = > {
const results = await brain . find ( {
query : 'frontend framework' ,
limit : 2
} )
2025-08-26 12:32:21 -07:00
expect ( results ) . toBeInstanceOf ( Array )
expect ( results . length ) . toBeGreaterThan ( 0 )
2025-09-11 16:23:32 -07:00
expect ( results . length ) . toBeLessThanOrEqual ( 2 )
2025-08-26 12:32:21 -07:00
2025-09-11 16:23:32 -07:00
// Results should have required properties
results . forEach ( ( result : any ) = > {
2025-08-26 12:32:21 -07:00
expect ( result ) . toHaveProperty ( 'id' )
expect ( result ) . toHaveProperty ( 'score' )
2025-09-11 16:23:32 -07:00
expect ( result ) . toHaveProperty ( 'entity' )
2025-08-26 12:32:21 -07:00
} )
} )
2025-09-11 16:23:32 -07:00
it ( 'should handle limit parameter' , async ( ) = > {
const limitedResults = await brain . find ( {
query : 'framework' ,
limit : 2
2025-08-26 12:32:21 -07:00
} )
2025-09-11 16:23:32 -07:00
const unlimitedResults = await brain . find ( {
query : 'framework' ,
limit : 10
2025-08-26 12:32:21 -07:00
} )
2025-09-11 16:23:32 -07:00
expect ( limitedResults . length ) . toBeLessThanOrEqual ( 2 )
expect ( unlimitedResults . length ) . toBeLessThanOrEqual ( 10 )
2025-08-26 12:32:21 -07:00
} )
2025-09-11 16:23:32 -07:00
it ( 'should search by metadata filters' , async ( ) = > {
const results = await brain . find ( {
where : { category : 'frontend' } ,
limit : 10
2025-08-26 12:32:21 -07:00
} )
2025-09-11 16:23:32 -07:00
expect ( results ) . toBeInstanceOf ( Array )
// All results should have frontend category
results . forEach ( ( item : any ) = > {
expect ( item . entity . metadata ? . category ) . toBe ( 'frontend' )
2025-08-26 12:32:21 -07:00
} )
} )
2025-09-11 16:23:32 -07:00
it ( 'should handle complex queries with Triple Intelligence' , async ( ) = > {
const results = await brain . find ( {
query : 'javascript' ,
where : { type : 'framework' } ,
limit : 5 ,
fusion : {
strategy : 'adaptive' ,
weights : { vector : 0.6 , field : 0.4 }
}
2025-08-26 12:32:21 -07:00
} )
2025-09-11 16:23:32 -07:00
expect ( results ) . toBeInstanceOf ( Array )
// Results should match both vector similarity and field filters
results . forEach ( ( item : any ) = > {
expect ( item . entity . metadata ? . type ) . toBe ( 'framework' )
} )
2025-08-26 12:32:21 -07:00
} )
} )
2025-09-11 16:23:32 -07:00
describe ( 'Statistics and Metadata' , ( ) = > {
refactor: remove augmentation system and semantic type matching
Remove the entire augmentation pipeline infrastructure (52 files,
~15,000 lines) and the semantic type matching system. These were
unused middleware layers adding complexity without value.
What was removed:
- src/augmentations/ directory (all augmentation implementations)
- src/augmentationManager.ts (pipeline orchestrator)
- src/types/augmentations.ts, src/types/pipelineTypes.ts
- src/shared/default-augmentations.ts
- Semantic type suggestion (BrainyTypes.suggestNoun/suggestVerb)
- src/utils/typeMatching/ (embedding-based type matcher)
What was preserved by relocating:
- Import handlers (CSV, PDF, Excel) -> src/importers/handlers/
- NeuralImportAugmentation -> src/cortex/neuralImportAugmentation.ts
- Type matching utilities -> heuristic inference in consumers
What was simplified:
- brainy.ts: operations call storage directly (no execute() wrapper)
- IntegrationBase: standalone class (no BaseAugmentation parent)
- BrainyTypes: validation-only (nouns, verbs, isValid*, get*)
- Pipeline: direct execution (no augmentation interception)
- index.ts: removed TypeSuggestion, suggestType exports
- package.json: removed stale types/augmentations export
Build passes, 1176 tests pass, 0 failures.
2026-02-01 10:48:56 -08:00
it ( 'should track statistics' , async ( ) = > {
2025-09-11 16:23:32 -07:00
await brain . add ( {
data : { name : 'Test1' } ,
type : NounType . Concept
} )
await brain . add ( {
data : { name : 'Test2' } ,
type : NounType . Concept
} )
2025-08-26 12:32:21 -07:00
2025-09-11 16:23:32 -07:00
// Statistics would be available through augmentation system
// The exact API depends on augmentation configuration
2025-08-26 12:32:21 -07:00
} )
} )
2025-09-11 16:23:32 -07:00
describe ( 'Clear Operations' , ( ) = > {
it ( 'should clear all data' , async ( ) = > {
await brain . add ( {
data : { name : 'Test1' } ,
type : NounType . Concept
} )
await brain . add ( {
data : { name : 'Test2' } ,
type : NounType . Concept
} )
await brain . add ( {
data : { name : 'Test3' } ,
type : NounType . Concept
2025-08-26 12:32:21 -07:00
} )
2025-09-11 16:23:32 -07:00
// Clear using DataAPI
const dataAPI = await brain . data ( )
await dataAPI . clear ( { entities : true , relations : false } )
2025-08-26 12:32:21 -07:00
2025-09-11 16:23:32 -07:00
// Verify data is cleared
const results = await brain . find ( {
query : 'Test' ,
limit : 10
} )
expect ( results . length ) . toBe ( 0 )
2025-08-26 12:32:21 -07:00
} )
} )
describe ( 'Edge Cases and Error Handling' , ( ) = > {
2025-09-11 16:23:32 -07:00
it ( 'should handle empty queries gracefully' , async ( ) = > {
const results = await brain . find ( {
query : '' ,
limit : 5
} )
2025-08-26 12:32:21 -07:00
2025-09-11 16:23:32 -07:00
expect ( results ) . toBeInstanceOf ( Array )
2025-08-26 12:32:21 -07:00
} )
2025-09-11 16:23:32 -07:00
it ( 'should handle special characters in data' , async ( ) = > {
const id = await brain . add ( {
feat: enforce data/metadata separation, numeric range queries, improved docs
- Store data opaquely in add() and update() instead of spreading object
properties into top-level metadata. data is for semantic search (HNSW),
metadata is for structured where-filter queries (MetadataIndex).
- Fix numeric range queries in MetadataIndex — use numeric-aware comparison
instead of lexicographic string comparison for normalized values.
- Add data field to RelateParams and Relation types for relationship content.
- Add where.type → where.noun alias in metadata-only find() path.
- Rewrite README: focused ~350 lines from 791, quick start first, feature
showcase with mini-snippets, organized doc links, no version callouts.
- Add DATA_MODEL.md and QUERY_OPERATORS.md reference docs.
- Remove 10 outdated/redundant doc files consolidated into API reference.
- Improve JSDoc on Entity, Relation, AddParams, FindParams, and core methods.
- Fix tests asserting data properties appear in metadata (data model violation).
- Deprecate verb.source/target in favor of from/to (public) and sourceId/targetId (storage).
2026-02-09 12:06:59 -08:00
data : 'Test with special chars: !@#$%^&*()' ,
type : NounType . Concept ,
metadata : { name : 'Test !@#$%^&*()' , description : 'Has "quotes" and \'apostrophes\'' }
2025-09-11 16:23:32 -07:00
} )
feat: enforce data/metadata separation, numeric range queries, improved docs
- Store data opaquely in add() and update() instead of spreading object
properties into top-level metadata. data is for semantic search (HNSW),
metadata is for structured where-filter queries (MetadataIndex).
- Fix numeric range queries in MetadataIndex — use numeric-aware comparison
instead of lexicographic string comparison for normalized values.
- Add data field to RelateParams and Relation types for relationship content.
- Add where.type → where.noun alias in metadata-only find() path.
- Rewrite README: focused ~350 lines from 791, quick start first, feature
showcase with mini-snippets, organized doc links, no version callouts.
- Add DATA_MODEL.md and QUERY_OPERATORS.md reference docs.
- Remove 10 outdated/redundant doc files consolidated into API reference.
- Improve JSDoc on Entity, Relation, AddParams, FindParams, and core methods.
- Fix tests asserting data properties appear in metadata (data model violation).
- Deprecate verb.source/target in favor of from/to (public) and sourceId/targetId (storage).
2026-02-09 12:06:59 -08:00
2025-09-11 16:23:32 -07:00
const retrieved = await brain . get ( id )
expect ( retrieved ? . metadata ? . name ) . toContain ( '!@#$%^&*()' )
2025-08-26 12:32:21 -07:00
} )
2025-09-11 16:23:32 -07:00
it ( 'should handle very long text' , async ( ) = > {
const longText = 'x' . repeat ( 10000 )
const id = await brain . add ( {
feat: enforce data/metadata separation, numeric range queries, improved docs
- Store data opaquely in add() and update() instead of spreading object
properties into top-level metadata. data is for semantic search (HNSW),
metadata is for structured where-filter queries (MetadataIndex).
- Fix numeric range queries in MetadataIndex — use numeric-aware comparison
instead of lexicographic string comparison for normalized values.
- Add data field to RelateParams and Relation types for relationship content.
- Add where.type → where.noun alias in metadata-only find() path.
- Rewrite README: focused ~350 lines from 791, quick start first, feature
showcase with mini-snippets, organized doc links, no version callouts.
- Add DATA_MODEL.md and QUERY_OPERATORS.md reference docs.
- Remove 10 outdated/redundant doc files consolidated into API reference.
- Improve JSDoc on Entity, Relation, AddParams, FindParams, and core methods.
- Fix tests asserting data properties appear in metadata (data model violation).
- Deprecate verb.source/target in favor of from/to (public) and sourceId/targetId (storage).
2026-02-09 12:06:59 -08:00
data : longText ,
2025-09-11 16:23:32 -07:00
type : NounType . Document
} )
feat: enforce data/metadata separation, numeric range queries, improved docs
- Store data opaquely in add() and update() instead of spreading object
properties into top-level metadata. data is for semantic search (HNSW),
metadata is for structured where-filter queries (MetadataIndex).
- Fix numeric range queries in MetadataIndex — use numeric-aware comparison
instead of lexicographic string comparison for normalized values.
- Add data field to RelateParams and Relation types for relationship content.
- Add where.type → where.noun alias in metadata-only find() path.
- Rewrite README: focused ~350 lines from 791, quick start first, feature
showcase with mini-snippets, organized doc links, no version callouts.
- Add DATA_MODEL.md and QUERY_OPERATORS.md reference docs.
- Remove 10 outdated/redundant doc files consolidated into API reference.
- Improve JSDoc on Entity, Relation, AddParams, FindParams, and core methods.
- Fix tests asserting data properties appear in metadata (data model violation).
- Deprecate verb.source/target in favor of from/to (public) and sourceId/targetId (storage).
2026-02-09 12:06:59 -08:00
2025-09-11 16:23:32 -07:00
const retrieved = await brain . get ( id )
feat: enforce data/metadata separation, numeric range queries, improved docs
- Store data opaquely in add() and update() instead of spreading object
properties into top-level metadata. data is for semantic search (HNSW),
metadata is for structured where-filter queries (MetadataIndex).
- Fix numeric range queries in MetadataIndex — use numeric-aware comparison
instead of lexicographic string comparison for normalized values.
- Add data field to RelateParams and Relation types for relationship content.
- Add where.type → where.noun alias in metadata-only find() path.
- Rewrite README: focused ~350 lines from 791, quick start first, feature
showcase with mini-snippets, organized doc links, no version callouts.
- Add DATA_MODEL.md and QUERY_OPERATORS.md reference docs.
- Remove 10 outdated/redundant doc files consolidated into API reference.
- Improve JSDoc on Entity, Relation, AddParams, FindParams, and core methods.
- Fix tests asserting data properties appear in metadata (data model violation).
- Deprecate verb.source/target in favor of from/to (public) and sourceId/targetId (storage).
2026-02-09 12:06:59 -08:00
expect ( retrieved ? . data ) . toHaveLength ( 10000 )
2025-08-26 12:32:21 -07:00
} )
} )
} )