test(hygiene): close every brain the remaining suites create
Some checks are pending
CI / Node 22 (push) Waiting to run
CI / Node 24 (push) Waiting to run
CI / Integration + conformance (Node 22) (push) Waiting to run
CI / Bun (latest) (push) Waiting to run
Some checks are pending
CI / Node 22 (push) Waiting to run
CI / Node 24 (push) Waiting to run
CI / Integration + conformance (Node 22) (push) Waiting to run
CI / Bun (latest) (push) Waiting to run
id-normalization.test.ts's makeBrain() and degraded-reads-surfaced.test.ts's per-test brains had nothing tracking them — both now use a describe-scoped opened[] array drained by afterEach. find-hybrid-filter-before-hydrate.test.ts had two beforeAll-built brains (one per describe block) with no matching afterAll. multi-process-safety.test.ts and plugin-autodetect.test.ts/plugin.test.ts left a brain whose init() was expected to reject (a rejected init() still registers the instance in Brainy's global instance registry — the constructor does that unconditionally — so it still needs close() to deregister, or the process-level shutdown hooks never see the registry go idle for the rest of the run).
This commit is contained in:
parent
be307a1579
commit
656d9f6f92
6 changed files with 50 additions and 5 deletions
|
|
@ -19,13 +19,19 @@ import { prodLog } from '../../../src/utils/logger.js'
|
|||
const UUID = (suffix: string): string => `00000000-0000-4000-8000-0000000000${suffix}`
|
||||
|
||||
describe('Finding 10 — degraded derived-index state is surfaced on reads', () => {
|
||||
const opened: Brainy[] = []
|
||||
|
||||
beforeEach(() => {
|
||||
process.env.BRAINY_DETERMINISTIC_EMBEDDINGS = 'true'
|
||||
})
|
||||
afterEach(() => vi.restoreAllMocks())
|
||||
afterEach(async () => {
|
||||
vi.restoreAllMocks()
|
||||
for (const b of opened.splice(0)) await b.close().catch(() => {})
|
||||
})
|
||||
|
||||
it('checkHealth() reports adopt-forward degraded ids as unhealthy', async () => {
|
||||
const brain = new Brainy({ storage: { type: 'memory' }, dimensions: 384, requireSubtype: false })
|
||||
opened.push(brain)
|
||||
await brain.init()
|
||||
;(brain as any)._indexDegradedIds.add(UUID('de'))
|
||||
|
||||
|
|
@ -37,6 +43,7 @@ describe('Finding 10 — degraded derived-index state is surfaced on reads', ()
|
|||
it('find()/get() warn loudly while degraded, ONCE, then repairIndex() clears it', async () => {
|
||||
const warn = vi.spyOn(prodLog, 'warn').mockImplementation(() => {})
|
||||
const brain = new Brainy({ storage: { type: 'memory' }, dimensions: 384, requireSubtype: false })
|
||||
opened.push(brain)
|
||||
await brain.init()
|
||||
await brain.add({ id: UUID('a1'), data: 'x', type: NounType.Document })
|
||||
;(brain as any)._indexRebuildFailed = new Error('rebuild boom')
|
||||
|
|
@ -59,6 +66,7 @@ describe('Finding 10 — degraded derived-index state is surfaced on reads', ()
|
|||
|
||||
it('persistSingleOp records receipt.degraded (widened return type, not dropped)', async () => {
|
||||
const brain = new Brainy({ storage: { type: 'memory' }, dimensions: 384, requireSubtype: false })
|
||||
opened.push(brain)
|
||||
await brain.init()
|
||||
// Simulate a degraded receipt by wrapping the generation store's commitSingleOp.
|
||||
const gs: any = (brain as any).generationStore
|
||||
|
|
|
|||
|
|
@ -89,12 +89,14 @@ describe('Guarded plugin auto-detection (plugins: undefined)', () => {
|
|||
})
|
||||
const brain: any = new Brainy({ requireSubtype: false, storage: { type: 'memory' }, silent: true })
|
||||
await expect(brain.init()).rejects.toThrow(/installed but failed to load/)
|
||||
await brain.close().catch(() => {})
|
||||
})
|
||||
|
||||
it('installed but not a valid plugin (missing activate) → init() throws', async () => {
|
||||
stubImport(async () => ({ default: { name: '@soulcraft/cor' } })) // no activate()
|
||||
const brain: any = new Brainy({ requireSubtype: false, storage: { type: 'memory' }, silent: true })
|
||||
await expect(brain.init()).rejects.toThrow(/not a valid Brainy plugin/)
|
||||
await brain.close().catch(() => {})
|
||||
})
|
||||
|
||||
it('installed but activation fails → init() throws (activateAll posture applies)', async () => {
|
||||
|
|
@ -108,6 +110,7 @@ describe('Guarded plugin auto-detection (plugins: undefined)', () => {
|
|||
}))
|
||||
const brain: any = new Brainy({ requireSubtype: false, storage: { type: 'memory' }, silent: true })
|
||||
await expect(brain.init()).rejects.toThrow(/failed to activate/)
|
||||
await brain.close().catch(() => {})
|
||||
})
|
||||
|
||||
it('plugins: [] and plugins: false → no probe at all (explicit opt-out)', async () => {
|
||||
|
|
@ -132,5 +135,6 @@ describe('Guarded plugin auto-detection (plugins: undefined)', () => {
|
|||
silent: true
|
||||
})
|
||||
await expect(brain.init()).rejects.toThrow(/listed in config\.plugins but could not be loaded/)
|
||||
await brain.close().catch(() => {})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -298,9 +298,10 @@ describe('Brainy plugin integration', () => {
|
|||
// must surface as a failed init(), NOT a silent degrade to the default
|
||||
// engine (the version-coupling guard; see plugin-version-coupling.test.ts).
|
||||
await expect(brain.init()).rejects.toThrow(/failed to activate|native module not found/)
|
||||
await brain.close().catch(() => {})
|
||||
})
|
||||
|
||||
it('should use() return this for chaining', () => {
|
||||
it('should use() return this for chaining', async () => {
|
||||
const plugin: BrainyPlugin = {
|
||||
name: 'chain-test',
|
||||
activate: async () => true
|
||||
|
|
@ -309,5 +310,8 @@ describe('Brainy plugin integration', () => {
|
|||
const brain = new Brainy({ requireSubtype: false, storage: { type: 'memory' } })
|
||||
const result = brain.use(plugin)
|
||||
expect(result).toBe(brain)
|
||||
// Never init()'d — the constructor still registered it in Brainy's global
|
||||
// instance registry, so it still needs a close() to deregister.
|
||||
await brain.close().catch(() => {})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Reference in a new issue