chore(8.0): final pre-RC1 sweep — API consistency, named errors, orphans, zero-cast codebase

This commit is contained in:
David Snelling 2026-06-11 14:51:00 -07:00
parent 970e08c466
commit 1f7e365a4e
237 changed files with 1951 additions and 49413 deletions

View file

@ -1,8 +1,9 @@
/**
* Integration Tests for getRelations() Fix (v4.1.3)
* Integration Tests for related() call patterns
*
* Tests for Bug: getRelations() returns empty array when called without parameters
* This validates that the fix allows retrieving all relationships with proper pagination
* Regression coverage (originally a v4.1.3 fix): related() must return all
* relationships with proper pagination when called without parameters, and
* support the string-id shorthand.
*
* NO MOCKS - Real integration tests with actual storage
*/
@ -12,7 +13,7 @@ import { Brainy } from '../../src/brainy.js'
import { NounType, VerbType } from '../../src/types/graphTypes.js'
import * as fs from 'fs/promises'
describe('getRelations() Fix (v4.1.3)', () => {
describe('related() call patterns', () => {
let brain: Brainy
const testPath = './test-brainy-get-relations-fix'
@ -56,7 +57,7 @@ describe('getRelations() Fix (v4.1.3)', () => {
await brain.flush()
// Get all relationships - THIS IS THE BUG FIX!
const relations = await brain.getRelations()
const relations = await brain.related()
// Should return all 3 relationships
expect(relations).toHaveLength(3)
@ -70,7 +71,7 @@ describe('getRelations() Fix (v4.1.3)', () => {
await brain.flush()
// Get all relationships
const relations = await brain.getRelations()
const relations = await brain.related()
// Should return empty array
expect(relations).toHaveLength(0)
@ -100,11 +101,11 @@ describe('getRelations() Fix (v4.1.3)', () => {
await brain.flush()
// Get first page (limit: 10)
const page1 = await brain.getRelations({ limit: 10 })
const page1 = await brain.related({ limit: 10 })
expect(page1).toHaveLength(10)
// Get second page (offset: 10, limit: 10)
const page2 = await brain.getRelations({ offset: 10, limit: 10 })
const page2 = await brain.related({ offset: 10, limit: 10 })
expect(page2).toHaveLength(10)
// Ensure no duplicates between pages
@ -127,12 +128,12 @@ describe('getRelations() Fix (v4.1.3)', () => {
await brain.flush()
// Get only FriendOf relationships
const friendRelations = await brain.getRelations({ type: VerbType.FriendOf })
const friendRelations = await brain.related({ type: VerbType.FriendOf })
expect(friendRelations).toHaveLength(2)
expect(friendRelations.every(r => r.type === VerbType.FriendOf)).toBe(true)
// Get only WorksWith relationships
const workRelations = await brain.getRelations({ type: VerbType.WorksWith })
const workRelations = await brain.related({ type: VerbType.WorksWith })
expect(workRelations).toHaveLength(1)
expect(workRelations[0].type).toBe(VerbType.WorksWith)
})
@ -152,14 +153,14 @@ describe('getRelations() Fix (v4.1.3)', () => {
await brain.flush()
// Get all relationships first to verify total count
const allRelations = await brain.getRelations()
const allRelations = await brain.related()
expect(allRelations).toHaveLength(4)
// Get FriendOf and WorksWith relationships using type array filter
// NOTE: Current storage layer may not support array filters directly
// So we test each type separately and combine
const friendRelations = await brain.getRelations({ type: VerbType.FriendOf })
const workRelations = await brain.getRelations({ type: VerbType.WorksWith })
const friendRelations = await brain.related({ type: VerbType.FriendOf })
const workRelations = await brain.related({ type: VerbType.WorksWith })
expect(friendRelations).toHaveLength(2)
expect(workRelations).toHaveLength(1)
@ -169,7 +170,7 @@ describe('getRelations() Fix (v4.1.3)', () => {
})
describe('String ID Shorthand Syntax', () => {
it('should support string ID shorthand: getRelations(id)', async () => {
it('should support string ID shorthand: related(id)', async () => {
// Create entities
const person1 = await brain.add({ data: 'Alice', type: NounType.Person })
const person2 = await brain.add({ data: 'Bob', type: NounType.Person })
@ -181,14 +182,14 @@ describe('getRelations() Fix (v4.1.3)', () => {
await brain.flush()
// Use string shorthand - THIS IS THE NEW SIGNATURE!
const relations = await brain.getRelations(person1)
const relations = await brain.related(person1)
// Should return both relationships from person1
expect(relations).toHaveLength(2)
expect(relations.every(r => r.from === person1)).toBe(true)
})
it('should be equivalent to getRelations({ from: id })', async () => {
it('should be equivalent to related({ from: id })', async () => {
// Create entities and relationships
const person1 = await brain.add({ data: 'Alice', type: NounType.Person })
const person2 = await brain.add({ data: 'Bob', type: NounType.Person })
@ -196,8 +197,8 @@ describe('getRelations() Fix (v4.1.3)', () => {
await brain.flush()
// Both syntaxes should return the same results
const shorthand = await brain.getRelations(person1)
const explicit = await brain.getRelations({ from: person1 })
const shorthand = await brain.related(person1)
const explicit = await brain.related({ from: person1 })
expect(shorthand).toEqual(explicit)
})
@ -217,7 +218,7 @@ describe('getRelations() Fix (v4.1.3)', () => {
await brain.flush()
// Get relationships from person1
const relations = await brain.getRelations({ from: person1 })
const relations = await brain.related({ from: person1 })
expect(relations).toHaveLength(2)
expect(relations.every(r => r.from === person1)).toBe(true)
@ -235,7 +236,7 @@ describe('getRelations() Fix (v4.1.3)', () => {
await brain.flush()
// Get relationships to person3
const relations = await brain.getRelations({ to: person3 })
const relations = await brain.related({ to: person3 })
expect(relations).toHaveLength(2)
expect(relations.every(r => r.to === person3)).toBe(true)
@ -253,7 +254,7 @@ describe('getRelations() Fix (v4.1.3)', () => {
await brain.flush()
// Get only FriendOf relationships from person1
const relations = await brain.getRelations({
const relations = await brain.related({
from: person1,
type: VerbType.FriendOf
})
@ -290,7 +291,7 @@ describe('getRelations() Fix (v4.1.3)', () => {
// Should handle query without issues
const startTime = Date.now()
const relations = await brain.getRelations({ limit: 100 })
const relations = await brain.related({ limit: 100 })
const duration = Date.now() - startTime
expect(relations).toHaveLength(100)
@ -331,11 +332,11 @@ describe('getRelations() Fix (v4.1.3)', () => {
await brain.flush()
// Verify we have 150 total relationships
const allRelations = await brain.getRelations({ limit: 200 })
const allRelations = await brain.related({ limit: 200 })
expect(allRelations.length).toBe(150)
// Call without limit - should default to 100
const relations = await brain.getRelations()
const relations = await brain.related()
// Should return exactly 100 (default limit)
expect(relations).toHaveLength(100)
@ -364,11 +365,11 @@ describe('getRelations() Fix (v4.1.3)', () => {
await brain.flush()
// Verify we have 50 total
const all = await brain.getRelations({ limit: 100 })
const all = await brain.related({ limit: 100 })
expect(all.length).toBe(50)
// Custom limit of 25
const relations = await brain.getRelations({ limit: 25 })
const relations = await brain.related({ limit: 25 })
expect(relations).toHaveLength(25)
})
})
@ -377,7 +378,7 @@ describe('getRelations() Fix (v4.1.3)', () => {
it('should reproduce and fix the a consumer team bug scenario', async () => {
// Reproduce the exact scenario from the bug report:
// - 524 relationships exist in GraphAdjacencyIndex
// - brain.getRelations() was returning empty array
// - brain.related() was returning empty array
// Create entities similar to Consumer import
const entities = []
@ -407,7 +408,7 @@ describe('getRelations() Fix (v4.1.3)', () => {
await brain.flush()
// BUG FIX TEST: This should now return relationships, not empty array!
const relations = await brain.getRelations()
const relations = await brain.related()
// CRITICAL: Should NOT be empty
expect(relations.length).toBeGreaterThan(0)