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)
This commit is contained in:
David Snelling 2026-06-09 14:58:25 -07:00
parent 221fc45889
commit 780fb6444b
117 changed files with 282 additions and 282 deletions

View file

@ -22,7 +22,7 @@ import type { StorageAdapter } from '../../src/storage/adapters/baseStorageAdapt
describe('COW Full Integration', () => {
describe('Storage Adapter Compatibility', () => {
it('should work with Memory adapter', async () => {
const brain = new Brainy({
const brain = new Brainy({ requireSubtype: false,
storage: { adapter: 'memory' }
})
@ -46,7 +46,7 @@ describe('COW Full Integration', () => {
})
it('should work with FileSystem adapter', async () => {
const brain = new Brainy({
const brain = new Brainy({ requireSubtype: false,
storage: {
adapter: 'filesystem',
path: '/tmp/brainy-cow-test-fs'
@ -70,7 +70,7 @@ describe('COW Full Integration', () => {
})
it('should work with TypeAware adapter (most advanced)', async () => {
const brain = new Brainy({
const brain = new Brainy({ requireSubtype: false,
storage: {
adapter: 'typeaware',
path: '/tmp/brainy-cow-test-typeaware'
@ -96,7 +96,7 @@ describe('COW Full Integration', () => {
// Note: S3/R2/GCS/Azure tests require cloud credentials
// Run these in CI/CD with proper credentials
it.skip('should work with S3 adapter', async () => {
const brain = new Brainy({
const brain = new Brainy({ requireSubtype: false,
storage: {
adapter: 's3',
bucket: 'test-brainy-cow',
@ -123,7 +123,7 @@ describe('COW Full Integration', () => {
describe('Billion-Scale Performance', () => {
it('should fork 1M entities in < 2 seconds', async () => {
const brain = new Brainy({
const brain = new Brainy({ requireSubtype: false,
storage: { adapter: 'memory' }
})
@ -172,7 +172,7 @@ describe('COW Full Integration', () => {
}, 120000) // 2-minute timeout for 1M entity test
it('should deduplicate billions of identical vectors', async () => {
const brain = new Brainy({
const brain = new Brainy({ requireSubtype: false,
storage: { adapter: 'memory' }
})
@ -208,7 +208,7 @@ describe('COW Full Integration', () => {
describe('find() Integration', () => {
it('should work with graph-aware find() queries', async () => {
const brain = new Brainy({
const brain = new Brainy({ requireSubtype: false,
storage: { adapter: 'memory' }
})
@ -249,7 +249,7 @@ describe('COW Full Integration', () => {
})
it('should preserve metadata index across fork', async () => {
const brain = new Brainy({
const brain = new Brainy({ requireSubtype: false,
storage: { adapter: 'memory' }
})
@ -284,7 +284,7 @@ describe('COW Full Integration', () => {
describe('Triple Intelligence Integration', () => {
it('should preserve Triple Intelligence across fork', async () => {
const brain = new Brainy({
const brain = new Brainy({ requireSubtype: false,
storage: { adapter: 'memory' },
intelligence: {
enabled: true,
@ -320,7 +320,7 @@ describe('COW Full Integration', () => {
describe('VFS Integration', () => {
it('should preserve VFS structure across fork', async () => {
const brain = new Brainy({
const brain = new Brainy({ requireSubtype: false,
storage: { adapter: 'memory' },
vfs: { enabled: true }
})
@ -345,7 +345,7 @@ describe('COW Full Integration', () => {
})
it('should support VFS paths in billions of entities', async () => {
const brain = new Brainy({
const brain = new Brainy({ requireSubtype: false,
storage: { adapter: 'memory' },
vfs: { enabled: true }
})
@ -376,7 +376,7 @@ describe('COW Full Integration', () => {
describe('All 4 Indexes Integration', () => {
it('should preserve HNSW index across fork', async () => {
const brain = new Brainy({
const brain = new Brainy({ requireSubtype: false,
storage: { adapter: 'memory' }
})
@ -407,7 +407,7 @@ describe('COW Full Integration', () => {
})
it('should preserve GraphAdjacency index across fork', async () => {
const brain = new Brainy({
const brain = new Brainy({ requireSubtype: false,
storage: { adapter: 'memory' }
})
@ -434,7 +434,7 @@ describe('COW Full Integration', () => {
})
it('should preserve DeletedItems index across fork', async () => {
const brain = new Brainy({
const brain = new Brainy({ requireSubtype: false,
storage: { adapter: 'memory' }
})
@ -461,7 +461,7 @@ describe('COW Full Integration', () => {
describe('Distributed Mode', () => {
it('should work with read-only instances', async () => {
// Main brain (read-write)
const main = new Brainy({
const main = new Brainy({ requireSubtype: false,
storage: { adapter: 'memory' }
})
@ -475,7 +475,7 @@ describe('COW Full Integration', () => {
await main.commit({ message: 'Add entity' })
// Read-only instance (shares storage)
const readonly = new Brainy({
const readonly = new Brainy({ requireSubtype: false,
storage: main.config.storage,
readOnly: true
})
@ -499,7 +499,7 @@ describe('COW Full Integration', () => {
it('should work with write-only instances', async () => {
// Write-only instance
const writeOnly = new Brainy({
const writeOnly = new Brainy({ requireSubtype: false,
storage: { adapter: 'memory' },
writeOnly: true
})
@ -525,7 +525,7 @@ describe('COW Full Integration', () => {
describe('256 UUID Sharding', () => {
it('should work with sharded storage', async () => {
const brain = new Brainy({
const brain = new Brainy({ requireSubtype: false,
storage: {
adapter: 'memory',
sharding: {
@ -562,7 +562,7 @@ describe('COW Full Integration', () => {
describe('Time-Travel Queries (Enterprise Preview)', () => {
it('should support asOf queries', async () => {
const brain = new Brainy({
const brain = new Brainy({ requireSubtype: false,
storage: { adapter: 'memory' }
})