@@ -20,7 +20,7 @@ import * as Sink from "effect/Sink";
2020import * as Stream from "effect/Stream" ;
2121import * as TestClock from "effect/testing/TestClock" ;
2222import { ChildProcess , ChildProcessSpawner } from "effect/process" ;
23- import { HttpClient } from "effect/http" ;
23+ import { HttpClient , HttpClientResponse } from "effect/http" ;
2424import type { RelayManagedEndpointRuntimeConfig } from "@t3tools/contracts/relay" ;
2525import * as RelayClient from "@t3tools/shared/relayClient" ;
2626
@@ -251,6 +251,68 @@ describe("CloudManagedEndpointRuntime", () => {
251251 } ) ,
252252 ) ;
253253
254+ it . effect ( "reads the public hostname and its origin from cloudflared's remote config" , ( ) =>
255+ Effect . gen ( function * ( ) {
256+ let ingress : unknown = [
257+ { hostname : "env.example.t3.codes" , service : "http://127.0.0.1:3773" } ,
258+ { service : "http_status:404" } ,
259+ ] ;
260+ const httpClient = HttpClient . make ( ( request ) =>
261+ Effect . succeed (
262+ HttpClientResponse . fromWeb (
263+ request ,
264+ Response . json (
265+ request . url . endsWith ( "/config" )
266+ ? { config : ingress === undefined ? { } : { ingress } }
267+ : { readyConnections : 4 } ,
268+ ) ,
269+ ) ,
270+ ) ,
271+ ) ;
272+ const output = yield * Queue . unbounded < Uint8Array > ( ) ;
273+ const spawner = ChildProcessSpawner . make ( ( ) =>
274+ Effect . gen ( function * ( ) {
275+ const handle = makeHandle ( {
276+ pid : 702 ,
277+ onKill : ( ) => { } ,
278+ output : Stream . fromQueue ( output ) ,
279+ } ) ;
280+ yield * Effect . addFinalizer ( ( ) => handle . kill ( ) . pipe ( Effect . ignore ) ) ;
281+ return handle ;
282+ } ) ,
283+ ) ;
284+ const runtime = yield * buildCloudManagedEndpointRuntime (
285+ spawner ,
286+ layerRelayClientAvailable ,
287+ httpClient ,
288+ ) ;
289+ yield * runtime . applyConfig ( {
290+ providerKind : "cloudflare_tunnel" ,
291+ connectorToken : "connector-token" ,
292+ tunnelId : "tunnel-1" ,
293+ } ) ;
294+ yield * Queue . offer (
295+ output ,
296+ new TextEncoder ( ) . encode (
297+ "2026-10-06T00:00:01Z INF Starting metrics server on 127.0.0.1:20241/metrics\n" +
298+ "2026-10-06T00:00:01Z INF Registered tunnel connection connIndex=0\n" ,
299+ ) ,
300+ ) ;
301+ yield * Stream . runHead ( runtime . tunnelConnected ) ;
302+
303+ expect ( yield * runtime . inspectConnector ) . toMatchObject ( {
304+ readyConnections : 4 ,
305+ hostname : "env.example.t3.codes" ,
306+ origin : "http://127.0.0.1:3773" ,
307+ } ) ;
308+ // Before the edge pushes a config, the origin is unknown rather than wrong.
309+ for ( const missing of [ null , undefined ] ) {
310+ ingress = missing ;
311+ expect ( yield * runtime . inspectConnector ) . toMatchObject ( { hostname : null , origin : null } ) ;
312+ }
313+ } ) ,
314+ ) ;
315+
254316 it . effect ( "logs a connection unregistration at info with the connector token redacted" , ( ) => {
255317 const logs : Array < { readonly level : string ; readonly message : unknown } > = [ ] ;
256318 const unregistrationLogged = Deferred . makeUnsafe < void > ( ) ;
0 commit comments