3 months ago
c4eae96Bun'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