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 () => {
const results = await brain.find({
where: { category: 'test-category' },

View file

@ -7,7 +7,7 @@
* - 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 { NounType } from '../../src/types/graphTypes.js'
@ -19,6 +19,10 @@ describe('Entity Confidence & Weight Exposure', () => {
await brain.init()
})
afterEach(async () => {
await brain.close()
})
describe('Entity interface', () => {
it('should expose confidence when adding entity with confidence', async () => {
const id = await brain.add({

View file

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

View file

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

View file

@ -9,7 +9,7 @@
* - 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 { RevisionConflictError } from '../../src/transaction/RevisionConflictError.js'
import { NounType } from '../../src/types/graphTypes.js'
@ -22,6 +22,10 @@ describe('7.31.0 — _rev CAS + ifAbsent', () => {
await brain.init()
})
afterEach(async () => {
await brain.close()
})
describe('_rev initialization + surface', () => {
it('initializes _rev to 1 on add()', async () => {
const id = await brain.add({ data: 'hello', type: NounType.Document })

View file

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

View file

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