Skip to content

Commit 8f0ae34

Browse files
TianqiZhangCopilot
andcommitted
Harden smoke test scripts
Convert smoke script working directories to filesystem paths and add timeout/retry handling for live catalog refreshes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 15b5ece commit 8f0ae34

2 files changed

Lines changed: 47 additions & 3 deletions

File tree

cli/scripts/smoke-fixture.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ import { execFile } from 'node:child_process';
22
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
33
import { tmpdir } from 'node:os';
44
import { join } from 'node:path';
5+
import { fileURLToPath } from 'node:url';
56
import { promisify } from 'node:util';
67
import { normalizeCatalog } from '../dist/data/normalize.js';
78

89
const execFileAsync = promisify(execFile);
10+
const cliRoot = fileURLToPath(new URL('..', import.meta.url));
11+
const commandTimeoutMs = 60_000;
912
const eventId = 'build-2025';
1013

1114
function assert(condition, message) {
@@ -14,8 +17,9 @@ function assert(condition, message) {
1417

1518
async function runCli(args, cacheDir) {
1619
return execFileAsync(process.execPath, ['dist/index.js', ...args], {
17-
cwd: new URL('..', import.meta.url),
20+
cwd: cliRoot,
1821
env: { ...process.env, MSEVENTS_CACHE_DIR: cacheDir },
22+
timeout: commandTimeoutMs,
1923
});
2024
}
2125

cli/scripts/smoke-live.mjs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ import { execFile } from 'node:child_process';
22
import { mkdtemp, readFile, rm } from 'node:fs/promises';
33
import { tmpdir } from 'node:os';
44
import { join } from 'node:path';
5+
import { fileURLToPath } from 'node:url';
56
import { promisify } from 'node:util';
67

78
const 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;
813
const eventId = 'build-2026';
914

1015
function assert(condition, message) {
@@ -13,15 +18,50 @@ function assert(condition, message) {
1318

1419
async 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+
2161
const cacheDir = await mkdtemp(join(tmpdir(), 'msevents-live-smoke-'));
2262

2363
try {
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

Comments
 (0)