@@ -108,31 +108,39 @@ describe("DesktopWslBackend", () => {
108108 ) ;
109109 it . effect ( "clears the stored preflight error when a registered WSL backend becomes ready" , ( ) => {
110110 let registeredSpec : DesktopBackendPool . BackendInstanceSpec | undefined ;
111+ let registeredWsl : DesktopBackendPool . DesktopBackendInstance | undefined ;
112+ let startCount = 0 ;
111113 const primary = makeStubInstance ( {
112114 id : DesktopBackendPool . PRIMARY_INSTANCE_ID ,
113115 label : "Windows" ,
114116 snapshot : primarySnapshot ,
115117 } ) ;
116- const wsl = makeStubInstance ( {
117- id : DesktopBackendPool . BackendInstanceId ( "wsl:Ubuntu" ) ,
118- label : "WSL (Ubuntu)" ,
119- snapshot : primarySnapshot ,
120- } ) ;
121118 const poolLayer = Layer . succeed ( DesktopBackendPool . DesktopBackendPool , {
122119 get : ( id ) =>
123120 Effect . succeed (
124121 id === DesktopBackendPool . PRIMARY_INSTANCE_ID
125122 ? Option . some ( primary )
126123 : Option . none < DesktopBackendPool . DesktopBackendInstance > ( ) ,
127124 ) ,
128- list : Effect . succeed ( [ primary ] ) ,
125+ list : Effect . sync ( ( ) => ( registeredWsl === undefined ? [ primary ] : [ primary , registeredWsl ] ) ) ,
129126 primary : Effect . succeed ( primary ) ,
130127 register : ( spec ) =>
131128 Effect . sync ( ( ) => {
132129 registeredSpec = spec ;
133- return wsl ;
130+ registeredWsl = makeStubInstance ( {
131+ id : spec . id ,
132+ label : "WSL" ,
133+ snapshot : idleSnapshot ,
134+ start : Effect . sync ( ( ) => {
135+ startCount += 1 ;
136+ } ) ,
137+ } ) ;
138+ return registeredWsl ;
139+ } ) ,
140+ unregister : ( ) =>
141+ Effect . sync ( ( ) => {
142+ registeredWsl = undefined ;
134143 } ) ,
135- unregister : ( ) => Effect . die ( "unexpected unregister" ) ,
136144 } satisfies DesktopBackendPool . DesktopBackendPool [ "Service" ] ) ;
137145
138146 return Effect . gen ( function * ( ) {
@@ -162,13 +170,29 @@ describe("DesktopWslBackend", () => {
162170 assert . deepEqual ( yield * backend . lastPreflightError , Option . some ( "Node.js not found" ) ) ;
163171
164172 yield * recordOwnershipFailure ( ) ;
165- assert . include (
166- Option . getOrThrow ( yield * backend . lastPreflightError ) ,
167- "This distro's T3 home is owned" ,
168- ) ;
173+ const refusal = yield * backend . lastPreflightError ;
174+ assert . include ( Option . getOrThrow ( refusal ) , "This distro's T3 home is owned" ) ;
175+ yield * backend . reconcile ;
176+ assert . equal ( startCount , 1 ) ;
177+ assert . deepEqual ( yield * backend . lastPreflightError , refusal ) ;
169178
170179 yield * clearFailure ( new URL ( "http://127.0.0.1:41773" ) ) ;
171180 assert . deepEqual ( yield * backend . lastPreflightError , Option . none ( ) ) ;
181+ yield * recordOwnershipFailure ( ) ;
182+ const settings = yield * DesktopAppSettings . DesktopAppSettings ;
183+ yield * settings . setWslDistro ( "Debian" ) ;
184+ yield * backend . reconcile ;
185+ assert . equal ( startCount , 2 ) ;
186+ assert . deepEqual ( yield * backend . lastPreflightError , Option . none ( ) ) ;
187+ const nextSpec = registeredSpec ;
188+ if ( nextSpec ?. onStateDirOwned === undefined ) throw new Error ( "Expected ownership callback" ) ;
189+ yield * nextSpec . onStateDirOwned ( ) ;
190+ yield * settings . setWslBackendEnabled ( false ) ;
191+ yield * backend . reconcile ;
192+ yield * settings . setWslBackendEnabled ( true ) ;
193+ yield * backend . reconcile ;
194+ assert . equal ( startCount , 3 ) ;
195+ assert . deepEqual ( yield * backend . lastPreflightError , Option . none ( ) ) ;
172196 } ) . pipe (
173197 Effect . provide (
174198 DesktopWslBackend . layer . pipe (
0 commit comments