Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): keep same-team mutations owner-held (R13-M1)
Josuéf28f46c17829
diff --git a/desktop-app/src/__tests__/appService.teamTransitionOwnership.test.ts b/desktop-app/src/__tests__/appService.teamTransitionOwnership.test.tsindex 749b2b3e8..72357ca0a 100644--- a/desktop-app/src/__tests__/appService.teamTransitionOwnership.test.ts+++ b/desktop-app/src/__tests__/appService.teamTransitionOwnership.test.ts@@ -8,6 +8,56 @@ import {afterEach(cleanupNativeCommitTestHarness)describe('AppService deliberate team transition ownership', () => {+ it('returns a committed same-team approval before a queued logout', async () => {+ const { service } = await createNativeCommitTestHarness()+ const decisionResponse = deferred<{ approvalId: string; status: string }>()+ const decisionStarted = deferred<void>()+ const logoutCleanupStarted = vi.fn()+ const me = {+ id: 'user-a',+ email: '[email protected]',+ name: 'User A',+ picture: null,+ teamId: 'team-a',+ teamName: 'Team A',+ role: 'member',+ }+ const app = service as unknown as {+ authClient: unknown+ decideWorkflowApproval(+ approvalId: string,+ decision: 'approve' | 'reject',+ note?: string,+ options?: { teamId?: string | null }+ ): Promise<{ approvalId: string; status: string }>+ suspendDesktopGfsUploadsForAuthBoundary: () => Promise<void>+ }+ app.authClient = {+ googleLogin: vi.fn().mockResolvedValue({ token: 'session-a', me }),+ decideWorkflowApproval: vi.fn(() => {+ decisionStarted.resolve()+ return decisionResponse.promise+ }),+ }+ app.suspendDesktopGfsUploadsForAuthBoundary = vi.fn(async () => {+ logoutCleanupStarted()+ })+ await service.googleLogin('synthetic-google-token')++ const decision = app.decideWorkflowApproval('approval-a', 'approve', undefined, {+ teamId: 'team-a',+ })+ await decisionStarted.promise+ const logout = service.logout()+ await new Promise(resolve => setTimeout(resolve, 0))+ expect(logoutCleanupStarted).not.toHaveBeenCalled()++ const committedResponse = { approvalId: 'approval-a', status: 'approved' }+ decisionResponse.resolve(committedResponse)+ await expect(decision).resolves.toEqual(committedResponse)+ await expect(logout).resolves.toBeTypeOf('number')+ })+it('rejects a stale handoff generation after a public login advances the session', async () => {const { service, runtimeConfig, optionA } = await createNativeCommitTestHarness()const app = service as unknown as {diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.tsindex 73ab62356..3836b702d 100644--- a/desktop-app/src/appService.ts+++ b/desktop-app/src/appService.ts@@ -1233,19 +1233,24 @@ export class AppService {private runWithTeamContext<T>(teamId: string | null | undefined,- operation: (sessionToken: string) => Promise<T>+ operation: (sessionToken: string) => Promise<T>,+ options: { mutation?: boolean } = {}): Promise<T> {const targetTeamId = String(teamId || '').trim()- const run = () => this.runWithTeamContextInTeamQueue(targetTeamId, operation)+ const run = () => this.runWithTeamContextInTeamQueue(targetTeamId, operation, options)return run()}private async runWithTeamContextInTeamQueue<T>(targetTeamId: string,- operation: (sessionToken: string) => Promise<T>+ operation: (sessionToken: string) => Promise<T>,+ options: { mutation?: boolean } = {}): Promise<T> {if (!targetTeamId) {await this.teamContextQueue.catch(() => undefined)+ if (options.mutation) {+ return this.withNativeAuthEnvironmentCommit(() => operation(this.requireSessionToken()))+ }return operation(this.requireSessionToken())}@@ -1299,6 +1304,14 @@ export class AppService {}if (context.teamId === targetTeamId) {+ if (options.mutation) {+ return this.withNativeAuthEnvironmentCommit(async () => {+ assertContextIsCurrent()+ const result = await operation(context.sessionToken)+ assertContextIsCurrent()+ return result+ })+ }const { request } = await this.withNativeAuthEnvironmentCommit(async () => {assertContextIsCurrent()return { request: operation(context.sessionToken) }@@ -3243,8 +3256,10 @@ export class AppService {): Promise<WorkflowApprovalDecisionResult> {const targetTeamId =String(options.teamId || '').trim() || this.workflowApprovalTeamById.get(approvalId) || null- const result = await this.runWithTeamContext(targetTeamId, token =>- this.authClient.decideWorkflowApproval(token, approvalId, decision, note)+ const result = await this.runWithTeamContext(+ targetTeamId,+ token => this.authClient.decideWorkflowApproval(token, approvalId, decision, note),+ { mutation: true })this.workflowApprovalTeamById.delete(approvalId)return result@@ -3702,8 +3717,10 @@ export class AppService {const body: Record<string, unknown> = {}if (inputs) body.inputs = inputsconst teamId = this.workflowTeamByKey.get(this.workflowKey(ns, name)) || null- return this.runWithTeamContext(teamId, token =>- this.authClient.triggerWorkflow(token, ns, name, body, idempotencyKey)+ return this.runWithTeamContext(+ teamId,+ token => this.authClient.triggerWorkflow(token, ns, name, body, idempotencyKey),+ { mutation: true })}