Home

giogio / openez-graph

public
Overview Code History Branches Pull requestsIssuesInsights
main
HomeOverview Code PRsIssues

test: restore embedding mock after hybrid-retrieval to prevent cross-file leak

3 months ago

c4eae96
Authored
asta-nguyen8/7/2026, 4:02:25 AM
Bun's mock.module is process-global unlike vitest's vi.mock, and cannot be
restored in bun 1.3.14 (neither mock.restore() nor re-mocking reverts the
cached namespace). Replace mock.module with spyOn on getEmbeddingProvider so
the spy can be reverted in afterAll, preventing the mock from leaking into
other test files that run in the same bun test process.

Also fix a related tokenizer leak: splitToTokenLimit used the real BPE
tokenizer for splitting even in fast mode (when gpt-tokenizer was already
loaded by an earlier retrieval call), while countTokens used the char-based
approximation. This mismatch produced chunks counted above the 1024 bound.
Guard the BPE path with !_fastMode so splitting and counting stay consistent.

Parent9ba276d

2 files changed
  • packages/core/src/tokenizer.ts+4−1
  • tests/hybrid-retrieval.test.ts+22−14