@@ -3,6 +3,7 @@ import { useEffect } from 'react';
33import { beforeEach , describe , expect , it , vi } from 'vitest' ;
44
55import * as coreStateApi from '../../services/coreStateApi' ;
6+ import * as tauriCommands from '../../utils/tauriCommands' ;
67import { setCoreStateSnapshot } from '../../lib/coreState/store' ;
78import CoreStateProvider , { useCoreState } from '../CoreStateProvider' ;
89
@@ -78,6 +79,7 @@ function resetCoreStateStore() {
7879 onboardingCompleted : false ,
7980 chatOnboardingCompleted : false ,
8081 analyticsEnabled : false ,
82+ meetAutoOrchestratorHandoff : false ,
8183 localState : { encryptionKey : null , primaryWalletAddress : null , onboardingTasks : null } ,
8284 runtime : { screenIntelligence : null , localAi : null , autocomplete : null , service : null } ,
8385 } ,
@@ -241,4 +243,68 @@ describe('CoreStateProvider — identity-change cache clearing', () => {
241243 expect ( ctx ?. snapshot . currentUser ) . toEqual ( { first_name : 'Ada' , username : 'ada' } )
242244 ) ;
243245 } ) ;
246+
247+ it ( 'setMeetAutoOrchestratorHandoff(true) calls update RPC + flips snapshot optimistically (#1299)' , async ( ) => {
248+ fetchSnapshot . mockResolvedValue ( makeSnapshot ( { userId : 'u1' , sessionToken : 'tok1' } ) ) ;
249+ listTeams . mockResolvedValue ( [ ] ) ;
250+ vi . mocked ( tauriCommands . openhumanUpdateMeetSettings ) . mockReset ( ) ;
251+ vi . mocked ( tauriCommands . openhumanUpdateMeetSettings ) . mockResolvedValue ( {
252+ result : { config : { } , workspace_dir : '/tmp' , config_path : '/tmp/cfg.toml' } ,
253+ logs : [ ] ,
254+ } as never ) ;
255+
256+ let ctx : CoreStateContextValue | undefined ;
257+ render (
258+ < CoreStateProvider >
259+ < Consumer
260+ captureCtx = { next => {
261+ ctx = next ;
262+ } }
263+ />
264+ </ CoreStateProvider >
265+ ) ;
266+
267+ await waitFor ( ( ) => expect ( screen . getByTestId ( 'ready' ) . textContent ) . toBe ( 'ready' ) ) ;
268+ expect ( ctx ?. snapshot . meetAutoOrchestratorHandoff ) . toBe ( false ) ;
269+
270+ await act ( async ( ) => {
271+ await ctx ! . setMeetAutoOrchestratorHandoff ( true ) ;
272+ } ) ;
273+
274+ expect ( vi . mocked ( tauriCommands . openhumanUpdateMeetSettings ) ) . toHaveBeenCalledWith ( {
275+ auto_orchestrator_handoff : true ,
276+ } ) ;
277+ } ) ;
278+
279+ it ( 'setMeetAutoOrchestratorHandoff swallows refresh errors after the RPC succeeds (#1299)' , async ( ) => {
280+ fetchSnapshot . mockResolvedValueOnce ( makeSnapshot ( { userId : 'u1' , sessionToken : 'tok1' } ) ) ;
281+ listTeams . mockResolvedValue ( [ ] ) ;
282+ vi . mocked ( tauriCommands . openhumanUpdateMeetSettings ) . mockReset ( ) ;
283+ vi . mocked ( tauriCommands . openhumanUpdateMeetSettings ) . mockResolvedValue ( {
284+ result : { config : { } , workspace_dir : '/tmp' , config_path : '/tmp/cfg.toml' } ,
285+ logs : [ ] ,
286+ } as never ) ;
287+
288+ let ctx : CoreStateContextValue | undefined ;
289+ render (
290+ < CoreStateProvider >
291+ < Consumer
292+ captureCtx = { next => {
293+ ctx = next ;
294+ } }
295+ />
296+ </ CoreStateProvider >
297+ ) ;
298+
299+ await waitFor ( ( ) => expect ( screen . getByTestId ( 'ready' ) . textContent ) . toBe ( 'ready' ) ) ;
300+ fetchSnapshot . mockRejectedValueOnce ( new Error ( 'refresh failed' ) ) ;
301+
302+ await act ( async ( ) => {
303+ await expect ( ctx ! . setMeetAutoOrchestratorHandoff ( false ) ) . resolves . toBeUndefined ( ) ;
304+ } ) ;
305+
306+ expect ( vi . mocked ( tauriCommands . openhumanUpdateMeetSettings ) ) . toHaveBeenCalledWith ( {
307+ auto_orchestrator_handoff : false ,
308+ } ) ;
309+ } ) ;
244310} ) ;
0 commit comments