2025-11-18 16:06:34 -08:00
|
|
|
import { NounType } from '../../src/types/graphTypes.js'
|
2025-11-01 11:56:11 -07:00
|
|
|
/**
|
|
|
|
|
* Comprehensive COW Integration Tests
|
|
|
|
|
*
|
|
|
|
|
* Verifies COW works with:
|
|
|
|
|
* - All 8 storage adapters (Memory, OPFS, FileSystem, S3, R2, GCS, Azure, TypeAware)
|
|
|
|
|
* - Billion-scale performance
|
|
|
|
|
* - find() graph-aware queries
|
|
|
|
|
* - Triple Intelligence natural language
|
|
|
|
|
* - VFS (Virtual File System)
|
|
|
|
|
* - All 4 indexes (HNSW, Metadata, GraphAdjacency, DeletedItems)
|
|
|
|
|
* - Distributed mode (read-only, write-only instances)
|
|
|
|
|
* - 256 UUID-based sharding
|
|
|
|
|
*
|
|
|
|
|
* This is the CRITICAL test that proves v5.0.0 is production-ready.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { describe, it, expect, beforeEach } from 'vitest'
|
|
|
|
|
import { Brainy } from '../../src/brainy.js'
|
|
|
|
|
import type { StorageAdapter } from '../../src/storage/adapters/baseStorageAdapter.js'
|
|
|
|
|
|
|
|
|
|
describe('COW Full Integration', () => {
|
|
|
|
|
describe('Storage Adapter Compatibility', () => {
|
|
|
|
|
it('should work with Memory adapter', async () => {
|
feat(8.0)!: flip requireSubtype default to true (BRAINY-8.0-SUBTYPE-CONTRACT § C-1)
Brainy 8.0 makes subtype required by default on every public write path
(`add`, `addMany`, `update`, `relate`, `relateMany`, `updateRelation`,
import). Per the locked C-1 contract, every entity and relation gets a
non-empty subtype string by the time the storage layer sees it.
OPT-OUT REMAINS FULLY SUPPORTED
The runtime flag is still consumer-controlled. Three opt-out paths
cover migration / legacy fixtures / typed escape:
- `new Brainy({ requireSubtype: false })` — last-resort: turn off the
contract entirely. Recommended only for migration windows or test
fixtures that legitimately can't supply a subtype.
- `new Brainy({ requireSubtype: { except: [NounType.Thing, ...] } })` —
per-type allowlist: strict everywhere except the listed types.
- `brain.requireSubtype(type, options)` — per-type registration with
optional vocabulary. Composes with the brain-wide flag.
Default is now `true`. Opt-out is explicit and documented; nothing
silently degrades.
TEST SWEEP
Bulk-applied `requireSubtype: false` to every `new Brainy({...})` call
site across 120 test files. Three sed patterns covered the shapes:
- `new Brainy({` → `new Brainy({ requireSubtype: false,`
- `new Brainy<T>({` → `new Brainy<T>({ requireSubtype: false,`
- `new Brainy()` → `new Brainy({ requireSubtype: false })`
tests/helpers/test-factory.ts → createTestConfig() defaults
`requireSubtype: false` so test files using the helper inherit the
opt-out without per-site edits.
The test sites that DO exercise subtype semantics (the
subtype-and-facets suite, the strict-mode-self-test suite, the verb-
subtype-and-enforcement suite, etc.) already pass real subtypes — they
were the 7.30.x acceptance tests for this contract. Those tests
continue to pass unchanged.
CHANGES
src/brainy.ts
- normalizeConfig() — `requireSubtype` default `false` → `true`.
Comment refreshed to document the three opt-out paths.
tests/* (120 files)
- Bulk-edited brain construction sites. No functional test changes; the
opt-out preserves the test author's original intent.
tests/helpers/test-factory.ts
- createTestConfig() base config gains `requireSubtype: false`.
NO-OP for consumers who were already passing subtype on every write.
For consumers who weren't, the upgrade path is one of the three opt-out
forms above. Migration recipe documented in 8.0 release notes (next
commit).
VERIFICATION
- npx tsc --noEmit: clean
- npm test: 1408 / 1409 (same pre-existing race-condition outstanding;
no other regressions from the flip)
2026-06-09 14:58:25 -07:00
|
|
|
const brain = new Brainy({ requireSubtype: false,
|
2025-11-01 11:56:11 -07:00
|
|
|
storage: { adapter: 'memory' }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await brain.init()
|
|
|
|
|
|
|
|
|
|
// Add entity
|
|
|
|
|
const entity = await brain.add({
|
2025-11-18 16:06:34 -08:00
|
|
|
type: NounType.Person,
|
2025-11-01 11:56:11 -07:00
|
|
|
data: { name: 'Alice' }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Fork (uses COW)
|
|
|
|
|
const fork = await brain.fork('test-branch')
|
|
|
|
|
|
|
|
|
|
// Verify entity exists in fork
|
|
|
|
|
const retrieved = await fork.get(entity.id)
|
|
|
|
|
expect(retrieved.data.name).toBe('Alice')
|
|
|
|
|
|
|
|
|
|
await brain.destroy()
|
|
|
|
|
await fork.destroy()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should work with FileSystem adapter', async () => {
|
feat(8.0)!: flip requireSubtype default to true (BRAINY-8.0-SUBTYPE-CONTRACT § C-1)
Brainy 8.0 makes subtype required by default on every public write path
(`add`, `addMany`, `update`, `relate`, `relateMany`, `updateRelation`,
import). Per the locked C-1 contract, every entity and relation gets a
non-empty subtype string by the time the storage layer sees it.
OPT-OUT REMAINS FULLY SUPPORTED
The runtime flag is still consumer-controlled. Three opt-out paths
cover migration / legacy fixtures / typed escape:
- `new Brainy({ requireSubtype: false })` — last-resort: turn off the
contract entirely. Recommended only for migration windows or test
fixtures that legitimately can't supply a subtype.
- `new Brainy({ requireSubtype: { except: [NounType.Thing, ...] } })` —
per-type allowlist: strict everywhere except the listed types.
- `brain.requireSubtype(type, options)` — per-type registration with
optional vocabulary. Composes with the brain-wide flag.
Default is now `true`. Opt-out is explicit and documented; nothing
silently degrades.
TEST SWEEP
Bulk-applied `requireSubtype: false` to every `new Brainy({...})` call
site across 120 test files. Three sed patterns covered the shapes:
- `new Brainy({` → `new Brainy({ requireSubtype: false,`
- `new Brainy<T>({` → `new Brainy<T>({ requireSubtype: false,`
- `new Brainy()` → `new Brainy({ requireSubtype: false })`
tests/helpers/test-factory.ts → createTestConfig() defaults
`requireSubtype: false` so test files using the helper inherit the
opt-out without per-site edits.
The test sites that DO exercise subtype semantics (the
subtype-and-facets suite, the strict-mode-self-test suite, the verb-
subtype-and-enforcement suite, etc.) already pass real subtypes — they
were the 7.30.x acceptance tests for this contract. Those tests
continue to pass unchanged.
CHANGES
src/brainy.ts
- normalizeConfig() — `requireSubtype` default `false` → `true`.
Comment refreshed to document the three opt-out paths.
tests/* (120 files)
- Bulk-edited brain construction sites. No functional test changes; the
opt-out preserves the test author's original intent.
tests/helpers/test-factory.ts
- createTestConfig() base config gains `requireSubtype: false`.
NO-OP for consumers who were already passing subtype on every write.
For consumers who weren't, the upgrade path is one of the three opt-out
forms above. Migration recipe documented in 8.0 release notes (next
commit).
VERIFICATION
- npx tsc --noEmit: clean
- npm test: 1408 / 1409 (same pre-existing race-condition outstanding;
no other regressions from the flip)
2026-06-09 14:58:25 -07:00
|
|
|
const brain = new Brainy({ requireSubtype: false,
|
2025-11-01 11:56:11 -07:00
|
|
|
storage: {
|
|
|
|
|
adapter: 'filesystem',
|
|
|
|
|
path: '/tmp/brainy-cow-test-fs'
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await brain.init()
|
|
|
|
|
|
|
|
|
|
const entity = await brain.add({
|
2025-11-18 16:06:34 -08:00
|
|
|
type: NounType.Document,
|
2025-11-01 11:56:11 -07:00
|
|
|
data: { title: 'Test' }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const fork = await brain.fork('fs-branch')
|
|
|
|
|
|
|
|
|
|
const retrieved = await fork.get(entity.id)
|
|
|
|
|
expect(retrieved.data.title).toBe('Test')
|
|
|
|
|
|
|
|
|
|
await brain.destroy()
|
|
|
|
|
await fork.destroy()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should work with TypeAware adapter (most advanced)', async () => {
|
feat(8.0)!: flip requireSubtype default to true (BRAINY-8.0-SUBTYPE-CONTRACT § C-1)
Brainy 8.0 makes subtype required by default on every public write path
(`add`, `addMany`, `update`, `relate`, `relateMany`, `updateRelation`,
import). Per the locked C-1 contract, every entity and relation gets a
non-empty subtype string by the time the storage layer sees it.
OPT-OUT REMAINS FULLY SUPPORTED
The runtime flag is still consumer-controlled. Three opt-out paths
cover migration / legacy fixtures / typed escape:
- `new Brainy({ requireSubtype: false })` — last-resort: turn off the
contract entirely. Recommended only for migration windows or test
fixtures that legitimately can't supply a subtype.
- `new Brainy({ requireSubtype: { except: [NounType.Thing, ...] } })` —
per-type allowlist: strict everywhere except the listed types.
- `brain.requireSubtype(type, options)` — per-type registration with
optional vocabulary. Composes with the brain-wide flag.
Default is now `true`. Opt-out is explicit and documented; nothing
silently degrades.
TEST SWEEP
Bulk-applied `requireSubtype: false` to every `new Brainy({...})` call
site across 120 test files. Three sed patterns covered the shapes:
- `new Brainy({` → `new Brainy({ requireSubtype: false,`
- `new Brainy<T>({` → `new Brainy<T>({ requireSubtype: false,`
- `new Brainy()` → `new Brainy({ requireSubtype: false })`
tests/helpers/test-factory.ts → createTestConfig() defaults
`requireSubtype: false` so test files using the helper inherit the
opt-out without per-site edits.
The test sites that DO exercise subtype semantics (the
subtype-and-facets suite, the strict-mode-self-test suite, the verb-
subtype-and-enforcement suite, etc.) already pass real subtypes — they
were the 7.30.x acceptance tests for this contract. Those tests
continue to pass unchanged.
CHANGES
src/brainy.ts
- normalizeConfig() — `requireSubtype` default `false` → `true`.
Comment refreshed to document the three opt-out paths.
tests/* (120 files)
- Bulk-edited brain construction sites. No functional test changes; the
opt-out preserves the test author's original intent.
tests/helpers/test-factory.ts
- createTestConfig() base config gains `requireSubtype: false`.
NO-OP for consumers who were already passing subtype on every write.
For consumers who weren't, the upgrade path is one of the three opt-out
forms above. Migration recipe documented in 8.0 release notes (next
commit).
VERIFICATION
- npx tsc --noEmit: clean
- npm test: 1408 / 1409 (same pre-existing race-condition outstanding;
no other regressions from the flip)
2026-06-09 14:58:25 -07:00
|
|
|
const brain = new Brainy({ requireSubtype: false,
|
2025-11-01 11:56:11 -07:00
|
|
|
storage: {
|
|
|
|
|
adapter: 'typeaware',
|
|
|
|
|
path: '/tmp/brainy-cow-test-typeaware'
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await brain.init()
|
|
|
|
|
|
|
|
|
|
const entity = await brain.add({
|
2025-11-18 16:06:34 -08:00
|
|
|
type: NounType.Product,
|
2025-11-01 11:56:11 -07:00
|
|
|
data: { name: 'Widget', price: 99.99 }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const fork = await brain.fork('typeaware-branch')
|
|
|
|
|
|
|
|
|
|
const retrieved = await fork.get(entity.id)
|
|
|
|
|
expect(retrieved.data.price).toBe(99.99)
|
|
|
|
|
|
|
|
|
|
await brain.destroy()
|
|
|
|
|
await fork.destroy()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('Billion-Scale Performance', () => {
|
|
|
|
|
it('should fork 1M entities in < 2 seconds', async () => {
|
feat(8.0)!: flip requireSubtype default to true (BRAINY-8.0-SUBTYPE-CONTRACT § C-1)
Brainy 8.0 makes subtype required by default on every public write path
(`add`, `addMany`, `update`, `relate`, `relateMany`, `updateRelation`,
import). Per the locked C-1 contract, every entity and relation gets a
non-empty subtype string by the time the storage layer sees it.
OPT-OUT REMAINS FULLY SUPPORTED
The runtime flag is still consumer-controlled. Three opt-out paths
cover migration / legacy fixtures / typed escape:
- `new Brainy({ requireSubtype: false })` — last-resort: turn off the
contract entirely. Recommended only for migration windows or test
fixtures that legitimately can't supply a subtype.
- `new Brainy({ requireSubtype: { except: [NounType.Thing, ...] } })` —
per-type allowlist: strict everywhere except the listed types.
- `brain.requireSubtype(type, options)` — per-type registration with
optional vocabulary. Composes with the brain-wide flag.
Default is now `true`. Opt-out is explicit and documented; nothing
silently degrades.
TEST SWEEP
Bulk-applied `requireSubtype: false` to every `new Brainy({...})` call
site across 120 test files. Three sed patterns covered the shapes:
- `new Brainy({` → `new Brainy({ requireSubtype: false,`
- `new Brainy<T>({` → `new Brainy<T>({ requireSubtype: false,`
- `new Brainy()` → `new Brainy({ requireSubtype: false })`
tests/helpers/test-factory.ts → createTestConfig() defaults
`requireSubtype: false` so test files using the helper inherit the
opt-out without per-site edits.
The test sites that DO exercise subtype semantics (the
subtype-and-facets suite, the strict-mode-self-test suite, the verb-
subtype-and-enforcement suite, etc.) already pass real subtypes — they
were the 7.30.x acceptance tests for this contract. Those tests
continue to pass unchanged.
CHANGES
src/brainy.ts
- normalizeConfig() — `requireSubtype` default `false` → `true`.
Comment refreshed to document the three opt-out paths.
tests/* (120 files)
- Bulk-edited brain construction sites. No functional test changes; the
opt-out preserves the test author's original intent.
tests/helpers/test-factory.ts
- createTestConfig() base config gains `requireSubtype: false`.
NO-OP for consumers who were already passing subtype on every write.
For consumers who weren't, the upgrade path is one of the three opt-out
forms above. Migration recipe documented in 8.0 release notes (next
commit).
VERIFICATION
- npx tsc --noEmit: clean
- npm test: 1408 / 1409 (same pre-existing race-condition outstanding;
no other regressions from the flip)
2026-06-09 14:58:25 -07:00
|
|
|
const brain = new Brainy({ requireSubtype: false,
|
2025-11-01 11:56:11 -07:00
|
|
|
storage: { adapter: 'memory' }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await brain.init()
|
|
|
|
|
|
|
|
|
|
// Add 1M entities (representative of billion-scale)
|
|
|
|
|
console.log('Adding 1M entities...')
|
|
|
|
|
const start = Date.now()
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < 1_000_000; i++) {
|
|
|
|
|
await brain.add({
|
2025-11-18 16:06:34 -08:00
|
|
|
type: NounType.Thing,
|
2025-11-01 11:56:11 -07:00
|
|
|
data: { index: i },
|
|
|
|
|
skipCommit: true // Batch commit
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (i % 100_000 === 0) {
|
|
|
|
|
console.log(` ${i / 1000}K entities added...`)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await brain.commit({ message: 'Add 1M entities' })
|
|
|
|
|
|
|
|
|
|
const addTime = Date.now() - start
|
|
|
|
|
console.log(`Added 1M entities in ${addTime}ms`)
|
|
|
|
|
|
|
|
|
|
// Fork (should be instant via COW)
|
|
|
|
|
console.log('Forking...')
|
|
|
|
|
const forkStart = Date.now()
|
|
|
|
|
|
|
|
|
|
const fork = await brain.fork('million-test')
|
|
|
|
|
|
|
|
|
|
const forkTime = Date.now() - forkStart
|
|
|
|
|
|
|
|
|
|
console.log(`Forked 1M entities in ${forkTime}ms`)
|
|
|
|
|
|
|
|
|
|
// CRITICAL: Fork must be < 2 seconds
|
|
|
|
|
expect(forkTime).toBeLessThan(2000)
|
|
|
|
|
|
|
|
|
|
// Verify data integrity
|
|
|
|
|
const entity = await fork.get((await brain.find({ limit: 1 }))[0].id)
|
|
|
|
|
expect(entity.noun).toBe('entity')
|
|
|
|
|
|
|
|
|
|
await brain.destroy()
|
|
|
|
|
await fork.destroy()
|
|
|
|
|
}, 120000) // 2-minute timeout for 1M entity test
|
|
|
|
|
|
|
|
|
|
it('should deduplicate billions of identical vectors', async () => {
|
feat(8.0)!: flip requireSubtype default to true (BRAINY-8.0-SUBTYPE-CONTRACT § C-1)
Brainy 8.0 makes subtype required by default on every public write path
(`add`, `addMany`, `update`, `relate`, `relateMany`, `updateRelation`,
import). Per the locked C-1 contract, every entity and relation gets a
non-empty subtype string by the time the storage layer sees it.
OPT-OUT REMAINS FULLY SUPPORTED
The runtime flag is still consumer-controlled. Three opt-out paths
cover migration / legacy fixtures / typed escape:
- `new Brainy({ requireSubtype: false })` — last-resort: turn off the
contract entirely. Recommended only for migration windows or test
fixtures that legitimately can't supply a subtype.
- `new Brainy({ requireSubtype: { except: [NounType.Thing, ...] } })` —
per-type allowlist: strict everywhere except the listed types.
- `brain.requireSubtype(type, options)` — per-type registration with
optional vocabulary. Composes with the brain-wide flag.
Default is now `true`. Opt-out is explicit and documented; nothing
silently degrades.
TEST SWEEP
Bulk-applied `requireSubtype: false` to every `new Brainy({...})` call
site across 120 test files. Three sed patterns covered the shapes:
- `new Brainy({` → `new Brainy({ requireSubtype: false,`
- `new Brainy<T>({` → `new Brainy<T>({ requireSubtype: false,`
- `new Brainy()` → `new Brainy({ requireSubtype: false })`
tests/helpers/test-factory.ts → createTestConfig() defaults
`requireSubtype: false` so test files using the helper inherit the
opt-out without per-site edits.
The test sites that DO exercise subtype semantics (the
subtype-and-facets suite, the strict-mode-self-test suite, the verb-
subtype-and-enforcement suite, etc.) already pass real subtypes — they
were the 7.30.x acceptance tests for this contract. Those tests
continue to pass unchanged.
CHANGES
src/brainy.ts
- normalizeConfig() — `requireSubtype` default `false` → `true`.
Comment refreshed to document the three opt-out paths.
tests/* (120 files)
- Bulk-edited brain construction sites. No functional test changes; the
opt-out preserves the test author's original intent.
tests/helpers/test-factory.ts
- createTestConfig() base config gains `requireSubtype: false`.
NO-OP for consumers who were already passing subtype on every write.
For consumers who weren't, the upgrade path is one of the three opt-out
forms above. Migration recipe documented in 8.0 release notes (next
commit).
VERIFICATION
- npx tsc --noEmit: clean
- npm test: 1408 / 1409 (same pre-existing race-condition outstanding;
no other regressions from the flip)
2026-06-09 14:58:25 -07:00
|
|
|
const brain = new Brainy({ requireSubtype: false,
|
2025-11-01 11:56:11 -07:00
|
|
|
storage: { adapter: 'memory' }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await brain.init()
|
|
|
|
|
|
|
|
|
|
// Same vector used for all entities (simulates common embeddings)
|
|
|
|
|
const commonVector = Array(384).fill(0.1)
|
|
|
|
|
|
|
|
|
|
// Add 10K entities with same vector
|
|
|
|
|
for (let i = 0; i < 10_000; i++) {
|
|
|
|
|
await brain.add({
|
2025-11-18 16:06:34 -08:00
|
|
|
type: NounType.Document,
|
2025-11-01 11:56:11 -07:00
|
|
|
data: { id: i },
|
|
|
|
|
vector: commonVector,
|
|
|
|
|
skipCommit: true
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await brain.commit({ message: 'Add 10K with duplicate vectors' })
|
|
|
|
|
|
|
|
|
|
// Check storage stats
|
|
|
|
|
const stats = brain.storage.blobStorage.getStats()
|
|
|
|
|
|
|
|
|
|
// Should have massive deduplication savings
|
|
|
|
|
// (10K vectors but only 1 unique blob)
|
|
|
|
|
expect(stats.dedupSavings).toBeGreaterThan(0)
|
|
|
|
|
|
|
|
|
|
console.log(`Deduplication savings: ${(stats.dedupSavings / 1024 / 1024).toFixed(2)}MB`)
|
|
|
|
|
|
|
|
|
|
await brain.destroy()
|
|
|
|
|
}, 60000)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('find() Integration', () => {
|
|
|
|
|
it('should work with graph-aware find() queries', async () => {
|
feat(8.0)!: flip requireSubtype default to true (BRAINY-8.0-SUBTYPE-CONTRACT § C-1)
Brainy 8.0 makes subtype required by default on every public write path
(`add`, `addMany`, `update`, `relate`, `relateMany`, `updateRelation`,
import). Per the locked C-1 contract, every entity and relation gets a
non-empty subtype string by the time the storage layer sees it.
OPT-OUT REMAINS FULLY SUPPORTED
The runtime flag is still consumer-controlled. Three opt-out paths
cover migration / legacy fixtures / typed escape:
- `new Brainy({ requireSubtype: false })` — last-resort: turn off the
contract entirely. Recommended only for migration windows or test
fixtures that legitimately can't supply a subtype.
- `new Brainy({ requireSubtype: { except: [NounType.Thing, ...] } })` —
per-type allowlist: strict everywhere except the listed types.
- `brain.requireSubtype(type, options)` — per-type registration with
optional vocabulary. Composes with the brain-wide flag.
Default is now `true`. Opt-out is explicit and documented; nothing
silently degrades.
TEST SWEEP
Bulk-applied `requireSubtype: false` to every `new Brainy({...})` call
site across 120 test files. Three sed patterns covered the shapes:
- `new Brainy({` → `new Brainy({ requireSubtype: false,`
- `new Brainy<T>({` → `new Brainy<T>({ requireSubtype: false,`
- `new Brainy()` → `new Brainy({ requireSubtype: false })`
tests/helpers/test-factory.ts → createTestConfig() defaults
`requireSubtype: false` so test files using the helper inherit the
opt-out without per-site edits.
The test sites that DO exercise subtype semantics (the
subtype-and-facets suite, the strict-mode-self-test suite, the verb-
subtype-and-enforcement suite, etc.) already pass real subtypes — they
were the 7.30.x acceptance tests for this contract. Those tests
continue to pass unchanged.
CHANGES
src/brainy.ts
- normalizeConfig() — `requireSubtype` default `false` → `true`.
Comment refreshed to document the three opt-out paths.
tests/* (120 files)
- Bulk-edited brain construction sites. No functional test changes; the
opt-out preserves the test author's original intent.
tests/helpers/test-factory.ts
- createTestConfig() base config gains `requireSubtype: false`.
NO-OP for consumers who were already passing subtype on every write.
For consumers who weren't, the upgrade path is one of the three opt-out
forms above. Migration recipe documented in 8.0 release notes (next
commit).
VERIFICATION
- npx tsc --noEmit: clean
- npm test: 1408 / 1409 (same pre-existing race-condition outstanding;
no other regressions from the flip)
2026-06-09 14:58:25 -07:00
|
|
|
const brain = new Brainy({ requireSubtype: false,
|
2025-11-01 11:56:11 -07:00
|
|
|
storage: { adapter: 'memory' }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await brain.init()
|
|
|
|
|
|
|
|
|
|
// Create entities with relationships
|
|
|
|
|
const alice = await brain.add({
|
2025-11-18 16:06:34 -08:00
|
|
|
type: NounType.Person,
|
2025-11-01 11:56:11 -07:00
|
|
|
data: { name: 'Alice' }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const bob = await brain.add({
|
2025-11-18 16:06:34 -08:00
|
|
|
type: NounType.Person,
|
2025-11-01 11:56:11 -07:00
|
|
|
data: { name: 'Bob' }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await brain.addRelationship(alice.id, 'knows', bob.id)
|
|
|
|
|
|
|
|
|
|
// Fork
|
|
|
|
|
const fork = await brain.fork('find-test')
|
|
|
|
|
|
|
|
|
|
// find() should work on fork
|
|
|
|
|
const results = await fork.find({
|
2025-11-18 16:06:34 -08:00
|
|
|
type: NounType.Person,
|
2025-11-01 11:56:11 -07:00
|
|
|
where: { name: 'Alice' }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(results).toHaveLength(1)
|
|
|
|
|
expect(results[0].data.name).toBe('Alice')
|
|
|
|
|
|
|
|
|
|
// Graph traversal should work
|
|
|
|
|
const connected = await fork.getVerbsBySource(alice.id)
|
|
|
|
|
expect(connected).toHaveLength(1)
|
|
|
|
|
expect(connected[0].verb).toBe('knows')
|
|
|
|
|
|
|
|
|
|
await brain.destroy()
|
|
|
|
|
await fork.destroy()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should preserve metadata index across fork', async () => {
|
feat(8.0)!: flip requireSubtype default to true (BRAINY-8.0-SUBTYPE-CONTRACT § C-1)
Brainy 8.0 makes subtype required by default on every public write path
(`add`, `addMany`, `update`, `relate`, `relateMany`, `updateRelation`,
import). Per the locked C-1 contract, every entity and relation gets a
non-empty subtype string by the time the storage layer sees it.
OPT-OUT REMAINS FULLY SUPPORTED
The runtime flag is still consumer-controlled. Three opt-out paths
cover migration / legacy fixtures / typed escape:
- `new Brainy({ requireSubtype: false })` — last-resort: turn off the
contract entirely. Recommended only for migration windows or test
fixtures that legitimately can't supply a subtype.
- `new Brainy({ requireSubtype: { except: [NounType.Thing, ...] } })` —
per-type allowlist: strict everywhere except the listed types.
- `brain.requireSubtype(type, options)` — per-type registration with
optional vocabulary. Composes with the brain-wide flag.
Default is now `true`. Opt-out is explicit and documented; nothing
silently degrades.
TEST SWEEP
Bulk-applied `requireSubtype: false` to every `new Brainy({...})` call
site across 120 test files. Three sed patterns covered the shapes:
- `new Brainy({` → `new Brainy({ requireSubtype: false,`
- `new Brainy<T>({` → `new Brainy<T>({ requireSubtype: false,`
- `new Brainy()` → `new Brainy({ requireSubtype: false })`
tests/helpers/test-factory.ts → createTestConfig() defaults
`requireSubtype: false` so test files using the helper inherit the
opt-out without per-site edits.
The test sites that DO exercise subtype semantics (the
subtype-and-facets suite, the strict-mode-self-test suite, the verb-
subtype-and-enforcement suite, etc.) already pass real subtypes — they
were the 7.30.x acceptance tests for this contract. Those tests
continue to pass unchanged.
CHANGES
src/brainy.ts
- normalizeConfig() — `requireSubtype` default `false` → `true`.
Comment refreshed to document the three opt-out paths.
tests/* (120 files)
- Bulk-edited brain construction sites. No functional test changes; the
opt-out preserves the test author's original intent.
tests/helpers/test-factory.ts
- createTestConfig() base config gains `requireSubtype: false`.
NO-OP for consumers who were already passing subtype on every write.
For consumers who weren't, the upgrade path is one of the three opt-out
forms above. Migration recipe documented in 8.0 release notes (next
commit).
VERIFICATION
- npx tsc --noEmit: clean
- npm test: 1408 / 1409 (same pre-existing race-condition outstanding;
no other regressions from the flip)
2026-06-09 14:58:25 -07:00
|
|
|
const brain = new Brainy({ requireSubtype: false,
|
2025-11-01 11:56:11 -07:00
|
|
|
storage: { adapter: 'memory' }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await brain.init()
|
|
|
|
|
|
|
|
|
|
// Add entities with indexed metadata
|
|
|
|
|
await brain.add({
|
2025-11-18 16:06:34 -08:00
|
|
|
type: NounType.Product,
|
2025-11-01 11:56:11 -07:00
|
|
|
data: { price: 100, category: 'electronics' }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await brain.add({
|
2025-11-18 16:06:34 -08:00
|
|
|
type: NounType.Product,
|
2025-11-01 11:56:11 -07:00
|
|
|
data: { price: 200, category: 'electronics' }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const fork = await brain.fork('metadata-test')
|
|
|
|
|
|
|
|
|
|
// Metadata queries should work
|
|
|
|
|
const cheap = await fork.find({
|
2025-11-18 16:06:34 -08:00
|
|
|
type: NounType.Product,
|
2025-11-01 11:56:11 -07:00
|
|
|
where: { price: { $lt: 150 } }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(cheap).toHaveLength(1)
|
|
|
|
|
expect(cheap[0].data.price).toBe(100)
|
|
|
|
|
|
|
|
|
|
await brain.destroy()
|
|
|
|
|
await fork.destroy()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('Triple Intelligence Integration', () => {
|
|
|
|
|
it('should preserve Triple Intelligence across fork', async () => {
|
feat(8.0)!: flip requireSubtype default to true (BRAINY-8.0-SUBTYPE-CONTRACT § C-1)
Brainy 8.0 makes subtype required by default on every public write path
(`add`, `addMany`, `update`, `relate`, `relateMany`, `updateRelation`,
import). Per the locked C-1 contract, every entity and relation gets a
non-empty subtype string by the time the storage layer sees it.
OPT-OUT REMAINS FULLY SUPPORTED
The runtime flag is still consumer-controlled. Three opt-out paths
cover migration / legacy fixtures / typed escape:
- `new Brainy({ requireSubtype: false })` — last-resort: turn off the
contract entirely. Recommended only for migration windows or test
fixtures that legitimately can't supply a subtype.
- `new Brainy({ requireSubtype: { except: [NounType.Thing, ...] } })` —
per-type allowlist: strict everywhere except the listed types.
- `brain.requireSubtype(type, options)` — per-type registration with
optional vocabulary. Composes with the brain-wide flag.
Default is now `true`. Opt-out is explicit and documented; nothing
silently degrades.
TEST SWEEP
Bulk-applied `requireSubtype: false` to every `new Brainy({...})` call
site across 120 test files. Three sed patterns covered the shapes:
- `new Brainy({` → `new Brainy({ requireSubtype: false,`
- `new Brainy<T>({` → `new Brainy<T>({ requireSubtype: false,`
- `new Brainy()` → `new Brainy({ requireSubtype: false })`
tests/helpers/test-factory.ts → createTestConfig() defaults
`requireSubtype: false` so test files using the helper inherit the
opt-out without per-site edits.
The test sites that DO exercise subtype semantics (the
subtype-and-facets suite, the strict-mode-self-test suite, the verb-
subtype-and-enforcement suite, etc.) already pass real subtypes — they
were the 7.30.x acceptance tests for this contract. Those tests
continue to pass unchanged.
CHANGES
src/brainy.ts
- normalizeConfig() — `requireSubtype` default `false` → `true`.
Comment refreshed to document the three opt-out paths.
tests/* (120 files)
- Bulk-edited brain construction sites. No functional test changes; the
opt-out preserves the test author's original intent.
tests/helpers/test-factory.ts
- createTestConfig() base config gains `requireSubtype: false`.
NO-OP for consumers who were already passing subtype on every write.
For consumers who weren't, the upgrade path is one of the three opt-out
forms above. Migration recipe documented in 8.0 release notes (next
commit).
VERIFICATION
- npx tsc --noEmit: clean
- npm test: 1408 / 1409 (same pre-existing race-condition outstanding;
no other regressions from the flip)
2026-06-09 14:58:25 -07:00
|
|
|
const brain = new Brainy({ requireSubtype: false,
|
2025-11-01 11:56:11 -07:00
|
|
|
storage: { adapter: 'memory' },
|
|
|
|
|
intelligence: {
|
|
|
|
|
enabled: true,
|
|
|
|
|
modelDelivery: 'local'
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await brain.init()
|
|
|
|
|
|
|
|
|
|
// Add entities
|
|
|
|
|
await brain.add({
|
2025-11-18 16:06:34 -08:00
|
|
|
type: NounType.Person,
|
2025-11-01 11:56:11 -07:00
|
|
|
data: { name: 'Alice', age: 30 }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await brain.add({
|
2025-11-18 16:06:34 -08:00
|
|
|
type: NounType.Person,
|
2025-11-01 11:56:11 -07:00
|
|
|
data: { name: 'Bob', age: 25 }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const fork = await brain.fork('intelligence-test')
|
|
|
|
|
|
|
|
|
|
// Natural language query should work on fork
|
|
|
|
|
const results = await fork.query('people older than 28')
|
|
|
|
|
|
|
|
|
|
// Should find Alice (age 30)
|
|
|
|
|
expect(results.length).toBeGreaterThan(0)
|
|
|
|
|
|
|
|
|
|
await brain.destroy()
|
|
|
|
|
await fork.destroy()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('VFS Integration', () => {
|
|
|
|
|
it('should preserve VFS structure across fork', async () => {
|
feat(8.0)!: flip requireSubtype default to true (BRAINY-8.0-SUBTYPE-CONTRACT § C-1)
Brainy 8.0 makes subtype required by default on every public write path
(`add`, `addMany`, `update`, `relate`, `relateMany`, `updateRelation`,
import). Per the locked C-1 contract, every entity and relation gets a
non-empty subtype string by the time the storage layer sees it.
OPT-OUT REMAINS FULLY SUPPORTED
The runtime flag is still consumer-controlled. Three opt-out paths
cover migration / legacy fixtures / typed escape:
- `new Brainy({ requireSubtype: false })` — last-resort: turn off the
contract entirely. Recommended only for migration windows or test
fixtures that legitimately can't supply a subtype.
- `new Brainy({ requireSubtype: { except: [NounType.Thing, ...] } })` —
per-type allowlist: strict everywhere except the listed types.
- `brain.requireSubtype(type, options)` — per-type registration with
optional vocabulary. Composes with the brain-wide flag.
Default is now `true`. Opt-out is explicit and documented; nothing
silently degrades.
TEST SWEEP
Bulk-applied `requireSubtype: false` to every `new Brainy({...})` call
site across 120 test files. Three sed patterns covered the shapes:
- `new Brainy({` → `new Brainy({ requireSubtype: false,`
- `new Brainy<T>({` → `new Brainy<T>({ requireSubtype: false,`
- `new Brainy()` → `new Brainy({ requireSubtype: false })`
tests/helpers/test-factory.ts → createTestConfig() defaults
`requireSubtype: false` so test files using the helper inherit the
opt-out without per-site edits.
The test sites that DO exercise subtype semantics (the
subtype-and-facets suite, the strict-mode-self-test suite, the verb-
subtype-and-enforcement suite, etc.) already pass real subtypes — they
were the 7.30.x acceptance tests for this contract. Those tests
continue to pass unchanged.
CHANGES
src/brainy.ts
- normalizeConfig() — `requireSubtype` default `false` → `true`.
Comment refreshed to document the three opt-out paths.
tests/* (120 files)
- Bulk-edited brain construction sites. No functional test changes; the
opt-out preserves the test author's original intent.
tests/helpers/test-factory.ts
- createTestConfig() base config gains `requireSubtype: false`.
NO-OP for consumers who were already passing subtype on every write.
For consumers who weren't, the upgrade path is one of the three opt-out
forms above. Migration recipe documented in 8.0 release notes (next
commit).
VERIFICATION
- npx tsc --noEmit: clean
- npm test: 1408 / 1409 (same pre-existing race-condition outstanding;
no other regressions from the flip)
2026-06-09 14:58:25 -07:00
|
|
|
const brain = new Brainy({ requireSubtype: false,
|
2025-11-01 11:56:11 -07:00
|
|
|
storage: { adapter: 'memory' },
|
|
|
|
|
vfs: { enabled: true }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await brain.init()
|
|
|
|
|
|
|
|
|
|
// Create VFS structure
|
|
|
|
|
const folder = await brain.vfs.mkdir('/documents')
|
|
|
|
|
const file = await brain.vfs.writeFile('/documents/readme.txt', 'Hello World')
|
|
|
|
|
|
|
|
|
|
const fork = await brain.fork('vfs-test')
|
|
|
|
|
|
|
|
|
|
// VFS should work on fork
|
|
|
|
|
const content = await fork.vfs.readFile('/documents/readme.txt')
|
|
|
|
|
expect(content).toBe('Hello World')
|
|
|
|
|
|
|
|
|
|
const files = await fork.vfs.readdir('/documents')
|
|
|
|
|
expect(files).toContain('readme.txt')
|
|
|
|
|
|
|
|
|
|
await brain.destroy()
|
|
|
|
|
await fork.destroy()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should support VFS paths in billions of entities', async () => {
|
feat(8.0)!: flip requireSubtype default to true (BRAINY-8.0-SUBTYPE-CONTRACT § C-1)
Brainy 8.0 makes subtype required by default on every public write path
(`add`, `addMany`, `update`, `relate`, `relateMany`, `updateRelation`,
import). Per the locked C-1 contract, every entity and relation gets a
non-empty subtype string by the time the storage layer sees it.
OPT-OUT REMAINS FULLY SUPPORTED
The runtime flag is still consumer-controlled. Three opt-out paths
cover migration / legacy fixtures / typed escape:
- `new Brainy({ requireSubtype: false })` — last-resort: turn off the
contract entirely. Recommended only for migration windows or test
fixtures that legitimately can't supply a subtype.
- `new Brainy({ requireSubtype: { except: [NounType.Thing, ...] } })` —
per-type allowlist: strict everywhere except the listed types.
- `brain.requireSubtype(type, options)` — per-type registration with
optional vocabulary. Composes with the brain-wide flag.
Default is now `true`. Opt-out is explicit and documented; nothing
silently degrades.
TEST SWEEP
Bulk-applied `requireSubtype: false` to every `new Brainy({...})` call
site across 120 test files. Three sed patterns covered the shapes:
- `new Brainy({` → `new Brainy({ requireSubtype: false,`
- `new Brainy<T>({` → `new Brainy<T>({ requireSubtype: false,`
- `new Brainy()` → `new Brainy({ requireSubtype: false })`
tests/helpers/test-factory.ts → createTestConfig() defaults
`requireSubtype: false` so test files using the helper inherit the
opt-out without per-site edits.
The test sites that DO exercise subtype semantics (the
subtype-and-facets suite, the strict-mode-self-test suite, the verb-
subtype-and-enforcement suite, etc.) already pass real subtypes — they
were the 7.30.x acceptance tests for this contract. Those tests
continue to pass unchanged.
CHANGES
src/brainy.ts
- normalizeConfig() — `requireSubtype` default `false` → `true`.
Comment refreshed to document the three opt-out paths.
tests/* (120 files)
- Bulk-edited brain construction sites. No functional test changes; the
opt-out preserves the test author's original intent.
tests/helpers/test-factory.ts
- createTestConfig() base config gains `requireSubtype: false`.
NO-OP for consumers who were already passing subtype on every write.
For consumers who weren't, the upgrade path is one of the three opt-out
forms above. Migration recipe documented in 8.0 release notes (next
commit).
VERIFICATION
- npx tsc --noEmit: clean
- npm test: 1408 / 1409 (same pre-existing race-condition outstanding;
no other regressions from the flip)
2026-06-09 14:58:25 -07:00
|
|
|
const brain = new Brainy({ requireSubtype: false,
|
2025-11-01 11:56:11 -07:00
|
|
|
storage: { adapter: 'memory' },
|
|
|
|
|
vfs: { enabled: true }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await brain.init()
|
|
|
|
|
|
|
|
|
|
// Create deep directory structure
|
|
|
|
|
await brain.vfs.mkdir('/project/src/components/ui')
|
|
|
|
|
|
|
|
|
|
// Add 1000 files
|
|
|
|
|
for (let i = 0; i < 1000; i++) {
|
|
|
|
|
await brain.vfs.writeFile(
|
|
|
|
|
`/project/src/components/ui/component${i}.tsx`,
|
|
|
|
|
`export default function Component${i}() { return null }`
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const fork = await brain.fork('vfs-scale-test')
|
|
|
|
|
|
|
|
|
|
// VFS operations should be fast on fork
|
|
|
|
|
const files = await fork.vfs.readdir('/project/src/components/ui')
|
|
|
|
|
expect(files).toHaveLength(1000)
|
|
|
|
|
|
|
|
|
|
await brain.destroy()
|
|
|
|
|
await fork.destroy()
|
|
|
|
|
}, 60000)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('All 4 Indexes Integration', () => {
|
|
|
|
|
it('should preserve HNSW index across fork', async () => {
|
feat(8.0)!: flip requireSubtype default to true (BRAINY-8.0-SUBTYPE-CONTRACT § C-1)
Brainy 8.0 makes subtype required by default on every public write path
(`add`, `addMany`, `update`, `relate`, `relateMany`, `updateRelation`,
import). Per the locked C-1 contract, every entity and relation gets a
non-empty subtype string by the time the storage layer sees it.
OPT-OUT REMAINS FULLY SUPPORTED
The runtime flag is still consumer-controlled. Three opt-out paths
cover migration / legacy fixtures / typed escape:
- `new Brainy({ requireSubtype: false })` — last-resort: turn off the
contract entirely. Recommended only for migration windows or test
fixtures that legitimately can't supply a subtype.
- `new Brainy({ requireSubtype: { except: [NounType.Thing, ...] } })` —
per-type allowlist: strict everywhere except the listed types.
- `brain.requireSubtype(type, options)` — per-type registration with
optional vocabulary. Composes with the brain-wide flag.
Default is now `true`. Opt-out is explicit and documented; nothing
silently degrades.
TEST SWEEP
Bulk-applied `requireSubtype: false` to every `new Brainy({...})` call
site across 120 test files. Three sed patterns covered the shapes:
- `new Brainy({` → `new Brainy({ requireSubtype: false,`
- `new Brainy<T>({` → `new Brainy<T>({ requireSubtype: false,`
- `new Brainy()` → `new Brainy({ requireSubtype: false })`
tests/helpers/test-factory.ts → createTestConfig() defaults
`requireSubtype: false` so test files using the helper inherit the
opt-out without per-site edits.
The test sites that DO exercise subtype semantics (the
subtype-and-facets suite, the strict-mode-self-test suite, the verb-
subtype-and-enforcement suite, etc.) already pass real subtypes — they
were the 7.30.x acceptance tests for this contract. Those tests
continue to pass unchanged.
CHANGES
src/brainy.ts
- normalizeConfig() — `requireSubtype` default `false` → `true`.
Comment refreshed to document the three opt-out paths.
tests/* (120 files)
- Bulk-edited brain construction sites. No functional test changes; the
opt-out preserves the test author's original intent.
tests/helpers/test-factory.ts
- createTestConfig() base config gains `requireSubtype: false`.
NO-OP for consumers who were already passing subtype on every write.
For consumers who weren't, the upgrade path is one of the three opt-out
forms above. Migration recipe documented in 8.0 release notes (next
commit).
VERIFICATION
- npx tsc --noEmit: clean
- npm test: 1408 / 1409 (same pre-existing race-condition outstanding;
no other regressions from the flip)
2026-06-09 14:58:25 -07:00
|
|
|
const brain = new Brainy({ requireSubtype: false,
|
2025-11-01 11:56:11 -07:00
|
|
|
storage: { adapter: 'memory' }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await brain.init()
|
|
|
|
|
|
|
|
|
|
// Add entities with vectors
|
|
|
|
|
const e1 = await brain.add({
|
2025-11-18 16:06:34 -08:00
|
|
|
type: NounType.Document,
|
2025-11-01 11:56:11 -07:00
|
|
|
data: { text: 'machine learning' },
|
|
|
|
|
vector: [1, 0, 0]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const e2 = await brain.add({
|
2025-11-18 16:06:34 -08:00
|
|
|
type: NounType.Document,
|
2025-11-01 11:56:11 -07:00
|
|
|
data: { text: 'artificial intelligence' },
|
|
|
|
|
vector: [0.9, 0.1, 0]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const fork = await brain.fork('hnsw-test')
|
|
|
|
|
|
|
|
|
|
// Vector search should work on fork
|
|
|
|
|
const similar = await fork.search([1, 0, 0], { limit: 1 })
|
|
|
|
|
|
|
|
|
|
expect(similar[0].id).toBe(e1.id)
|
|
|
|
|
|
|
|
|
|
await brain.destroy()
|
|
|
|
|
await fork.destroy()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should preserve GraphAdjacency index across fork', async () => {
|
feat(8.0)!: flip requireSubtype default to true (BRAINY-8.0-SUBTYPE-CONTRACT § C-1)
Brainy 8.0 makes subtype required by default on every public write path
(`add`, `addMany`, `update`, `relate`, `relateMany`, `updateRelation`,
import). Per the locked C-1 contract, every entity and relation gets a
non-empty subtype string by the time the storage layer sees it.
OPT-OUT REMAINS FULLY SUPPORTED
The runtime flag is still consumer-controlled. Three opt-out paths
cover migration / legacy fixtures / typed escape:
- `new Brainy({ requireSubtype: false })` — last-resort: turn off the
contract entirely. Recommended only for migration windows or test
fixtures that legitimately can't supply a subtype.
- `new Brainy({ requireSubtype: { except: [NounType.Thing, ...] } })` —
per-type allowlist: strict everywhere except the listed types.
- `brain.requireSubtype(type, options)` — per-type registration with
optional vocabulary. Composes with the brain-wide flag.
Default is now `true`. Opt-out is explicit and documented; nothing
silently degrades.
TEST SWEEP
Bulk-applied `requireSubtype: false` to every `new Brainy({...})` call
site across 120 test files. Three sed patterns covered the shapes:
- `new Brainy({` → `new Brainy({ requireSubtype: false,`
- `new Brainy<T>({` → `new Brainy<T>({ requireSubtype: false,`
- `new Brainy()` → `new Brainy({ requireSubtype: false })`
tests/helpers/test-factory.ts → createTestConfig() defaults
`requireSubtype: false` so test files using the helper inherit the
opt-out without per-site edits.
The test sites that DO exercise subtype semantics (the
subtype-and-facets suite, the strict-mode-self-test suite, the verb-
subtype-and-enforcement suite, etc.) already pass real subtypes — they
were the 7.30.x acceptance tests for this contract. Those tests
continue to pass unchanged.
CHANGES
src/brainy.ts
- normalizeConfig() — `requireSubtype` default `false` → `true`.
Comment refreshed to document the three opt-out paths.
tests/* (120 files)
- Bulk-edited brain construction sites. No functional test changes; the
opt-out preserves the test author's original intent.
tests/helpers/test-factory.ts
- createTestConfig() base config gains `requireSubtype: false`.
NO-OP for consumers who were already passing subtype on every write.
For consumers who weren't, the upgrade path is one of the three opt-out
forms above. Migration recipe documented in 8.0 release notes (next
commit).
VERIFICATION
- npx tsc --noEmit: clean
- npm test: 1408 / 1409 (same pre-existing race-condition outstanding;
no other regressions from the flip)
2026-06-09 14:58:25 -07:00
|
|
|
const brain = new Brainy({ requireSubtype: false,
|
2025-11-01 11:56:11 -07:00
|
|
|
storage: { adapter: 'memory' }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await brain.init()
|
|
|
|
|
|
2025-11-18 16:06:34 -08:00
|
|
|
const a = await brain.add({ type: NounType.Thing, data: { name: 'A' } })
|
|
|
|
|
const b = await brain.add({ type: NounType.Thing, data: { name: 'B' } })
|
|
|
|
|
const c = await brain.add({ type: NounType.Thing, data: { name: 'C' } })
|
2025-11-01 11:56:11 -07:00
|
|
|
|
|
|
|
|
await brain.addRelationship(a.id, 'connects', b.id)
|
|
|
|
|
await brain.addRelationship(b.id, 'connects', c.id)
|
|
|
|
|
|
|
|
|
|
const fork = await brain.fork('graph-test')
|
|
|
|
|
|
|
|
|
|
// Graph queries should work
|
|
|
|
|
const outgoing = await fork.getVerbsBySource(a.id)
|
|
|
|
|
const incoming = await fork.getVerbsByTarget(b.id)
|
|
|
|
|
|
|
|
|
|
expect(outgoing).toHaveLength(1)
|
|
|
|
|
expect(incoming).toHaveLength(1)
|
|
|
|
|
|
|
|
|
|
await brain.destroy()
|
|
|
|
|
await fork.destroy()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should preserve DeletedItems index across fork', async () => {
|
feat(8.0)!: flip requireSubtype default to true (BRAINY-8.0-SUBTYPE-CONTRACT § C-1)
Brainy 8.0 makes subtype required by default on every public write path
(`add`, `addMany`, `update`, `relate`, `relateMany`, `updateRelation`,
import). Per the locked C-1 contract, every entity and relation gets a
non-empty subtype string by the time the storage layer sees it.
OPT-OUT REMAINS FULLY SUPPORTED
The runtime flag is still consumer-controlled. Three opt-out paths
cover migration / legacy fixtures / typed escape:
- `new Brainy({ requireSubtype: false })` — last-resort: turn off the
contract entirely. Recommended only for migration windows or test
fixtures that legitimately can't supply a subtype.
- `new Brainy({ requireSubtype: { except: [NounType.Thing, ...] } })` —
per-type allowlist: strict everywhere except the listed types.
- `brain.requireSubtype(type, options)` — per-type registration with
optional vocabulary. Composes with the brain-wide flag.
Default is now `true`. Opt-out is explicit and documented; nothing
silently degrades.
TEST SWEEP
Bulk-applied `requireSubtype: false` to every `new Brainy({...})` call
site across 120 test files. Three sed patterns covered the shapes:
- `new Brainy({` → `new Brainy({ requireSubtype: false,`
- `new Brainy<T>({` → `new Brainy<T>({ requireSubtype: false,`
- `new Brainy()` → `new Brainy({ requireSubtype: false })`
tests/helpers/test-factory.ts → createTestConfig() defaults
`requireSubtype: false` so test files using the helper inherit the
opt-out without per-site edits.
The test sites that DO exercise subtype semantics (the
subtype-and-facets suite, the strict-mode-self-test suite, the verb-
subtype-and-enforcement suite, etc.) already pass real subtypes — they
were the 7.30.x acceptance tests for this contract. Those tests
continue to pass unchanged.
CHANGES
src/brainy.ts
- normalizeConfig() — `requireSubtype` default `false` → `true`.
Comment refreshed to document the three opt-out paths.
tests/* (120 files)
- Bulk-edited brain construction sites. No functional test changes; the
opt-out preserves the test author's original intent.
tests/helpers/test-factory.ts
- createTestConfig() base config gains `requireSubtype: false`.
NO-OP for consumers who were already passing subtype on every write.
For consumers who weren't, the upgrade path is one of the three opt-out
forms above. Migration recipe documented in 8.0 release notes (next
commit).
VERIFICATION
- npx tsc --noEmit: clean
- npm test: 1408 / 1409 (same pre-existing race-condition outstanding;
no other regressions from the flip)
2026-06-09 14:58:25 -07:00
|
|
|
const brain = new Brainy({ requireSubtype: false,
|
2025-11-01 11:56:11 -07:00
|
|
|
storage: { adapter: 'memory' }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await brain.init()
|
|
|
|
|
|
|
|
|
|
const entity = await brain.add({
|
2025-11-18 16:06:34 -08:00
|
|
|
type: NounType.Thing,
|
2025-11-01 11:56:11 -07:00
|
|
|
data: { value: 'test' }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await brain.delete(entity.id)
|
|
|
|
|
|
|
|
|
|
const fork = await brain.fork('deleted-test')
|
|
|
|
|
|
|
|
|
|
// Deleted items should be tracked in fork
|
|
|
|
|
const exists = await fork.get(entity.id).catch(() => null)
|
|
|
|
|
expect(exists).toBeNull()
|
|
|
|
|
|
|
|
|
|
await brain.destroy()
|
|
|
|
|
await fork.destroy()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('Distributed Mode', () => {
|
|
|
|
|
it('should work with read-only instances', async () => {
|
|
|
|
|
// Main brain (read-write)
|
feat(8.0)!: flip requireSubtype default to true (BRAINY-8.0-SUBTYPE-CONTRACT § C-1)
Brainy 8.0 makes subtype required by default on every public write path
(`add`, `addMany`, `update`, `relate`, `relateMany`, `updateRelation`,
import). Per the locked C-1 contract, every entity and relation gets a
non-empty subtype string by the time the storage layer sees it.
OPT-OUT REMAINS FULLY SUPPORTED
The runtime flag is still consumer-controlled. Three opt-out paths
cover migration / legacy fixtures / typed escape:
- `new Brainy({ requireSubtype: false })` — last-resort: turn off the
contract entirely. Recommended only for migration windows or test
fixtures that legitimately can't supply a subtype.
- `new Brainy({ requireSubtype: { except: [NounType.Thing, ...] } })` —
per-type allowlist: strict everywhere except the listed types.
- `brain.requireSubtype(type, options)` — per-type registration with
optional vocabulary. Composes with the brain-wide flag.
Default is now `true`. Opt-out is explicit and documented; nothing
silently degrades.
TEST SWEEP
Bulk-applied `requireSubtype: false` to every `new Brainy({...})` call
site across 120 test files. Three sed patterns covered the shapes:
- `new Brainy({` → `new Brainy({ requireSubtype: false,`
- `new Brainy<T>({` → `new Brainy<T>({ requireSubtype: false,`
- `new Brainy()` → `new Brainy({ requireSubtype: false })`
tests/helpers/test-factory.ts → createTestConfig() defaults
`requireSubtype: false` so test files using the helper inherit the
opt-out without per-site edits.
The test sites that DO exercise subtype semantics (the
subtype-and-facets suite, the strict-mode-self-test suite, the verb-
subtype-and-enforcement suite, etc.) already pass real subtypes — they
were the 7.30.x acceptance tests for this contract. Those tests
continue to pass unchanged.
CHANGES
src/brainy.ts
- normalizeConfig() — `requireSubtype` default `false` → `true`.
Comment refreshed to document the three opt-out paths.
tests/* (120 files)
- Bulk-edited brain construction sites. No functional test changes; the
opt-out preserves the test author's original intent.
tests/helpers/test-factory.ts
- createTestConfig() base config gains `requireSubtype: false`.
NO-OP for consumers who were already passing subtype on every write.
For consumers who weren't, the upgrade path is one of the three opt-out
forms above. Migration recipe documented in 8.0 release notes (next
commit).
VERIFICATION
- npx tsc --noEmit: clean
- npm test: 1408 / 1409 (same pre-existing race-condition outstanding;
no other regressions from the flip)
2026-06-09 14:58:25 -07:00
|
|
|
const main = new Brainy({ requireSubtype: false,
|
2025-11-01 11:56:11 -07:00
|
|
|
storage: { adapter: 'memory' }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await main.init()
|
|
|
|
|
|
|
|
|
|
const entity = await main.add({
|
2025-11-18 16:06:34 -08:00
|
|
|
type: NounType.Thing,
|
2025-11-01 11:56:11 -07:00
|
|
|
data: { value: 'test' }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await main.commit({ message: 'Add entity' })
|
|
|
|
|
|
|
|
|
|
// Read-only instance (shares storage)
|
feat(8.0)!: flip requireSubtype default to true (BRAINY-8.0-SUBTYPE-CONTRACT § C-1)
Brainy 8.0 makes subtype required by default on every public write path
(`add`, `addMany`, `update`, `relate`, `relateMany`, `updateRelation`,
import). Per the locked C-1 contract, every entity and relation gets a
non-empty subtype string by the time the storage layer sees it.
OPT-OUT REMAINS FULLY SUPPORTED
The runtime flag is still consumer-controlled. Three opt-out paths
cover migration / legacy fixtures / typed escape:
- `new Brainy({ requireSubtype: false })` — last-resort: turn off the
contract entirely. Recommended only for migration windows or test
fixtures that legitimately can't supply a subtype.
- `new Brainy({ requireSubtype: { except: [NounType.Thing, ...] } })` —
per-type allowlist: strict everywhere except the listed types.
- `brain.requireSubtype(type, options)` — per-type registration with
optional vocabulary. Composes with the brain-wide flag.
Default is now `true`. Opt-out is explicit and documented; nothing
silently degrades.
TEST SWEEP
Bulk-applied `requireSubtype: false` to every `new Brainy({...})` call
site across 120 test files. Three sed patterns covered the shapes:
- `new Brainy({` → `new Brainy({ requireSubtype: false,`
- `new Brainy<T>({` → `new Brainy<T>({ requireSubtype: false,`
- `new Brainy()` → `new Brainy({ requireSubtype: false })`
tests/helpers/test-factory.ts → createTestConfig() defaults
`requireSubtype: false` so test files using the helper inherit the
opt-out without per-site edits.
The test sites that DO exercise subtype semantics (the
subtype-and-facets suite, the strict-mode-self-test suite, the verb-
subtype-and-enforcement suite, etc.) already pass real subtypes — they
were the 7.30.x acceptance tests for this contract. Those tests
continue to pass unchanged.
CHANGES
src/brainy.ts
- normalizeConfig() — `requireSubtype` default `false` → `true`.
Comment refreshed to document the three opt-out paths.
tests/* (120 files)
- Bulk-edited brain construction sites. No functional test changes; the
opt-out preserves the test author's original intent.
tests/helpers/test-factory.ts
- createTestConfig() base config gains `requireSubtype: false`.
NO-OP for consumers who were already passing subtype on every write.
For consumers who weren't, the upgrade path is one of the three opt-out
forms above. Migration recipe documented in 8.0 release notes (next
commit).
VERIFICATION
- npx tsc --noEmit: clean
- npm test: 1408 / 1409 (same pre-existing race-condition outstanding;
no other regressions from the flip)
2026-06-09 14:58:25 -07:00
|
|
|
const readonly = new Brainy({ requireSubtype: false,
|
2025-11-01 11:56:11 -07:00
|
|
|
storage: main.config.storage,
|
|
|
|
|
readOnly: true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await readonly.init()
|
|
|
|
|
|
|
|
|
|
// Can read from main
|
|
|
|
|
const retrieved = await readonly.get(entity.id)
|
|
|
|
|
expect(retrieved.data.value).toBe('test')
|
|
|
|
|
|
|
|
|
|
// Can fork read-only instance
|
|
|
|
|
const fork = await readonly.fork('readonly-fork')
|
|
|
|
|
|
|
|
|
|
const forked = await fork.get(entity.id)
|
|
|
|
|
expect(forked.data.value).toBe('test')
|
|
|
|
|
|
|
|
|
|
await main.destroy()
|
|
|
|
|
await readonly.destroy()
|
|
|
|
|
await fork.destroy()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should work with write-only instances', async () => {
|
|
|
|
|
// Write-only instance
|
feat(8.0)!: flip requireSubtype default to true (BRAINY-8.0-SUBTYPE-CONTRACT § C-1)
Brainy 8.0 makes subtype required by default on every public write path
(`add`, `addMany`, `update`, `relate`, `relateMany`, `updateRelation`,
import). Per the locked C-1 contract, every entity and relation gets a
non-empty subtype string by the time the storage layer sees it.
OPT-OUT REMAINS FULLY SUPPORTED
The runtime flag is still consumer-controlled. Three opt-out paths
cover migration / legacy fixtures / typed escape:
- `new Brainy({ requireSubtype: false })` — last-resort: turn off the
contract entirely. Recommended only for migration windows or test
fixtures that legitimately can't supply a subtype.
- `new Brainy({ requireSubtype: { except: [NounType.Thing, ...] } })` —
per-type allowlist: strict everywhere except the listed types.
- `brain.requireSubtype(type, options)` — per-type registration with
optional vocabulary. Composes with the brain-wide flag.
Default is now `true`. Opt-out is explicit and documented; nothing
silently degrades.
TEST SWEEP
Bulk-applied `requireSubtype: false` to every `new Brainy({...})` call
site across 120 test files. Three sed patterns covered the shapes:
- `new Brainy({` → `new Brainy({ requireSubtype: false,`
- `new Brainy<T>({` → `new Brainy<T>({ requireSubtype: false,`
- `new Brainy()` → `new Brainy({ requireSubtype: false })`
tests/helpers/test-factory.ts → createTestConfig() defaults
`requireSubtype: false` so test files using the helper inherit the
opt-out without per-site edits.
The test sites that DO exercise subtype semantics (the
subtype-and-facets suite, the strict-mode-self-test suite, the verb-
subtype-and-enforcement suite, etc.) already pass real subtypes — they
were the 7.30.x acceptance tests for this contract. Those tests
continue to pass unchanged.
CHANGES
src/brainy.ts
- normalizeConfig() — `requireSubtype` default `false` → `true`.
Comment refreshed to document the three opt-out paths.
tests/* (120 files)
- Bulk-edited brain construction sites. No functional test changes; the
opt-out preserves the test author's original intent.
tests/helpers/test-factory.ts
- createTestConfig() base config gains `requireSubtype: false`.
NO-OP for consumers who were already passing subtype on every write.
For consumers who weren't, the upgrade path is one of the three opt-out
forms above. Migration recipe documented in 8.0 release notes (next
commit).
VERIFICATION
- npx tsc --noEmit: clean
- npm test: 1408 / 1409 (same pre-existing race-condition outstanding;
no other regressions from the flip)
2026-06-09 14:58:25 -07:00
|
|
|
const writeOnly = new Brainy({ requireSubtype: false,
|
2025-11-01 11:56:11 -07:00
|
|
|
storage: { adapter: 'memory' },
|
|
|
|
|
writeOnly: true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await writeOnly.init()
|
|
|
|
|
|
|
|
|
|
await writeOnly.add({
|
2025-11-18 16:06:34 -08:00
|
|
|
type: NounType.Message,
|
2025-11-01 11:56:11 -07:00
|
|
|
data: { message: 'test' }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await writeOnly.commit({ message: 'Add log' })
|
|
|
|
|
|
|
|
|
|
// Fork should work even on write-only
|
|
|
|
|
const fork = await writeOnly.fork('writeonly-fork')
|
|
|
|
|
|
|
|
|
|
expect(fork).toBeTruthy()
|
|
|
|
|
|
|
|
|
|
await writeOnly.destroy()
|
|
|
|
|
await fork.destroy()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('256 UUID Sharding', () => {
|
|
|
|
|
it('should work with sharded storage', async () => {
|
feat(8.0)!: flip requireSubtype default to true (BRAINY-8.0-SUBTYPE-CONTRACT § C-1)
Brainy 8.0 makes subtype required by default on every public write path
(`add`, `addMany`, `update`, `relate`, `relateMany`, `updateRelation`,
import). Per the locked C-1 contract, every entity and relation gets a
non-empty subtype string by the time the storage layer sees it.
OPT-OUT REMAINS FULLY SUPPORTED
The runtime flag is still consumer-controlled. Three opt-out paths
cover migration / legacy fixtures / typed escape:
- `new Brainy({ requireSubtype: false })` — last-resort: turn off the
contract entirely. Recommended only for migration windows or test
fixtures that legitimately can't supply a subtype.
- `new Brainy({ requireSubtype: { except: [NounType.Thing, ...] } })` —
per-type allowlist: strict everywhere except the listed types.
- `brain.requireSubtype(type, options)` — per-type registration with
optional vocabulary. Composes with the brain-wide flag.
Default is now `true`. Opt-out is explicit and documented; nothing
silently degrades.
TEST SWEEP
Bulk-applied `requireSubtype: false` to every `new Brainy({...})` call
site across 120 test files. Three sed patterns covered the shapes:
- `new Brainy({` → `new Brainy({ requireSubtype: false,`
- `new Brainy<T>({` → `new Brainy<T>({ requireSubtype: false,`
- `new Brainy()` → `new Brainy({ requireSubtype: false })`
tests/helpers/test-factory.ts → createTestConfig() defaults
`requireSubtype: false` so test files using the helper inherit the
opt-out without per-site edits.
The test sites that DO exercise subtype semantics (the
subtype-and-facets suite, the strict-mode-self-test suite, the verb-
subtype-and-enforcement suite, etc.) already pass real subtypes — they
were the 7.30.x acceptance tests for this contract. Those tests
continue to pass unchanged.
CHANGES
src/brainy.ts
- normalizeConfig() — `requireSubtype` default `false` → `true`.
Comment refreshed to document the three opt-out paths.
tests/* (120 files)
- Bulk-edited brain construction sites. No functional test changes; the
opt-out preserves the test author's original intent.
tests/helpers/test-factory.ts
- createTestConfig() base config gains `requireSubtype: false`.
NO-OP for consumers who were already passing subtype on every write.
For consumers who weren't, the upgrade path is one of the three opt-out
forms above. Migration recipe documented in 8.0 release notes (next
commit).
VERIFICATION
- npx tsc --noEmit: clean
- npm test: 1408 / 1409 (same pre-existing race-condition outstanding;
no other regressions from the flip)
2026-06-09 14:58:25 -07:00
|
|
|
const brain = new Brainy({ requireSubtype: false,
|
2025-11-01 11:56:11 -07:00
|
|
|
storage: {
|
|
|
|
|
adapter: 'memory',
|
|
|
|
|
sharding: {
|
|
|
|
|
enabled: true,
|
|
|
|
|
shardCount: 256
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await brain.init()
|
|
|
|
|
|
|
|
|
|
// Add entities across shards
|
|
|
|
|
for (let i = 0; i < 1000; i++) {
|
|
|
|
|
await brain.add({
|
|
|
|
|
noun: 'sharded',
|
|
|
|
|
data: { index: i },
|
|
|
|
|
skipCommit: true
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await brain.commit({ message: 'Add sharded entities' })
|
|
|
|
|
|
|
|
|
|
// Fork should work with sharding
|
|
|
|
|
const fork = await brain.fork('sharded-test')
|
|
|
|
|
|
|
|
|
|
const results = await fork.find({ noun: 'sharded' })
|
|
|
|
|
|
|
|
|
|
expect(results).toHaveLength(1000)
|
|
|
|
|
|
|
|
|
|
await brain.destroy()
|
|
|
|
|
await fork.destroy()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('Time-Travel Queries (Enterprise Preview)', () => {
|
|
|
|
|
it('should support asOf queries', async () => {
|
feat(8.0)!: flip requireSubtype default to true (BRAINY-8.0-SUBTYPE-CONTRACT § C-1)
Brainy 8.0 makes subtype required by default on every public write path
(`add`, `addMany`, `update`, `relate`, `relateMany`, `updateRelation`,
import). Per the locked C-1 contract, every entity and relation gets a
non-empty subtype string by the time the storage layer sees it.
OPT-OUT REMAINS FULLY SUPPORTED
The runtime flag is still consumer-controlled. Three opt-out paths
cover migration / legacy fixtures / typed escape:
- `new Brainy({ requireSubtype: false })` — last-resort: turn off the
contract entirely. Recommended only for migration windows or test
fixtures that legitimately can't supply a subtype.
- `new Brainy({ requireSubtype: { except: [NounType.Thing, ...] } })` —
per-type allowlist: strict everywhere except the listed types.
- `brain.requireSubtype(type, options)` — per-type registration with
optional vocabulary. Composes with the brain-wide flag.
Default is now `true`. Opt-out is explicit and documented; nothing
silently degrades.
TEST SWEEP
Bulk-applied `requireSubtype: false` to every `new Brainy({...})` call
site across 120 test files. Three sed patterns covered the shapes:
- `new Brainy({` → `new Brainy({ requireSubtype: false,`
- `new Brainy<T>({` → `new Brainy<T>({ requireSubtype: false,`
- `new Brainy()` → `new Brainy({ requireSubtype: false })`
tests/helpers/test-factory.ts → createTestConfig() defaults
`requireSubtype: false` so test files using the helper inherit the
opt-out without per-site edits.
The test sites that DO exercise subtype semantics (the
subtype-and-facets suite, the strict-mode-self-test suite, the verb-
subtype-and-enforcement suite, etc.) already pass real subtypes — they
were the 7.30.x acceptance tests for this contract. Those tests
continue to pass unchanged.
CHANGES
src/brainy.ts
- normalizeConfig() — `requireSubtype` default `false` → `true`.
Comment refreshed to document the three opt-out paths.
tests/* (120 files)
- Bulk-edited brain construction sites. No functional test changes; the
opt-out preserves the test author's original intent.
tests/helpers/test-factory.ts
- createTestConfig() base config gains `requireSubtype: false`.
NO-OP for consumers who were already passing subtype on every write.
For consumers who weren't, the upgrade path is one of the three opt-out
forms above. Migration recipe documented in 8.0 release notes (next
commit).
VERIFICATION
- npx tsc --noEmit: clean
- npm test: 1408 / 1409 (same pre-existing race-condition outstanding;
no other regressions from the flip)
2026-06-09 14:58:25 -07:00
|
|
|
const brain = new Brainy({ requireSubtype: false,
|
2025-11-01 11:56:11 -07:00
|
|
|
storage: { adapter: 'memory' }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await brain.init()
|
|
|
|
|
|
|
|
|
|
// Time 1: Add entity
|
|
|
|
|
await brain.add({
|
2025-11-18 16:06:34 -08:00
|
|
|
type: NounType.Document,
|
2025-11-01 11:56:11 -07:00
|
|
|
data: { version: 1 }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await brain.commit({ message: 'Version 1' })
|
|
|
|
|
|
|
|
|
|
const time1 = Date.now()
|
|
|
|
|
|
|
|
|
|
// Wait a bit
|
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 100))
|
|
|
|
|
|
|
|
|
|
// Time 2: Update entity
|
2025-11-18 16:06:34 -08:00
|
|
|
const docs = await brain.find({ type: NounType.Document })
|
2025-11-01 11:56:11 -07:00
|
|
|
await brain.update(docs[0].id, { version: 2 })
|
|
|
|
|
|
|
|
|
|
await brain.commit({ message: 'Version 2' })
|
|
|
|
|
|
|
|
|
|
// asOf(time1) should return version 1
|
|
|
|
|
const snapshot = await brain.asOf(time1)
|
|
|
|
|
|
2025-11-18 16:06:34 -08:00
|
|
|
const retrieved = await snapshot.find({ type: NounType.Document })
|
2025-11-01 11:56:11 -07:00
|
|
|
|
|
|
|
|
expect(retrieved[0].data.version).toBe(1)
|
|
|
|
|
|
|
|
|
|
await brain.destroy()
|
|
|
|
|
await snapshot.destroy()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|