@@ -7,6 +7,15 @@ type RelayerKeyUrls = {
77 crsUrl : string ;
88} ;
99
10+ function replaceRelayerHostWithIp ( url : string , relayerHost : string ) : string {
11+ return url . replace ( / ^ h t t p s ? : \/ \/ f h e v m - r e l a y e r (? = [: / ] | $ ) / , ( prefix ) => {
12+ if ( prefix . startsWith ( "https://" ) ) {
13+ return `https://${ relayerHost } ` ;
14+ }
15+ return `http://${ relayerHost } ` ;
16+ } ) ;
17+ }
18+
1019function parseRelayerKeyUrls ( payloadRaw : string ) : RelayerKeyUrls | undefined {
1120 const payload = payloadRaw . trim ( ) ;
1221 if ( ! payload ) {
@@ -157,20 +166,69 @@ export function createTestHandlers(deps: CommandDeps) {
157166 } else if ( ! testSuiteContainer || ! isContainerRunningExact ( "fhevm-test-suite-e2e-debug" ) ) {
158167 lastMessage = "fhevm-test-suite-e2e-debug container is not running" ;
159168 } else {
160- const keyurlResult = runCommand (
161- [ "docker" , "exec " , testSuiteContainer , "curl ", "-fsS " , "http://fhevm-relayer:3000/v2/keyurl" ] ,
169+ const relayerIpInspect = runCommand (
170+ [ "docker" , "inspect " , "-f ", "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} " , relayerContainer ] ,
162171 { capture : true , check : false , allowFailure : true } ,
163172 ) ;
173+ const relayerIp = relayerIpInspect . status === 0 ? relayerIpInspect . stdout . trim ( ) : "" ;
174+ const relayerHosts = [ "fhevm-relayer" ] ;
175+ if ( relayerIp ) {
176+ relayerHosts . push ( relayerIp ) ;
177+ }
164178
165- if ( keyurlResult . status !== 0 ) {
166- const details = [ keyurlResult . stdout . trim ( ) , keyurlResult . stderr . trim ( ) ] . filter ( Boolean ) . join ( " " ) ;
179+ let keyurlResult :
180+ | {
181+ stdout : string ;
182+ stderr : string ;
183+ status : number ;
184+ }
185+ | undefined ;
186+ let resolvedRelayerHost = relayerHosts [ 0 ] ;
187+
188+ for ( const relayerHost of relayerHosts ) {
189+ const result = runCommand (
190+ [ "docker" , "exec" , testSuiteContainer , "curl" , "-fsS" , `http://${ relayerHost } :3000/v2/keyurl` ] ,
191+ { capture : true , check : false , allowFailure : true } ,
192+ ) ;
193+ if ( result . status === 0 ) {
194+ keyurlResult = result ;
195+ resolvedRelayerHost = relayerHost ;
196+ break ;
197+ }
198+ keyurlResult = result ;
199+ }
200+
201+ if ( ! keyurlResult || keyurlResult . status !== 0 ) {
202+ const details = keyurlResult
203+ ? [ keyurlResult . stdout . trim ( ) , keyurlResult . stderr . trim ( ) ] . filter ( Boolean ) . join ( " " )
204+ : "failed to query relayer keyurl endpoint" ;
167205 lastMessage = details || "failed to query relayer keyurl endpoint" ;
168206 } else {
169207 const urls = parseRelayerKeyUrls ( keyurlResult . stdout ) ;
170208 if ( ! urls ) {
171209 lastMessage = "relayer keyurl payload is missing required public key / CRS URLs" ;
172210 } else {
173211 const unreachable = [ urls . publicKeyUrl , urls . crsUrl ] . filter ( ( url ) => {
212+ const urlCandidates = [ url ] ;
213+ if ( resolvedRelayerHost !== "fhevm-relayer" ) {
214+ const rewritten = replaceRelayerHostWithIp ( url , resolvedRelayerHost ) ;
215+ if ( rewritten !== url ) {
216+ urlCandidates . push ( rewritten ) ;
217+ }
218+ }
219+
220+ const reachable = urlCandidates . some ( ( candidateUrl ) => {
221+ const probe = runCommand (
222+ [ "docker" , "exec" , testSuiteContainer , "curl" , "-fsS" , "--max-time" , "5" , "-o" , "/dev/null" , candidateUrl ] ,
223+ { capture : true , check : false , allowFailure : true } ,
224+ ) ;
225+ return probe . status === 0 ;
226+ } ) ;
227+
228+ if ( reachable ) {
229+ return false ;
230+ }
231+
174232 const probe = runCommand (
175233 [ "docker" , "exec" , testSuiteContainer , "curl" , "-fsS" , "--max-time" , "5" , "-o" , "/dev/null" , url ] ,
176234 { capture : true , check : false , allowFailure : true } ,
0 commit comments