Recover saves with malformed battle reports
This commit is contained in:
@@ -117,6 +117,29 @@ try {
|
||||
assert(invalidStep.step === 'new', `Expected unknown campaign step to reset safely: ${JSON.stringify(invalidStep)}`);
|
||||
assert(invalidStep.gold === 90, `Expected unknown-step save to keep harmless economy data: ${JSON.stringify(invalidStep)}`);
|
||||
|
||||
storage.clear();
|
||||
storage.set(
|
||||
campaignStorageKey,
|
||||
JSON.stringify({
|
||||
version: 1,
|
||||
updatedAt: '2026-07-04T00:00:00.000Z',
|
||||
step: 'fourth-camp',
|
||||
activeSaveSlot: 1,
|
||||
gold: 320,
|
||||
firstBattleReport: {
|
||||
battleId: 'first-battle-zhuo-commandery',
|
||||
outcome: 'victory',
|
||||
completedCampVisits: { corrupted: true }
|
||||
}
|
||||
})
|
||||
);
|
||||
const malformedReport = loadCampaignState();
|
||||
assert(
|
||||
malformedReport.step === 'fourth-camp' && malformedReport.gold === 320,
|
||||
`Expected malformed report to be dropped without losing campaign progress: ${JSON.stringify(malformedReport)}`
|
||||
);
|
||||
assert(malformedReport.firstBattleReport === undefined, `Expected malformed report to be discarded: ${JSON.stringify(malformedReport)}`);
|
||||
|
||||
storage.clear();
|
||||
storage.set(campaignStorageKey, JSON.stringify({ version: 99, step: 'sixty-sixth-camp' }));
|
||||
const unsupported = loadCampaignState();
|
||||
@@ -137,7 +160,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 recovery, unsupported-version rejection, and slotted fallback.');
|
||||
console.log('Verified campaign save normalization, malformed-field recovery, unknown-step and report recovery, unsupported-version rejection, and slotted fallback.');
|
||||
} finally {
|
||||
await server.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user