Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

onboarding.test.ts

648 lines23.7 KB

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);
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 );
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)?.enabled).toBe(false);
372​
373 const environmentId = yield* onboarding.registerPairing(PAIRING_INPUT);
374​
375 expect(environmentId).toBe(PAIRED_ENVIRONMENT_ID);
376 const after = yield* SubscriptionRef.get(registry.entries);
377 expect(after).toEqual(before);
378 expect(after.get(PAIRED_ENVIRONMENT_ID)?.unsupportedReason).toBe(UNSUPPORTED_ERROR.message);
379 }).pipe(Effect.provide(layerPairingOnboarding())),
380 );
381​
382 it.effect("leaves a switched-off environment unchanged when the pairing exchange fails", () =>
383 Effect.gen(function* () {
384 const registry = yield* EnvironmentRegistry.EnvironmentRegistry;
385 const onboarding = yield* Onboarding.ConnectionOnboarding;
386 const before = yield* registerSwitchedOffEnvironment;
387​
388 const error = yield* onboarding.registerPairing(PAIRING_INPUT).pipe(Effect.flip);
389​
390 expect(error).toMatchObject({
391 _tag: "ConnectionBlockedError",
392 reason: "authentication",
393 traceId: "trace-pairing-test",
394 });
395 const after = yield* SubscriptionRef.get(registry.entries);
396 expect(after).toEqual(before);
397 expect(after.get(PAIRED_ENVIRONMENT_ID)?.enabled).toBe(false);
398 expect(after.get(PAIRED_ENVIRONMENT_ID)?.unsupportedReason).toBe(UNSUPPORTED_ERROR.message);
399 }).pipe(Effect.provide(layerPairingOnboarding({ failExchange: true }))),
400 );
401​
402 it.effect("rejects an incompatible server without consuming the pairing credential", () =>
403 Effect.gen(function* () {
404 const calls: Array<{ readonly url: string; readonly init: RequestInit }> = [];
405 const error = yield* preparePairingRegistration({
406 host: "remote.example.test",
407 pairingCode: "pairing-token",
408 }).pipe(
409 Effect.provide(
410 Layer.mergeAll(
411 layerClientPresentation,
412 layerPairingHttp(calls, { protocolVersion: ORCHESTRATION_PROTOCOL_VERSION + 1 }),
413 ),
414 ),
415 Effect.flip,
416 );
417 expect(error).toMatchObject({ reason: "unsupported" });
418 expect(calls.map((call) => call.url)).toEqual([
419 "https://remote.example.test/.well-known/t3/environment",
420 ]);
421 }),
422 );
423 it.effect.each([
424 { label: "read-only", scopes: ["orchestration:read"] },
425 { label: "default", scopes: AuthStandardClientScopes },
426 ] as const)("preserves the $label grant when pairing a remote environment", ({ scopes }) =>
427 Effect.gen(function* () {
428 const calls: Array<{ readonly url: string; readonly init: RequestInit }> = [];
429 const httpLayer = layerPairingHttp(calls, { grantScopes: scopes });
430 const registration = yield* preparePairingRegistration({
431 host: "remote.example.test",
432 pairingCode: "pairing-token",
433 }).pipe(Effect.provide(Layer.mergeAll(layerClientPresentation, httpLayer)));
434​
435 const session = yield* fetchRemoteSessionState({
436 httpBaseUrl: registration.profile.httpBaseUrl,
437 bearerToken: registration.credential.token,
438 }).pipe(Effect.provide(httpLayer));
439​
440 expect(session.authenticated).toBe(true);
441 expect(session.scopes).toEqual(scopes);
442 }),
443 );
444​
445 it.effect("refuses to add a route that reaches a different machine, keeping the code", () =>
446 Effect.gen(function* () {
447 const calls: Array<{ readonly url: string; readonly init: RequestInit }> = [];
448 const error = yield* preparePairingRegistration({
449 host: "remote.example.test",
450 pairingCode: "pairing-token",
451 expectedEnvironmentId: EnvironmentId.make("some-other-machine"),
452 }).pipe(
453 Effect.provide(Layer.mergeAll(layerClientPresentation, layerPairingHttp(calls))),
454 Effect.flip,
455 );
456 expect(error).toMatchObject({ reason: "configuration" });
457 expect(error.message).toContain("different machine");
458 expect(calls.map((call) => call.url)).toEqual([
459 "https://remote.example.test/.well-known/t3/environment",
460 ]);
461 }),
462 );
463​
464 it.effect("pairs an outdated server so it can be updated from this client", () =>
465 Effect.gen(function* () {
466 const calls: Array<{ readonly url: string; readonly init: RequestInit }> = [];
467 const registration = yield* preparePairingRegistration({
468 host: "remote.example.test",
469 pairingCode: "pairing-token",
470 }).pipe(
471 Effect.provide(
472 Layer.mergeAll(
473 layerClientPresentation,
474 layerPairingHttp(calls, {
475 protocolVersion: ORCHESTRATION_PROTOCOL_VERSION - 1,
476 selfUpdate: true,
477 }),
478 ),
479 ),
480 );
481 expect(registration.target.environmentId).toBe("environment-paired");
482 expect(calls.map((call) => call.url)).toContain("https://remote.example.test/oauth/token");
483 }),
484 );
485​
486 it.effect("refuses an outdated server that cannot update itself", () =>
487 Effect.gen(function* () {
488 const calls: Array<{ readonly url: string; readonly init: RequestInit }> = [];
489 const error = yield* preparePairingRegistration({
490 host: "remote.example.test",
491 pairingCode: "pairing-token",
492 }).pipe(
493 Effect.provide(
494 Layer.mergeAll(
495 layerClientPresentation,
496 layerPairingHttp(calls, { protocolVersion: ORCHESTRATION_PROTOCOL_VERSION - 1 }),
497 ),
498 ),
499 Effect.flip,
500 );
501 expect(error).toMatchObject({ reason: "unsupported" });
502 expect(error).not.toHaveProperty("serverUpdateRequired");
503 expect(calls.map((call) => call.url)).toEqual([
504 "https://remote.example.test/.well-known/t3/environment",
505 ]);
506 }),
507 );
508​
509 it.effect("does not consume a pairing credential when descriptor discovery fails", () =>
510 Effect.gen(function* () {
511 const calls: Array<{ readonly url: string; readonly init: RequestInit }> = [];
512​
513 yield* preparePairingRegistration({
514 host: "remote.example.test",
515 pairingCode: "pairing-token",
516 }).pipe(
517 Effect.provide(
518 Layer.mergeAll(
519 layerClientPresentation,
520 layerPairingHttp(calls, { failDescriptor: true }),
521 ),
522 ),
523 Effect.flip,
524 );
525​
526 expect(calls.map((call) => call.url)).toEqual([
527 "https://remote.example.test/.well-known/t3/environment",
528 ]);
529 }),
530 );
531​
532 it.effect("rejects invalid pairing details before making a request", () =>
533 Effect.gen(function* () {
534 const calls: Array<{ readonly url: string; readonly init: RequestInit }> = [];
535 const error = yield* preparePairingRegistration({
536 host: "",
537 pairingCode: "",
538 }).pipe(
539 Effect.provide(Layer.mergeAll(layerClientPresentation, layerPairingHttp(calls))),
540 Effect.flip,
541 );
542​
543 expect(error).toMatchObject({
544 _tag: "ConnectionBlockedError",
545 reason: "configuration",
546 message: "Enter a backend URL.",
547 });
548 expect(calls).toEqual([]);
549 }),
550 );
551​
552 it.effect("updates bearer metadata while preserving the credential and identity", () =>
553 Effect.gen(function* () {
554 const environmentId = EnvironmentId.make("environment-paired");
555 const registration = yield* prepareBearerConnectionUpdate({
556 input: {
557 environmentId,
558 label: " Renamed environment ",
559 httpBaseUrl: "http://100.65.180.100:3773/path",
560 },
561 entry: Option.some({
562 target: new BearerConnectionTarget({
563 environmentId,
564 label: "Old label",
565 connectionId: "bearer:environment-paired",
566 }),
567 profile: Option.some(
568 new BearerConnectionProfile({
569 connectionId: "bearer:environment-paired",
570 environmentId,
571 label: "Old label",
572 httpBaseUrl: "http://old.example.test/",
573 wsBaseUrl: "ws://old.example.test/",
574 }),
575 ),
576 enabled: true,
577 }),
578 credential: Option.some(new BearerConnectionCredential({ token: "bearer-token" })),
579 });
580​
581 expect(registration).toMatchObject({
582 target: {
583 environmentId,
584 label: "Renamed environment",
585 connectionId: "bearer:environment-paired",
586 },
587 profile: {
588 environmentId,
589 label: "Renamed environment",
590 httpBaseUrl: "http://100.65.180.100:3773/",
591 wsBaseUrl: "ws://100.65.180.100:3773/",
592 },
593 credential: { token: "bearer-token" },
594 });
595 }),
596 );
597​
598 it.effect("prepares an SSH registration from the provisioned platform environment", () =>
599 Effect.gen(function* () {
600 const target = {
601 alias: "devbox",
602 hostname: "devbox.example.test",
603 username: "developer",
604 port: 22,
605 };
606 const registration = yield* prepareSshRegistration({
607 target,
608 }).pipe(
609 Effect.provideService(
610 ClientCapabilities.SshEnvironmentGateway,
611 ClientCapabilities.SshEnvironmentGateway.of({
612 provision: () =>
613 Effect.succeed({
614 environmentId: EnvironmentId.make("environment-ssh"),
615 label: "Remote development box",
616 bootstrap: {
617 target,
618 httpBaseUrl: "http://127.0.0.1:3201",
619 wsBaseUrl: "ws://127.0.0.1:3201",
620 pairingToken: "pairing-token",
621 },
622 bearerToken: "bearer-token",
623 }),
624 prepare: () => Effect.die("unused"),
625 disconnect: () => Effect.die("unused"),
626 }),
627 ),
628 );
629​
630 expect(registration).toMatchObject({
631 _tag: "SshConnectionRegistration",
632 target: {
633 environmentId: "environment-ssh",
634 label: "Remote development box",
635 connectionId: 'ssh:environment-ssh:["devbox","devbox.example.test","developer",22]',
636 },
637 profile: {
638 environmentId: "environment-ssh",
639 label: "Remote development box",
640 connectionId: 'ssh:environment-ssh:["devbox","devbox.example.test","developer",22]',
641 target,
642 },
643 // Saved so the first connect reuses this pairing instead of adding another.
644 credential: { token: "bearer-token" },
645 });
646 }),
647 );
648});