@@ -89,42 +89,49 @@ describe("ResourceMonitorBinary", () => {
8989 } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
9090 ) ;
9191
92- it . effect ( "looks for cargo build output from both the source and the bundled server layout" , ( ) =>
93- Effect . gen ( function * ( ) {
94- const fileSystem = yield * FileSystem . FileSystem ;
95- const path = yield * Path . Path ;
96- const baseDir = yield * fileSystem . makeTempDirectoryScoped ( {
97- prefix : "t3-resource-monitor-binary-" ,
98- } ) ;
99- const service = yield * ResourceMonitorBinary . make ( ) . pipe (
100- // Isolates the lookup from binaries a local cargo build left at the candidate paths.
101- Effect . provideService (
102- FileSystem . FileSystem ,
103- FileSystem . makeNoop ( { exists : ( ) => Effect . succeed ( false ) } ) ,
104- ) ,
105- Effect . provide ( ServerConfig . layerTest ( process . cwd ( ) , baseDir ) ) ,
106- Effect . provideService ( HostProcess . Platform , "darwin" ) ,
107- Effect . provideService ( HostProcess . Architecture , "arm64" ) ,
108- Effect . provideService ( HostProcess . Environment , { } ) ,
109- ) ;
110- const error = yield * Effect . flip ( service . resolve ) ;
111-
112- assert . instanceOf ( error , ResourceMonitorBinary . ResourceMonitorBinaryNotFound ) ;
113- const candidates = ( error as ResourceMonitorBinary . ResourceMonitorBinaryNotFound ) . candidates ;
114- for ( const crateRelative of [
115- "../../../../native/resource-monitor" ,
116- "../../../native/resource-monitor" ,
117- ] ) {
118- const crateDirectory = path . resolve ( import . meta. dirname , crateRelative ) ;
119- for ( const output of [
120- path . join ( "target" , "aarch64-apple-darwin" , "release" ) ,
121- path . join ( "target" , "release" ) ,
122- path . join ( "target" , "debug" ) ,
123- ] ) {
124- assert . include ( candidates , path . join ( crateDirectory , output , "t3-resource-monitor" ) ) ;
125- }
126- }
127- } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
92+ it . effect . each ( [ "release" , "debug" ] ) (
93+ "resolves a cargo %s binary from the built server layout" ,
94+ ( profile ) =>
95+ Effect . gen ( function * ( ) {
96+ const fileSystem = yield * FileSystem . FileSystem ;
97+ const path = yield * Path . Path ;
98+ const baseDir = yield * fileSystem . makeTempDirectoryScoped ( {
99+ prefix : "t3-resource-monitor-binary-" ,
100+ } ) ;
101+ const projectDirectory = path . join ( baseDir , "repo" ) ;
102+ const distDirectory = path . join ( projectDirectory , "apps" , "server" , "dist" ) ;
103+ const binaryDirectory = path . join (
104+ projectDirectory ,
105+ "native" ,
106+ "resource-monitor" ,
107+ "target" ,
108+ profile ,
109+ ) ;
110+ const binaryPath = path . join ( binaryDirectory , "t3-resource-monitor.exe" ) ;
111+ yield * fileSystem . makeDirectory ( distDirectory , { recursive : true } ) ;
112+ yield * fileSystem . makeDirectory ( binaryDirectory , { recursive : true } ) ;
113+ yield * fileSystem . writeFileString ( binaryPath , "binary" ) ;
114+ yield * fileSystem . chmod ( binaryPath , 0o755 ) ;
115+
116+ const service = yield * ResourceMonitorBinary . make ( ) . pipe (
117+ // The bundled module lives in dist rather than src/resourceTelemetry.
118+ Effect . provideService ( Path . Path , {
119+ ...path ,
120+ resolve : ( ...segments ) =>
121+ path . resolve (
122+ ...segments . map ( ( segment ) =>
123+ segment === import . meta. dirname ? distDirectory : segment ,
124+ ) ,
125+ ) ,
126+ } ) ,
127+ Effect . provide ( ServerConfig . layerTest ( projectDirectory , baseDir ) ) ,
128+ Effect . provideService ( HostProcess . Platform , "win32" ) ,
129+ Effect . provideService ( HostProcess . Architecture , "arm64" ) ,
130+ Effect . provideService ( HostProcess . Environment , { } ) ,
131+ ) ;
132+
133+ assert . equal ( yield * service . resolve , binaryPath ) ;
134+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
128135 ) ;
129136
130137 it . effect ( "rejects bundled glibc binaries on musl Linux hosts" , ( ) =>
0 commit comments