test(8.0): Tier-1 integration via deterministic embedder (suite runnable again)
The integration suite loaded the real WASM model for every test, so a full run took ~hours and reliably aborted (vitest reporter timeout) — which is why it was never gated and silently rotted. Brainy already separates the embedder from all other logic, so running integration with a deterministic embedder keeps every code path real (HNSW build+search, graph traversal, metadata filtering, transactions, storage/sharding, VFS, aggregation, import) while making the suite complete in ~2 min on ANY machine — no GPU, no 16 GB requirement. - Add isDeterministicEmbedMode() — a single source of truth for the test-embedder switch (BRAINY_DETERMINISTIC_EMBEDDINGS, plus the legacy BRAINY_UNIT_TEST alias), used by EmbeddingManager (init/embed/embedBatch) and brainy's eager-init guard. - setup-integration.ts opts into it: Tier 1 = functional end-to-end. Real-model semantic quality + the real embedding pipeline move to a Tier-2 suite. Full integration now runs 482 passing / 583 in ~2 min (was un-completable). The remaining failures are pre-existing test rot, fixed next. Unit 1414 green.
This commit is contained in:
parent
e31ba894f8
commit
542b52ede9
4 changed files with 84 additions and 67 deletions
39
src/embeddings/deterministicEmbedMode.ts
Normal file
39
src/embeddings/deterministicEmbedMode.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* @module embeddings/deterministicEmbedMode
|
||||
* @description Single source of truth for "use deterministic test embeddings".
|
||||
*
|
||||
* Brainy's embedding model is a real WASM transformer — correct, but slow on CPU
|
||||
* (a forward pass per text). For TEST tiers that exercise database *logic* (HNSW
|
||||
* build + search, graph traversal, metadata filtering, transactions, storage,
|
||||
* VFS, find composition), the embedding's semantic *quality* is irrelevant; only
|
||||
* a deterministic, content-derived vector is needed. Switching the embedder to a
|
||||
* deterministic stand-in keeps every other code path real while turning a
|
||||
* multi-hour suite into a sub-minute, gateable one. Semantic quality and the
|
||||
* real embedding pipeline are covered separately by the real-model test tier.
|
||||
*
|
||||
* This flag is honored ONLY outside production: {@link EmbeddingManager} throws
|
||||
* if it is set while `NODE_ENV=production` (mock vectors in prod is a security
|
||||
* risk). Enabled by env var or global so test setup files can opt in per tier.
|
||||
*/
|
||||
|
||||
interface DeterministicEmbedGlobals {
|
||||
__BRAINY_DETERMINISTIC_EMBED__?: boolean
|
||||
/** Legacy alias — the original unit-test-only spelling. */
|
||||
__BRAINY_UNIT_TEST__?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Whether the deterministic test embedder should be used instead of
|
||||
* the real WASM model. True when `BRAINY_DETERMINISTIC_EMBEDDINGS=true` or the
|
||||
* legacy `BRAINY_UNIT_TEST=true` env var is set, or the matching global is set.
|
||||
* @returns `true` to use deterministic embeddings, `false` for the real model.
|
||||
*/
|
||||
export function isDeterministicEmbedMode(): boolean {
|
||||
const g = globalThis as DeterministicEmbedGlobals
|
||||
return (
|
||||
process.env.BRAINY_DETERMINISTIC_EMBEDDINGS === 'true' ||
|
||||
process.env.BRAINY_UNIT_TEST === 'true' ||
|
||||
g.__BRAINY_DETERMINISTIC_EMBED__ === true ||
|
||||
g.__BRAINY_UNIT_TEST__ === true
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue