|
7 | 7 | deleteCacheEntry, |
8 | 8 | clearCache, |
9 | 9 | evictStaleEntries, |
10 | | - evictByPrefix, |
11 | 10 | cachedFetch, |
12 | 11 | } from "../../src/app/stores/cache"; |
13 | 12 |
|
@@ -203,64 +202,6 @@ describe("evictStaleEntries", () => { |
203 | 202 | }); |
204 | 203 | }); |
205 | 204 |
|
206 | | -// ── qa-8: evictByPrefix ────────────────────────────────────────────────────── |
207 | | - |
208 | | -describe("evictByPrefix", () => { |
209 | | - it("deletes prefix entries not in keepKeys, retains kept and non-prefix entries", async () => { |
210 | | - // Seed two "pr-detail:" entries and one non-prefixed entry |
211 | | - await setCacheEntry("pr-detail:octocat/Hello-World:42", { pr: 42 }, "etag-42"); |
212 | | - await setCacheEntry("pr-detail:octocat/Hello-World:99", { pr: 99 }, "etag-99"); |
213 | | - await setCacheEntry("other:key", { other: true }, "etag-other"); |
214 | | - |
215 | | - // Keep pr-detail:octocat/Hello-World:42 but evict :99 |
216 | | - const keepKeys = new Set(["pr-detail:octocat/Hello-World:42"]); |
217 | | - const count = await evictByPrefix("pr-detail:", keepKeys); |
218 | | - |
219 | | - // Only :99 should have been evicted |
220 | | - expect(count).toBe(1); |
221 | | - // Kept prefix entry must still exist |
222 | | - expect(await getCacheEntry("pr-detail:octocat/Hello-World:42")).toBeDefined(); |
223 | | - // Evicted prefix entry must be gone |
224 | | - expect(await getCacheEntry("pr-detail:octocat/Hello-World:99")).toBeUndefined(); |
225 | | - // Non-prefix entry must be untouched |
226 | | - expect(await getCacheEntry("other:key")).toBeDefined(); |
227 | | - }); |
228 | | - |
229 | | - it("evicts all prefix entries when keepKeys is empty", async () => { |
230 | | - await setCacheEntry("pr-detail:a/b:1", { pr: 1 }, null); |
231 | | - await setCacheEntry("pr-detail:a/b:2", { pr: 2 }, null); |
232 | | - await setCacheEntry("keep:this", { keep: true }, null); |
233 | | - |
234 | | - const count = await evictByPrefix("pr-detail:", new Set()); |
235 | | - |
236 | | - expect(count).toBe(2); |
237 | | - expect(await getCacheEntry("pr-detail:a/b:1")).toBeUndefined(); |
238 | | - expect(await getCacheEntry("pr-detail:a/b:2")).toBeUndefined(); |
239 | | - expect(await getCacheEntry("keep:this")).toBeDefined(); |
240 | | - }); |
241 | | - |
242 | | - it("returns 0 when no entries match the prefix", async () => { |
243 | | - await setCacheEntry("other:entry", { data: true }, null); |
244 | | - |
245 | | - const count = await evictByPrefix("pr-detail:", new Set()); |
246 | | - |
247 | | - expect(count).toBe(0); |
248 | | - expect(await getCacheEntry("other:entry")).toBeDefined(); |
249 | | - }); |
250 | | - |
251 | | - it("returns 0 when all prefix entries are in keepKeys", async () => { |
252 | | - await setCacheEntry("pr-detail:x/y:1", { pr: 1 }, null); |
253 | | - await setCacheEntry("pr-detail:x/y:2", { pr: 2 }, null); |
254 | | - |
255 | | - const keepKeys = new Set(["pr-detail:x/y:1", "pr-detail:x/y:2"]); |
256 | | - const count = await evictByPrefix("pr-detail:", keepKeys); |
257 | | - |
258 | | - expect(count).toBe(0); |
259 | | - expect(await getCacheEntry("pr-detail:x/y:1")).toBeDefined(); |
260 | | - expect(await getCacheEntry("pr-detail:x/y:2")).toBeDefined(); |
261 | | - }); |
262 | | -}); |
263 | | - |
264 | 205 | describe("cachedFetch", () => { |
265 | 206 | it("calls fetchFn with null headers when no cache entry exists", async () => { |
266 | 207 | const fetchFn = vi.fn().mockResolvedValue({ |
|
0 commit comments