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

http.test.ts

611 lines23.2 KB

1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { describe, expect, it } from "@effect/vitest";
3import * as Effect from "effect/Effect";
4import * as FileSystem from "effect/FileSystem";
5import * as Layer from "effect/Layer";
6import * as Option from "effect/Option";
7import * as Path from "effect/Path";
8import * as PlatformError from "effect/PlatformError";
9import * as Tracer from "effect/Tracer";
10import {
11 HttpClient,
12 HttpClientResponse,
13 HttpServerRequest,
14 type HttpClientRequest,
15} from "effect/unstable/http";
16​
17import { EnvironmentId } from "@t3tools/contracts";
18import { RelayClientTracer } from "@t3tools/shared/relayTracing";
19import * as EnvironmentAuth from "../auth/EnvironmentAuth.ts";
20import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
21import * as ServerConfigModule from "../config.ts";
22import { writeServiceState } from "../serviceLauncher.ts";
23import {
24 SERVICE_LAUNCHER_PROTOCOL,
25 SERVICE_STATE_FILE,
26 SERVICE_STOP_MARKER_FILE,
27 type ServiceUpdateRecord,
28} from "./serviceProtocol.ts";
29import * as ServerEnvironment from "../environment/ServerEnvironment.ts";
30import { CLOUD_CLI_DESIRED_LINK_SECRET } from "./CliState.ts";
31import * as CliTokenManager from "./CliTokenManager.ts";
32import type { RelayLinkProofRequest } from "@t3tools/contracts/relay";
33import { CLOUD_ENDPOINT_RUNTIME_CONFIG, RELAY_URL_SECRET } from "./config.ts";
34import {
35 consumeCloudReplayGuards,
36 isSupportedLinkProviderKind,
37 linkProofScopes,
38 pendingServiceUpdateExists,
39 reconcileDesiredCloudLink,
40 releaseManagedTunnelOnShutdown,
41} from "./http.ts";
42import * as ManagedEndpointRuntime from "./ManagedEndpointRuntime.ts";
43import { traceAuthenticatedRelayRequest, traceRelayRequest } from "./traceRelayRequest.ts";
44​
45const storeFailure = (tag: "AlreadyExists" | "PermissionDenied") =>
46 new ServerSecretStore.SecretStorePersistError({
47 resource: "cloud replay guard",
48 cause: PlatformError.systemError({
49 _tag: tag,
50 module: "FileSystem",
51 method: "open",
52 pathOrDescriptor: "cloud-replay-guard.bin",
53 }),
54 });
55​
56const unusedSecretStoreOperation = () => Effect.die("unused secret-store operation");
57​
58function makeSecretStore(
59 create: ServerSecretStore.ServerSecretStore["Service"]["create"],
60): ServerSecretStore.ServerSecretStore["Service"] {
61 return {
62 get: unusedSecretStoreOperation,
63 set: unusedSecretStoreOperation,
64 create,
65 getOrCreateRandom: unusedSecretStoreOperation,
66 remove: unusedSecretStoreOperation,
67 };
69​
70it("preserves messages surfaced by cloud 500 responses", () => {
71 const cause = new Error("cloud operation failed");
72​
73 expect([
74 new EnvironmentAuth.ServerAuthLinkedCloudAccountVerificationError({ cause }).message,
75 new EnvironmentAuth.ServerAuthLinkedCloudAccountReadError({ cause }).message,
76 new EnvironmentAuth.ServerAuthLinkedCloudAccountMissingError({}).message,
77 new EnvironmentAuth.ServerAuthCloudLinkJwtSigningError({ cause }).message,
78 new EnvironmentAuth.ServerAuthCloudMintPublicKeyMissingError({}).message,
79 new EnvironmentAuth.ServerAuthCloudRelayIssuerMissingError({}).message,
80 new EnvironmentAuth.ServerAuthCloudHealthJwtSigningError({ cause }).message,
81 new EnvironmentAuth.ServerAuthCloudMintJwtSigningError({ cause }).message,
82 ]).toEqual([
83 "Could not verify the linked cloud account.",
84 "Could not read the linked cloud account.",
85 "Cloud linked user is not installed for this environment.",
86 "Failed to sign cloud link JWT.",
87 "Cloud mint public key is not installed for this environment.",
88 "Cloud relay issuer is not installed for this environment.",
89 "Failed to sign cloud health JWT.",
90 "Failed to sign cloud mint JWT.",
91 ]);
92});
93​
94describe("consumeCloudReplayGuards", () => {
95 it.effect("reports already-created guards as replay conflicts", () =>
96 Effect.gen(function* () {
97 const consumed = yield* consumeCloudReplayGuards({
98 secrets: makeSecretStore(() => Effect.fail(storeFailure("AlreadyExists"))),
99 names: ["cloud-jti", "cloud-nonce"],
100 value: new Uint8Array(),
101 });
102​
103 expect(consumed).toBe(false);
104 }),
105 );
106​
107 it.effect("preserves replay-store availability failures", () =>
108 Effect.gen(function* () {
109 const failure = storeFailure("PermissionDenied");
110 const error = yield* Effect.flip(
111 consumeCloudReplayGuards({
112 secrets: makeSecretStore(() => Effect.fail(failure)),
113 names: ["cloud-jti", "cloud-nonce"],
114 value: new Uint8Array(),
115 }),
116 );
117​
118 expect(error).toBe(failure);
119 }),
120 );
121});
122​
123describe("relay request tracing", () => {
124 it.effect("does not accept an unauthenticated request trace parent", () =>
125 Effect.gen(function* () {
126 const spans: Array<Tracer.Span> = [];
127 const productTracer = Tracer.make({
128 span: (options) => {
129 const span = new Tracer.NativeSpan(options);
130 spans.push(span);
131 return span;
132 },
133 });
134 const request = HttpServerRequest.fromWeb(
135 new Request("https://environment.example.test/api/t3-cloud/mint-credential", {
136 headers: {
137 traceparent: "00-0123456789abcdef0123456789abcdef-0123456789abcdef-01",
138 },
139 }),
140 );
141​
142 yield* traceRelayRequest(Effect.void.pipe(Effect.withSpan("relay.mint.handler"))).pipe(
143 Effect.provideService(HttpServerRequest.HttpServerRequest, request),
144 Effect.provideService(RelayClientTracer, Option.some(productTracer)),
145 );
146​
147 expect(spans).toHaveLength(1);
148 const span = spans[0]!;
149 expect(span.traceId).not.toBe("0123456789abcdef0123456789abcdef");
150 expect(Option.isNone(span.parent)).toBe(true);
151 }),
152 );
153​
154 it.effect("continues an authenticated relay trace with the product tracer", () =>
155 Effect.gen(function* () {
156 const spans: Array<Tracer.Span> = [];
157 const productTracer = Tracer.make({
158 span: (options) => {
159 const span = new Tracer.NativeSpan(options);
160 spans.push(span);
161 return span;
162 },
163 });
164 const request = HttpServerRequest.fromWeb(
165 new Request("https://environment.example.test/api/t3-cloud/mint-credential", {
166 headers: {
167 traceparent: "00-0123456789abcdef0123456789abcdef-0123456789abcdef-01",
168 },
169 }),
170 );
171​
172 yield* traceAuthenticatedRelayRequest(
173 Effect.void.pipe(Effect.withSpan("relay.mint.handler")),
174 ).pipe(
175 Effect.provideService(HttpServerRequest.HttpServerRequest, request),
176 Effect.provideService(RelayClientTracer, Option.some(productTracer)),
177 );
178​
179 expect(spans).toHaveLength(1);
180 const span = spans[0]!;
181 expect(span.traceId).toBe("0123456789abcdef0123456789abcdef");
182 expect(Option.getOrUndefined(span.parent)?.spanId).toBe("0123456789abcdef");
183 }),
184 );
185});
186​
187describe("reconcileDesiredCloudLink", () => {
188 it.effect("requires stored CLI authorization without exposing an HTTP endpoint", () =>
189 Effect.gen(function* () {
190 const error = yield* Effect.flip(reconcileDesiredCloudLink("http://127.0.0.1:3774"));
191​
192 expect(error).toMatchObject({
193 _tag: "EnvironmentHttpUnauthorizedError",
194 message: "Run `t3 connect link` to authorize this environment.",
195 });
196 }).pipe(
197 Effect.provideService(
198 ServerSecretStore.ServerSecretStore,
199 makeSecretStore(unusedSecretStoreOperation),
200 ),
201 Effect.provideService(
202 ServerEnvironment.ServerEnvironment,
203 ServerEnvironment.ServerEnvironment.of({
204 getEnvironmentId: unusedSecretStoreOperation(),
205 getDescriptor: unusedSecretStoreOperation(),
206 }),
207 ),
208 Effect.provideService(
209 ManagedEndpointRuntime.CloudManagedEndpointRuntime,
210 ManagedEndpointRuntime.CloudManagedEndpointRuntime.of({
211 applyConfig: unusedSecretStoreOperation,
212 } satisfies ManagedEndpointRuntime.CloudManagedEndpointRuntime["Service"]),
213 ),
214 Effect.provideService(
215 EnvironmentAuth.EnvironmentAuth,
216 EnvironmentAuth.EnvironmentAuth.of({} as EnvironmentAuth.EnvironmentAuth["Service"]),
217 ),
218 Effect.provideService(
219 CliTokenManager.CloudCliTokenManager,
220 CliTokenManager.CloudCliTokenManager.of({
221 get: unusedSecretStoreOperation(),
222 getExisting: Effect.succeed(Option.none()),
223 hasCredential: unusedSecretStoreOperation(),
224 store: () => unusedSecretStoreOperation(),
225 clear: unusedSecretStoreOperation(),
226 }),
227 ),
228 Effect.provideService(
229 HttpClient.HttpClient,
230 HttpClient.make(() => unusedSecretStoreOperation()),
231 ),
232 Effect.provide(NodeServices.layer),
233 ),
234 );
235});
236​
237describe("releaseManagedTunnelOnShutdown", () => {
238 const cliToken: CliTokenManager.PersistedToken = {
239 accessToken: "cli-access-token",
240 refreshToken: "cli-refresh-token",
241 expiresAtEpochMs: Number.MAX_SAFE_INTEGER,
242 };
243​
244 function makeMemorySecretStore(initial: Iterable<readonly [string, string]> = []) {
245 const values = new Map<string, Uint8Array>(
246 Array.from(initial, ([name, value]) => [name, new TextEncoder().encode(value)] as const),
247 );
248 const store: ServerSecretStore.ServerSecretStore["Service"] = {
249 get: (name) => Effect.sync(() => Option.fromNullishOr(values.get(name))),
250 set: (name, value) =>
251 Effect.sync(() => {
252 values.set(name, value);
253 }),
254 create: unusedSecretStoreOperation,
255 getOrCreateRandom: unusedSecretStoreOperation,
256 remove: (name) =>
257 Effect.sync(() => {
258 values.delete(name);
259 }),
260 };
261 return { store, values };
262 }
263​
264 interface ReleaseHarness {
265 readonly store: ServerSecretStore.ServerSecretStore["Service"];
266 readonly applyConfigCalls: Array<unknown>;
267 readonly requests: Array<HttpClientRequest.HttpClientRequest>;
268 readonly respond?: () => Response;
269 }
270​
271 // Writes the launcher's durable state file into this test's baseDir with
272 // the launcher's own writer; the release reads it to detect an in-flight
273 // update handoff.
274 const writeLauncherState = (update: ServiceUpdateRecord) =>
275 Effect.gen(function* () {
276 const path = yield* Path.Path;
277 const config = yield* ServerConfigModule.ServerConfig;
278 const statePath = path.join(config.baseDir, "runtime", SERVICE_STATE_FILE);
279 yield* Effect.promise(() =>
280 writeServiceState(statePath, {
281 protocol: SERVICE_LAUNCHER_PROTOCOL,
282 activeVersion: "0.0.30",
283 update,
284 }),
285 );
286 });
287​
288 const provideReleaseHarness =
289 (harness: ReleaseHarness) =>
290 <A, E, R>(effect: Effect.Effect<A, E, R>) =>
291 effect.pipe(
292 Effect.provideService(ServerSecretStore.ServerSecretStore, harness.store),
293 Effect.provideService(
294 ServerEnvironment.ServerEnvironment,
295 ServerEnvironment.ServerEnvironment.of({
296 getEnvironmentId: Effect.succeed(EnvironmentId.make("env_123")),
297 getDescriptor: Effect.die("unused"),
298 }),
299 ),
300 Effect.provideService(
301 ManagedEndpointRuntime.CloudManagedEndpointRuntime,
302 ManagedEndpointRuntime.CloudManagedEndpointRuntime.of({
303 applyConfig: (config) =>
304 Effect.sync(() => {
305 harness.applyConfigCalls.push(config);
306 return {
307 status: "disabled",
308 } satisfies ManagedEndpointRuntime.CloudManagedEndpointRuntimeStatus;
309 }),
310 }),
311 ),
312 Effect.provideService(
313 EnvironmentAuth.EnvironmentAuth,
314 EnvironmentAuth.EnvironmentAuth.of({} as EnvironmentAuth.EnvironmentAuth["Service"]),
315 ),
316 Effect.provideService(
317 CliTokenManager.CloudCliTokenManager,
318 CliTokenManager.CloudCliTokenManager.of({
319 get: unusedSecretStoreOperation(),
320 getExisting: Effect.succeed(Option.some(cliToken)),
321 hasCredential: unusedSecretStoreOperation(),
322 store: () => unusedSecretStoreOperation(),
323 clear: unusedSecretStoreOperation(),
324 }),
325 ),
326 Effect.provideService(
327 HttpClient.HttpClient,
328 HttpClient.make((request) =>
329 Effect.sync(() => {
330 harness.requests.push(request);
331 return HttpClientResponse.fromWeb(
332 request,
333 (harness.respond ?? (() => Response.json({ ok: true })))(),
334 );
335 }),
336 ),
337 ),
338 // The release consults the launcher state file under the configured
339 // baseDir, so every harness run gets a scoped temp baseDir.
340 Effect.provide(
341 ServerConfigModule.layerTest("/", { prefix: "t3-http-release-test-" }).pipe(
342 Layer.provideMerge(NodeServices.layer),
343 ),
344 ),
345 Effect.scoped,
346 );
347​
348 // The persisted state of a CLI-managed link whose tunnel is releasable.
349 const managedLinkSecrets = [
350 [CLOUD_ENDPOINT_RUNTIME_CONFIG, "runtime-config"],
351 [RELAY_URL_SECRET, "https://relay.example.test"],
352 [CLOUD_CLI_DESIRED_LINK_SECRET, "managed"],
353 ] as const;
354​
355 it.effect("stops the connector, releases the relay tunnel, and drops the dead token", () => {
356 const { store, values } = makeMemorySecretStore(managedLinkSecrets);
357 const applyConfigCalls: Array<unknown> = [];
358 const requests: Array<HttpClientRequest.HttpClientRequest> = [];
359​
360 return Effect.gen(function* () {
361 const released = yield* releaseManagedTunnelOnShutdown();
362​
363 expect(released).toBe(true);
364 expect(applyConfigCalls).toEqual([null]);
365 expect(requests).toHaveLength(1);
366 const request = requests[0]!;
367 expect(request.method).toBe("DELETE");
368 expect(request.url).toBe(
369 "https://relay.example.test/v1/client/environment-links/env_123/tunnel",
370 );
371 expect(request.headers.authorization).toBe("Bearer cli-access-token");
372 expect(values.has(CLOUD_ENDPOINT_RUNTIME_CONFIG)).toBe(false);
373 }).pipe(provideReleaseHarness({ store, applyConfigCalls, requests }));
374 });
375​
376 it.effect("does nothing for links without a stored managed tunnel runtime config", () => {
377 const { store } = makeMemorySecretStore();
378 const applyConfigCalls: Array<unknown> = [];
379 const requests: Array<HttpClientRequest.HttpClientRequest> = [];
380​
381 return Effect.gen(function* () {
382 const released = yield* releaseManagedTunnelOnShutdown();
383​
384 expect(released).toBe(false);
385 expect(applyConfigCalls).toEqual([]);
386 expect(requests).toEqual([]);
387 }).pipe(provideReleaseHarness({ store, applyConfigCalls, requests }));
388 });
389​
390 it.effect("leaves the tunnel of a web/mobile-installed link untouched", () => {
391 // A managed runtime config without a CLI-desired link: the environment was
392 // linked by a web/mobile client, and nothing re-provisions the tunnel on
393 // the next boot, so shutdown must not release it.
394 const { store, values } = makeMemorySecretStore([
395 [CLOUD_ENDPOINT_RUNTIME_CONFIG, "runtime-config"],
396 [RELAY_URL_SECRET, "https://relay.example.test"],
397 ]);
398 const applyConfigCalls: Array<unknown> = [];
399 const requests: Array<HttpClientRequest.HttpClientRequest> = [];
400​
401 return Effect.gen(function* () {
402 const released = yield* releaseManagedTunnelOnShutdown();
403​
404 expect(released).toBe(false);
405 expect(applyConfigCalls).toEqual([]);
406 expect(requests).toEqual([]);
407 expect(values.has(CLOUD_ENDPOINT_RUNTIME_CONFIG)).toBe(true);
408 }).pipe(provideReleaseHarness({ store, applyConfigCalls, requests }));
409 });
410​
411 it.effect("leaves the tunnel of a publish-only desired link untouched", () => {
412 const { store, values } = makeMemorySecretStore([
413 [CLOUD_ENDPOINT_RUNTIME_CONFIG, "runtime-config"],
414 [RELAY_URL_SECRET, "https://relay.example.test"],
415 [CLOUD_CLI_DESIRED_LINK_SECRET, "publish_only"],
416 ]);
417 const applyConfigCalls: Array<unknown> = [];
418 const requests: Array<HttpClientRequest.HttpClientRequest> = [];
419​
420 return Effect.gen(function* () {
421 const released = yield* releaseManagedTunnelOnShutdown();
422​
423 expect(released).toBe(false);
424 expect(applyConfigCalls).toEqual([]);
425 expect(requests).toEqual([]);
426 expect(values.has(CLOUD_ENDPOINT_RUNTIME_CONFIG)).toBe(true);
427 }).pipe(provideReleaseHarness({ store, applyConfigCalls, requests }));
428 });
429​
430 it.effect("keeps the tunnel when shutdown hands off to a pending update", () => {
431 const { store, values } = makeMemorySecretStore(managedLinkSecrets);
432 const applyConfigCalls: Array<unknown> = [];
433 const requests: Array<HttpClientRequest.HttpClientRequest> = [];
434​
435 return Effect.gen(function* () {
436 yield* writeLauncherState({
437 id: "update-1",
438 fromVersion: "0.0.30",
439 targetVersion: "0.0.31",
440 dbPath: "/tmp/state.sqlite",
441 status: "pending",
442 });
443​
444 const released = yield* releaseManagedTunnelOnShutdown();
445​
446 // The launcher restarts a server immediately, so the tunnel is not
447 // orphaned; keeping it avoids the hostname route re-propagation that
448 // dominates update downtime. The stored config must survive so the
449 // next boot respawns the connector against the same tunnel.
450 expect(released).toBe(false);
451 expect(applyConfigCalls).toEqual([]);
452 expect(requests).toEqual([]);
453 expect(values.has(CLOUD_ENDPOINT_RUNTIME_CONFIG)).toBe(true);
454 }).pipe(provideReleaseHarness({ store, applyConfigCalls, requests }));
455 });
456​
457 it.effect("still releases a pending update when the launcher is stopping", () => {
458 // `t3 service uninstall` or `systemctl stop` during the pending window:
459 // the launcher writes its stop marker before signalling the child, so no
460 // replacement server is coming and the tunnel must not be kept.
461 const { store, values } = makeMemorySecretStore(managedLinkSecrets);
462 const applyConfigCalls: Array<unknown> = [];
463 const requests: Array<HttpClientRequest.HttpClientRequest> = [];
464​
465 return Effect.gen(function* () {
466 yield* writeLauncherState({
467 id: "update-1",
468 fromVersion: "0.0.30",
469 targetVersion: "0.0.31",
470 dbPath: "/tmp/state.sqlite",
471 status: "pending",
472 });
473 const fs = yield* FileSystem.FileSystem;
474 const path = yield* Path.Path;
475 const config = yield* ServerConfigModule.ServerConfig;
476 yield* fs.writeFileString(path.join(config.baseDir, "runtime", SERVICE_STOP_MARKER_FILE), "");
477​
478 expect(yield* pendingServiceUpdateExists).toBe(true);
479 const released = yield* releaseManagedTunnelOnShutdown();
480​
481 expect(released).toBe(true);
482 expect(requests).toHaveLength(1);
483 expect(values.has(CLOUD_ENDPOINT_RUNTIME_CONFIG)).toBe(false);
484 }).pipe(provideReleaseHarness({ store, applyConfigCalls, requests }));
485 });
486​
487 it.effect("still releases when the recorded update already settled", () => {
488 const { store, values } = makeMemorySecretStore(managedLinkSecrets);
489 const applyConfigCalls: Array<unknown> = [];
490 const requests: Array<HttpClientRequest.HttpClientRequest> = [];
491​
492 return Effect.gen(function* () {
493 yield* writeLauncherState({
494 id: "update-1",
495 fromVersion: "0.0.30",
496 targetVersion: "0.0.31",
497 status: "committed",
498 });
499​
500 const released = yield* releaseManagedTunnelOnShutdown();
501​
502 expect(released).toBe(true);
503 expect(requests).toHaveLength(1);
504 expect(values.has(CLOUD_ENDPOINT_RUNTIME_CONFIG)).toBe(false);
505 }).pipe(provideReleaseHarness({ store, applyConfigCalls, requests }));
506 });
507​
508 it.effect("keeps a runtime config that a fast restart replaced mid-release", () => {
509 const { store, values } = makeMemorySecretStore(managedLinkSecrets);
510 const applyConfigCalls: Array<unknown> = [];
511 const requests: Array<HttpClientRequest.HttpClientRequest> = [];
512 const freshConfig = new TextEncoder().encode("fresh-runtime-config");
513​
514 return Effect.gen(function* () {
515 const released = yield* releaseManagedTunnelOnShutdown();
516​
517 expect(released).toBe(true);
518 // The finalizer only drops the config it released; the one written by
519 // the restarted process while the DELETE was in flight stays.
520 expect(values.get(CLOUD_ENDPOINT_RUNTIME_CONFIG)).toBe(freshConfig);
521 }).pipe(
522 provideReleaseHarness({
523 store,
524 applyConfigCalls,
525 requests,
526 respond: () => {
527 // A restarted process reconciled and stored a fresh connector config
528 // while this shutdown's release request was in flight.
529 values.set(CLOUD_ENDPOINT_RUNTIME_CONFIG, freshConfig);
530 return Response.json({ ok: true });
531 },
532 }),
533 );
534 });
535​
536 it.effect("keeps the stored connector token when the relay skipped the release", () => {
537 // ok:false means a concurrent provision owns the recorded tunnel, so the
538 // stored runtime config (possibly freshly written by that provision) must
539 // survive.
540 const { store, values } = makeMemorySecretStore(managedLinkSecrets);
541 const applyConfigCalls: Array<unknown> = [];
542 const requests: Array<HttpClientRequest.HttpClientRequest> = [];
543​
544 return Effect.gen(function* () {
545 const released = yield* releaseManagedTunnelOnShutdown();
546​
547 expect(released).toBe(false);
548 expect(requests).toHaveLength(1);
549 expect(values.has(CLOUD_ENDPOINT_RUNTIME_CONFIG)).toBe(true);
550 }).pipe(
551 provideReleaseHarness({
552 store,
553 applyConfigCalls,
554 requests,
555 respond: () => Response.json({ ok: false }),
556 }),
557 );
558 });
559​
560 it.effect("keeps the stored connector token when the relay release request fails", () => {
561 const { store, values } = makeMemorySecretStore(managedLinkSecrets);
562 const applyConfigCalls: Array<unknown> = [];
563 const requests: Array<HttpClientRequest.HttpClientRequest> = [];
564​
565 return Effect.gen(function* () {
566 const result = yield* Effect.result(releaseManagedTunnelOnShutdown());
567​
568 expect(result._tag).toBe("Failure");
569 expect(requests).toHaveLength(1);
570 // The tunnel still exists, so the stored token stays valid across the
571 // restart and the next boot can bring the connector back immediately.
572 expect(values.has(CLOUD_ENDPOINT_RUNTIME_CONFIG)).toBe(true);
573 }).pipe(
574 provideReleaseHarness({
575 store,
576 applyConfigCalls,
577 requests,
578 respond: () => Response.json({ ok: false }, { status: 503 }),
579 }),
580 );
581 });
582});
583​
584describe("link proof provider kinds", () => {
585 const proofRequest = (
586 providerKind: RelayLinkProofRequest["endpoint"]["providerKind"],
587 ): RelayLinkProofRequest => ({
588 challenge: "challenge",
589 relayIssuer: "https://relay.example.test",
590 endpoint: {
591 httpBaseUrl: "http://127.0.0.1:7331",
592 wsBaseUrl: "ws://127.0.0.1:7331",
593 providerKind,
594 },
595 origin: { localHttpHost: "127.0.0.1", localHttpPort: 7331 },
596 });
597​
598 it("accepts managed and manual endpoints but not t3_relay", () => {
599 expect(isSupportedLinkProviderKind(proofRequest("cloudflare_tunnel"))).toBe(true);
600 expect(isSupportedLinkProviderKind(proofRequest("manual"))).toBe(true);
601 expect(isSupportedLinkProviderKind(proofRequest("t3_relay"))).toBe(false);
602 });
603​
604 it("only claims the managed-tunnel scope for tunnel links", () => {
605 expect(linkProofScopes(proofRequest("cloudflare_tunnel"))).toEqual([
606 "agent_activity_notifications",
607 "managed_tunnels",
608 ]);
609 expect(linkProofScopes(proofRequest("manual"))).toEqual(["agent_activity_notifications"]);
610 });
611});