From fc384e662c4b24cceef793aefb3666cc1729209b Mon Sep 17 00:00:00 2001 From: Zaldaryon <273555259+Zaldaryon@users.noreply.github.com> Date: Tue, 10 Nov 2026 22:20:11 -0300 Subject: [PATCH 1/3] Address review follow-ups for merged pull requests --- src/global.d.ts | 15 +++--- src/ipc/handlers/modConfigs.ts | 2 + src/ipc/handlers/worldsHandlers.ts | 3 +- src/renderer/src/locales/fr-FR.json | 4 +- tests/ipc/modConfigs.test.ts | 48 +++++++++++++++++ tests/ipc/worldsHandlers.test.ts | 51 ++++++++++++++++--- .../configRecoveryNotice.test.tsx | 33 ++++++++++++ tests/renderer-dom/manageMods.test.tsx | 2 +- 8 files changed, 139 insertions(+), 19 deletions(-) diff --git a/src/global.d.ts b/src/global.d.ts index 2dc71fdd..726c8911 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -672,24 +672,25 @@ declare global { /** SAVE_CONFIG's verdict. `ok: false` means nothing was written to disk. */ type SaveConfigResult = { ok: true } | { ok: false; reason: SaveConfigFailureReason; refusedPaths?: string[] } + type ConfigRecoveryUnreadableCause = "invalid-json" | "not-an-object" + /** * What `getConfig` found on the read that mattered, pulled once by the renderer through * GET_CONFIG_RECOVERY_NOTICE (#554). Three shapes: * * - `kind: "unreadable"`: `config.json` parsed to bad JSON, or to valid JSON that is not an - * object. `restored` says whether a pre-migration backup was usable, or the launcher fell back - * to defaults. `preserved`/`copyName` say whether a copy of the unreadable file could be kept - * aside: when it could not, `getConfig` runs the recovered config in memory only, for this - * session, and never wrote it over the original file, so `copyName` is null and there is - * nothing to point the player at. + * object. `cause` distinguishes invalid JSON from valid JSON with an unexpected top-level + * value, so the notice can describe what happened accurately. `restored` says whether a + * pre-migration backup was usable, or the launcher fell back to defaults. `preserved`/`copyName` + * say whether a copy of the unreadable file could be kept aside: when it could not, `getConfig` + * runs the recovered config in memory only, for this session, and never wrote it over the + * original file, so `copyName` is null and there is nothing to point the player at. * - `kind: "read-failed"`: the file itself could not even be opened (permissions, a Windows * sharing lock). Nothing says the document inside is corrupt, so there is nothing to preserve * and no copy name to give: this session simply runs on defaults, in memory only. * - `kind: "import-failed"`: the first-run copy of VS Launcher's data failed (#708). The launcher * started on an empty profile and leaves a marker so the next start tries the import again. */ - type ConfigRecoveryUnreadableCause = "invalid-json" | "not-an-object" - type ConfigRecoveryNotice = | { kind: "unreadable"; restored: boolean; preserved: boolean; copyName: string | null; cause: ConfigRecoveryUnreadableCause } | { kind: "read-failed" } diff --git a/src/ipc/handlers/modConfigs.ts b/src/ipc/handlers/modConfigs.ts index 90ec530d..6dbe51a8 100644 --- a/src/ipc/handlers/modConfigs.ts +++ b/src/ipc/handlers/modConfigs.ts @@ -805,6 +805,8 @@ ipcMain.handle(IPC_CHANNELS.MODS_MANAGER.APPLY_MOD_CONFIGS, async (event, instal } if (refused.has(entry.key)) return try { + // Copying and verifying the recovery file can take long enough for the folder to become a + // link. Recheck before the config write, and remove the copy if its path changed meanwhile. await assertManagedPath(dirname(entry.destination), "mod config folder", { allowMissing: true }) } catch (error) { await fse.remove(backupPath) diff --git a/src/ipc/handlers/worldsHandlers.ts b/src/ipc/handlers/worldsHandlers.ts index c54bc576..d0f923be 100644 --- a/src/ipc/handlers/worldsHandlers.ts +++ b/src/ipc/handlers/worldsHandlers.ts @@ -148,7 +148,8 @@ async function removeWorldBackupArchive(archivePath: string, expectedBackupId: s if (!stat.isFile() || stat.isSymbolicLink()) return false await fse.remove(safePath) return !(await fse.pathExists(safePath)) - } catch { + } catch (error) { + logMessage("debug", `${LOG_PREFIX} [WORLD BACKUP] ${getErrorMessage(error)}`) return false } } diff --git a/src/renderer/src/locales/fr-FR.json b/src/renderer/src/locales/fr-FR.json index 6f7f2663..2208f017 100644 --- a/src/renderer/src/locales/fr-FR.json +++ b/src/renderer/src/locales/fr-FR.json @@ -1012,8 +1012,8 @@ "configUnreadableReset": "Votre fichier de réglages n'a pas pu être lu. Une copie a été conservée sous le nom {{copyName}}, mais aucun réglage antérieur n'a pu être restauré : les valeurs par défaut sont utilisées. Pour récupérer ce qu'il contenait, fermez RiftLauncher, corrigez le JSON dans {{copyName}}, puis renommez-le en config.json.", "configUnreadableRestoredUnsaved": "Votre fichier de réglages n'a pas pu être lu, et aucune copie n'a pu en être conservée. Cette session tourne avec les réglages d'avant la dernière mise à jour ayant changé le format des réglages, et rien ne sera enregistré durant cette session.", "configUnreadableResetUnsaved": "Votre fichier de réglages n'a pas pu être lu, et aucune copie n'a pu en être conservée. Cette session tourne avec les réglages par défaut, et rien ne sera enregistré durant cette session.", - "configNotAnObjectRestored": "Votre fichier ne contenait aucun réglage. Une copie a été conservée sous le nom {{copyName}} et les réglages d’avant la dernière mise à jour qui a modifié leur format ont été restaurés.", - "configNotAnObjectReset": "Votre fichier ne contenait aucun réglage. Une copie a été conservée sous le nom {{copyName}} et les réglages par défaut sont utilisés.", + "configNotAnObjectRestored": "Votre fichier de réglages ne contenait aucun réglage. Une copie a été conservée sous le nom {{copyName}} et les réglages d'avant la dernière mise à jour qui a modifié le format des réglages ont été restaurés.", + "configNotAnObjectReset": "Votre fichier de réglages ne contenait aucun réglage. Une copie a été conservée sous le nom {{copyName}} et les réglages par défaut sont utilisés.", "userDataImportFailed": "Vos données de VS Launcher n'ont pas pu être importées : RiftLauncher a démarré avec un profil vide. L'import sera retenté au prochain démarrage, tant que vous ne modifiez rien dans RiftLauncher d'ici là. Les données de VS Launcher n'ont pas été modifiées.", "missingFields": "Remplissez tous les champs avant d'enregistrer.", "compressed": "Compression terminée : {{compressName}}.", diff --git a/tests/ipc/modConfigs.test.ts b/tests/ipc/modConfigs.test.ts index 48b83101..542d3a68 100644 --- a/tests/ipc/modConfigs.test.ts +++ b/tests/ipc/modConfigs.test.ts @@ -1363,6 +1363,54 @@ describe("APPLY_MOD_CONFIGS", () => { } }) + it("rechecks a folder swapped during config reading before keeping a recovery copy (#626)", async () => { + writeConfig() + const outside = join(temporaryRoot, "outside") + mkdirSync(outside, { recursive: true }) + writeFileSync(join(outside, "target.json"), "theirs-secret", "utf-8") + + mkdirSync(join(modConfigFolder(), "swapped"), { recursive: true }) + writeFileSync(join(modConfigFolder(), "legit.json"), '{"legit":1}', "utf-8") + const swappedConfig = join(modConfigFolder(), "swapped", "target.json") + writeFileSync(swappedConfig, '{"target":1}', "utf-8") + + const event = await createTrustedEvent() + const fse = (await import("fs-extra")).default + const originalReadFile = fse.readFile.bind(fse) + let swapped = false + const readFile = vi.spyOn(fse, "readFile").mockImplementation((async (target: unknown, ...rest: unknown[]) => { + if (!swapped && String(target) === swappedConfig) { + swapped = true + rmSync(join(modConfigFolder(), "swapped"), { recursive: true, force: true }) + symlinkSync(outside, join(modConfigFolder(), "swapped")) + } + return (originalReadFile as (...args: unknown[]) => Promise)(target, ...rest) + }) as never) + const copy = vi.spyOn(fse, "copy") + + try { + const applied = await applyModConfigsHandler()(event, installationPath, [ + { name: "legit.json", ...entry('{"legit":2}') }, + { name: "swapped/target.json", ...entry('{"target":2}') } + ]) + + assert.equal(applied.ok, true) + if (applied.ok !== true) return + assert.deepEqual(applied.failed, [{ name: "swapped/target.json", reason: "write-failed" }]) + assert.deepEqual(applied.applied, [{ name: "legit.json", kind: "replace" }]) + assert.notEqual(applied.backupFolder, "") + assert.equal(existsSync(join(applied.backupFolder, "swapped", "target.json")), false) + assert.equal( + copy.mock.calls.some(([from]) => String(from) === swappedConfig), + false + ) + assert.equal(readFileSync(join(outside, "target.json"), "utf-8"), "theirs-secret") + } finally { + readFile.mockRestore() + copy.mockRestore() + } + }) + it("refuses a linked destination file at lstat without reading, copying or writing through it", async () => { writeConfig() const outside = join(temporaryRoot, "outside") diff --git a/tests/ipc/worldsHandlers.test.ts b/tests/ipc/worldsHandlers.test.ts index 0902ac5b..68d3a531 100644 --- a/tests/ipc/worldsHandlers.test.ts +++ b/tests/ipc/worldsHandlers.test.ts @@ -892,9 +892,38 @@ describe("worlds IPC handlers", () => { assert.deepEqual(resultMismatch, { ok: false, reason: "operation-failed" }) expect(existsSync(mismatchArchive)).toBe(true) - const resultInst = await handler("worlds-delete-backup")(event, "install-a", "inst-worlds-id") - assert.deepEqual(resultInst, { ok: false, reason: "operation-failed" }) - expect(existsSync(instArchive)).toBe(true) + const logSpy = vi.spyOn(await import("@src/utils/logManager"), "logMessage") + try { + const resultInst = await handler("worlds-delete-backup")(event, "install-a", "inst-worlds-id") + assert.deepEqual(resultInst, { ok: false, reason: "operation-failed" }) + expect(existsSync(instArchive)).toBe(true) + expect(logSpy).toHaveBeenCalledWith("warn", expect.stringContaining("[DELETE BACKUP] Could not remove world backup inst-worlds-id.")) + } finally { + logSpy.mockRestore() + } + }) + + it("logs the reason a world backup archive could not be removed", async () => { + const sourcePath = join(installationsRoot, "install-a") + mkdirSync(join(sourcePath, "Saves"), { recursive: true }) + writeFileSync(join(sourcePath, "Saves", "World.vcdbs"), "live-world", "utf8") + + const backupId = "80000000-0000-4000-8000-000000000008" + const archivePath = join(backupsFolder, "Worlds", `${backupId}.tar.gz`) + mkdirSync(join(backupsFolder, "Worlds"), { recursive: true }) + writeFileSync(archivePath, "archive", "utf8") + writeConfig([installation("install-a", sourcePath, "1.22.7", [{ id: backupId, date: 1, path: archivePath, worldName: "World.vcdbs" }])]) + const event = await createTrustedEvent() + const logSpy = vi.spyOn(await import("@src/utils/logManager"), "logMessage") + + assertManagedDeletionPathSpy.mockRejectedValueOnce(new Error("EACCES permission denied")) + try { + const result = await handler("worlds-delete-backup")(event, "install-a", backupId) + assert.deepEqual(result, { ok: false, reason: "operation-failed" }) + expect(logSpy).toHaveBeenCalledWith("debug", expect.stringContaining("EACCES permission denied")) + } finally { + logSpy.mockRestore() + } }) it("refuses to delete another world's archive when pruning older backups (#620)", async () => { @@ -916,12 +945,18 @@ describe("worlds IPC handlers", () => { writeConfig([inst]) const event = await createTrustedEvent() - const result = (await handler("worlds-backup")(event, "install-a", "World.vcdbs")) as WorldBackupResult - assert.equal(result.ok, true) - if (!result.ok) return + const logSpy = vi.spyOn(await import("@src/utils/logManager"), "logMessage") + try { + const result = (await handler("worlds-backup")(event, "install-a", "World.vcdbs")) as WorldBackupResult + assert.equal(result.ok, true) + if (!result.ok) return - expect(existsSync(otherWorldArchive)).toBe(true) - expect(result.deletedBackupIds).toEqual([]) + expect(existsSync(otherWorldArchive)).toBe(true) + expect(result.deletedBackupIds).toEqual([]) + expect(logSpy).toHaveBeenCalledWith("warn", expect.stringContaining(`[BACKUP] Could not prune world backup ${idPruned}.`)) + } finally { + logSpy.mockRestore() + } }) it("refuses to make a world backup when backupsLimit is 0", async () => { diff --git a/tests/renderer-dom/configRecoveryNotice.test.tsx b/tests/renderer-dom/configRecoveryNotice.test.tsx index 1d98672a..7a6a7476 100644 --- a/tests/renderer-dom/configRecoveryNotice.test.tsx +++ b/tests/renderer-dom/configRecoveryNotice.test.tsx @@ -118,6 +118,39 @@ describe("config not-an-object notice (#625)", () => { expect(seen[0]?.body).toContain("A copy was kept as config.unreadable-1727690000000.json") expect(getConfigRecoveryNotice).toHaveBeenCalledTimes(1) }) + + it("does not name a preserved copy when an unreadable config could not be saved", async () => { + vi.resetModules() + const { NotificationsProvider: FreshProvider, useNotificationsContext: useFreshNotifications } = await import("@renderer/contexts/NotificationsContext") + let seen: NotificationType[] = [] + function Probe(): null { + seen = useFreshNotifications().notifications + return null + } + const getConfigRecoveryNotice = vi.fn( + async () => + ({ + kind: "unreadable", + cause: "not-an-object", + restored: true, + preserved: false, + copyName: null + }) as ConfigRecoveryNotice + ) + installMockWindowApi({ configManager: { getConfigRecoveryNotice } }) + + render( + + + + ) + + await waitFor(() => expect(seen).toHaveLength(1)) + expect(seen[0]?.type).toBe("warning") + expect(seen[0]?.body).toContain("a copy of it could not be kept") + expect(seen[0]?.body).not.toContain("{{copyName}}") + expect(getConfigRecoveryNotice).toHaveBeenCalledTimes(1) + }) }) describe("failed VS Launcher import notice (#708)", () => { diff --git a/tests/renderer-dom/manageMods.test.tsx b/tests/renderer-dom/manageMods.test.tsx index 030d5b58..45ada160 100644 --- a/tests/renderer-dom/manageMods.test.tsx +++ b/tests/renderer-dom/manageMods.test.tsx @@ -2532,7 +2532,7 @@ describe("startup update notices on Manage Mods (#752)", () => { if (scenario === "all" || scenario === "row") { await waitFor(() => expect(screen.queryByText(notice)).toBeNull()) } else { - expect(screen.getByText(notice)).toBeTruthy() + await expect(waitFor(() => expect(screen.queryByText(notice)).toBeNull(), { timeout: 1_500 })).rejects.toThrow() } expect(downloadOnPath).toHaveBeenCalledTimes(scenario === "all" ? 2 : scenario === "offline" ? 0 : 1) }, From 31fd21dfe21e7228a422cc98ee077bb737b04ded Mon Sep 17 00:00:00 2001 From: Zaldaryon <273555259+Zaldaryon@users.noreply.github.com> Date: Wed, 11 Nov 2026 08:22:07 -0300 Subject: [PATCH 2/3] Test recovery folder recheck after copy --- tests/ipc/modConfigs.test.ts | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/ipc/modConfigs.test.ts b/tests/ipc/modConfigs.test.ts index 542d3a68..7c10d721 100644 --- a/tests/ipc/modConfigs.test.ts +++ b/tests/ipc/modConfigs.test.ts @@ -1411,6 +1411,50 @@ describe("APPLY_MOD_CONFIGS", () => { } }) + it("rechecks a folder swapped during the recovery copy before keeping that copy (#626)", async () => { + writeConfig() + const outside = join(temporaryRoot, "outside") + mkdirSync(outside, { recursive: true }) + writeFileSync(join(outside, "target.json"), "theirs-secret", "utf-8") + + mkdirSync(join(modConfigFolder(), "swapped"), { recursive: true }) + writeFileSync(join(modConfigFolder(), "legit.json"), '{"legit":1}', "utf-8") + const swappedConfig = join(modConfigFolder(), "swapped", "target.json") + writeFileSync(swappedConfig, '{"target":1}', "utf-8") + + const event = await createTrustedEvent() + const fse = (await import("fs-extra")).default + const originalCopy = fse.copy.bind(fse) + let swapped = false + const copy = vi.spyOn(fse, "copy").mockImplementation(async (from, to, options) => { + await originalCopy(from, to, options) + if (!swapped && String(from) === swappedConfig) { + swapped = true + rmSync(join(modConfigFolder(), "swapped"), { recursive: true, force: true }) + symlinkSync(outside, join(modConfigFolder(), "swapped")) + } + }) + + try { + const applied = await applyModConfigsHandler()(event, installationPath, [ + { name: "legit.json", ...entry('{"legit":2}') }, + { name: "swapped/target.json", ...entry('{"target":2}') } + ]) + + assert.equal(applied.ok, true) + if (applied.ok !== true) return + assert.equal(swapped, true, "the destination folder changes only after its backup copy lands") + assert.deepEqual(applied.failed, [{ name: "swapped/target.json", reason: "write-failed" }]) + assert.deepEqual(applied.applied, [{ name: "legit.json", kind: "replace" }]) + assert.notEqual(applied.backupFolder, "") + assert.equal(existsSync(join(applied.backupFolder, "legit.json")), true) + assert.equal(existsSync(join(applied.backupFolder, "swapped", "target.json")), false) + assert.equal(readFileSync(join(outside, "target.json"), "utf-8"), "theirs-secret") + } finally { + copy.mockRestore() + } + }) + it("refuses a linked destination file at lstat without reading, copying or writing through it", async () => { writeConfig() const outside = join(temporaryRoot, "outside") From facf8a02dfae6c54148a45238f284c2690e55da5 Mon Sep 17 00:00:00 2001 From: Zaldaryon <273555259+Zaldaryon@users.noreply.github.com> Date: Wed, 11 Nov 2026 08:22:13 -0300 Subject: [PATCH 3/3] Align French config recovery messages --- src/renderer/src/locales/fr-FR.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/locales/fr-FR.json b/src/renderer/src/locales/fr-FR.json index 64077a0a..76d26992 100644 --- a/src/renderer/src/locales/fr-FR.json +++ b/src/renderer/src/locales/fr-FR.json @@ -1018,8 +1018,8 @@ "configUnreadableReset": "Votre fichier de réglages n'a pas pu être lu. Une copie a été conservée sous le nom {{copyName}}, mais aucun réglage antérieur n'a pu être restauré : les valeurs par défaut sont utilisées. Pour récupérer ce qu'il contenait, fermez RiftLauncher, corrigez le JSON dans {{copyName}}, puis renommez-le en config.json.", "configUnreadableRestoredUnsaved": "Votre fichier de réglages n'a pas pu être lu, et aucune copie n'a pu en être conservée. Cette session tourne avec les réglages d'avant la dernière mise à jour ayant changé le format des réglages, et rien ne sera enregistré durant cette session.", "configUnreadableResetUnsaved": "Votre fichier de réglages n'a pas pu être lu, et aucune copie n'a pu en être conservée. Cette session tourne avec les réglages par défaut, et rien ne sera enregistré durant cette session.", - "configNotAnObjectRestored": "Votre fichier de réglages ne contenait aucun réglage. Une copie a été conservée sous le nom {{copyName}} et les réglages d'avant la dernière mise à jour qui a modifié le format des réglages ont été restaurés.", - "configNotAnObjectReset": "Votre fichier de réglages ne contenait aucun réglage. Une copie a été conservée sous le nom {{copyName}} et les réglages par défaut sont utilisés.", + "configNotAnObjectRestored": "Votre fichier de réglages ne contenait aucun réglage. Une copie a été conservée sous le nom {{copyName}}, et les réglages d'avant la dernière mise à jour ayant changé le format des réglages ont été restaurés.", + "configNotAnObjectReset": "Votre fichier de réglages ne contenait aucun réglage. Une copie a été conservée sous le nom {{copyName}}, et les valeurs par défaut sont utilisées.", "userDataImportFailed": "Vos données de VS Launcher n'ont pas pu être importées : RiftLauncher a démarré avec un profil vide. L'import sera retenté au prochain démarrage, tant que vous ne modifiez rien dans RiftLauncher d'ici là. Les données de VS Launcher n'ont pas été modifiées.", "missingFields": "Remplissez tous les champs avant d'enregistrer.", "compressed": "Compression terminée : {{compressName}}.",