Normalize malformed battle history saves
This commit is contained in:
@@ -140,6 +140,49 @@ try {
|
||||
);
|
||||
assert(malformedReport.firstBattleReport === undefined, `Expected malformed report to be discarded: ${JSON.stringify(malformedReport)}`);
|
||||
|
||||
storage.clear();
|
||||
storage.set(
|
||||
campaignStorageKey,
|
||||
JSON.stringify({
|
||||
version: 1,
|
||||
updatedAt: '2026-07-04T01:00:00.000Z',
|
||||
step: 'fifth-camp',
|
||||
battleHistory: {
|
||||
'first-battle-zhuo-commandery': {
|
||||
battleId: 'first-battle-zhuo-commandery',
|
||||
battleTitle: 'Zhuo Commandery',
|
||||
outcome: 'victory',
|
||||
rewardGold: '120',
|
||||
itemRewards: ['Bean', 12, 'Bean'],
|
||||
campaignRewards: {
|
||||
supplies: { corrupted: true },
|
||||
equipment: ['Iron Sword'],
|
||||
reputation: 'Fame',
|
||||
recruits: [{ unitId: 'test-recruit', name: 'Test Recruit' }, { broken: true }],
|
||||
unlocks: { corrupted: true }
|
||||
},
|
||||
objectives: [],
|
||||
units: [],
|
||||
bonds: [],
|
||||
completedAt: '2026-07-04T01:00:00.000Z'
|
||||
},
|
||||
corrupted: 'not-a-settlement'
|
||||
}
|
||||
})
|
||||
);
|
||||
const malformedHistory = loadCampaignState();
|
||||
assert(
|
||||
Object.keys(malformedHistory.battleHistory).length === 1 &&
|
||||
malformedHistory.battleHistory['first-battle-zhuo-commandery']?.rewardGold === 120,
|
||||
`Expected malformed battle history entries to be filtered while keeping valid settlements: ${JSON.stringify(malformedHistory)}`
|
||||
);
|
||||
assert(
|
||||
malformedHistory.battleHistory['first-battle-zhuo-commandery']?.itemRewards.length === 1 &&
|
||||
malformedHistory.battleHistory['first-battle-zhuo-commandery']?.campaignRewards?.equipment[0] === 'Iron Sword' &&
|
||||
malformedHistory.battleHistory['first-battle-zhuo-commandery']?.campaignRewards?.recruits.length === 1,
|
||||
`Expected nested battle history rewards to normalize: ${JSON.stringify(malformedHistory)}`
|
||||
);
|
||||
|
||||
storage.clear();
|
||||
storage.set(campaignStorageKey, JSON.stringify({ version: 99, step: 'sixty-sixth-camp' }));
|
||||
const unsupported = loadCampaignState();
|
||||
@@ -160,7 +203,7 @@ try {
|
||||
const fallback = loadCampaignState();
|
||||
assert(fallback.step === 'second-camp' && fallback.activeSaveSlot === 2, `Expected valid slotted save fallback: ${JSON.stringify(fallback)}`);
|
||||
|
||||
console.log('Verified campaign save normalization, malformed-field recovery, unknown-step and report recovery, unsupported-version rejection, and slotted fallback.');
|
||||
console.log('Verified campaign save normalization, malformed-field recovery, unknown-step/report/history recovery, unsupported-version rejection, and slotted fallback.');
|
||||
} finally {
|
||||
await server.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user