@@ -88,9 +88,10 @@ function makeMockSettingsKeyAtom(
8888}
8989
9090function makeMockGlobalAtoms (
91- settingsOverrides ?: Partial < SettingsType > ,
92- atomOverrides ?: Partial < GlobalAtomsType > ,
93- tabId ?: string
91+ settingsOverrides : Partial < SettingsType > ,
92+ atomOverrides : Partial < GlobalAtomsType > ,
93+ tabId : string ,
94+ getWaveObjectAtom : < T extends WaveObj > ( oref : string ) => PrimitiveAtom < T >
9495) : GlobalAtomsType {
9596 let fullConfig = DefaultFullConfig ;
9697 if ( settingsOverrides ) {
@@ -101,11 +102,20 @@ function makeMockGlobalAtoms(
101102 }
102103 const fullConfigAtom = atom ( fullConfig ) as PrimitiveAtom < FullConfigType > ;
103104 const settingsAtom = atom ( ( get ) => get ( fullConfigAtom ) ?. settings ?? { } ) as Atom < SettingsType > ;
105+ const workspaceIdAtom : Atom < string > = atomOverrides ?. workspaceId ?? ( atom ( null as string ) as Atom < string > ) ;
106+ const workspaceAtom : Atom < Workspace > = atom ( ( get ) => {
107+ const wsId = get ( workspaceIdAtom ) ;
108+ if ( wsId == null ) {
109+ return null ;
110+ }
111+ return get ( getWaveObjectAtom < Workspace > ( "workspace:" + wsId ) ) ;
112+ } ) ;
104113 const defaults : GlobalAtomsType = {
105114 builderId : atom ( "" ) ,
106115 builderAppId : atom ( "" ) as any ,
107116 uiContext : atom ( { windowid : "" , activetabid : tabId ?? "" } as UIContext ) ,
108- workspace : atom ( null as Workspace ) ,
117+ workspaceId : workspaceIdAtom ,
118+ workspace : workspaceAtom ,
109119 fullConfigAtom,
110120 waveaiModeConfigAtom : atom ( { } ) as any ,
111121 settingsAtom,
@@ -125,7 +135,11 @@ function makeMockGlobalAtoms(
125135 if ( ! atomOverrides ) {
126136 return defaults ;
127137 }
128- return { ...defaults , ...atomOverrides } ;
138+ const merged = { ...defaults , ...atomOverrides } ;
139+ if ( ! atomOverrides . workspace ) {
140+ merged . workspace = workspaceAtom ;
141+ }
142+ return merged ;
129143}
130144
131145type MockWosFns = {
@@ -221,7 +235,14 @@ export function makeMockWaveEnv(mockEnv?: MockEnv): MockWaveEnv {
221235 const waveObjectDerivedAtomCache = new Map < string , Atom < any > > ( ) ;
222236 const blockMetaKeyAtomCache = new Map < string , Atom < any > > ( ) ;
223237 const connConfigKeyAtomCache = new Map < string , Atom < any > > ( ) ;
224- const atoms = makeMockGlobalAtoms ( overrides . settings , overrides . atoms , overrides . tabId ) ;
238+ const getWaveObjectAtom = < T extends WaveObj > ( oref : string ) : PrimitiveAtom < T > => {
239+ if ( ! waveObjectValueAtomCache . has ( oref ) ) {
240+ const obj = ( overrides . mockWaveObjs ?. [ oref ] ?? null ) as T ;
241+ waveObjectValueAtomCache . set ( oref , atom ( obj ) as PrimitiveAtom < T > ) ;
242+ }
243+ return waveObjectValueAtomCache . get ( oref ) as PrimitiveAtom < T > ;
244+ } ;
245+ const atoms = makeMockGlobalAtoms ( overrides . settings , overrides . atoms , overrides . tabId , getWaveObjectAtom ) ;
225246 const localHostDisplayNameAtom = atom < string > ( ( get ) => {
226247 const configValue = get ( atoms . settingsAtom ) ?. [ "conn:localhostdisplayname" ] ;
227248 if ( configValue != null ) {
@@ -230,13 +251,7 @@ export function makeMockWaveEnv(mockEnv?: MockEnv): MockWaveEnv {
230251 return "user@localhost" ;
231252 } ) ;
232253 const mockWosFns : MockWosFns = {
233- getWaveObjectAtom : < T extends WaveObj > ( oref : string ) => {
234- if ( ! waveObjectValueAtomCache . has ( oref ) ) {
235- const obj = ( overrides . mockWaveObjs ?. [ oref ] ?? null ) as T ;
236- waveObjectValueAtomCache . set ( oref , atom ( obj ) as PrimitiveAtom < T > ) ;
237- }
238- return waveObjectValueAtomCache . get ( oref ) as PrimitiveAtom < T > ;
239- } ,
254+ getWaveObjectAtom,
240255 mockSetWaveObj : < T extends WaveObj > ( oref : string , obj : T ) => {
241256 if ( ! waveObjectValueAtomCache . has ( oref ) ) {
242257 waveObjectValueAtomCache . set ( oref , atom ( null as WaveObj ) ) ;
0 commit comments