Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): r1-m6 invalidate drag ownership on every scope switch
Mb1ec3f07e6e6
diff --git a/desktop-app/ui/src/gfs/__tests__/dragSession.test.tsx b/desktop-app/ui/src/gfs/__tests__/dragSession.test.tsxindex ad53044ea..a9e2c98a1 100644--- a/desktop-app/ui/src/gfs/__tests__/dragSession.test.tsx+++ b/desktop-app/ui/src/gfs/__tests__/dragSession.test.tsx@@ -121,6 +121,76 @@ describe('GfsDragSessionProvider — lifecycle binding', () => {await waitFor(() => expect(api!.activeSource()).toBeNull())})+ for (const [dimension, nextScope] of [+ ['team', 'test:user-1:team-2'],+ ['user', 'test:user-2:team-1'],+ ['environment', 'other:user-1:team-1'],+ ] as const) {+ for (const nativeEnded of [false, true]) {+ it(`invalidates ${dimension} scope changes with native end ${nativeEnded}`, () => {+ const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })+ let api: ReturnType<typeof useGfsDragSession> | null = null+ const view = () => (+ <QueryClientProvider client={queryClient}>+ <GfsDragSessionProvider>+ <Probe onApi={captured => (api = captured)} />+ </GfsDragSessionProvider>+ </QueryClientProvider>+ )+ const mounted = render(view())+ expect(api!.beginDrag(source())).toBe(true)+ const admittedGeneration = api!.currentGeneration()+ if (nativeEnded) {+ api!.endDrag()+ expect(api!.activeSource()).toBeNull()+ // Native end preserves an admitted drop until authority changes.+ expect(api!.currentGeneration()).toBe(admittedGeneration)+ }+ authState = {+ ...authState,+ me: {+ ...authState.me,+ ...(dimension === 'team' ? { teamId: 'team-2' } : {}),+ ...(dimension === 'user' ? { id: 'user-2' } : {}),+ },+ runtimeConfigState: { envKey: dimension === 'environment' ? 'other' : 'test' },+ }+ mounted.rerender(view())+ expect(api!.activeSource()).toBeNull()+ expect(api!.currentGeneration()).toBeGreaterThan(admittedGeneration)+ expect(api!.beginDrag(source({ resourceId: 'r-2', scope: nextScope }))).toBe(true)+ expect(api!.activeSource()?.resourceId).toBe('r-2')+ const newGeneration = api!.currentGeneration()+ expect(api!.beginDrag(source())).toBe(false)+ expect(api!.currentGeneration()).toBe(newGeneration)+ expect(api!.activeSource()?.resourceId).toBe('r-2')+ })+ }+ }++ it('invalidates on logout and unmount while refusing further drags', () => {+ const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })+ let api: ReturnType<typeof useGfsDragSession> | null = null+ const view = () => (+ <QueryClientProvider client={queryClient}>+ <GfsDragSessionProvider>+ <Probe onApi={captured => (api = captured)} />+ </GfsDragSessionProvider>+ </QueryClientProvider>+ )+ const mounted = render(view())+ expect(api!.beginDrag(source())).toBe(true)+ const generation = api!.currentGeneration()+ authState = { ...authState, isAuthenticated: false }+ mounted.rerender(view())+ expect(api!.activeSource()).toBeNull()+ expect(api!.currentGeneration()).toBeGreaterThan(generation)+ expect(api!.beginDrag(source())).toBe(false)+ const loggedOutGeneration = api!.currentGeneration()+ mounted.unmount()+ expect(api!.currentGeneration()).toBeGreaterThan(loggedOutGeneration)+ })+it('refuses to begin a drag for a foreign scope', () => {const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })let api: ReturnType<typeof useGfsDragSession> | null = nulldiff --git a/desktop-app/ui/src/gfs/dragSession.tsx b/desktop-app/ui/src/gfs/dragSession.tsxindex 0aa7c6b37..e06fea4a6 100644--- a/desktop-app/ui/src/gfs/dragSession.tsx+++ b/desktop-app/ui/src/gfs/dragSession.tsx@@ -97,9 +97,15 @@ export function GfsDragSessionProvider({ children }: { children: React.ReactNodestaleTime: Infinity,})const accessState: GfsAccessState = accessStateQuery.data ?? 'active'+ const previousScopeRef = useRef(scope)useEffect(() => {- if (scope === null || accessState === 'revoked') store.invalidate('authority')+ const scopeChanged = previousScopeRef.current !== scope+ previousScopeRef.current = scope+ // Native end may already have cleared the transport source while a drop+ // is pending. Every scope transition still invalidates its ownership.+ if (scopeChanged) store.invalidate('scope-change')+ else if (scope === null || accessState === 'revoked') store.invalidate('authority')}, [accessState, scope, store])useEffect(() => () => store.invalidate('authority'), [store])