Skip to content

Commit 7393d27

Browse files
🐛 Clear IndexedDB kc_cache between cold batch retries (#15860)
* 🐛 Clear IndexedDB kc_cache between cold batch runs in cache compliance test Signed-off-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * 🐛 Clear IndexedDB kc_cache between cold batch retries in cache compliance test Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Signed-off-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 882cfbe commit 7393d27

1 file changed

Lines changed: 32 additions & 19 deletions

File tree

web/e2e/compliance/card-cache-compliance.spec.ts

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ const CI_TIMEOUT_MULTIPLIER = 2
151151
*/
152152
const WARM_TTC_THRESHOLD_MS = process.env.CI ? 45_000 : 500
153153
const MAX_REAL_CACHE_FAILURES = process.env.CI ? 1 : 0
154+
const CACHE_DB_NAME = 'kc_cache'
154155

155156

156157
// Mock data, setupAuth, setupLiveMocks, setLiveColdMode, navigateToBatch,
@@ -438,11 +439,36 @@ async function softNavigateToBatch(
438439
// Cache inspection helpers
439440
// ---------------------------------------------------------------------------
440441

442+
async function clearColdBatchStorage(page: Page): Promise<void> {
443+
await page.evaluate(async (cacheDbName: string) => {
444+
const KEEP_KEYS = new Set([
445+
'token', 'kc-demo-mode', 'demo-user-onboarded',
446+
'kubestellar-console-tour-completed', 'kc-user-cache',
447+
'kc-backend-status', 'kc-sqlite-migrated',
448+
])
449+
for (let i = localStorage.length - 1; i >= 0; i--) {
450+
const key = localStorage.key(i)
451+
if (!key || KEEP_KEYS.has(key)) continue
452+
localStorage.removeItem(key)
453+
}
454+
localStorage.setItem('kc-demo-mode', 'false')
455+
localStorage.setItem('token', 'test-token')
456+
localStorage.setItem('kc-agent-setup-dismissed', 'true')
457+
458+
await new Promise<void>((resolve) => {
459+
const req = indexedDB.deleteDatabase(cacheDbName)
460+
req.onsuccess = () => resolve()
461+
req.onerror = () => resolve()
462+
req.onblocked = () => resolve()
463+
})
464+
}, CACHE_DB_NAME)
465+
}
466+
441467
async function snapshotCacheState(page: Page): Promise<{
442468
indexedDBEntries: CacheEntry[]
443469
localStorageKeys: string[]
444470
}> {
445-
return await page.evaluate(async () => {
471+
return await page.evaluate(async (cacheDbName: string) => {
446472
// Read localStorage cache-related keys
447473
const lsKeys: string[] = []
448474
for (let i = 0; i < localStorage.length; i++) {
@@ -462,7 +488,7 @@ async function snapshotCacheState(page: Page): Promise<{
462488
dataSize: number; dataType: string; isArray: boolean; arrayLength: number | null;
463489
}>>((resolve) => {
464490
try {
465-
const req = indexedDB.open('kc_cache', 1)
491+
const req = indexedDB.open(cacheDbName, 1)
466492
req.onupgradeneeded = () => {
467493
const db = req.result
468494
if (!db.objectStoreNames.contains('cache')) {
@@ -508,7 +534,7 @@ async function snapshotCacheState(page: Page): Promise<{
508534
})
509535

510536
return { indexedDBEntries: idbEntries, localStorageKeys: lsKeys }
511-
})
537+
}, CACHE_DB_NAME)
512538
}
513539

514540
// Data delay is controlled via mockControl.setDelayMode(true) from shared mocks.
@@ -638,22 +664,9 @@ test('card cache compliance — storage and retrieval', async ({ page }, testInf
638664

639665
for (let batch = 0; batch < totalBatches; batch++) {
640666
// Clear caches before each batch — allowlist keeps only essential settings
641-
// so card-specific localStorage backup keys (e.g. nightly-e2e-cache) are cleared too
642-
await page.evaluate(() => {
643-
const KEEP_KEYS = new Set([
644-
'token', 'kc-demo-mode', 'demo-user-onboarded',
645-
'kubestellar-console-tour-completed', 'kc-user-cache',
646-
'kc-backend-status', 'kc-sqlite-migrated',
647-
])
648-
for (let i = localStorage.length - 1; i >= 0; i--) {
649-
const key = localStorage.key(i)
650-
if (!key || KEEP_KEYS.has(key)) continue
651-
localStorage.removeItem(key)
652-
}
653-
localStorage.setItem('kc-demo-mode', 'false')
654-
localStorage.setItem('token', 'test-token')
655-
localStorage.setItem('kc-agent-setup-dismissed', 'true')
656-
})
667+
// so card-specific localStorage backup keys (e.g. nightly-e2e-cache) and
668+
// IndexedDB cache state from previous retries are cleared too.
669+
await clearColdBatchStorage(page)
657670

658671
const manifest = await navigateToBatch(page, batch, BATCH_NAV_TIMEOUT_MS)
659672
const selected = manifest.selected || []

0 commit comments

Comments
 (0)