From ce3502be9a6ddc05ab5dce4b79d1233a3ace4b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E8=87=AA=E8=BE=BE?= <980324341@qq.com> Date: Thu, 19 Nov 2026 22:30:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(jd-collect):=20=E6=B8=85=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E5=A6=82=E5=AE=9E=E5=9B=9E=20false=EF=BC=8C?= =?UTF-8?q?=E9=9D=99=E9=BB=98=E6=A3=98=E8=BD=AE=20blocks=20=E6=8C=89?= =?UTF-8?q?=E4=B8=89=E6=94=AF=E9=80=90=E6=9D=A1=E7=99=BB=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit jd-category-cache.ts 的三支 try/catch(读/写/清)兜法都是把结果交给调用方,没有 console 糊过去;清缓存原先是空 catch(被 catch-silence-ratchet 判「新增静默 catch」),改成 return false 后静默数不动、只进 blocks 324→327。 --- frontend-vue/src/pages/jd/jd-category-cache.ts | 10 ++++++---- frontend-vue/tests/catch-silence-ratchet.test.ts | 7 ++++++- frontend-vue/tests/jd-category-cache.test.ts | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) 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) })