mirror of
https://github.com/moeru-ai/airi.git
synced 2026-10-30 19:34:10 +08:00
fix(stage-tamagotchi): write the updater log in the user data directory (#3187)
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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<typeof app.getPath>[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) {
|
||||
|
||||
Reference in New Issue
Block a user