@@ -20,12 +20,7 @@ import {
2020 type ConnectionProfile ,
2121} from "./catalog.ts" ;
2222import * as ConnectionCredentialStore from "./credentialStore.ts" ;
23- import {
24- ConnectionTransientError ,
25- PrimaryConnectionTarget ,
26- SshConnectionTarget ,
27- type ConnectionTarget ,
28- } from "./model.ts" ;
23+ import { PrimaryConnectionTarget , SshConnectionTarget , type ConnectionTarget } from "./model.ts" ;
2924import * as ConnectionProfileStore from "./profileStore.ts" ;
3025import * as RpcHttp from "../rpc/http.ts" ;
3126import {
@@ -250,99 +245,74 @@ describe("ConnectionResolver", () => {
250245 } ) ,
251246 ) ;
252247
253- it . effect . each ( [ "unchanged" , "changed" , "revocation-failed" ] as const ) (
254- "handles %s SSH routing consent before saving or authorizing" ,
255- ( scenario ) =>
256- Effect . gen ( function * ( ) {
257- const calls : string [ ] = [ ] ;
258- const target = new SshConnectionTarget ( {
259- environmentId : ENVIRONMENT_ID ,
260- label : "SSH" ,
261- connectionId : "ssh-1" ,
262- } ) ;
263- const profile = new SshConnectionProfile ( {
264- connectionId : target . connectionId ,
265- environmentId : ENVIRONMENT_ID ,
266- label : "SSH" ,
267- target : SSH_TARGET ,
268- } ) ;
269- const entry = catalogEntry ( target , Option . some ( profile ) ) ;
270- const preparedTarget =
271- scenario === "unchanged"
272- ? SSH_TARGET
273- : { ...SSH_TARGET , hostname : "replacement.example.test" } ;
274- const failure = new ConnectionTransientError ( {
275- reason : "remote-unavailable" ,
276- detail : "Could not persist routing consent." ,
277- } ) ;
278- const permissions = yield * makePullRequestRoutingPermissions ( {
279- read : Effect . succeed ( [
280- {
281- environmentId : ENVIRONMENT_ID ,
282- connectionKey : pullRequestRoutingConnectionKey ( entry ) ! ,
283- permission : "read-write" ,
284- } ,
285- ] ) ,
286- write : ( ) =>
287- Effect . sync ( ( ) => {
288- calls . push ( "revoke" ) ;
289- } ) . pipe (
290- Effect . andThen ( scenario === "revocation-failed" ? Effect . fail ( failure ) : Effect . void ) ,
291- ) ,
292- } ) ;
293- let savedProfile : ConnectionProfile = profile ;
294- const layerBroker = yield * makeDependencies ( {
295- profileStore : {
296- get : ( ) => Effect . sync ( ( ) => Option . some ( savedProfile ) ) ,
297- put : ( value ) =>
298- Effect . sync ( ( ) => {
299- calls . push ( "profile" ) ;
300- savedProfile = value ;
301- } ) ,
302- remove : ( ) => Effect . die ( "unused" ) ,
248+ it . effect ( "keeps the SSH target as entered and its routing consent across reconnects" , ( ) =>
249+ Effect . gen ( function * ( ) {
250+ const target = new SshConnectionTarget ( {
251+ environmentId : ENVIRONMENT_ID ,
252+ label : "SSH" ,
253+ connectionId : "ssh-1" ,
254+ } ) ;
255+ const enteredTarget = { ...SSH_TARGET , hostname : "development" , port : null } ;
256+ const profile = new SshConnectionProfile ( {
257+ connectionId : target . connectionId ,
258+ environmentId : ENVIRONMENT_ID ,
259+ label : "SSH" ,
260+ target : enteredTarget ,
261+ } ) ;
262+ const entry = catalogEntry ( target , Option . some ( profile ) ) ;
263+ const permissions = yield * makePullRequestRoutingPermissions ( {
264+ read : Effect . succeed ( [
265+ {
266+ environmentId : ENVIRONMENT_ID ,
267+ connectionKey : pullRequestRoutingConnectionKey ( entry ) ! ,
268+ permission : "read-write" ,
303269 } ,
304- prepareSsh : ( ) =>
305- Effect . succeed ( {
270+ ] ) ,
271+ write : ( ) => Effect . void ,
272+ } ) ;
273+ const preparedTargets : Array < DesktopSshEnvironmentTarget > = [ ] ;
274+ // ssh config resolves the alias, and its port changes between connects.
275+ const configPorts = [ 24568 , 24569 ] ;
276+ let savedProfile : ConnectionProfile = profile ;
277+ const layerBroker = yield * makeDependencies ( {
278+ profileStore : {
279+ get : ( ) => Effect . sync ( ( ) => Option . some ( savedProfile ) ) ,
280+ put : ( value ) =>
281+ Effect . sync ( ( ) => {
282+ savedProfile = value ;
283+ } ) ,
284+ remove : ( ) => Effect . die ( "unused" ) ,
285+ } ,
286+ prepareSsh : ( input ) =>
287+ Effect . sync ( ( ) => {
288+ preparedTargets . push ( input . target ) ;
289+ return {
306290 bootstrap : {
307- target : preparedTarget ,
291+ target : {
292+ ...input . target ,
293+ hostname : "127.0.0.1" ,
294+ port : configPorts [ preparedTargets . length - 1 ] ! ,
295+ } ,
308296 httpBaseUrl : "http://127.0.0.1:4010" ,
309297 wsBaseUrl : "ws://127.0.0.1:4010" ,
310298 pairingToken : null ,
311299 } ,
312300 bearerToken : "ssh-bearer" ,
313- } ) ,
314- authorizeBearer : ( input ) =>
315- Effect . sync ( ( ) => {
316- calls . push ( "authorize" ) ;
317- return {
318- environmentId : input . expectedEnvironmentId ,
319- label : "SSH" ,
320- httpBaseUrl : input . httpBaseUrl ,
321- socketUrl : "ws://127.0.0.1:4010/ws?wsTicket=ssh" ,
322- httpAuthorization : { _tag : "Bearer" as const , token : input . bearerToken } ,
323- } ;
324- } ) ,
325- } ) ;
326- const broker = yield * ConnectionResolver . ConnectionResolver . pipe (
327- Effect . provide ( layerBroker ) ,
328- ) ;
329- const prepare = broker
330- . prepare ( entry )
301+ } ;
302+ } ) ,
303+ } ) ;
304+ const broker = yield * ConnectionResolver . ConnectionResolver . pipe ( Effect . provide ( layerBroker ) ) ;
305+ const prepare = ( current : ConnectionCatalogEntry ) =>
306+ broker
307+ . prepare ( current )
331308 . pipe ( Effect . provideService ( PullRequestRoutingPermissions , permissions ) ) ;
332- if ( scenario === "revocation-failed" ) {
333- expect ( yield * Effect . flip ( prepare ) ) . toBe ( failure ) ;
334- expect ( savedProfile ) . toBe ( profile ) ;
335- expect ( calls ) . toEqual ( [ "revoke" ] ) ;
336- } else {
337- expect ( ( yield * prepare ) . socketUrl ) . toContain ( "wsTicket=ssh" ) ;
338- expect ( savedProfile ) . toMatchObject ( { target : preparedTarget } ) ;
339- expect ( calls ) . toEqual (
340- scenario === "unchanged"
341- ? [ "profile" , "authorize" ]
342- : [ "revoke" , "profile" , "authorize" ] ,
343- ) ;
344- }
345- expect ( yield * permissions . get ( entry ) ) . toBe ( scenario === "changed" ? "off" : "read-write" ) ;
346- } ) ,
309+
310+ yield * prepare ( entry ) ;
311+ yield * prepare ( catalogEntry ( target , Option . some ( savedProfile ) ) ) ;
312+
313+ expect ( preparedTargets ) . toEqual ( [ enteredTarget , enteredTarget ] ) ;
314+ expect ( savedProfile ) . toBe ( profile ) ;
315+ expect ( yield * permissions . get ( entry ) ) . toBe ( "read-write" ) ;
316+ } ) ,
347317 ) ;
348318} ) ;
0 commit comments