Skip to content

fix(config): replace unusable pre-migration backup and clarify non-object recovery notice (#625) - #797

Merged
Zaldaryon merged 2 commits into
devfrom
fix/issue-625-config-recovery-backup-and-notice
Nov 10, 2026
Merged

Zaldaryon merged 2 commits into
devfrom
fix/issue-625-config-recovery-backup-and-notice

Conversation

@Zaldaryon

@Zaldaryon Zaldaryon commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Addresses two gaps in configuration recovery reported in #625:

  1. In reconcileConfigBackup (src/config/configManager.ts), the existing backup file is inspected with migrateConfigDocument to confirm it is a usable restore point (outcome === "migrated" || outcome === "already-current"). If the existing backup is corrupt or unusable (for example, an empty array or malformed JSON), it is replaced by the valid pre-migration document when a migration runs, rather than preserving an unusable backup file indefinitely.
  2. When config.json is valid JSON but does not contain a configuration object (such as an array, number, boolean, or null), the recovery notification explains that the file contained no settings and that migrated settings or defaults are in use. It does not advise editing the preserved copy. Matching localized keys were added to en-US.json and fr-FR.json, and docs/contribute/translation-status.md was updated.

Type

  • Bug fix
  • Feature
  • Performance
  • Refactor or cleanup
  • Tests only
  • Docs or build

Checklist

  • Targets dev, not main.
  • npm run typecheck passes.
  • npm run lint:ci passes.
  • npm run format:check passes.
  • npm run test:coverage passes, coverage at or above the floor in vitest.config.ts.
  • npm run build:unpack passes.

Testing

Executed the full test suite and build verification:

  • npm run typecheck: 0 errors.
  • npm run lint:ci: 0 errors.
  • npm run format:check: all files formatted.
  • npm run test:coverage: 304 test files passed (1,921 tests passed, 2 skipped). Coverage floors exceeded across all metrics:
    • Statements: 95.07% (floor: 94.0%)
    • Branches: 91.26% (floor: 89.0%)
    • Functions: 95.89% (floor: 94.0%)
    • Lines: 97.02% (floor: 96.0%)
  • npm run build:unpack: unpacked Linux binary built successfully in dist/linux-unpacked.
  • Added unit tests in tests/ipc/configManager.test.ts verifying that:
    • An unusable or corrupted pre-migration backup is replaced on a subsequent migration.
    • Non-object JSON config files produce a recovery notice with cause: "not-an-object".
  • Added DOM tests in tests/renderer-dom/configRecoveryNotice.test.tsx verifying that:
    • The banner displays the specific non-object recovery message and names the kept copy.
    • The banner displays the non-object reset message when no backup is available.
  • Ran i18n-parity and verified zero missing French keys and zero placeholder issues.

Related issues

Fixes #625

@Zaldaryon
Zaldaryon requested a review from Pixnop October 27, 2026 17:44
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Translation status

en-US is the source and carries 960 keys.

Locale Keys Missing Stale To review on Weblate
be-BY 882 115 0 Needs editing
de-DE 855 105 0 Needs editing
es-ES 882 115 0 Needs editing
fr-FR 997 0 0 Needs editing
hu-HU 855 105 0 Needs editing
it-IT 882 115 0 Needs editing
nl-NL 855 105 0 Needs editing
pl-PL 882 115 0 Needs editing
pt-BR 883 114 0 Needs editing
pt-PT 882 115 0 Needs editing
ru-RU 996 3 2 Needs editing
uk-UA 882 115 0 Needs editing
zh-CN 828 95 0 Needs editing

The links open the strings Weblate marks Needs editing for each language: the machine drafts made before Weblate, plus any string whose English changed since it was translated. See #496.

@Pixnop Pixnop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed 3c4f05cc against dev adab6b96: ran your new tests against dev's code, read reconcileConfigBackup next to recoverUnreadableConfig, and tried the whole sequence on disk: a [] backup, a schema 2 config.json that migrates, then a broken config.json on the next launch.

The backup fix is in the right place. reconcileConfigBackup now asks migrateConfigDocument the same question recoverUnreadableConfig asks before it restores (configManager.ts:606-607 and :414-415), so the code that writes the backup and the code that reads it agree on what "usable" means. migrateConfigDocument is pure, so running it on every launch costs next to nothing. In my run the [] backup was replaced at the migration, and the broken config.json on the next launch came back with restored: true and lastUsedInstallation kept. A usable backup is still left alone, and the replacement still goes through the secret scrub and 0o600. An unusable backup with no migration pending stays until the next migration, which matches the fix #625 suggested. On dev's code, 11 of the 171 tests in the two changed test files fail: your four new ones, plus seven #554 tests that now expect cause on the notice. On this head those two files and configHandlers.test.ts pass, 189 tests, and translation-status.md matches what the generator writes.

Approving. Note 1 is worth taking here, since the wording is half of #625. The rest can wait.

On merge order: this conflicts with #793 and #794 in docs/contribute/translation-status.md, and only there. Whichever lands second should rerun node scripts/i18n-status.js --write docs/contribute/translation-status.md instead of resolving the conflict by hand.

Not blocking

  1. The not-an-object notice still asks the player to repair the kept copy. configNotAnObjectRestored and configNotAnObjectReset (en-US.json:975-976) end with "restore a settings object in {{copyName}}, and rename it to config.json". This path only runs when config.json parsed as an array, null, a number, a string or a boolean (configManager.ts:295-300), so the copy rarely holds anything to recover. Following the advice means writing a settings object by hand, and on the Restored variant that gives a worse result than what the launcher just restored. It is the "repair a file that has nothing to repair" from #625 in new words. I'd drop the instruction and say what happened, for example "Your settings file didn't contain any settings. A copy was kept as {{copyName}}, and settings from before the last update that changed the settings format were restored." and "..., and defaults are being used." for Reset. That also reads less technical than "valid JSON but does not contain a settings object". fr-FR (fr-FR.json:1012-1013) follows, and the tests at configRecoveryNotice.test.tsx:56 and :89 will need the new text.

  2. The two Unsaved strings could stay shared. The Unsaved strings never said "fix the JSON", and "couldn't be read" still fits a [] file. Keeping configUnreadableRestoredUnsaved and configUnreadableResetUnsaved for both causes saves every locale two strings, and the eight-way ternary at NotificationsContext.tsx:381-395 only needs the cause check on the preserved branch. Your call.

  3. A failed secret scrub now reads as an unreadable backup. The inner try (configManager.ts:603-614) also wraps the writeJsonAtomic that scrubs pre-#253 secrets out of the backup. On dev a failed write logged "Could not reconcile the pre-migration config backup." at warn. Now it logs "could not be read" at debug and the backup counts as unusable. The effect is small, since at worst a migration replaces that backup with a newer snapshot that is scrubbed too, but the log points the wrong way. Keeping only the read and the usability check inside the inner try, and doing the scrub write after it as dev did, keeps the old message.

  4. cause can be required. Both calls pass it (configManager.ts:292 and :299), so the default at :326 never applies, and cause? at global.d.ts:689 is wider than what is produced. A future caller that forgets it would silently get the "fix the JSON" text. The deferred notice at configRecoveryNotice.test.tsx:215 would then need a cause as well, or typecheck:tests fails. Separately, existingUsable = false at configManager.ts:613 sets the value it already holds.

@Zaldaryon
Zaldaryon merged commit b425fed into dev Nov 10, 2026
12 checks passed
@Zaldaryon
Zaldaryon deleted the fix/issue-625-config-recovery-backup-and-notice branch November 10, 2026 23:33
@Pixnop

Pixnop commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

I reviewed 095d5cd8 against 3c4f05cc: compared this pull request's diff against its base before and after the merge, read how the merge was resolved, reran the two changed test files and configHandlers.test.ts (189 pass), and put each old behaviour back to see which test catches it.

Round one

The not-an-object notice no longer asks for a repair. configNotAnObjectRestored and configNotAnObjectReset (en-US.json:976-977) now say what happened and stop there, and fr-FR follows at fr-FR.json:1013-1014. When I made the renderer ignore cause (NotificationsContext.tsx:388), both tests in "config not-an-object notice (#625)" went red.

The Unsaved strings are shared again. !preserved is now checked first (NotificationsContext.tsx:384-387), so both causes land on configUnreadable*Unsaved and the pull request adds two keys instead of four. Nothing tests that routing yet, see below.

A failed scrub logs as it did on dev. Only the read and the usability check sit in the inner try (configManager.ts:604-613). The scrub write at :615 reaches the outer warn again.

cause is required. The default is gone (configManager.ts:326) and global.d.ts:694 matches. Dropping the argument at configManager.ts:299 fails typecheck with TS2554. The redundant existingUsable = false is gone too.

The backup fix is unchanged. With dev's unconditional return put back at configManager.ts:616, both #625 tests (configManager.test.ts:1326 and :1341) fail. The merge with dev is clean: only translation-status.md conflicted, it matches what the generator writes, and every file outside the eight this pull request owns is identical to dev at f0401642.

Still approved. It's merged now, so the notes below are for a follow-up.

#791 and #803 also add locale keys, so both now conflict with dev in docs/contribute/translation-status.md, and only there. Each should rerun node scripts/i18n-status.js --write docs/contribute/translation-status.md instead of resolving it by hand.

Not blocking

  1. No test renders an Unsaved notice. If the ternary order is ever flipped, a [] config that could not be copied would show "A copy was kept as {{copyName}}" with the raw placeholder. I changed NotificationsContext.tsx:384 to !preserved && cause !== "not-an-object" and all 171 tests in the two changed test files still passed. One more case in the describe at configRecoveryNotice.test.tsx:55, with cause: "not-an-object", restored: true, preserved: false and copyName: null, that expects "a copy of it could not be kept" and no "{{copyName}}", would hold it.

  2. The new fr-FR strings drift from their neighbours. fr-FR.json:1013 has the file's only curly apostrophe (d’avant), where :1009 uses d'avant. Both new strings also open with "Votre fichier ne contenait", while the English and every neighbour say which file: "Votre fichier de réglages". "Votre fichier de réglages ne contenait aucun réglage." would match.

  3. The ConfigRecoveryNotice doc comment now documents the cause alias. type ConfigRecoveryUnreadableCause (global.d.ts:691) sits between the comment block (:675-690) and ConfigRecoveryNotice (:693), so the "Three shapes" text attaches to the alias on hover. Moving the alias above the comment fixes it, and the kind: "unreadable" bullet could say what cause is for.

  4. The description still mentions the advice you dropped. It says the notice "advises restoring a settings object in the preserved file". Worth updating so it matches what shipped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants