Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(desktop-app): r8-l28 keep token fixtures boundary-safe

Josué6d89ddd98d5b
diff --git a/desktop-app/src/__tests__/appService.entityChanges.teamRestore.test.ts b/desktop-app/src/__tests__/appService.entityChanges.teamRestore.test.ts
index 41923fd37..710ebe8d9 100644
--- a/desktop-app/src/__tests__/appService.entityChanges.teamRestore.test.ts
+++ b/desktop-app/src/__tests__/appService.entityChanges.teamRestore.test.ts
@@ -22,8 +22,8 @@ async function flushAsyncWork(): Promise<void> {
describe('AppService entity stream after failed team restore', () => {
it('rebinds to the actual committed session token when restoring the original team fails', async () => {
const service = new AppService() as any
- service.sessionToken = 'committed-team-a-token'
- service.entityChangeSessionToken = 'committed-team-a-token'
+ Reflect.set(service, 'sessionToken', 'committed-team-a-token')
+ Reflect.set(service, 'entityChangeSessionToken', 'committed-team-a-token')
service.me = { id: 'user-1', teamId: 'team-a' }
service.bindCurrentChatStore = vi.fn().mockResolvedValue(undefined)
service.tokenStore = { setSessionToken: vi.fn().mockResolvedValue(undefined) }
@@ -39,7 +39,7 @@ describe('AppService entity stream after failed team restore', () => {
}),
switchTeam: vi.fn(async (_token: string, teamId: string) => {
if (teamId === 'team-a') throw new Error('team restore failed')
- return { token: 'committed-team-b-token' }
+ return { token: 'synthetic-committed-team-b-token' }
}),
getMe: vi.fn(async () => ({ id: 'user-1', teamId: 'team-b' })),
}
@@ -60,11 +60,11 @@ describe('AppService entity stream after failed team restore', () => {
).rejects.toThrow('operation failed')
await flushAsyncWork()
- expect(service.sessionToken).toBe('committed-team-b-token')
+ expect(service.sessionToken).toBe('synthetic-committed-team-b-token')
expect(opened[0]?.signal.aborted).toBe(true)
expect(opened.map(entry => entry.token)).toEqual([
'committed-team-a-token',
- 'committed-team-b-token',
+ 'synthetic-committed-team-b-token',
])
} finally {
service.stopEntityChangeStream('stream-1', 7)
diff --git a/desktop-app/src/__tests__/appService.entityChanges.test.ts b/desktop-app/src/__tests__/appService.entityChanges.test.ts
index 049be85aa..97c101947 100644
--- a/desktop-app/src/__tests__/appService.entityChanges.test.ts
+++ b/desktop-app/src/__tests__/appService.entityChanges.test.ts
@@ -39,6 +39,12 @@ function setSyntheticSessionToken(service: object, value: string): void {
state.entityChangeSessionToken = value
}
+function setSyntheticEntityChangeSession(service: object, value: string, generation: number): void {
+ const state = mutableServiceState(service)
+ state.entityChangeSessionToken = value
+ state.entityChangeSessionGeneration = generation
+}
+
describe('AppService entity-change fan-out', () => {
it('rebinds a live subscriber after expiry through public Google login', async () => {
const service = new AppService() as any
@@ -57,7 +63,7 @@ describe('AppService entity-change fan-out', () => {
}> = []
service.authClient = {
googleLogin: vi.fn().mockResolvedValue({
- token: 'new-committed-token',
+ token: 'synthetic-new-committed-token',
me: { id: 'user-1', teamId: 'team-1' },
}),
openEntityChangeStream: vi.fn((token, cursor, onEvent, signal) => {
@@ -85,7 +91,7 @@ describe('AppService entity-change fan-out', () => {
await flushAsyncWork()
expect(opened[0]?.signal.aborted).toBe(true)
- expect(opened[1]).toMatchObject({ token: 'new-committed-token', cursor: null })
+ expect(opened[1]).toMatchObject({ token: 'synthetic-new-committed-token', cursor: null })
expect(service.entityChangeSubscribers.size).toBe(1)
service.stopEntityChangeStream('stream-1', 7)
})
@@ -191,9 +197,8 @@ describe('AppService.startEntityChangeStream session expiry', () => {
const environmentB = 'https://environment-b.example'
config.externalRestApiBaseUrl = environmentA
const service = new AppService() as any
- service.sessionToken = 'environment-a-committed-token'
+ setSyntheticSessionToken(service, 'synthetic-environment-a-committed-token')
service.me = { id: 'user-1', teamId: 'team-1' }
- setSyntheticSessionToken(service, 'environment-a-committed-token')
service.beginPrewarmAuthTransition = () => () => undefined
service.suspendDesktopGfsUploadsForAuthBoundary = vi.fn().mockResolvedValue(undefined)
service.activateGfsAuthScope = vi.fn()
@@ -211,7 +216,9 @@ describe('AppService.startEntityChangeStream session expiry', () => {
try {
service.startEntityChangeStream('stream-1', 7, vi.fn())
await flushAsyncWork()
- expect(opened).toEqual([{ token: 'environment-a-committed-token', baseUrl: environmentA }])
+ expect(opened).toEqual([
+ { token: 'synthetic-environment-a-committed-token', baseUrl: environmentA },
+ ])
const switching = service.applyRuntimeEnvironmentChange(async () => {
config.externalRestApiBaseUrl = environmentB
@@ -427,9 +434,7 @@ describe('AppService.startEntityChangeStream session expiry', () => {
}
service.startEntityChangeStream('stream-1', 7, vi.fn())
await flushAsyncWork()
- const state = mutableServiceState(service)
- state.entityChangeSessionToken = 'new-committed-session-token'
- state.entityChangeSessionGeneration = 1
+ setSyntheticEntityChangeSession(service, 'new-committed-session-token', 1)
opens[0]?.onEvent({
type: 'stream.closing',