test(memory-b): add F8 checkpoint for width validation

This commit is contained in:
2026-11-01 11:01:44 +08:00
parent b5d3f6ec73
commit 96adb172eb

View File

@ -441,6 +441,41 @@ await checkpoint('F7', 'store stats groups active and stale fingerprints with DB
}
})
// ── F8: explicit width errors, provider width errors degrade ─────────────
await checkpoint('F8', 'dimension validation separates caller errors from provider degradation', async () => {
const explicitApp = makeApp()
const explicit = applyMemory(explicitApp.ctx, {
path: join(workspace, 'f8-explicit.db'),
embedder: { info: () => ({ fingerprint: 'fp-f8', dimension: 3 }), embedText: async () => [1, 0, 0] },
})
try {
await assert.rejects(
() => explicit.commit({ text: 'F8 caller error', vector: [1, 2], fingerprint: 'fp-f8' }),
/does not match the active space/,
)
assert.equal(explicit.store.countBlocks(), 0, 'caller width error must not write a block')
await explicit.commit({ text: 'F8 matching caller vector', vector: [1, 2, 3], fingerprint: 'fp-f8' })
assert.equal(explicit.store.countBlocks(), 1, 'matching explicit vector is accepted')
} finally {
await explicitApp.ctx.fiber.dispose()
}
const providerApp = makeApp()
const provider = applyMemory(providerApp.ctx, {
path: join(workspace, 'f8-provider.db'),
embedder: { info: () => ({ fingerprint: 'fp-f8-provider', dimension: 3 }), embedText: async () => [1, 2] },
})
try {
const result = await provider.commit({ text: 'F8 provider error' })
assert.equal(result.embedded, false, 'provider width error must degrade without throwing')
assert.equal(provider.store.countBlocks(), 1, 'degraded provider write still persists the block')
assert.equal(provider.store.allBlocks(1)[0].vector, '', 'the bad provider vector is not stored')
} finally {
await providerApp.ctx.fiber.dispose()
}
return 'caller wrong width: rejected/no row; matching width: accepted; provider wrong width: degraded/row retained/vector empty'
})
// ── cleanup ───────────────────────────────────────────────────────────────
rmSync(workspace, { recursive: true, force: true })