@@ -2,9 +2,14 @@ import { execFile } from 'node:child_process';
22import { mkdtemp , readFile , rm } from 'node:fs/promises' ;
33import { tmpdir } from 'node:os' ;
44import { join } from 'node:path' ;
5+ import { fileURLToPath } from 'node:url' ;
56import { promisify } from 'node:util' ;
67
78const execFileAsync = promisify ( execFile ) ;
9+ const cliRoot = fileURLToPath ( new URL ( '..' , import . meta. url ) ) ;
10+ const commandTimeoutMs = 60_000 ;
11+ const liveRefreshAttempts = 3 ;
12+ const liveRefreshRetryDelayMs = 5_000 ;
813const eventId = 'build-2026' ;
914
1015function assert ( condition , message ) {
@@ -13,15 +18,50 @@ function assert(condition, message) {
1318
1419async function runCli ( args , cacheDir ) {
1520 return execFileAsync ( process . execPath , [ 'dist/index.js' , ...args ] , {
16- cwd : new URL ( '..' , import . meta . url ) ,
21+ cwd : cliRoot ,
1722 env : { ...process . env , MSEVENTS_CACHE_DIR : cacheDir } ,
23+ timeout : commandTimeoutMs ,
1824 } ) ;
1925}
2026
27+ function formatError ( error ) {
28+ if ( error && typeof error === 'object' ) {
29+ const message = error . message ?? String ( error ) ;
30+ const stderr = error . stderr ? `\n${ error . stderr } ` : '' ;
31+ return `${ message } ${ stderr } ` ;
32+ }
33+ return String ( error ) ;
34+ }
35+
36+ async function delay ( ms ) {
37+ await new Promise ( ( resolve ) => {
38+ setTimeout ( resolve , ms ) ;
39+ } ) ;
40+ }
41+
42+ async function retryLiveRefresh ( cacheDir ) {
43+ let lastError ;
44+ for ( let attempt = 1 ; attempt <= liveRefreshAttempts ; attempt += 1 ) {
45+ try {
46+ return await runCli ( [ 'refresh' , '--event' , eventId , '--force' ] , cacheDir ) ;
47+ } catch ( error ) {
48+ lastError = error ;
49+ if ( attempt === liveRefreshAttempts ) break ;
50+ process . stderr . write (
51+ `Live catalog refresh failed on attempt ${ attempt } /${ liveRefreshAttempts } : ${ formatError ( error ) } \n` +
52+ `Retrying in ${ liveRefreshRetryDelayMs / 1000 } s...\n` ,
53+ ) ;
54+ await delay ( liveRefreshRetryDelayMs ) ;
55+ }
56+ }
57+
58+ throw lastError ;
59+ }
60+
2161const cacheDir = await mkdtemp ( join ( tmpdir ( ) , 'msevents-live-smoke-' ) ) ;
2262
2363try {
24- const refresh = await runCli ( [ 'refresh' , '--event' , eventId , '--force' ] , cacheDir ) ;
64+ const refresh = await retryLiveRefresh ( cacheDir ) ;
2565 process . stderr . write ( refresh . stderr ) ;
2666
2767 const { stdout : statusStdout } = await runCli ( [ 'status' , '--json' ] , cacheDir ) ;
0 commit comments