@@ -11,6 +11,7 @@ import * as Layer from "effect/Layer";
1111import * as Path from "effect/Path" ;
1212import * as ChildProcess from "effect/process/ChildProcess" ;
1313import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner" ;
14+ import * as TestClock from "effect/testing/TestClock" ;
1415import * as NodeOS from "node:os" ;
1516import { vi } from "vite-plus/test" ;
1617
@@ -30,7 +31,13 @@ const target = {
3031} ;
3132
3233function runRecoveryScenario (
33- operation : "resolve" | "connect" | "still-unavailable" | "fallback-shell" | "launchctl" ,
34+ operation :
35+ | "resolve"
36+ | "connect"
37+ | "disconnect"
38+ | "still-unavailable"
39+ | "fallback-shell"
40+ | "launchctl" ,
3441) {
3542 return Effect . gen ( function * ( ) {
3643 const fs = yield * FileSystem . FileSystem ;
@@ -76,7 +83,7 @@ function runRecoveryScenario(
7683 yield * fs . chmod ( path . join ( helpers , "workspace-check" ) , 0o700 ) ;
7784 yield * fs . writeFileString (
7885 path . join ( helpers , "workspace-proxy" ) ,
79- `#!/bin/sh\nprintf 'proxy invoked\\n' > '${ proxyReached } '\nexit 1\n` ,
86+ `#!/bin/sh\nprintf 'proxy invoked %s \\n' "$1" > '${ proxyReached } '\nexit 1\n` ,
8087 ) ;
8188 yield * fs . chmod ( path . join ( helpers , "workspace-proxy" ) , 0o700 ) ;
8289 yield * fs . writeFileString (
@@ -86,7 +93,7 @@ function runRecoveryScenario(
8693 " HostName helper-ready.invalid" ,
8794 "Host managed-workspace" ,
8895 " HostName helper-missing.invalid" ,
89- " ProxyCommand workspace-proxy" ,
96+ " ProxyCommand workspace-proxy %h " ,
9097 " ControlMaster no" ,
9198 " ControlPath none" ,
9299 "" ,
@@ -121,28 +128,60 @@ function runRecoveryScenario(
121128 const ssh = yield * DesktopSshEnvironment . DesktopSshEnvironment ;
122129 assert . equal ( yield * shell . installIntoProcess , false ) ;
123130 if ( operation !== "still-unavailable" ) yield * fs . writeFileString ( ready , "" ) ;
131+ const initialProbes = operation === "fallback-shell" ? "probe\nprobe\n" : "probe\n" ;
132+ assert . equal ( yield * shell . installIntoProcess , false ) ;
133+ assert . equal ( ( yield * ssh . resolveHost ( target . alias ) ) . hostname , "helper-missing.invalid" ) ;
134+ assert . equal ( yield * fs . readFileString ( probes ) , initialProbes ) ;
135+ yield * TestClock . adjust ( "4999 millis" ) ;
136+ assert . equal ( ( yield * ssh . resolveHost ( target . alias ) ) . hostname , "helper-missing.invalid" ) ;
137+ assert . equal ( yield * fs . readFileString ( probes ) , initialProbes ) ;
138+ yield * TestClock . adjust ( "1 millis" ) ;
124139 if ( operation === "resolve" || operation === "fallback-shell" || operation === "launchctl" ) {
125140 assert . equal ( ( yield * ssh . resolveHost ( target . alias ) ) . hostname , "helper-ready.invalid" ) ;
126141 assert . equal ( ( yield * ssh . resolveHost ( target . alias ) ) . hostname , "helper-ready.invalid" ) ;
127142 } else {
128- const result = yield * Effect . result ( ssh . ensureEnvironment ( target ) ) ;
143+ if ( operation === "disconnect" ) {
144+ assert . equal ( ( yield * ssh . resolveHost ( target . alias ) ) . hostname , "helper-ready.invalid" ) ;
145+ }
146+ const result = yield * Effect . result (
147+ operation === "disconnect"
148+ ? ssh . disconnectEnvironment ( target )
149+ : ssh . ensureEnvironment ( target ) ,
150+ ) ;
129151 assert . equal ( result . _tag , "Failure" ) ;
130152 if ( result . _tag === "Failure" ) assert . instanceOf ( result . failure , SshCommandError ) ;
131- if ( operation === "connect" ) {
132- assert . equal ( yield * fs . readFileString ( proxyReached ) , "proxy invoked\n" ) ;
153+ if ( operation === "connect" || operation === "disconnect" ) {
154+ assert . equal (
155+ yield * fs . readFileString ( proxyReached ) ,
156+ operation === "disconnect"
157+ ? "proxy invoked helper-missing.invalid\n"
158+ : "proxy invoked helper-ready.invalid\n" ,
159+ ) ;
133160 assert . equal ( ( yield * ssh . resolveHost ( target . alias ) ) . hostname , "helper-ready.invalid" ) ;
134161 } else {
135162 assert . equal ( yield * fs . exists ( proxyReached ) , false ) ;
136163 if ( result . _tag === "Failure" ) {
137164 assert . include ( result . failure . message , "workspace-proxy" ) ;
138165 }
166+ assert . equal ( ( yield * ssh . resolveHost ( target . alias ) ) . hostname , "helper-missing.invalid" ) ;
139167 }
140168 }
141169 assert . equal (
142170 yield * fs . readFileString ( probes ) ,
143171 operation === "fallback-shell" ? "probe\nprobe\nprobe\n" : "probe\nprobe\n" ,
144172 ) ;
145173 assert . equal ( process . env . PATH , operation === "still-unavailable" ? inheritedPath : shellPath ) ;
174+ yield * TestClock . adjust ( "1 hour" ) ;
175+ assert . equal (
176+ ( yield * ssh . resolveHost ( target . alias ) ) . hostname ,
177+ operation === "still-unavailable" ? "helper-missing.invalid" : "helper-ready.invalid" ,
178+ ) ;
179+ assert . equal (
180+ yield * fs . readFileString ( probes ) ,
181+ operation === "still-unavailable" || operation === "fallback-shell"
182+ ? "probe\nprobe\nprobe\n"
183+ : "probe\nprobe\n" ,
184+ ) ;
146185 } ) . pipe (
147186 Effect . provide (
148187 layerSsh . pipe (
@@ -189,6 +228,10 @@ function runRecoveryScenario(
189228}
190229
191230describe ( "SSH shell PATH recovery with real OpenSSH" , ( ) => {
231+ it . effect . runIf ( HostProcess . Platform . defaultValue ( ) === "darwin" ) (
232+ "pins remote cleanup to the supplied host after PATH recovery changes alias resolution" ,
233+ ( ) => runRecoveryScenario ( "disconnect" ) ,
234+ ) ;
192235 it . effect . runIf ( HostProcess . Platform . defaultValue ( ) === "darwin" ) (
193236 "retries the preferred shell when a fallback shell supplied only a degraded PATH" ,
194237 ( ) => runRecoveryScenario ( "fallback-shell" ) ,
0 commit comments