@@ -29,6 +29,21 @@ import { resolveServerConfig } from "./config.ts";
2929const deriveExplicitServerPaths = ( baseDir : string , devUrl : URL | undefined ) =>
3030 deriveServerPaths ( baseDir , devUrl , { baseDirIsExplicit : true } ) ;
3131
32+ const minimalDesktopFlags = ( baseDir : string ) => ( {
33+ mode : Option . some ( "desktop" as const ) ,
34+ port : Option . some ( 4888 ) ,
35+ host : Option . none < string > ( ) ,
36+ baseDir : Option . some ( baseDir ) ,
37+ cwd : Option . none < string > ( ) ,
38+ devUrl : Option . none < URL > ( ) ,
39+ noBrowser : Option . none < boolean > ( ) ,
40+ bootstrapFd : Option . none < number > ( ) ,
41+ autoBootstrapProjectFromCwd : Option . none < boolean > ( ) ,
42+ logWebSocketEvents : Option . none < boolean > ( ) ,
43+ tailscaleServeEnabled : Option . none < boolean > ( ) ,
44+ tailscaleServePort : Option . none < number > ( ) ,
45+ } ) ;
46+
3247const encodeDesktopBootstrap = Schema . encodeEffect ( Schema . fromJsonString ( DesktopBackendBootstrap ) ) ;
3348const encodeUnknownJson = Schema . encodeEffect ( Schema . fromJsonString ( Schema . Unknown ) ) ;
3449
@@ -429,6 +444,77 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
429444 } ) ,
430445 ) ;
431446
447+ it . effect ( "reports the desktop bootstrap as the source of endpoints it supplied" , ( ) =>
448+ Effect . gen ( function * ( ) {
449+ const fs = yield * FileSystem . FileSystem ;
450+ const baseDir = yield * fs . makeTempDirectoryScoped ( {
451+ prefix : "t3-cli-config-otlp-bootstrap-" ,
452+ } ) ;
453+ const fd = yield * openBootstrapFd (
454+ makeDesktopBootstrap ( {
455+ otlpTracesUrl : "http://localhost:4318/v1/traces" ,
456+ otlpMetricsUrl : "http://localhost:4318/v1/metrics" ,
457+ otlpLogsUrl : "http://localhost:4318/v1/logs" ,
458+ } ) ,
459+ ) ;
460+
461+ const resolved = yield * resolveServerConfig (
462+ { ...minimalDesktopFlags ( baseDir ) , bootstrapFd : Option . some ( fd ) } ,
463+ Option . none ( ) ,
464+ ) . pipe (
465+ Effect . provide (
466+ Layer . mergeAll (
467+ ConfigProvider . layer ( ConfigProvider . fromEnv ( { env : { } } ) ) ,
468+ NetService . layer ,
469+ ) ,
470+ ) ,
471+ ) ;
472+
473+ expect ( resolved ) . toMatchObject ( {
474+ otlpTracesUrl : "http://localhost:4318/v1/traces" ,
475+ otlpTracesSource : "bootstrap" ,
476+ otlpMetricsSource : "bootstrap" ,
477+ otlpLogsSource : "bootstrap" ,
478+ } ) ;
479+ } ) ,
480+ ) ;
481+
482+ it . effect ( "reports saved settings as the source of endpoints read from settings.json" , ( ) =>
483+ Effect . gen ( function * ( ) {
484+ const fs = yield * FileSystem . FileSystem ;
485+ const path = yield * Path . Path ;
486+ const baseDir = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-cli-config-otlp-settings-" } ) ;
487+ const derivedPaths = yield * deriveExplicitServerPaths ( baseDir , undefined ) ;
488+ yield * fs . makeDirectory ( path . dirname ( derivedPaths . settingsPath ) , { recursive : true } ) ;
489+ yield * fs . writeFileString (
490+ derivedPaths . settingsPath ,
491+ `${ JSON . stringify ( {
492+ observability : {
493+ otlpTracesUrl : "http://localhost:4318/v1/traces" ,
494+ otlpMetricsUrl : "http://localhost:4318/v1/metrics" ,
495+ otlpLogsUrl : "http://localhost:4318/v1/logs" ,
496+ } ,
497+ } ) } \n`,
498+ ) ;
499+
500+ const resolved = yield * resolveServerConfig ( minimalDesktopFlags ( baseDir ) , Option . none ( ) ) . pipe (
501+ Effect . provide (
502+ Layer . mergeAll (
503+ ConfigProvider . layer ( ConfigProvider . fromEnv ( { env : { } } ) ) ,
504+ NetService . layer ,
505+ ) ,
506+ ) ,
507+ ) ;
508+
509+ expect ( resolved ) . toMatchObject ( {
510+ otlpTracesUrl : "http://localhost:4318/v1/traces" ,
511+ otlpTracesSource : "settings" ,
512+ otlpMetricsSource : "settings" ,
513+ otlpLogsSource : "settings" ,
514+ } ) ;
515+ } ) ,
516+ ) ;
517+
432518 it . effect ( "zeroes an endpoint stored in Settings when the SDK is disabled" , ( ) =>
433519 Effect . gen ( function * ( ) {
434520 const fs = yield * FileSystem . FileSystem ;
@@ -712,6 +798,11 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
712798 } ) ;
713799 expect ( resolved . otlpLogsUrl ) . toBe ( "http://settings:4318/v1/logs" ) ;
714800 expect ( resolved . otlpLogsExport . headers ) . toEqual ( { "x-key" : "secret" } ) ;
801+ expect ( resolved ) . toMatchObject ( {
802+ otlpTracesVariable : "T3CODE_OTLP_TRACES_URL" ,
803+ otlpMetricsVariable : "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT" ,
804+ } ) ;
805+ expect ( resolved . otlpLogsVariable ) . toBeUndefined ( ) ;
715806 } ) ,
716807 ) ;
717808
0 commit comments