From 95ea6609c6be5691e0cc5d3410fef4953fc2d41a Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Tue, 15 Sep 2026 21:10:33 +0800 Subject: [PATCH] fix(07-07): #06-09-5 warn code 178 for unloaded save keys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - core.ts loadState: 差集方向改为 loaded.difference(total),178 = 存档出现但未加载的 key - saveablesRoundTrip.test.ts:322-334 改写为「缺 key 不触发 178、仍触发 177」负向见证并更名 - saveablesRoundTrip.test.ts:337-349 取消 it.skip,承担「多出 key 触发 178」正向见证 --- packages-user/data-state/src/core.ts | 2 +- .../data-state/test/saveablesRoundTrip.test.ts | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages-user/data-state/src/core.ts b/packages-user/data-state/src/core.ts index 35e45ab..879bbc5 100644 --- a/packages-user/data-state/src/core.ts +++ b/packages-user/data-state/src/core.ts @@ -530,7 +530,7 @@ export class CoreState implements ICoreState { } const loaded = new Set(state.keys()); const total = new Set(this.saveables.keys()); - const remain = total.difference(loaded); + const remain = loaded.difference(total); if (remain.size > 0) { const ids = [...remain].join(' | '); logger.warn(178, ids); diff --git a/packages-user/data-state/test/saveablesRoundTrip.test.ts b/packages-user/data-state/test/saveablesRoundTrip.test.ts index 0c43657..3f95dc7 100644 --- a/packages-user/data-state/test/saveablesRoundTrip.test.ts +++ b/packages-user/data-state/test/saveablesRoundTrip.test.ts @@ -318,8 +318,8 @@ describe('CoreState save and load guards', () => { expect(result.info.map(info => info.code)).toContain(177); }); - // 验证存档缺失 saveable key 时同时观测到警告码 178(当前实现的实际触发路径) - it('warns code 178 when the save data misses a saveable key', () => { + // 验证存档缺失 saveable key 时只触发警告码 177,不再误报 178(177/178 语义互斥) + it('warns code 177 but not 178 when the save data misses a saveable key', () => { const state = createCoreState(); const snapshot = new Map( state.saveState(SaveCompression.NoCompression) @@ -330,11 +330,13 @@ describe('CoreState save and load guards', () => { state.loadState(snapshot, SaveCompression.NoCompression) ); - expect(result.info.map(info => info.code)).toContain(178); + const codes = result.info.map(info => info.code); + expect(codes).toContain(177); + expect(codes).not.toContain(178); }); - // 疑似 bug:码 178 的判定与文案相反,对「存档多出的 key」不告警,详见 06-TEST-FINDINGS.md #06-09-5 - it.skip('warns code 178 when the save data has keys that are not loaded', () => { + // 验证存档含未注册(未加载)key 时经 logger.catch 观测到警告码 178(#06-09-5) + it('warns code 178 when the save data has keys that are not loaded', () => { const state = createCoreState(); const snapshot = new Map( state.saveState(SaveCompression.NoCompression)