Harden campaign save timestamp recovery

This commit is contained in:
2026-07-05 10:54:59 +09:00
parent 118d668002
commit d827239813
2 changed files with 89 additions and 12 deletions

View File

@@ -596,6 +596,19 @@ try {
reserveTraining: [],
completedAt: '2026-07-04T02:00:00.000Z'
},
'invalid-date-history-key': {
battleId: 'second-battle-yellow-turban-pursuit',
battleTitle: 'Invalid Date Battle',
outcome: 'victory',
rewardGold: 999,
itemRewards: [],
campaignRewards: { supplies: [], equipment: [], reputation: [], recruits: [], unlocks: [] },
objectives: [],
units: [],
bonds: [],
reserveTraining: [],
completedAt: 'not-a-date'
},
corrupted: 'not-a-settlement'
}
})
@@ -654,7 +667,41 @@ 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, reward resettlement, camp reward idempotence, malformed-field/roster-equipment/bond-roster/report-reference/sortie-roster/latest-history/detail recovery, unknown-step/report/history recovery, unsupported-version rejection, and slotted fallback.');
storage.clear();
storage.set(campaignStorageKey, JSON.stringify({ version: 99, step: 'sixty-sixth-camp' }));
storage.set(
`${campaignStorageKey}:slot-1`,
JSON.stringify({
version: 1,
updatedAt: 'zzzz-latest-looking-corruption',
step: 'sixty-sixth-camp',
activeSaveSlot: 1,
gold: 999
})
);
storage.set(
`${campaignStorageKey}:slot-2`,
JSON.stringify({
version: 1,
updatedAt: '2026-07-02T00:00:00.000Z',
step: 'second-camp',
activeSaveSlot: 2,
gold: 260
})
);
const timestampSafeFallback = loadCampaignState();
assert(
timestampSafeFallback.step === 'second-camp' && timestampSafeFallback.activeSaveSlot === 2,
`Expected latest slotted fallback to ignore invalid timestamp saves: ${JSON.stringify(timestampSafeFallback)}`
);
const corruptedSlot = loadCampaignState(1);
assert(
!Number.isNaN(Date.parse(corruptedSlot.updatedAt)) && corruptedSlot.updatedAt !== 'zzzz-latest-looking-corruption',
`Expected explicitly loaded corrupted slot timestamp to be normalized: ${JSON.stringify(corruptedSlot)}`
);
console.log('Verified campaign save normalization, reward resettlement, camp reward idempotence, malformed-field/roster-equipment/bond-roster/report-reference/sortie-roster/latest-history/detail recovery, timestamp-safe history/slot recovery, unknown-step/report/history recovery, unsupported-version rejection, and slotted fallback.');
} finally {
await server.close();
}