Harden malformed campaign save recovery
This commit is contained in:
@@ -59,6 +59,49 @@ try {
|
||||
`Expected modern sortie fields to be restored: ${JSON.stringify(legacy)}`
|
||||
);
|
||||
|
||||
storage.clear();
|
||||
storage.set(
|
||||
campaignStorageKey,
|
||||
JSON.stringify({
|
||||
version: 1,
|
||||
updatedAt: '',
|
||||
step: 'third-camp',
|
||||
activeSaveSlot: '2',
|
||||
gold: '410',
|
||||
roster: { corrupted: true },
|
||||
bonds: { corrupted: true },
|
||||
completedCampDialogues: ['dialogue-a', 17, 'dialogue-a', ''],
|
||||
completedCampVisits: 'visit-a',
|
||||
inventory: { bean: '3', wine: -2, empty: 0 },
|
||||
selectedSortieUnitIds: { corrupted: true },
|
||||
sortieFormationAssignments: 'front',
|
||||
sortieItemAssignments: {
|
||||
'liu-bei': { bean: '2', wine: -1 },
|
||||
'guan-yu': 'broken'
|
||||
},
|
||||
battleHistory: []
|
||||
})
|
||||
);
|
||||
const malformed = loadCampaignState();
|
||||
assert(malformed.step === 'third-camp', `Expected malformed save progress to survive: ${JSON.stringify(malformed)}`);
|
||||
assert(malformed.activeSaveSlot === 2 && malformed.gold === 410, `Expected malformed numeric fields to normalize: ${JSON.stringify(malformed)}`);
|
||||
assert(Array.isArray(malformed.roster) && malformed.roster.length === 0, `Expected malformed roster to reset to an array: ${JSON.stringify(malformed)}`);
|
||||
assert(Array.isArray(malformed.bonds) && malformed.bonds.length === 0, `Expected malformed bonds to reset to an array: ${JSON.stringify(malformed)}`);
|
||||
assert(
|
||||
malformed.completedCampDialogues.length === 1 &&
|
||||
malformed.completedCampDialogues[0] === 'dialogue-a' &&
|
||||
malformed.completedCampVisits.length === 0,
|
||||
`Expected malformed completion lists to keep unique strings only: ${JSON.stringify(malformed)}`
|
||||
);
|
||||
assert(
|
||||
malformed.inventory.bean === 3 &&
|
||||
malformed.inventory.wine === undefined &&
|
||||
malformed.sortieItemAssignments['liu-bei']?.bean === 2 &&
|
||||
malformed.sortieItemAssignments['liu-bei']?.wine === undefined &&
|
||||
Object.keys(malformed.sortieFormationAssignments).length === 0,
|
||||
`Expected malformed inventory and sortie assignments to normalize: ${JSON.stringify(malformed)}`
|
||||
);
|
||||
|
||||
storage.clear();
|
||||
storage.set(campaignStorageKey, JSON.stringify({ version: 99, step: 'sixty-sixth-camp' }));
|
||||
const unsupported = loadCampaignState();
|
||||
@@ -79,7 +122,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, legacy recovery, unsupported-version rejection, and slotted fallback.');
|
||||
console.log('Verified campaign save normalization, malformed-field recovery, unsupported-version rejection, and slotted fallback.');
|
||||
} finally {
|
||||
await server.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user