test(hygiene): close every brain the integration suite creates

Each file opened a Brainy in beforeAll/beforeEach (or a single it()) and
never closed it. related-verb-array.test.ts and vfs-containment-batched.test.ts
were real bugs: their afterAll discarded the brain with `brain = null as any`
without ever calling close() first.
This commit is contained in:
David Snelling 2026-09-03 09:06:04 -07:00
parent 4c344782a7
commit d6e7453f1f
7 changed files with 24 additions and 5 deletions

View file

@ -34,6 +34,10 @@ describe('API Parameter Validation', () => {
}) })
}) })
afterAll(async () => {
await brain.close()
})
it('should use "where" parameter for metadata filtering', async () => { it('should use "where" parameter for metadata filtering', async () => {
const results = await brain.find({ const results = await brain.find({
where: { category: 'test-category' }, where: { category: 'test-category' },

View file

@ -7,7 +7,7 @@
* - Backward compatibility preserved * - Backward compatibility preserved
*/ */
import { describe, it, expect, beforeEach } from 'vitest' import { describe, it, expect, beforeEach, afterEach } from 'vitest'
import { Brainy } from '../../src/brainy.js' import { Brainy } from '../../src/brainy.js'
import { NounType } from '../../src/types/graphTypes.js' import { NounType } from '../../src/types/graphTypes.js'
@ -19,6 +19,10 @@ describe('Entity Confidence & Weight Exposure', () => {
await brain.init() await brain.init()
}) })
afterEach(async () => {
await brain.close()
})
describe('Entity interface', () => { describe('Entity interface', () => {
it('should expose confidence when adding entity with confidence', async () => { it('should expose confidence when adding entity with confidence', async () => {
const id = await brain.add({ const id = await brain.add({

View file

@ -30,6 +30,7 @@ describe('related() with a verb-type array returns every requested type', () =>
}) })
afterAll(async () => { afterAll(async () => {
await brain.close()
brain = null as any brain = null as any
}) })

View file

@ -59,7 +59,8 @@ describe('Relationship Intelligence', () => {
await brain.init() await brain.init()
}) })
afterEach(() => { afterEach(async () => {
await brain.close()
if (fs.existsSync(testDir)) { if (fs.existsSync(testDir)) {
fs.rmSync(testDir, { recursive: true }) fs.rmSync(testDir, { recursive: true })
} }

View file

@ -9,7 +9,7 @@
* - addMany({ ifAbsent: true }) applies the flag to every item * - addMany({ ifAbsent: true }) applies the flag to every item
*/ */
import { describe, it, expect, beforeEach } from 'vitest' import { describe, it, expect, beforeEach, afterEach } from 'vitest'
import { Brainy } from '../../src/brainy.js' import { Brainy } from '../../src/brainy.js'
import { RevisionConflictError } from '../../src/transaction/RevisionConflictError.js' import { RevisionConflictError } from '../../src/transaction/RevisionConflictError.js'
import { NounType } from '../../src/types/graphTypes.js' import { NounType } from '../../src/types/graphTypes.js'
@ -22,6 +22,10 @@ describe('7.31.0 — _rev CAS + ifAbsent', () => {
await brain.init() await brain.init()
}) })
afterEach(async () => {
await brain.close()
})
describe('_rev initialization + surface', () => { describe('_rev initialization + surface', () => {
it('initializes _rev to 1 on add()', async () => { it('initializes _rev to 1 on add()', async () => {
const id = await brain.add({ data: 'hello', type: NounType.Document }) const id = await brain.add({ data: 'hello', type: NounType.Document })

View file

@ -81,6 +81,7 @@ describe('repairContainment: batched pass 2', () => {
}) })
afterAll(async () => { afterAll(async () => {
await brain.close()
brain = null as any brain = null as any
}) })

View file

@ -9,6 +9,7 @@ import * as XLSX from 'xlsx'
describe('VFS Debug', () => { describe('VFS Debug', () => {
it('minimal VFS writeFile test', async () => { it('minimal VFS writeFile test', async () => {
const brain = new Brainy({ requireSubtype: false, storage: { type: 'memory' } }) const brain = new Brainy({ requireSubtype: false, storage: { type: 'memory' } })
try {
await brain.init() await brain.init()
console.log('✅ Brain initialized') console.log('✅ Brain initialized')
@ -77,5 +78,8 @@ describe('VFS Debug', () => {
// THE REAL TEST: Can we query VFS? // THE REAL TEST: Can we query VFS?
expect(children.length).toBeGreaterThan(0) expect(children.length).toBeGreaterThan(0)
expect(rootContents.length).toBeGreaterThan(0) expect(rootContents.length).toBeGreaterThan(0)
} finally {
await brain.close()
}
}) })
}) })