Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop-app): [R6-M1] keep generation after empty restore
Josué6fdce3865430
diff --git a/desktop-app/src/__tests__/appService.bootstrap.test.ts b/desktop-app/src/__tests__/appService.bootstrap.test.tsindex a3731a2d8..8ef74355b 100644--- a/desktop-app/src/__tests__/appService.bootstrap.test.ts+++ b/desktop-app/src/__tests__/appService.bootstrap.test.ts@@ -503,6 +503,52 @@ describe('AppService invitation configuration lookup', () => {expect(getMe).toHaveBeenCalledTimes(1)})+ it('keeps the completed logout generation when an expired restore finds no saved token', async () => {+ const configPath = await createTempConfigPath('clerum-desktop-restore-after-logout')+ await fs.writeFile(+ configPath,+ JSON.stringify({+ externalRestApiBaseUrl: 'https://api.example.com',+ rpcProxyBaseUrl: 'https://rpc.example.com',+ appName: 'Example',+ })+ )+ process.env.CLERUM_DESKTOP_CONFIG_PATH = configPath+ process.env.EXTERNAL_REST_API_BASE_URL = 'https://api.example.com'+ process.env.RPC_PROXY_BASE_URL = 'https://rpc.example.com'+ vi.resetModules()++ const [{ AppService }, { getActiveEnvKey }] = await Promise.all([+ import('../appService.js'),+ import('../config.js'),+ ])+ const service = new AppService() as unknown as {+ getSessionGeneration: () => number+ getSessionState: () => Promise<unknown>+ logout: () => Promise<number>+ savedSessionRestoreAttemptedEnvKey: string+ savedSessionRestoreAttemptedAtMs: number+ tokenStore: {+ clearSessionToken: ReturnType<typeof vi.fn>+ getSessionToken: ReturnType<typeof vi.fn>+ }+ }+ service.tokenStore = {+ clearSessionToken: vi.fn().mockResolvedValue(undefined),+ getSessionToken: vi.fn().mockResolvedValue(null),+ } as never++ const logoutGeneration = await service.logout()+ service.savedSessionRestoreAttemptedEnvKey = getActiveEnvKey()+ service.savedSessionRestoreAttemptedAtMs = 0++ await expect(service.getSessionState()).resolves.toEqual({ authenticated: false, me: null })+ expect(service.getSessionGeneration()).toBe(logoutGeneration)+ expect(service.tokenStore.getSessionToken).toHaveBeenCalledWith(getActiveEnvKey(), {+ legacyEnvKeys: expect.any(Array),+ })+ })+it('clears a saved token when startup session restore is rejected by the API', async () => {const configPath = await createTempConfigPath('clerum-desktop-restore-api')await fs.writeFile(diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.tsindex 0508c30ae..1d35c6cab 100644--- a/desktop-app/src/appService.ts+++ b/desktop-app/src/appService.ts@@ -1506,14 +1506,20 @@ export class AppService {token = await this.tokenStore.getSessionToken(envKey, { legacyEnvKeys })} catch (error) {console.warn('[AppService] Failed to read the saved session token:', error)- if (this.sessionGeneration === restoreGeneration) {+ if (+ this.sessionGeneration === restoreGeneration &&+ (this.sessionToken !== null || this.me !== null)+ ) {this.clearAuthenticatedSessionState()}return { authenticated: false, me: null }}if (this.logoutInProgress) return { authenticated: false, me: null }if (!token) {- if (this.sessionGeneration === restoreGeneration) {+ if (+ this.sessionGeneration === restoreGeneration &&+ (this.sessionToken !== null || this.me !== null)+ ) {this.clearAuthenticatedSessionState()}return { authenticated: false, me: null }