55} from "@t3tools/contracts" ;
66import {
77 SshCommandSpawnError ,
8- SshCommandTimeoutError ,
98 SshHttpBridgeError ,
109 SshPasswordPromptWindowClosedError ,
1110} from "@t3tools/ssh/errors" ;
@@ -21,9 +20,9 @@ import * as HttpClientResponse from "effect/unstable/http/HttpClientResponse";
2120
2221import {
2322 DesktopSshEnvironmentRequestError ,
23+ disconnectSshEnvironment ,
2424 ensureSshEnvironment ,
2525 fetchSshEnvironmentDescriptor ,
26- toDesktopSshIpcPresentationError ,
2726} from "./sshEnvironment.ts" ;
2827import * as DesktopSshEnvironment from "../../ssh/DesktopSshEnvironment.ts" ;
2928import * as DesktopSshPasswordPrompts from "../../ssh/DesktopSshPasswordPrompts.ts" ;
@@ -95,30 +94,43 @@ describe("SSH environment IPC", () => {
9594 } ) . pipe ( Effect . provide ( layer ) ) ;
9695 } ) ;
9796
98- it ( "presents legacy process causes without weakening structured errors ", ( ) => {
97+ it . effect ( "preserves structural SSH errors and exact causes at the IPC boundary ", ( ) => {
9998 const cause = new Error ( "ssh executable was not found" ) ;
10099 const structured = new SshCommandSpawnError ( {
101100 command : "ssh" ,
102101 argumentCount : 0 ,
103102 target : "devbox" ,
104103 cause,
105104 } ) ;
105+ const target = {
106+ alias : "devbox" ,
107+ hostname : "devbox.example.test" ,
108+ username : "developer" ,
109+ port : 22 ,
110+ } ;
111+ const layer = Layer . succeed (
112+ DesktopSshEnvironment . DesktopSshEnvironment ,
113+ DesktopSshEnvironment . DesktopSshEnvironment . of ( {
114+ discoverHosts : ( ) => Effect . die ( "unexpected host discovery" ) ,
115+ ensureEnvironment : ( ) => Effect . fail ( structured ) ,
116+ disconnectEnvironment : ( ) => Effect . fail ( structured ) ,
117+ } ) ,
118+ ) ;
106119
107- const presentation = toDesktopSshIpcPresentationError ( structured ) ;
108- assert . equal ( structured . message , "Failed to spawn SSH command for devbox." ) ;
109- assert . equal ( presentation . message , cause . message ) ;
110- assert . strictEqual ( presentation . cause , structured ) ;
111- } ) ;
112-
113- it ( "passes structural SSH errors without process causes through the IPC boundary" , ( ) => {
114- const structured = new SshCommandTimeoutError ( {
115- command : "ssh" ,
116- argumentCount : 0 ,
117- target : "devbox" ,
118- timeoutMs : 30_000 ,
119- } ) ;
120-
121- assert . strictEqual ( toDesktopSshIpcPresentationError ( structured ) , structured ) ;
120+ return Effect . gen ( function * ( ) {
121+ const exits = yield * Effect . all ( [
122+ Effect . exit ( ensureSshEnvironment . handler ( { target } ) ) ,
123+ Effect . exit ( disconnectSshEnvironment . handler ( target ) ) ,
124+ ] ) ;
125+ for ( const exit of exits ) {
126+ assert ( Exit . isFailure ( exit ) ) ;
127+ const failure = Cause . findErrorOption ( exit . cause ) ;
128+ assert ( Option . isSome ( failure ) ) ;
129+ assert . strictEqual ( failure . value , structured ) ;
130+ }
131+ assert . equal ( structured . message , "Failed to spawn SSH command for devbox." ) ;
132+ assert . strictEqual ( structured . cause , cause ) ;
133+ } ) . pipe ( Effect . provide ( layer ) ) ;
122134 } ) ;
123135
124136 it . effect ( "fetches and decodes the remote environment descriptor" , ( ) => {
0 commit comments