Recover battle history keys by id

This commit is contained in:
2026-07-05 09:41:40 +09:00
parent 7185566b5d
commit 5c7cfed12e
2 changed files with 7 additions and 6 deletions

View File

@@ -164,7 +164,7 @@ try {
updatedAt: '2026-07-04T01:00:00.000Z',
step: 'fifth-camp',
battleHistory: {
'first-battle-zhuo-commandery': {
'wrong-history-key': {
battleId: 'first-battle-zhuo-commandery',
battleTitle: 'Zhuo Commandery',
outcome: 'victory',
@@ -220,8 +220,9 @@ try {
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)}`
malformedHistory.battleHistory['first-battle-zhuo-commandery']?.rewardGold === 120 &&
malformedHistory.battleHistory['wrong-history-key'] === undefined,
`Expected malformed battle history entries to be filtered while valid settlements are keyed by battleId: ${JSON.stringify(malformedHistory)}`
);
assert(
malformedHistory.battleHistory['first-battle-zhuo-commandery']?.itemRewards.length === 1 &&
@@ -263,7 +264,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/bond/sortie-item/history-detail recovery, unknown-step/report/history recovery, unsupported-version rejection, and slotted fallback.');
console.log('Verified campaign save normalization, malformed-field/bond/sortie-item/history-key/detail recovery, unknown-step/report/history recovery, unsupported-version rejection, and slotted fallback.');
} finally {
await server.close();
}

View File

@@ -852,13 +852,13 @@ function normalizeInventory(value: unknown) {
}
function normalizeBattleHistory(value: unknown) {
return Object.entries(recordOrEmpty<unknown>(value)).reduce<Record<string, CampaignBattleSettlement>>((history, [key, settlement]) => {
return Object.entries(recordOrEmpty<unknown>(value)).reduce<Record<string, CampaignBattleSettlement>>((history, [, settlement]) => {
const normalizedSettlement = normalizeCampaignBattleSettlement(settlement);
if (!normalizedSettlement) {
return history;
}
history[key] = normalizedSettlement;
history[normalizedSettlement.battleId] = normalizedSettlement;
return history;
}, {});
}