Validate campaign save steps

This commit is contained in:
2026-07-05 09:13:10 +09:00
parent 70933a7f51
commit d513aec22c
2 changed files with 33 additions and 1 deletions

View File

@@ -102,6 +102,21 @@ try {
`Expected malformed inventory and sortie assignments to normalize: ${JSON.stringify(malformed)}`
);
storage.clear();
storage.set(
campaignStorageKey,
JSON.stringify({
version: 1,
updatedAt: '2026-07-03T00:00:00.000Z',
step: 'lost-between-battles',
activeSaveSlot: 1,
gold: 90
})
);
const invalidStep = loadCampaignState();
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: 99, step: 'sixty-sixth-camp' }));
const unsupported = loadCampaignState();
@@ -122,7 +137,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, unsupported-version rejection, and slotted fallback.');
console.log('Verified campaign save normalization, malformed-field recovery, unknown-step recovery, unsupported-version rejection, and slotted fallback.');
} finally {
await server.close();
}