diff --git a/frontend-vue/src/pages/jd/jd-category-cache.ts b/frontend-vue/src/pages/jd/jd-category-cache.ts index 476bf1538..499725d95 100644 --- a/frontend-vue/src/pages/jd/jd-category-cache.ts +++ b/frontend-vue/src/pages/jd/jd-category-cache.ts @@ -94,13 +94,15 @@ export function saveCategoryCache(storage: StorageLike | null, cache: JdCategory } } -/** 清缓存(当前没有调用方;留给「换店/换号」这类显式失效场景)。 */ -export function clearCategoryCache(storage: StorageLike | null): void { - if (!storage) return +/** 清缓存;返回是否清掉了(`false` 只说明本次没清成,下一次成功同步会覆盖)。 */ +export function clearCategoryCache(storage: StorageLike | null): boolean { + if (!storage) return false try { storage.removeItem(JD_CATEGORY_CACHE_KEY) + return true } catch { - /* 清不掉不影响功能:下一次成功同步会覆盖 */ + // 隐私模式/配额异常下清不掉:把「没清成」交给调用方,不吞成"清过了"。 + return false } } diff --git a/frontend-vue/tests/catch-silence-ratchet.test.ts b/frontend-vue/tests/catch-silence-ratchet.test.ts index df9368bb5..bc7e182ec 100644 --- a/frontend-vue/tests/catch-silence-ratchet.test.ts +++ b/frontend-vue/tests/catch-silence-ratchet.test.ts @@ -95,7 +95,12 @@ const BASELINE = { // jd-publish.ts 新增 5 支 try/catch(分类/商品列表拉取失败落到界面反馈、激活失败 // 降级为提示由客户端兜底拉取认领、重试/建单入口异常 ElMessage),全部非静默 // ("新增静默文件"断言未触发),silent 一格没涨,只进 blocks。 - blocks: 324, + // 327 = 324 + 3(2026-11-19 京东店内分类本机缓存 jd-category-cache.ts,客户口径 + // 「同步后就记住呀 别每次都同步」):读缓存(脏 JSON/私有模式 ⇒ 返回 null=当没缓存)、 + // 写缓存(配额满 ⇒ 返回 false=这次没记住)、清缓存(清不掉 ⇒ 返回 false)三支。 + // 三支的兜法都是**把结果交给调用方**,没有 console 糊过去也没有吞成"成功", + // 所以 silent 一格没涨(仍 82)、perFile 台账无新增条目,只进 blocks。 + blocks: 327, // 2026-10-30(ops Phase 6/可读棘轮):ApiSecretSettingsPanel.vue 1113→775 行,面板里那处 // 静默 catch(余额查询失败只 console.warn、界面留空)随 loadBalance 整块搬进 // useProxyPlan.ts。不是新增静默:面板 1→0、新文件记 1,silent 总数与 blocks 都一格没动, diff --git a/frontend-vue/tests/jd-category-cache.test.ts b/frontend-vue/tests/jd-category-cache.test.ts index 1b2701444..ae40adf82 100644 --- a/frontend-vue/tests/jd-category-cache.test.ts +++ b/frontend-vue/tests/jd-category-cache.test.ts @@ -90,7 +90,7 @@ test('storage 不可用(隐私模式/配额)只影响缓存,不抛异常', assert.equal(saveCategoryCache(broken, { shopName: 'A', shopId: '', categories: [{ label: '其他', value: '1' }], fetchedAt: '', }), false) - assert.doesNotThrow(() => clearCategoryCache(broken)) + assert.equal(clearCategoryCache(broken), false, '清不掉要如实回 false,不许吞成"清过了"') }) test('清缓存后读不到', () => { @@ -99,7 +99,7 @@ test('清缓存后读不到', () => { shopName: 'A', shopId: '', categories: [{ label: '其他', value: '1' }], fetchedAt: '', }) assert.ok(loadCategoryCache(storage)) - clearCategoryCache(storage) + assert.equal(clearCategoryCache(storage), true) assert.equal(loadCategoryCache(storage), null) })