Repository navigation
fix(config): replace unusable pre-migration backup and clarify non-object recovery notice (#625) - #797
Conversation
…ject recovery notice (#625)
Translation statusen-US is the source and carries 960 keys.
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
left a comment
There was a problem hiding this comment.
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
-
The not-an-object notice still asks the player to repair the kept copy.
configNotAnObjectRestoredandconfigNotAnObjectReset(en-US.json:975-976) end with "restore a settings object in {{copyName}}, and rename it to config.json". This path only runs whenconfig.jsonparsed 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 atconfigRecoveryNotice.test.tsx:56and:89will need the new text. -
The two Unsaved strings could stay shared. The Unsaved strings never said "fix the JSON", and "couldn't be read" still fits a
[]file. KeepingconfigUnreadableRestoredUnsavedandconfigUnreadableResetUnsavedfor both causes saves every locale two strings, and the eight-way ternary atNotificationsContext.tsx:381-395only needs the cause check on the preserved branch. Your call. -
A failed secret scrub now reads as an unreadable backup. The inner
try(configManager.ts:603-614) also wraps thewriteJsonAtomicthat 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 innertry, and doing the scrub write after it as dev did, keeps the old message. -
causecan be required. Both calls pass it (configManager.ts:292and:299), so the default at:326never applies, andcause?atglobal.d.ts:689is wider than what is produced. A future caller that forgets it would silently get the "fix the JSON" text. The deferred notice atconfigRecoveryNotice.test.tsx:215would then need acauseas well, ortypecheck:testsfails. Separately,existingUsable = falseatconfigManager.ts:613sets the value it already holds.
|
I reviewed Round oneThe not-an-object notice no longer asks for a repair. The Unsaved strings are shared again. A failed scrub logs as it did on dev. Only the read and the usability check sit in the inner
The backup fix is unchanged. With dev's unconditional 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 Not blocking
|
Summary
Addresses two gaps in configuration recovery reported in #625:
reconcileConfigBackup(src/config/configManager.ts), the existing backup file is inspected withmigrateConfigDocumentto 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.config.jsonis 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 toen-US.jsonandfr-FR.json, anddocs/contribute/translation-status.mdwas updated.Type
Checklist
dev, notmain.npm run typecheckpasses.npm run lint:cipasses.npm run format:checkpasses.npm run test:coveragepasses, coverage at or above the floor invitest.config.ts.npm run build:unpackpasses.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:npm run build:unpack: unpacked Linux binary built successfully indist/linux-unpacked.tests/ipc/configManager.test.tsverifying that:cause: "not-an-object".tests/renderer-dom/configRecoveryNotice.test.tsxverifying that:i18n-parityand verified zero missing French keys and zero placeholder issues.Related issues
Fixes #625