import type { CacheSetOptions, CacheStats } from "@suaveplan/cache"; import { AbstractCache } from "@suaveplan/cache"; /** * In-memory `AbstractCache` used by every middleware/handle/plugin * unit test. Tracks every call shape (key, value, signal) so tests can assert * the exact arguments the middleware forwarded into the cache surface. * * This is a real class, not a mock — no `vi.mock`/`jest.mock` involved. */ export class FakeCache extends AbstractCache { public store = new Map(); public getCalls: { key: string; signal?: AbortSignal }[] = []; public setCalls: { key: string; value: Uint8Array }[] = []; public deleteCalls: string[] = []; public clearCalls = 0; public throwOnGet: Error | undefined; public throwOnSet: Error | undefined; public throwOnDelete: Error | undefined; public async get( key: string, signal?: AbortSignal ): Promise { this.getCalls.push({ key, signal }); if (this.throwOnGet !== undefined) throw this.throwOnGet; return this.store.get(key); } public async set( key: string, value: Uint8Array, _options?: CacheSetOptions ): Promise { this.setCalls.push({ key, value }); if (this.throwOnSet !== undefined) throw this.throwOnSet; this.store.set(key, value); } public async delete(key: string): Promise { this.deleteCalls.push(key); if (this.throwOnDelete !== undefined) throw this.throwOnDelete; return this.store.delete(key); } public async clear(): Promise { this.clearCalls += 1; this.store.clear(); } public async has(key: string): Promise { return this.store.has(key); } public getStats(): CacheStats { return { hits: 0, misses: 0, size: this.store.size, hitRate: 0, evictions: 0, }; } }