Open History to see the last commit
1import {
2 AuthStandardClientScopes,
3 EnvironmentId,
4 type AuthEnvironmentScope,
5 ORCHESTRATION_PROTOCOL_VERSION,
6} from "@t3tools/contracts";
7import { describe, expect, it } from "@effect/vitest";
8import * as Effect from "effect/Effect";
9import * as Layer from "effect/Layer";
10import * as Option from "effect/Option";
11import * as Stream from "effect/Stream";
12import * as SubscriptionRef from "effect/SubscriptionRef";
13
14import * as RpcHttp from "../rpc/http.ts";
15import * as ClientCapabilities from "../platform/capabilities.ts";
16import * as Persistence from "../platform/persistence.ts";
17import { fetchRemoteSessionState } from "../authorization/remote.ts";
18import {
19 BearerConnectionCredential,
20 BearerConnectionProfile,
21 BearerConnectionRegistration,
22 PrimaryConnectionRegistration,
23} from "./catalog.ts";
24import * as Connectivity from "./connectivity.ts";
25import * as ConnectionCredentialStore from "./credentialStore.ts";
26import * as ConnectionDriver from "./driver.ts";
27import {
28 BearerConnectionTarget,
29 ConnectionBlockedError,
30 PrimaryConnectionTarget,
31} from "./model.ts";
32import * as Onboarding from "./onboarding.ts";
33import {
34 prepareBearerConnectionUpdate,
35 preparePairingRegistration,
36 prepareSshRegistration,
37} from "./onboarding.ts";
38import * as EnvironmentRegistry from "./registry.ts";
39import * as ConnectionProfileStore from "./profileStore.ts";
40import * as ConnectionWakeups from "./wakeups.ts";
41
42const layerClientPresentation = Layer.succeed(
43 ClientCapabilities.ClientPresentation,
44 ClientCapabilities.ClientPresentation.of({
45 metadata: {
46 label: "T3 Code Test",
47 deviceType: "desktop",
48 os: "Test OS",
49 },
50 }),
51);
52
53function layerPairingHttp(
54 calls: Array<{ readonly url: string; readonly init: RequestInit }>,
55 options?: {
56 readonly failDescriptor?: boolean;
57 readonly failExchange?: boolean;
58 readonly protocolVersion?: number;
59 readonly selfUpdate?: boolean;
60 readonly grantScopes?: ReadonlyArray<AuthEnvironmentScope>;
61 },
62) {
63 const grantScopes = options?.grantScopes ?? AuthStandardClientScopes;
64 let sessionScopes: ReadonlyArray<string> = [];
65 const fetchFn = ((input, init = {}) => {
66 const url = String(input);
67 calls.push({ url, init });
68
69 if (url.endsWith("/.well-known/t3/environment")) {
70 if (options?.failDescriptor === true) {
71 return Promise.resolve(
72 Response.json({ message: "descriptor unavailable" }, { status: 503 }),
73 );
74 }
75 return Promise.resolve(
76 Response.json({
77 environmentId: "environment-paired",
78 label: "Paired environment",
79 platform: {
80 os: "linux",
81 arch: "x64",
82 },
83 serverVersion: "0.0.0-test",
84 orchestrationProtocolVersion: options?.protocolVersion ?? ORCHESTRATION_PROTOCOL_VERSION,
85 capabilities: {
86 repositoryIdentity: true,
87 ...(options?.selfUpdate === true ? { serverSelfUpdate: "boot-service" } : {}),
88 },
89 }),
90 );
91 }
92
93 if (url.endsWith("/oauth/token")) {
94 if (options?.failExchange === true) {
95 return Promise.resolve(
96 Response.json(
97 {
98 _tag: "EnvironmentAuthInvalidError",
99 code: "auth_invalid",
100 reason: "invalid_credential",
101 traceId: "trace-pairing-test",
102 },
103 { status: 401 },
104 ),
105 );
106 }
107 const body =
108 init.body instanceof Uint8Array ? new TextDecoder().decode(init.body) : String(init.body);
109 const requestedScope = new URLSearchParams(body).get("scope");
110 sessionScopes = requestedScope === null ? grantScopes : requestedScope.split(" ");
111 if (!sessionScopes.every((scope) => grantScopes.some((granted) => granted === scope))) {
112 return Promise.resolve(
113 Response.json(
114 {
115 _tag: "EnvironmentRequestInvalidError",
116 code: "invalid_request",
117 reason: "scope_not_granted",
118 traceId: "pairing-scope-test",
119 },
120 { status: 400 },
121 ),
122 );
123 }
124 return Promise.resolve(
125 Response.json({
126 access_token: "bearer-token",
127 issued_token_type: "urn:ietf:params:oauth:token-type:access_token",
128 token_type: "Bearer",
129 expires_in: 3600,
130 scope: sessionScopes.join(" "),
131 }),
132 );
133 }
134
135 if (url.endsWith("/api/auth/session")) {
136 return Promise.resolve(
137 Response.json({
138 authenticated: true,
139 auth: {
140 policy: "remote-reachable",
141 bootstrapMethods: ["one-time-token"],
142 sessionMethods: ["bearer-access-token"],
143 sessionCookieName: "t3_session",
144 },
145 scopes: sessionScopes,
146 sessionMethod: "bearer-access-token",
147 }),
148 );
149 }
150
151 return Promise.reject(new Error(`Unexpected request: ${url}`));
152 }) satisfies typeof fetch;
153
154 return RpcHttp.layerRemoteHttpClient(fetchFn);
155}
156
157function layerPairingOnboarding(options?: Parameters<typeof layerPairingHttp>[1]) {
158 const dependencies = Layer.mergeAll(
159 layerClientPresentation,
160 layerPairingHttp([], options),
161 Layer.mock(Persistence.ConnectionTargetStore)({
162 list: Effect.succeed([]),
163 listDisabled: Effect.succeed([]),
164 }),
165 Layer.mock(Persistence.ConnectionRegistrationStore)({
166 register: () => Effect.void,
167 setEnabled: () => Effect.void,
168 }),
169 Layer.mock(Persistence.EnvironmentCacheStore)({}),
170 Layer.mock(ConnectionProfileStore.ConnectionProfileStore)({}),
171 Layer.mock(ConnectionCredentialStore.ConnectionCredentialStore)({}),
172 Layer.mock(ClientCapabilities.SshEnvironmentGateway)({}),
173 Layer.succeed(
174 Connectivity.Connectivity,
175 Connectivity.Connectivity.of({ status: Effect.succeed("online"), changes: Stream.never }),
176 ),
177 Layer.mock(ConnectionDriver.ConnectionDriver)({ connect: () => Effect.never }),
178 Layer.succeed(
179 ConnectionWakeups.ConnectionWakeups,
180 ConnectionWakeups.ConnectionWakeups.of({ changes: Stream.never }),
181 ),
182 );
183 return Onboarding.layer.pipe(
184 Layer.provideMerge(EnvironmentRegistry.layer.pipe(Layer.provideMerge(dependencies))),
185 );
186}
187
188const PAIRED_ENVIRONMENT_ID = EnvironmentId.make("environment-paired");
189const PAIRING_INPUT = { host: "remote.example.test", pairingCode: "pairing-token" };
190const PAIRED_PROFILE = new BearerConnectionProfile({
191 connectionId: "bearer:environment-paired:https://remote.example.test",
192 environmentId: PAIRED_ENVIRONMENT_ID,
193 label: "Paired environment",
194 httpBaseUrl: "https://remote.example.test/",
195 wsBaseUrl: "wss://remote.example.test/",
196});
197const UNSUPPORTED_ERROR = new ConnectionBlockedError({
198 reason: "unsupported",
199 detail: "The saved server used an incompatible orchestration protocol.",
200});
201
202const registerSwitchedOffEnvironment = Effect.gen(function* () {
203 const registry = yield* EnvironmentRegistry.EnvironmentRegistry;
204 const registration = new BearerConnectionRegistration({
205 target: new BearerConnectionTarget({
206 environmentId: PAIRED_ENVIRONMENT_ID,
207 connectionId: PAIRED_PROFILE.connectionId,
208 label: "Old label",
209 }),
210 profile: new BearerConnectionProfile({ ...PAIRED_PROFILE, label: "Old label" }),
211 credential: new BearerConnectionCredential({ token: "old-token" }),
212 });
213 yield* registry.register(registration);
214 yield* registry.setEnabled(PAIRED_ENVIRONMENT_ID, false);
215 yield* registry.setCompatibility(PAIRED_ENVIRONMENT_ID, UNSUPPORTED_ERROR);
216 const entries = yield* SubscriptionRef.get(registry.entries);
217 expect(entries.get(PAIRED_ENVIRONMENT_ID)).toEqual({
218 target: registration.target,
219 profile: Option.some(registration.profile),
220 enabled: false,
221 unsupportedReason: UNSUPPORTED_ERROR.message,
222 });
223 return entries;
224});
225
226describe("connection onboarding", () => {
227 it.effect("prepares a persisted bearer registration from pairing details", () =>
228 Effect.gen(function* () {
229 const calls: Array<{ readonly url: string; readonly init: RequestInit }> = [];
230 const registration = yield* preparePairingRegistration({
231 host: "remote.example.test",
232 pairingCode: "pairing-token",
233 }).pipe(Effect.provide(Layer.mergeAll(layerClientPresentation, layerPairingHttp(calls))));
234
235 expect(registration).toMatchObject({
236 _tag: "BearerConnectionRegistration",
237 target: {
238 environmentId: "environment-paired",
239 label: "Paired environment",
240 connectionId: "bearer:environment-paired:https://remote.example.test",
241 },
242 profile: {
243 environmentId: "environment-paired",
244 label: "Paired environment",
245 connectionId: "bearer:environment-paired:https://remote.example.test",
246 httpBaseUrl: "https://remote.example.test/",
247 wsBaseUrl: "wss://remote.example.test/",
248 },
249 credential: {
250 token: "bearer-token",
251 },
252 });
253 expect(calls.map((call) => call.url)).toEqual([
254 "https://remote.example.test/.well-known/t3/environment",
255 "https://remote.example.test/oauth/token",
256 ]);
257
258 const tokenRequest = calls.find((call) => call.url.endsWith("/oauth/token"));
259 const tokenBody =
260 tokenRequest?.init.body instanceof Uint8Array
261 ? new TextDecoder().decode(tokenRequest.init.body)
262 : String(tokenRequest?.init.body);
263 const tokenParams = new URLSearchParams(tokenBody);
264 expect(tokenParams.get("subject_token")).toBe("pairing-token");
265 expect(tokenParams.has("scope")).toBe(false);
266 expect(tokenParams.get("client_label")).toBe("T3 Code Test");
267 expect(tokenParams.get("client_device_type")).toBe("desktop");
268 expect(tokenParams.get("client_os")).toBe("Test OS");
269 }),
270 );
271
272 it.effect("turns a switched-off environment back on when it is paired again", () =>
273 Effect.gen(function* () {
274 const registry = yield* EnvironmentRegistry.EnvironmentRegistry;
275 const onboarding = yield* Onboarding.ConnectionOnboarding;
276 yield* registerSwitchedOffEnvironment;
277
278 const environmentId = yield* onboarding.registerPairing(PAIRING_INPUT);
279
280 expect(environmentId).toBe(PAIRED_ENVIRONMENT_ID);
281 const entries = yield* SubscriptionRef.get(registry.entries);
282 const entry = entries.get(environmentId);
283 expect(entries.size).toBe(1);
284 expect(entry?.enabled).toBe(true);
285 expect(entry?.unsupportedReason).toBeUndefined();
286 expect(entry?.profile).toEqual(Option.some(PAIRED_PROFILE));
287 expect(entry?.target).toEqual(
288 new BearerConnectionTarget({
289 environmentId,
290 connectionId: PAIRED_PROFILE.connectionId,
291 label: PAIRED_PROFILE.label,
292 }),
293 );
294 }).pipe(Effect.provide(layerPairingOnboarding())),
295 );
296
297 it.effect(
298 "re-pairs an outdated self-updatable environment so its connection can be rechecked",
299 () =>
300 Effect.gen(function* () {
301 const registry = yield* EnvironmentRegistry.EnvironmentRegistry;
302 const onboarding = yield* Onboarding.ConnectionOnboarding;
303 yield* registerSwitchedOffEnvironment;
304 yield* registry.setCompatibility(
305 PAIRED_ENVIRONMENT_ID,
306 new ConnectionBlockedError({
307 reason: "unsupported",
308 detail: "The saved server needs an update.",
309 serverUpdateRequired: true,
310 }),
311 );
312 expect(
313 (yield* SubscriptionRef.get(registry.entries)).get(PAIRED_ENVIRONMENT_ID),
314 ).toMatchObject({
315 enabled: false,
316 serverUpdateRequired: true,
317 });
318
319 const environmentId = yield* onboarding.registerPairing(PAIRING_INPUT);
320
321 expect(environmentId).toBe(PAIRED_ENVIRONMENT_ID);
322 const entry = (yield* SubscriptionRef.get(registry.entries)).get(environmentId);
323 expect(entry?.enabled).toBe(true);
324 expect(entry?.unsupportedReason).toBeUndefined();
325 expect(entry?.serverUpdateRequired).toBeUndefined();
326 expect(entry?.profile).toEqual(Option.some(PAIRED_PROFILE));
327 }).pipe(
328 Effect.provide(
329 layerPairingOnboarding({
330 protocolVersion: ORCHESTRATION_PROTOCOL_VERSION - 1,
331 selfUpdate: true,
332 }),
333 ),
334 ),
335 );
336
337 it.effect("registers an enabled environment on first-time pairing", () =>
338 Effect.gen(function* () {
339 const registry = yield* EnvironmentRegistry.EnvironmentRegistry;
340 const onboarding = yield* Onboarding.ConnectionOnboarding;
341 expect((yield* SubscriptionRef.get(registry.entries)).size).toBe(0);
342
343 const environmentId = yield* onboarding.registerPairing(PAIRING_INPUT);
344
345 expect(environmentId).toBe(PAIRED_ENVIRONMENT_ID);
346 const entries = yield* SubscriptionRef.get(registry.entries);
347 const entry = entries.get(environmentId);
348 expect(entries.size).toBe(1);
349 expect(entry?.enabled).toBe(true);
350 expect(entry?.unsupportedReason).toBeUndefined();
351 expect(entry?.profile).toEqual(Option.some(PAIRED_PROFILE));
352 }).pipe(Effect.provide(layerPairingOnboarding())),
353 );
354
355 it.effect("leaves a platform-managed environment untouched when its id is paired", () =>
356 Effect.gen(function* () {
357 const registry = yield* EnvironmentRegistry.EnvironmentRegistry;
358 const onboarding = yield* Onboarding.ConnectionOnboarding;
359 yield* registry.registerPlatform(
360 new PrimaryConnectionRegistration({
361 target: new PrimaryConnectionTarget({
362 environmentId: PAIRED_ENVIRONMENT_ID,
363 label: "Host environment",
364 httpBaseUrl: "http://127.0.0.1:3773",
365 wsBaseUrl: "ws://127.0.0.1:3773",
366 }),
367 }),
368 );
369 yield* registry.setCompatibility(PAIRED_ENVIRONMENT_ID, UNSUPPORTED_ERROR);
370 const before = yield* SubscriptionRef.get(registry.entries);
371 expect(before.get(PAIRED_ENVIRONMENT_ID)).toMatchObject({
372 enabled: true,
373 unsupportedReason: UNSUPPORTED_ERROR.message,
374 });
375
376 const environmentId = yield* onboarding.registerPairing(PAIRING_INPUT);
377
378 expect(environmentId).toBe(PAIRED_ENVIRONMENT_ID);
379 const after = yield* SubscriptionRef.get(registry.entries);
380 expect(after).toEqual(before);
381 expect(after.get(PAIRED_ENVIRONMENT_ID)?.unsupportedReason).toBe(UNSUPPORTED_ERROR.message);
382 }).pipe(Effect.provide(layerPairingOnboarding())),
383 );
384
385 it.effect("leaves a switched-off environment unchanged when the pairing exchange fails", () =>
386 Effect.gen(function* () {
387 const registry = yield* EnvironmentRegistry.EnvironmentRegistry;
388 const onboarding = yield* Onboarding.ConnectionOnboarding;
389 const before = yield* registerSwitchedOffEnvironment;
390
391 const error = yield* onboarding.registerPairing(PAIRING_INPUT).pipe(Effect.flip);
392
393 expect(error).toMatchObject({
394 _tag: "ConnectionBlockedError",
395 reason: "authentication",
396 traceId: "trace-pairing-test",
397 });
398 const after = yield* SubscriptionRef.get(registry.entries);
399 expect(after).toEqual(before);
400 expect(after.get(PAIRED_ENVIRONMENT_ID)?.enabled).toBe(false);
401 expect(after.get(PAIRED_ENVIRONMENT_ID)?.unsupportedReason).toBe(UNSUPPORTED_ERROR.message);
402 }).pipe(Effect.provide(layerPairingOnboarding({ failExchange: true }))),
403 );
404
405 it.effect("rejects an incompatible server without consuming the pairing credential", () =>
406 Effect.gen(function* () {
407 const calls: Array<{ readonly url: string; readonly init: RequestInit }> = [];
408 const error = yield* preparePairingRegistration({
409 host: "remote.example.test",
410 pairingCode: "pairing-token",
411 }).pipe(
412 Effect.provide(
413 Layer.mergeAll(
414 layerClientPresentation,
415 layerPairingHttp(calls, { protocolVersion: ORCHESTRATION_PROTOCOL_VERSION + 1 }),
416 ),
417 ),
418 Effect.flip,
419 );
420 expect(error).toMatchObject({ reason: "unsupported" });
421 expect(calls.map((call) => call.url)).toEqual([
422 "https://remote.example.test/.well-known/t3/environment",
423 ]);
424 }),
425 );
426 it.effect.each([
427 { label: "read-only", scopes: ["orchestration:read"] },
428 { label: "default", scopes: AuthStandardClientScopes },
429 ] as const)("preserves the $label grant when pairing a remote environment", ({ scopes }) =>
430 Effect.gen(function* () {
431 const calls: Array<{ readonly url: string; readonly init: RequestInit }> = [];
432 const httpLayer = layerPairingHttp(calls, { grantScopes: scopes });
433 const registration = yield* preparePairingRegistration({
434 host: "remote.example.test",
435 pairingCode: "pairing-token",
436 }).pipe(Effect.provide(Layer.mergeAll(layerClientPresentation, httpLayer)));
437
438 const session = yield* fetchRemoteSessionState({
439 httpBaseUrl: registration.profile.httpBaseUrl,
440 bearerToken: registration.credential.token,
441 }).pipe(Effect.provide(httpLayer));
442
443 expect(session.authenticated).toBe(true);
444 expect(session.scopes).toEqual(scopes);
445 }),
446 );
447
448 it.effect("refuses to add a route that reaches a different machine, keeping the code", () =>
449 Effect.gen(function* () {
450 const calls: Array<{ readonly url: string; readonly init: RequestInit }> = [];
451 const error = yield* preparePairingRegistration({
452 host: "remote.example.test",
453 pairingCode: "pairing-token",
454 expectedEnvironmentId: EnvironmentId.make("some-other-machine"),
455 }).pipe(
456 Effect.provide(Layer.mergeAll(layerClientPresentation, layerPairingHttp(calls))),
457 Effect.flip,
458 );
459 expect(error).toMatchObject({ reason: "configuration" });
460 expect(error.message).toContain("different machine");
461 expect(calls.map((call) => call.url)).toEqual([
462 "https://remote.example.test/.well-known/t3/environment",
463 ]);
464 }),
465 );
466
467 it.effect("pairs an outdated server so it can be updated from this client", () =>
468 Effect.gen(function* () {
469 const calls: Array<{ readonly url: string; readonly init: RequestInit }> = [];
470 const registration = yield* preparePairingRegistration({
471 host: "remote.example.test",
472 pairingCode: "pairing-token",
473 }).pipe(
474 Effect.provide(
475 Layer.mergeAll(
476 layerClientPresentation,
477 layerPairingHttp(calls, {
478 protocolVersion: ORCHESTRATION_PROTOCOL_VERSION - 1,
479 selfUpdate: true,
480 }),
481 ),
482 ),
483 );
484 expect(registration.target.environmentId).toBe("environment-paired");
485 expect(calls.map((call) => call.url)).toContain("https://remote.example.test/oauth/token");
486 }),
487 );
488
489 it.effect("refuses an outdated server that cannot update itself", () =>
490 Effect.gen(function* () {
491 const calls: Array<{ readonly url: string; readonly init: RequestInit }> = [];
492 const error = yield* preparePairingRegistration({
493 host: "remote.example.test",
494 pairingCode: "pairing-token",
495 }).pipe(
496 Effect.provide(
497 Layer.mergeAll(
498 layerClientPresentation,
499 layerPairingHttp(calls, { protocolVersion: ORCHESTRATION_PROTOCOL_VERSION - 1 }),
500 ),
501 ),
502 Effect.flip,
503 );
504 expect(error).toMatchObject({ reason: "unsupported" });
505 expect(error).not.toHaveProperty("serverUpdateRequired");
506 expect(calls.map((call) => call.url)).toEqual([
507 "https://remote.example.test/.well-known/t3/environment",
508 ]);
509 }),
510 );
511
512 it.effect("does not consume a pairing credential when descriptor discovery fails", () =>
513 Effect.gen(function* () {
514 const calls: Array<{ readonly url: string; readonly init: RequestInit }> = [];
515
516 yield* preparePairingRegistration({
517 host: "remote.example.test",
518 pairingCode: "pairing-token",
519 }).pipe(
520 Effect.provide(
521 Layer.mergeAll(
522 layerClientPresentation,
523 layerPairingHttp(calls, { failDescriptor: true }),
524 ),
525 ),
526 Effect.flip,
527 );
528
529 expect(calls.map((call) => call.url)).toEqual([
530 "https://remote.example.test/.well-known/t3/environment",
531 ]);
532 }),
533 );
534
535 it.effect("rejects invalid pairing details before making a request", () =>
536 Effect.gen(function* () {
537 const calls: Array<{ readonly url: string; readonly init: RequestInit }> = [];
538 const error = yield* preparePairingRegistration({
539 host: "",
540 pairingCode: "",
541 }).pipe(
542 Effect.provide(Layer.mergeAll(layerClientPresentation, layerPairingHttp(calls))),
543 Effect.flip,
544 );
545
546 expect(error).toMatchObject({
547 _tag: "ConnectionBlockedError",
548 reason: "configuration",
549 message: "Enter a backend URL.",
550 });
551 expect(calls).toEqual([]);
552 }),
553 );
554
555 it.effect("updates bearer metadata while preserving the credential and identity", () =>
556 Effect.gen(function* () {
557 const environmentId = EnvironmentId.make("environment-paired");
558 const registration = yield* prepareBearerConnectionUpdate({
559 input: {
560 environmentId,
561 label: " Renamed environment ",
562 httpBaseUrl: "http://100.65.180.100:3773/path",
563 },
564 entry: Option.some({
565 target: new BearerConnectionTarget({
566 environmentId,
567 label: "Old label",
568 connectionId: "bearer:environment-paired",
569 }),
570 profile: Option.some(
571 new BearerConnectionProfile({
572 connectionId: "bearer:environment-paired",
573 environmentId,
574 label: "Old label",
575 httpBaseUrl: "http://old.example.test/",
576 wsBaseUrl: "ws://old.example.test/",
577 }),
578 ),
579 enabled: true,
580 }),
581 credential: Option.some(new BearerConnectionCredential({ token: "bearer-token" })),
582 });
583
584 expect(registration).toMatchObject({
585 target: {
586 environmentId,
587 label: "Renamed environment",
588 connectionId: "bearer:environment-paired",
589 },
590 profile: {
591 environmentId,
592 label: "Renamed environment",
593 httpBaseUrl: "http://100.65.180.100:3773/",
594 wsBaseUrl: "ws://100.65.180.100:3773/",
595 },
596 credential: { token: "bearer-token" },
597 });
598 }),
599 );
600
601 it.effect("prepares an SSH registration from the provisioned platform environment", () =>
602 Effect.gen(function* () {
603 const target = {
604 alias: "devbox",
605 hostname: "devbox.example.test",
606 username: "developer",
607 port: 22,
608 };
609 const registration = yield* prepareSshRegistration({
610 target,
611 }).pipe(
612 Effect.provideService(
613 ClientCapabilities.SshEnvironmentGateway,
614 ClientCapabilities.SshEnvironmentGateway.of({
615 provision: () =>
616 Effect.succeed({
617 environmentId: EnvironmentId.make("environment-ssh"),
618 label: "Remote development box",
619 bootstrap: {
620 target,
621 httpBaseUrl: "http://127.0.0.1:3201",
622 wsBaseUrl: "ws://127.0.0.1:3201",
623 pairingToken: "pairing-token",
624 },
625 bearerToken: "bearer-token",
626 }),
627 prepare: () => Effect.die("unused"),
628 disconnect: () => Effect.die("unused"),
629 }),
630 ),
631 );
632
633 expect(registration).toMatchObject({
634 _tag: "SshConnectionRegistration",
635 target: {
636 environmentId: "environment-ssh",
637 label: "Remote development box",
638 connectionId: 'ssh:environment-ssh:["devbox","devbox.example.test","developer",22]',
639 },
640 profile: {
641 environmentId: "environment-ssh",
642 label: "Remote development box",
643 connectionId: 'ssh:environment-ssh:["devbox","devbox.example.test","developer",22]',
644 target,
645 },
646 // Saved so the first connect reuses this pairing instead of adding another.
647 credential: { token: "bearer-token" },
648 });
649 }),
650 );
651});