refactor(stage-tamagotchi): drop Steam userData isolation

This commit is contained in:
Lulu
2026-08-07 23:21:45 +08:00
parent b87888d0f5
commit 7cdbb33217
3 changed files with 1 additions and 77 deletions
@@ -1,40 +0,0 @@
import { join } from 'node:path'
import { describe, expect, it } from 'vitest'
import { resolveUserDataPath } from './userData'
describe('resolveUserDataPath', () => {
it('keeps the Electron default for direct builds', () => {
expect(resolveUserDataPath({
defaultPath: join('app-data', 'AIRI'),
distribution: 'direct',
})).toBeUndefined()
})
it('prefers an explicit operational override', () => {
expect(resolveUserDataPath({
defaultPath: join('app-data', 'AIRI'),
distribution: 'steam',
overridePath: ` ${join('test-data', 'airi')} `,
})).toBe(join('test-data', 'airi'))
})
// https://github.com/moeru-ai/airi/pull/1966#discussion_r3432862899
it('isolates Steam user data from direct installations for PR #1966', () => {
// ROOT CAUSE:
//
// Steam and direct builds both accepted Electron's default userData path,
// so a Steam launch could restore credentials and local state written by a
// direct installation before startup Steam authentication ran.
//
// Before the fix, this returned undefined and kept the shared default.
//
// We fixed this by deriving a Steam-only sibling directory while keeping
// the explicit APP_USER_DATA_PATH override authoritative.
expect(resolveUserDataPath({
defaultPath: join('app-data', 'AIRI'),
distribution: 'steam',
})).toBe(join('app-data', 'AIRI-steam'))
})
})
@@ -1,31 +0,0 @@
import { basename, dirname, join } from 'node:path'
/**
* Selects an explicit Electron user-data directory when the runtime requests
* one. Returning `undefined` preserves Electron's default directory.
*
* `APP_USER_DATA_PATH` is an operational override used by smoke tests and
* remains authoritative over build-distribution policy. Steam builds use a
* sibling directory so channel-local credentials, plugins, settings, and
* caches cannot be restored from a direct installation.
*/
export function resolveUserDataPath(params: {
defaultPath: string
distribution?: string
overridePath?: string
}): string | undefined {
const overridePath = params.overridePath?.trim()
if (overridePath)
return overridePath
if (params.distribution === 'steam') {
// Derive from Electron's platform-specific default instead of hardcoding
// macOS, Windows, or Linux application-data locations.
return join(
dirname(params.defaultPath),
`${basename(params.defaultPath)}-steam`,
)
}
return undefined
}
+1 -6
View File
@@ -23,7 +23,6 @@ import icon from '../../resources/icon.png?asset'
import { openDebugger, setupDebugger } from './app/debugger'
import { nullFileLoggerHandle, setupFileLogger } from './app/file-logger'
import { installSingleInstanceGuard } from './app/single-instance'
import { resolveUserDataPath } from './app/userData'
import { createArtistryConfig } from './configs/artistry'
import { createGlobalAppConfig } from './configs/global'
import { emitAppBeforeQuit, emitAppReady, emitAppWindowAllClosed } from './libs/bootkit/lifecycle'
@@ -66,11 +65,7 @@ setupDebugger()
const log = useLogg('main').useGlobalConfig()
const appUserDataPath = resolveUserDataPath({
defaultPath: app.getPath('userData'),
distribution: import.meta.env.VITE_DISTRIBUTION,
overridePath: env.APP_USER_DATA_PATH,
})
const appUserDataPath = env.APP_USER_DATA_PATH?.trim()
if (appUserDataPath) {
app.setPath('userData', appUserDataPath)
}