@@ -112,36 +112,59 @@ const authAccessHarness = vi.hoisted(() => {
112112 } ;
113113} ) ;
114114
115- vi . mock ( "../../environments/runtime" , async ( ) => {
116- const actual = await vi . importActual < typeof import ( "../../environments/runtime" ) > (
117- "../../environments/runtime" ,
118- ) ;
119-
120- return {
121- ...actual ,
122- getPrimaryEnvironmentConnection : ( ) => ( {
123- kind : "primary" as const ,
124- knownEnvironment : {
125- id : "environment-local" ,
126- label : "Local environment" ,
127- source : "manual" as const ,
128- environmentId : EnvironmentId . makeUnsafe ( "environment-local" ) ,
129- target : {
130- httpBaseUrl : "http://localhost:3000" ,
131- wsBaseUrl : "ws://localhost:3000" ,
132- } ,
133- } ,
115+ vi . mock ( "../../environments/runtime" , ( ) => {
116+ const primaryConnection = {
117+ kind : "primary" as const ,
118+ knownEnvironment : {
119+ id : "environment-local" ,
120+ label : "Local environment" ,
121+ source : "manual" as const ,
134122 environmentId : EnvironmentId . makeUnsafe ( "environment-local" ) ,
135- client : {
136- server : {
137- subscribeAuthAccess : ( listener : Parameters < typeof authAccessHarness . subscribe > [ 0 ] ) =>
138- authAccessHarness . subscribe ( listener ) ,
139- } ,
123+ target : {
124+ httpBaseUrl : "http://localhost:3000" ,
125+ wsBaseUrl : "ws://localhost:3000" ,
140126 } ,
141- ensureBootstrapped : async ( ) => undefined ,
142- reconnect : async ( ) => undefined ,
143- dispose : async ( ) => undefined ,
144- } ) ,
127+ } ,
128+ environmentId : EnvironmentId . makeUnsafe ( "environment-local" ) ,
129+ client : {
130+ server : {
131+ subscribeAuthAccess : ( listener : Parameters < typeof authAccessHarness . subscribe > [ 0 ] ) =>
132+ authAccessHarness . subscribe ( listener ) ,
133+ } ,
134+ } ,
135+ ensureBootstrapped : async ( ) => undefined ,
136+ reconnect : async ( ) => undefined ,
137+ dispose : async ( ) => undefined ,
138+ } ;
139+
140+ return {
141+ getEnvironmentHttpBaseUrl : ( ) => "http://localhost:3000" ,
142+ getSavedEnvironmentRecord : ( ) => null ,
143+ getSavedEnvironmentRuntimeState : ( ) => null ,
144+ hasSavedEnvironmentRegistryHydrated : ( ) => true ,
145+ listSavedEnvironmentRecords : ( ) => [ ] ,
146+ resetSavedEnvironmentRegistryStoreForTests : ( ) => undefined ,
147+ resetSavedEnvironmentRuntimeStoreForTests : ( ) => undefined ,
148+ resolveEnvironmentHttpUrl : ( _environmentId : unknown , path : string ) =>
149+ new URL ( path , "http://localhost:3000" ) . toString ( ) ,
150+ waitForSavedEnvironmentRegistryHydration : async ( ) => undefined ,
151+ addSavedEnvironment : vi . fn ( ) ,
152+ disconnectSavedEnvironment : vi . fn ( ) ,
153+ ensureEnvironmentConnectionBootstrapped : async ( ) => undefined ,
154+ getPrimaryEnvironmentConnection : ( ) => primaryConnection ,
155+ readEnvironmentConnection : ( ) => primaryConnection ,
156+ reconnectSavedEnvironment : vi . fn ( ) ,
157+ removeSavedEnvironment : vi . fn ( ) ,
158+ requireEnvironmentConnection : ( ) => primaryConnection ,
159+ resetEnvironmentServiceForTests : ( ) => undefined ,
160+ startEnvironmentConnectionService : ( ) => undefined ,
161+ subscribeEnvironmentConnections : ( ) => ( ) => { } ,
162+ useSavedEnvironmentRegistryStore : (
163+ selector : ( state : { byId : Record < string , never > } ) => unknown ,
164+ ) => selector ( { byId : { } } ) ,
165+ useSavedEnvironmentRuntimeStore : (
166+ selector : ( state : { byId : Record < string , never > } ) => unknown ,
167+ ) => selector ( { byId : { } } ) ,
145168 } ;
146169} ) ;
147170
@@ -292,6 +315,13 @@ const createDesktopBridgeStub = (overrides?: {
292315} ;
293316
294317describe ( "GeneralSettingsPanel observability" , ( ) => {
318+ let mounted :
319+ | ( Awaited < ReturnType < typeof render > > & {
320+ cleanup ?: ( ) => Promise < void > ;
321+ unmount ?: ( ) => Promise < void > ;
322+ } )
323+ | null = null ;
324+
295325 beforeEach ( async ( ) => {
296326 resetServerStateForTests ( ) ;
297327 await __resetLocalApiForTests ( ) ;
@@ -300,6 +330,15 @@ describe("GeneralSettingsPanel observability", () => {
300330 } ) ;
301331
302332 afterEach ( async ( ) => {
333+ if ( mounted ) {
334+ const teardown = mounted . cleanup ?? mounted . unmount ;
335+ await teardown ?. call ( mounted ) . catch ( ( ) => { } ) ;
336+ }
337+ mounted = null ;
338+ vi . unstubAllGlobals ( ) ;
339+ Reflect . deleteProperty ( window , "desktopBridge" ) ;
340+ Reflect . deleteProperty ( window , "nativeApi" ) ;
341+ document . body . innerHTML = "" ;
303342 resetServerStateForTests ( ) ;
304343 await __resetLocalApiForTests ( ) ;
305344 authAccessHarness . reset ( ) ;
@@ -351,7 +390,7 @@ describe("GeneralSettingsPanel observability", () => {
351390 } ) ;
352391 vi . stubGlobal ( "fetch" , fetchMock ) ;
353392
354- await render (
393+ mounted = await render (
355394 < AppAtomRegistryProvider >
356395 < ConnectionsSettings />
357396 </ AppAtomRegistryProvider > ,
@@ -376,7 +415,7 @@ describe("GeneralSettingsPanel observability", () => {
376415 it ( "shows diagnostics inside About with a single logs-folder action" , async ( ) => {
377416 setServerConfigSnapshot ( createBaseServerConfig ( ) ) ;
378417
379- await render (
418+ mounted = await render (
380419 < AppAtomRegistryProvider >
381420 < GeneralSettingsPanel />
382421 </ AppAtomRegistryProvider > ,
@@ -490,7 +529,7 @@ describe("GeneralSettingsPanel observability", () => {
490529
491530 setServerConfigSnapshot ( createBaseServerConfig ( ) ) ;
492531
493- await render (
532+ mounted = await render (
494533 < AppAtomRegistryProvider >
495534 < ConnectionsSettings />
496535 </ AppAtomRegistryProvider > ,
@@ -583,7 +622,7 @@ describe("GeneralSettingsPanel observability", () => {
583622
584623 setServerConfigSnapshot ( createBaseServerConfig ( ) ) ;
585624
586- await render (
625+ mounted = await render (
587626 < AppAtomRegistryProvider >
588627 < ConnectionsSettings />
589628 </ AppAtomRegistryProvider > ,
@@ -602,7 +641,7 @@ describe("GeneralSettingsPanel observability", () => {
602641
603642 setServerConfigSnapshot ( createBaseServerConfig ( ) ) ;
604643
605- await render (
644+ mounted = await render (
606645 < AppAtomRegistryProvider >
607646 < ConnectionsSettings />
608647 </ AppAtomRegistryProvider > ,
@@ -634,7 +673,7 @@ describe("GeneralSettingsPanel observability", () => {
634673
635674 setServerConfigSnapshot ( createBaseServerConfig ( ) ) ;
636675
637- await render (
676+ mounted = await render (
638677 < AppAtomRegistryProvider >
639678 < GeneralSettingsPanel />
640679 </ AppAtomRegistryProvider > ,
0 commit comments