fix: cherry-pick improvements from feature/semantic_caching

- semantic-cache.ts: use upsert instead of add to avoid duplicate-ID errors
- semantic-cache.ts: add crypto.randomUUID() fallback for constrained runtimes
- ollama-client.ts: JSON.stringify non-string Ollama errors to avoid [object Object]
- tests: update semantic-cache mocks and assertions for upsert
This commit is contained in:
2026-05-19 18:02:23 +02:00
parent 378642152e
commit d31c989423
3 changed files with 28 additions and 9 deletions
+3 -2
View File
@@ -10,6 +10,7 @@ jest.mock('chromadb', () => ({
getOrCreateCollection: jest.fn().mockResolvedValue({
query: jest.fn(),
add: jest.fn(),
upsert: jest.fn(),
reset: jest.fn(),
}),
deleteCollection: jest.fn(),
@@ -135,13 +136,13 @@ describe('SemanticCacheService', () => {
await disabledCacheService.setCache('test query', 'test response');
expect(mockCollection.add).not.toHaveBeenCalled();
expect(mockCollection.upsert).not.toHaveBeenCalled();
});
it('should add content to cache', async () => {
await cacheService.setCache('test query', 'test response');
expect(mockCollection.add).toHaveBeenCalled();
expect(mockCollection.upsert).toHaveBeenCalled();
});
});