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, 04:45 UTC
| 1 | import { assert, describe, it } from "@effect/vitest"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import { HttpClient, HttpClientResponse } from "effect/http"; |
| 5 | import { ChildProcessSpawner } from "effect/process"; |
| 6 | |
| 7 | import { resolveTailscaleAdvertisedEndpoints } from "./tailscaleEndpointProvider.ts"; |
| 8 | |
| 9 | const layerUnusedTailscaleExternalServices = Layer.mergeAll( |
| 10 | Layer.succeed( |
| 11 | HttpClient.HttpClient, |
| 12 | HttpClient.make(() => Effect.die("unexpected Tailscale HTTPS probe")), |
| 13 | ), |
| 14 | Layer.succeed( |
| 15 | ChildProcessSpawner.ChildProcessSpawner, |
| 16 | ChildProcessSpawner.make(() => Effect.die("unexpected tailscale status process")), |
| 17 | ), |
| 18 | ); |
| 19 | |
| 20 | const protonAndTailscaleInterfaces = { |
| 21 | pvpnksintrf1: [{ address: "100.85.0.1", family: "IPv4", internal: false }], |
| 22 | tailscale0: [{ address: "100.74.126.34", family: "IPv4", internal: false }], |
| 23 | }; |
| 24 | |
| 25 | describe("tailscale endpoint provider", () => { |
| 26 | it.effect("does not advertise Proton's CGNAT address as a Tailscale pairing endpoint", () => |
| 27 | Effect.gen(function* () { |
| 28 | const endpoints = yield* resolveTailscaleAdvertisedEndpoints({ |
| 29 | port: 3773, |
| 30 | networkInterfaces: protonAndTailscaleInterfaces, |
| 31 | statusJson: `{"Self":{"TailscaleIPs":["100.74.126.34"]}}`, |
| 32 | }); |
| 33 | assert.deepEqual( |
| 34 | endpoints.map((endpoint) => endpoint.httpBaseUrl), |
| 35 | ["http://100.74.126.34:3773/"], |
| 36 | ); |
| 37 | }).pipe(Effect.provide(layerUnusedTailscaleExternalServices)), |
| 38 | ); |
| 39 | |
| 40 | it.effect("keeps native Tailscale interfaces with missing, malformed, or stale status", () => |
| 41 | Effect.gen(function* () { |
| 42 | for (const interfaceName of ["tailscale0", "Tailscale"]) { |
| 43 | for (const statusJson of [null, "not-json", `{"Self":{"TailscaleIPs":[]}}`]) { |
| 44 | const endpoints = yield* resolveTailscaleAdvertisedEndpoints({ |
| 45 | port: 3773, |
| 46 | networkInterfaces: { |
| 47 | pvpnksintrf1: protonAndTailscaleInterfaces.pvpnksintrf1, |
| 48 | [interfaceName]: protonAndTailscaleInterfaces.tailscale0, |
| 49 | }, |
| 50 | statusJson, |
| 51 | }); |
| 52 | assert.deepEqual( |
| 53 | endpoints.map((endpoint) => endpoint.httpBaseUrl), |
| 54 | ["http://100.74.126.34:3773/"], |
| 55 | ); |
| 56 | } |
| 57 | } |
| 58 | }).pipe(Effect.provide(layerUnusedTailscaleExternalServices)), |
| 59 | ); |
| 60 | |
| 61 | it.effect( |
| 62 | "recognizes a macOS Tailscale tunnel by its IPv6 address when status is unavailable", |
| 63 | () => |
| 64 | Effect.gen(function* () { |
| 65 | const endpoints = yield* resolveTailscaleAdvertisedEndpoints({ |
| 66 | port: 3773, |
| 67 | networkInterfaces: { |
| 68 | utun3: [{ address: "100.85.0.1", family: "IPv4", internal: false }], |
| 69 | utun4: [ |
| 70 | { address: "100.74.126.34", family: "IPv4", internal: false }, |
| 71 | { address: "fd7a:115c:a1e0::1234", family: "IPv6", internal: false }, |
| 72 | ], |
| 73 | }, |
| 74 | statusJson: null, |
| 75 | }); |
| 76 | assert.deepEqual( |
| 77 | endpoints.map((endpoint) => endpoint.httpBaseUrl), |
| 78 | ["http://100.74.126.34:3773/"], |
| 79 | ); |
| 80 | }).pipe(Effect.provide(layerUnusedTailscaleExternalServices)), |
| 81 | ); |
| 82 | |
| 83 | it.effect("offers Tailscale HTTPS only when Serve reaches this desktop's backend", () => |
| 84 | Effect.gen(function* () { |
| 85 | const magicDnsStatus = (servedEnvironmentId: string) => |
| 86 | resolveTailscaleAdvertisedEndpoints({ |
| 87 | port: 3773, |
| 88 | serveEnabled: true, |
| 89 | networkInterfaces: {}, |
| 90 | statusJson: `{"Self":{"DNSName":"desktop.example.ts.net.","TailscaleIPs":[]}}`, |
| 91 | }).pipe( |
| 92 | Effect.map((endpoints) => endpoints.map((endpoint) => endpoint.status)), |
| 93 | Effect.provideService( |
| 94 | HttpClient.HttpClient, |
| 95 | HttpClient.make((request) => |
| 96 | Effect.succeed( |
| 97 | HttpClientResponse.fromWeb( |
| 98 | request, |
| 99 | Response.json({ |
| 100 | environmentId: |
| 101 | new URL(request.url).hostname === "127.0.0.1" |
| 102 | ? "desktop-backend" |
| 103 | : servedEnvironmentId, |
| 104 | label: "T3 server", |
| 105 | platform: { os: "linux", arch: "x64" }, |
| 106 | serverVersion: "0.1.9", |
| 107 | capabilities: { repositoryIdentity: true }, |
| 108 | }), |
| 109 | ), |
| 110 | ), |
| 111 | ), |
| 112 | ), |
| 113 | ); |
| 114 | |
| 115 | assert.deepEqual(yield* magicDnsStatus("desktop-backend"), ["available"]); |
| 116 | assert.deepEqual(yield* magicDnsStatus("another-server"), ["unavailable"]); |
| 117 | }).pipe(Effect.provide(layerUnusedTailscaleExternalServices)), |
| 118 | ); |
| 119 | }); |