Add projects
This commit is contained in:
parent
2d3a9ad623
commit
8b607dd700
1802 changed files with 503346 additions and 2 deletions
31
frontend/tests/providerRecentRequestsIsolation.test.ts
Normal file
31
frontend/tests/providerRecentRequestsIsolation.test.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { describe, expect, test } from 'vitest';
|
||||
import { createProviderRecentRequestsCacheController } from '../src/components/providers/hooks/useProviderRecentRequests';
|
||||
|
||||
describe('provider recent request cache isolation', () => {
|
||||
test('creates a fresh cache when the backend or management key changes', () => {
|
||||
const controller = createProviderRecentRequestsCacheController();
|
||||
const serverA = controller.forScope('https://server-a.example', 'key-a');
|
||||
serverA.cachedUsageByProvider = new Map([['provider-a', new Map()]]);
|
||||
serverA.cachedAt = Date.now();
|
||||
serverA.inFlightRequest = Promise.resolve(serverA.cachedUsageByProvider);
|
||||
|
||||
const serverB = controller.forScope('https://server-b.example', 'key-b');
|
||||
|
||||
expect(serverB).not.toBe(serverA);
|
||||
expect(serverB.cachedUsageByProvider.size).toBe(0);
|
||||
expect(serverB.cachedAt).toBe(0);
|
||||
expect(serverB.inFlightRequest).toBeNull();
|
||||
|
||||
serverA.cachedUsageByProvider = new Map([['late-provider-a', new Map()]]);
|
||||
expect(controller.forScope('https://server-b.example', 'key-b')).toBe(serverB);
|
||||
expect(serverB.cachedUsageByProvider.size).toBe(0);
|
||||
});
|
||||
|
||||
test('reuses the cache only within the same connection scope', () => {
|
||||
const controller = createProviderRecentRequestsCacheController();
|
||||
const first = controller.forScope('https://server.example', 'key-a');
|
||||
|
||||
expect(controller.forScope('https://server.example', 'key-a')).toBe(first);
|
||||
expect(controller.forScope('https://server.example', 'key-b')).not.toBe(first);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue