fix(07-04): #06-09-2 deep copy the equipment save snapshot

- saveState returns new Map(this.equips) and [...this.slots] so the snapshot is decoupled from the live state
- un-skip the independent-snapshot and container round-trip cases
This commit is contained in:
unanmed 2026-09-15 20:27:57 +08:00
parent e7f341095d
commit 02786047d2
2 changed files with 6 additions and 6 deletions

View File

@ -328,8 +328,8 @@ export class HeroEquipment<THero> implements IHeroEquipment<THero> {
saveState(): IHeroEquipmentSave {
return {
equipped: this.equips,
slots: this.slots
equipped: new Map(this.equips),
slots: [...this.slots]
};
}

View File

@ -308,8 +308,8 @@ describe('HeroEquipment save and load round trips', () => {
expect(env.equipment.slots).toEqual(['weapon']);
});
// 疑似 bug<75>E<EFBFBD>saveState 直接返回冁E<E58681><45> equipped/slots 引用而非深拷贝,详见E06-TEST-FINDINGS.md #06-09-2
it.skip('returns an equipment snapshot independent from the live state', () => {
// 验证 saveState 返回与活对象解耦的深拷贝快照(#06-09-2)
it('returns an equipment snapshot independent from the live state', () => {
const env = createEquipEnv();
registerItem(env, createEquipItem(10, 'sword', [0], [['atk', 5]]));
env.equipment.setSlots(['weapon']);
@ -585,8 +585,8 @@ describe('HeroState container save and load coverage for sub systems', () => {
}
});
// 疑似 bug<75>E<EFBFBD>HeroEquipment.saveState 未深拷贁Eequipped/slots<74>E<EFBFBD>经容器三档往返均丢失已裁E<E8A381><45>E<EFBFBD><45>封E<E5B081><45>详见E06-TEST-FINDINGS.md #06-09-2
it.skip('restores the equipped mapping through the container across all compressions', () => {
// 验证经容器三档往返均恢复已装备映射与槽位(#06-09-2)
it('restores the equipped mapping through the container across all compressions', () => {
for (const compression of SAVE_COMPRESSIONS) {
const env = createEquipEnv();
registerItem(env, createEquipItem(10, 'sword', [0], [['atk', 5]]));