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, 07:15 UTC
| 1 | import * as Cloudflare from "@alchemy.run/cloudflare"; |
| 2 | import { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import { Action } from "alchemy/Action"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: Cloudflare.providers() }); |
| 9 | |
| 10 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 11 | |
| 12 | // Binding a Cloudflare Tunnel inside an Action via `ReadWriteTunnelLocal` — the |
| 13 | // local (current-credentials) implementation of the `ReadWriteTunnel` binding. |
| 14 | // Exercises the write side (`putConfiguration`) and the read side |
| 15 | // (`getConfiguration`/`get`/`getToken`) against a real tunnel, plus the deferred |
| 16 | // `yield* tunnel.tunnelId` accessor resolved at apply time. |
| 17 | test.provider( |
| 18 | "ReadWriteTunnelLocal: configure and read a tunnel from an Action", |
| 19 | (stack) => |
| 20 | Effect.gen(function* () { |
| 21 | yield* stack.destroy(); |
| 22 | |
| 23 | const out = yield* stack.deploy( |
| 24 | Effect.gen(function* () { |
| 25 | const tunnel = yield* Cloudflare.Tunnel.Tunnel("LocalBindingTunnel"); |
| 26 | |
| 27 | const Manage = Action( |
| 28 | "Manage", |
| 29 | Effect.gen(function* () { |
| 30 | const tunnels = yield* Cloudflare.Tunnel.ReadWriteTunnel(); |
| 31 | // Accessor — resolved at apply time against the tracker. |
| 32 | const tunnelId = yield* tunnel.tunnelId; |
| 33 | |
| 34 | return Effect.fn(function* () { |
| 35 | const id = yield* tunnelId; |
| 36 | |
| 37 | // Write: push ingress configuration. |
| 38 | yield* tunnels.putConfiguration(id, { |
| 39 | ingress: [ |
| 40 | { |
| 41 | hostname: "local-binding.alchemy-test-2.us", |
| 42 | service: "http://localhost:3000", |
| 43 | }, |
| 44 | { service: "http_status:404" }, |
| 45 | ], |
| 46 | }); |
| 47 | |
| 48 | // Read back the configuration we just wrote. |
| 49 | const cfg = yield* tunnels.getConfiguration(id); |
| 50 | // Read the tunnel + its connector token. |
| 51 | const t = yield* tunnels.get(id); |
| 52 | const token = yield* tunnels.getToken(id); |
| 53 | |
| 54 | return { |
| 55 | tunnelId: id, |
| 56 | name: t.id === id ? t.name : undefined, |
| 57 | ingress: (cfg.config?.ingress ?? []).map((rule) => ({ |
| 58 | hostname: rule.hostname ?? undefined, |
| 59 | service: rule.service, |
| 60 | })), |
| 61 | hasToken: typeof token === "string" && token.length > 0, |
| 62 | }; |
| 63 | }); |
| 64 | }).pipe(Effect.provide(Cloudflare.Tunnel.ReadWriteTunnelLocal)), |
| 65 | ); |
| 66 | |
| 67 | return yield* Manage({}); |
| 68 | }), |
| 69 | ); |
| 70 | |
| 71 | expect(out.tunnelId).toBeTruthy(); |
| 72 | expect(out.hasToken).toBe(true); |
| 73 | expect(out.ingress).toEqual([ |
| 74 | { |
| 75 | hostname: "local-binding.alchemy-test-2.us", |
| 76 | service: "http://localhost:3000", |
| 77 | }, |
| 78 | { hostname: undefined, service: "http_status:404" }, |
| 79 | ]); |
| 80 | |
| 81 | yield* stack.destroy(); |
| 82 | }).pipe(logLevel), |
| 83 | { |
| 84 | tags: ["provider:cloudflare", "provider:cloudflare:tunnel", "live"], |
| 85 | timeout: 120_000, |
| 86 | }, |
| 87 | ); |