The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import { describe, expect, it } from "@effect/vitest"; |
| 2 | import type { RelayLinkProofRequest } from "@t3tools/contracts/relay"; |
| 3 | |
| 4 | import { linkProofScopes, parseManagedEndpointLocalOrigin } from "./linkChecks.ts"; |
| 5 | |
| 6 | describe("parseManagedEndpointLocalOrigin", () => { |
| 7 | it.each([ |
| 8 | { |
| 9 | input: "http://127.0.0.1:80", |
| 10 | httpBaseUrl: "http://127.0.0.1", |
| 11 | wsBaseUrl: "ws://127.0.0.1", |
| 12 | port: 80, |
| 13 | }, |
| 14 | { |
| 15 | input: "https://127.0.0.1:443", |
| 16 | httpBaseUrl: "https://127.0.0.1", |
| 17 | wsBaseUrl: "wss://127.0.0.1", |
| 18 | port: 443, |
| 19 | }, |
| 20 | ])("accepts an explicit default port in $input", ({ input, httpBaseUrl, wsBaseUrl, port }) => { |
| 21 | expect(parseManagedEndpointLocalOrigin(input)).toEqual({ |
| 22 | httpBaseUrl, |
| 23 | wsBaseUrl, |
| 24 | origin: { localHttpHost: "127.0.0.1", localHttpPort: port }, |
| 25 | }); |
| 26 | }); |
| 27 | |
| 28 | it.each([ |
| 29 | "ftp://127.0.0.1:3773", |
| 30 | "http://user:password@127.0.0.1:3773", |
| 31 | "http://127.0.0.1:3773/api", |
| 32 | "http://127.0.0.1:3773?mode=test", |
| 33 | "http://127.0.0.1:3773#fragment", |
| 34 | ])("rejects non-origin URL %s", (input) => { |
| 35 | expect(() => parseManagedEndpointLocalOrigin(input)).toThrow("Invalid local origin"); |
| 36 | }); |
| 37 | }); |
| 38 | |
| 39 | describe("link proof provider kinds", () => { |
| 40 | const proofRequest = ( |
| 41 | providerKind: RelayLinkProofRequest["endpoint"]["providerKind"], |
| 42 | ): RelayLinkProofRequest => ({ |
| 43 | challenge: "challenge", |
| 44 | relayIssuer: "https://relay.example.test", |
| 45 | endpoint: { |
| 46 | httpBaseUrl: "http://127.0.0.1:7331", |
| 47 | wsBaseUrl: "ws://127.0.0.1:7331", |
| 48 | providerKind, |
| 49 | }, |
| 50 | origin: { localHttpHost: "127.0.0.1", localHttpPort: 7331 }, |
| 51 | }); |
| 52 | |
| 53 | it("only claims the managed-tunnel scope for tunnel links", () => { |
| 54 | expect(linkProofScopes(proofRequest("cloudflare_tunnel"))).toEqual([ |
| 55 | "agent_activity_notifications", |
| 56 | "managed_tunnels", |
| 57 | ]); |
| 58 | expect(linkProofScopes(proofRequest("manual"))).toEqual(["agent_activity_notifications"]); |
| 59 | }); |
| 60 | }); |