fix(8.0): close GA-blocking correctness gaps from the readiness audit
- Version-coupling cold-init: getBrainyVersion() returned a stale build-time
default ('3.14.0') on the FIRST synchronous call — the one loadPlugins() makes
to build context.version — because the package.json read was async. A native
provider declaring a realistic `>=8.0.0` range was therefore rejected on cold
init. version.ts now reads package.json synchronously (8.0 targets Node-like
runtimes only); added a cold-init coupling regression with a `^8.0.0` plugin.
- No-silent-failures on the highest-fan-in read path: getNouns()/getVerbs()
converted a storage read failure into a success-shaped empty page, which the
cold-start rebuild then read as "store empty" and skipped the rebuild — booting
a permanently-empty index with no signal (the same silent-failure class as the
phantom bug). Both now re-throw a named BrainyError; the rebuild path re-throws
read failures (fail loud) and records a queryable degraded state, surfaced via
checkHealth(), for non-fatal rebuild hiccups.
- LSM SSTable leak: graph compaction wrote a merged SSTable but only dropped the
old ones from the manifest, orphaning their payloads forever ("In production
we'd add a cleanup mechanism"). Added StorageAdapter.deleteMetadata() and now
reclaim each compacted-away SSTable.
- Documented the two headline methods add() and find() (the only undocumented
public methods on the class).
Full gate green: build, unit 1512, integration 607.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
40d2cd5419
commit
47e8031124
7 changed files with 291 additions and 133 deletions
|
|
@ -12,9 +12,17 @@
|
|||
* 6. a graceful decline (activate()→false) → no throw, loud warn
|
||||
*/
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { Brainy } from '../../src/brainy.js'
|
||||
import { getBrainyVersion } from '../../src/utils/version.js'
|
||||
import { pluginRangeSatisfies, type BrainyPlugin, type BrainyPluginContext } from '../../src/plugin.js'
|
||||
|
||||
const PACKAGE_VERSION: string = JSON.parse(
|
||||
readFileSync(join(dirname(fileURLToPath(import.meta.url)), '../../package.json'), 'utf8')
|
||||
).version
|
||||
|
||||
function memBrain(): Brainy {
|
||||
return new Brainy({ requireSubtype: false, storage: { type: 'memory' }, silent: true })
|
||||
}
|
||||
|
|
@ -44,6 +52,21 @@ describe('pluginRangeSatisfies (dep-free range matcher)', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('getBrainyVersion() — synchronously correct on first call', () => {
|
||||
it('returns the real package version, not a stale build-time default', () => {
|
||||
// Regression: the version was read async, so the FIRST (synchronous) call —
|
||||
// the one loadPlugins() makes to build context.version — returned a stale
|
||||
// default ('3.14.0'), which fails any realistic cor 3.x `>=8.0.0` range and
|
||||
// hard-rejects the matched native pairing on cold init. The sync read makes
|
||||
// the first call correct.
|
||||
const v = getBrainyVersion()
|
||||
expect(v).toBe(PACKAGE_VERSION)
|
||||
expect(v).not.toBe('3.14.0')
|
||||
expect(v).not.toBe('0.0.0') // the unknown-read sentinel must not surface in a real install
|
||||
expect(v.startsWith('8.')).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
/** A minimal fake plugin; `onActivate` lets a test register providers / throw. */
|
||||
function fakePlugin(
|
||||
name: string,
|
||||
|
|
@ -72,6 +95,17 @@ describe('version coupling at init() — no silent fallback', () => {
|
|||
await brain.close()
|
||||
})
|
||||
|
||||
it('does NOT throw for a realistic cor 3.x range (^8.0.0) on a COLD init', async () => {
|
||||
// The actual regression: loadPlugins() is the first init step and makes the
|
||||
// first getBrainyVersion() call, so a stale sync default would reject a
|
||||
// correctly-matched native provider declaring the real 8.x range. A fresh
|
||||
// brain registering a `^8.0.0` plugin must init cleanly.
|
||||
const brain = memBrain()
|
||||
brain.use(fakePlugin('@fake/cor-3x', { brainyRange: '^8.0.0' }))
|
||||
await expect(brain.init()).resolves.toBeUndefined()
|
||||
await brain.close()
|
||||
})
|
||||
|
||||
it('throws (does not swallow) when activate() throws', async () => {
|
||||
const brain = memBrain()
|
||||
brain.use(fakePlugin('@fake/boom', { onActivate: () => { throw new Error('kaboom') } }))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue