diff --git a/apps/stage-tamagotchi/src/main/services/electron/auto-updater.test.ts b/apps/stage-tamagotchi/src/main/services/electron/auto-updater.test.ts index 91b7e8bf68..37c52ee887 100644 --- a/apps/stage-tamagotchi/src/main/services/electron/auto-updater.test.ts +++ b/apps/stage-tamagotchi/src/main/services/electron/auto-updater.test.ts @@ -293,6 +293,21 @@ describe('setupAutoUpdater', () => { expect(service.state.status).toBe('not-available') }) + // An install with its own user data directory, for example a test build, must not write into the log of another install. + it('writes the updater log in the user data directory and reports that path', async () => { + const { appendFile } = await import('node:fs/promises') + const { join } = await import('node:path') + const fake = createFakeUpdater() + const { setupAutoUpdater } = await import('./auto-updater') + const service = setupAutoUpdater({ updater: fake.updater }) + const logFile = join('/tmp/userData', 'logs', 'updater-log.txt') + + fake.setStatus({ status: 'error', error: { code: 'network-error', message: 'Offline.' } }) + + await vi.waitFor(() => expect(appendFile).toHaveBeenCalledWith(logFile, expect.stringContaining('network-error'))) + expect(service.state.diagnostics?.logFilePath).toBe(logFile) + }) + it('does not touch the updater when the launcher turned it off', async () => { const fake = createFakeUpdater({ status: 'disabled', reason: 'store-build' }) const { setupAutoUpdater } = await import('./auto-updater') diff --git a/apps/stage-tamagotchi/src/main/services/electron/auto-updater.ts b/apps/stage-tamagotchi/src/main/services/electron/auto-updater.ts index 85407b0358..b8690208ea 100644 --- a/apps/stage-tamagotchi/src/main/services/electron/auto-updater.ts +++ b/apps/stage-tamagotchi/src/main/services/electron/auto-updater.ts @@ -28,14 +28,12 @@ import { channelOfVersion, updateChannels } from '../../../shared/update-channel const UPDATE_CHANNEL_ENV_KEY = 'AIRI_UPDATE_CHANNEL' -function getCacheRoot() { - // NOTICE: Electron resolves the cache directory per platform/app, but the - // shipped type definitions here do not expose `cache`, so we cast the key. - return app.getPath('cache' as Parameters[0]) -} - +/** + * The updater log is next to the session logs of `app/file-logger.ts`, in the user data directory. So an install with + * its own user data directory, for example a test build, writes its own log. + */ function updaterLogFile() { - return join(getCacheRoot(), 'stage-tamagotchi-updater', 'updater-log.txt') + return join(app.getPath('userData'), 'logs', 'updater-log.txt') } async function logToFile(level: 'INFO' | 'WARN' | 'ERROR', message: string) {