test(hygiene): close every brain the unit suite creates
Each file opened one or more Brainy instances (beforeEach, or a small per-test helper like migration-gate-family-scoped's module-level seed()) and never closed them. migration-gate-family-scoped.test.ts now tracks every brain seed() hands back in a describe-scoped array drained by afterEach, since the helper itself lives outside the describe block.
This commit is contained in:
parent
d6e7453f1f
commit
de79d6b5a4
16 changed files with 83 additions and 15 deletions
|
|
@ -18,7 +18,7 @@
|
|||
* exercised by cor's combined matrix); they inject probe/spy hooks onto the live JS
|
||||
* metadata index, which has neither method by default.
|
||||
*/
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
||||
import { Brainy } from '../../../src/brainy'
|
||||
import { NounType } from '../../../src/types/graphTypes'
|
||||
|
||||
|
|
@ -34,6 +34,10 @@ describe('metadata-provider contract wiring (getIdsForFilter opts)', () => {
|
|||
mi = (brain as any).metadataIndex
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await brain.close()
|
||||
})
|
||||
|
||||
it('RETIRED: a read never calls probeConsistency() / self-heals via detectAndRepairCorruption — that is the read-triggered dark rebuild the health-gate law forbids', async () => {
|
||||
let probes = 0
|
||||
let repairs = 0
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
* gate that hung getStats / readdir / readFile behind an unrelated family's
|
||||
* migration until the wait timed out.
|
||||
*/
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
||||
import { Brainy } from '../../../src/brainy.js'
|
||||
import { MigrationInProgressError } from '../../../src/errors/brainyError.js'
|
||||
|
||||
|
|
@ -38,12 +38,19 @@ const jam = (provider: unknown) => {
|
|||
}
|
||||
|
||||
describe('migration LOCK is family-scoped', () => {
|
||||
const opened: Brainy[] = []
|
||||
|
||||
beforeEach(() => {
|
||||
process.env.BRAINY_DETERMINISTIC_EMBEDDINGS = 'true'
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
for (const b of opened.splice(0)) await b.close().catch(() => {})
|
||||
})
|
||||
|
||||
it('a stuck VECTOR migration does not block canonical or graph/metadata reads', async () => {
|
||||
const brain = await seed()
|
||||
opened.push(brain)
|
||||
const childId = (
|
||||
(await brain.vfs.readdir('/notes', { withFileTypes: true })) as Array<{ entityId: string }>
|
||||
)[0].entityId
|
||||
|
|
@ -60,6 +67,7 @@ describe('migration LOCK is family-scoped', () => {
|
|||
|
||||
it('a stuck VECTOR migration STILL blocks a read that needs the vector family', async () => {
|
||||
const brain = await seed()
|
||||
opened.push(brain)
|
||||
jam((brain as any).index)
|
||||
|
||||
// A semantic query consults the vector index — it must wait, and (bounded by
|
||||
|
|
@ -70,6 +78,7 @@ describe('migration LOCK is family-scoped', () => {
|
|||
|
||||
it('a stuck GRAPH migration blocks traversal but not vector/canonical reads', async () => {
|
||||
const brain = await seed()
|
||||
opened.push(brain)
|
||||
const childId = (
|
||||
(await brain.vfs.readdir('/notes', { withFileTypes: true })) as Array<{ entityId: string }>
|
||||
)[0].entityId
|
||||
|
|
@ -87,6 +96,7 @@ describe('migration LOCK is family-scoped', () => {
|
|||
|
||||
it('with no migration in flight, every read serves (the fast path is a no-op)', async () => {
|
||||
const brain = await seed()
|
||||
opened.push(brain)
|
||||
await expect(brain.getStats()).resolves.toBeDefined()
|
||||
await expect(brain.find({ query: 'doc' })).resolves.toBeDefined()
|
||||
await expect(brain.vfs.readdir('/notes')).resolves.toHaveLength(1)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ describe('Duplicate Check Optimization', () => {
|
|||
})
|
||||
|
||||
afterEach(async () => {
|
||||
// Cleanup is automatic with memory storage
|
||||
await brain.close()
|
||||
})
|
||||
|
||||
it('should detect duplicate relationships using GraphAdjacencyIndex', async () => {
|
||||
|
|
|
|||
Reference in a new issue