From f02bef36d2f6e61d4d675d7505527708bb3714a6 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Mon, 22 Jun 2026 14:36:58 +0800 Subject: [PATCH] test: skip unusable Bun compile probes --- tests/cli-generate-cli.integration.test.ts | 61 +++++++++++++++++++--- tests/generate-cli.test.ts | 39 +++++++++++++- 2 files changed, 92 insertions(+), 8 deletions(-) diff --git a/tests/cli-generate-cli.integration.test.ts b/tests/cli-generate-cli.integration.test.ts index 4829aed..8293b8d 100644 --- a/tests/cli-generate-cli.integration.test.ts +++ b/tests/cli-generate-cli.integration.test.ts @@ -34,12 +34,50 @@ async function ensureDistBuilt(): Promise { async function hasBun(): Promise { return await new Promise((resolve) => { - execFile('bun', ['--version'], { cwd: process.cwd(), env: process.env }, (error) => { + execFile(process.env.BUN_BIN ?? 'bun', ['--version'], { cwd: process.cwd(), env: process.env }, (error) => { resolve(!error); }); }); } +let bunCompileSupport: Promise | undefined; + +async function hasRunnableBunCompile(): Promise { + bunCompileSupport ??= probeRunnableBunCompile(); + return await bunCompileSupport; +} + +async function probeRunnableBunCompile(): Promise { + if (!(await hasBun())) { + return false; + } + const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mcporter-bun-compile-probe-')); + const sourcePath = path.join(tempDir, 'probe.ts'); + const binaryPath = path.join(tempDir, 'probe'); + try { + await fs.writeFile(sourcePath, 'console.log("mcporter-bun-compile-probe");\n', 'utf8'); + const bun = process.env.BUN_BIN ?? 'bun'; + const built = await new Promise((resolve) => { + execFile( + bun, + ['build', sourcePath, '--compile', '--outfile', binaryPath], + { cwd: tempDir, env: process.env }, + (error) => resolve(!error) + ); + }); + if (!built) { + return false; + } + return await new Promise((resolve) => { + execFile(binaryPath, [], { cwd: tempDir, env: process.env }, (error, stdout) => { + resolve(!error && stdout.trim() === 'mcporter-bun-compile-probe'); + }); + }); + } finally { + await fs.rm(tempDir, { recursive: true, force: true }).catch(() => {}); + } +} + async function ensureBunSupport(reason: string): Promise { if (process.platform === 'win32') { console.warn(`bun not supported on Windows; skipping ${reason}.`); @@ -52,6 +90,17 @@ async function ensureBunSupport(reason: string): Promise { return true; } +async function ensureRunnableBunCompile(reason: string): Promise { + if (!(await ensureBunSupport(reason))) { + return false; + } + if (!(await hasRunnableBunCompile())) { + console.warn(`bun-compiled binaries cannot run on this runner; skipping ${reason}.`); + return false; + } + return true; +} + async function runGeneratedCli( bundlePath: string, args: string[], @@ -566,7 +615,7 @@ await new Promise((resolve) => { transport.onclose = resolve; }); }, 20000); it('runs "node dist/cli.js generate-cli --compile" when bun is available', async () => { - if (!(await ensureBunSupport('compile integration test'))) { + if (!(await ensureRunnableBunCompile('compile integration test'))) { return; } const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mcporter-cli-compile-')); @@ -616,7 +665,7 @@ await new Promise((resolve) => { transport.onclose = resolve; }); }, 20000); it('end-to-end: compiles a "bun" CLI and calls ping', async () => { - if (!(await ensureBunSupport('Bun CLI end-to-end test'))) { + if (!(await ensureRunnableBunCompile('Bun CLI end-to-end test'))) { return; } const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mcporter-cli-bun-')); @@ -690,7 +739,7 @@ await new Promise((resolve) => { transport.onclose = resolve; }); }, 30000); it('runs "node dist/cli.js generate-cli --compile" using the Bun bundler by default', async () => { - if (!(await ensureBunSupport('Bun bundler compile integration test'))) { + if (!(await ensureRunnableBunCompile('Bun bundler compile integration test'))) { return; } const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mcporter-cli-compile-bun-')); @@ -739,7 +788,7 @@ await new Promise((resolve) => { transport.onclose = resolve; }); }, 20000); it('accepts inline stdio commands (e.g., "npx -y chrome-devtools-mcp@latest") when compiling', async () => { - if (!(await ensureBunSupport('inline stdio compile integration test'))) { + if (!(await ensureRunnableBunCompile('inline stdio compile integration test'))) { return; } const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mcporter-inline-stdio-')); @@ -884,7 +933,7 @@ await new Promise((resolve) => { transport.onclose = resolve; }); console.warn('set MCPORTER_STANDALONE_BINARY_TEST=1 to run standalone Bun release binary smoke'); return; } - if (!(await ensureBunSupport('standalone Bun release binary smoke'))) { + if (!(await ensureRunnableBunCompile('standalone Bun release binary smoke'))) { return; } await new Promise((resolve, reject) => { diff --git a/tests/generate-cli.test.ts b/tests/generate-cli.test.ts index d6ca320..eb4eb15 100644 --- a/tests/generate-cli.test.ts +++ b/tests/generate-cli.test.ts @@ -203,9 +203,9 @@ describeGenerateCli('generateCli', () => { }); await fs.mkdir(path.join(tmpDir, 'schema-cache'), { recursive: true }); const exec = await import('node:child_process'); - const bunAvailable = await hasBun(exec); + const bunAvailable = await hasRunnableBunCompile(exec); if (!bunAvailable) { - console.warn('bun is not available on this runner; skipping compilation checks.'); + console.warn('bun-compiled binaries cannot run on this runner; skipping compilation checks.'); return; } await ensureDistBuilt(); @@ -891,3 +891,38 @@ async function hasBun(exec: typeof import('node:child_process')) { }); }); } + +let bunCompileSupport: Promise | undefined; + +async function hasRunnableBunCompile(exec: typeof import('node:child_process')) { + bunCompileSupport ??= probeRunnableBunCompile(exec); + return await bunCompileSupport; +} + +async function probeRunnableBunCompile(exec: typeof import('node:child_process')) { + if (!(await hasBun(exec))) { + return false; + } + const tempDir = await fs.mkdtemp(path.join(tmpDir, 'bun-compile-probe-')); + const sourcePath = path.join(tempDir, 'probe.ts'); + const binaryPath = path.join(tempDir, 'probe'); + try { + await fs.writeFile(sourcePath, 'console.log("mcporter-bun-compile-probe");\n', 'utf8'); + const bun = process.env.BUN_BIN ?? 'bun'; + const built = await new Promise((resolve) => { + exec.execFile(bun, ['build', sourcePath, '--compile', '--outfile', binaryPath], execOptions(), (error) => + resolve(!error) + ); + }); + if (!built) { + return false; + } + return await new Promise((resolve) => { + exec.execFile(binaryPath, [], execOptions(), (error, stdout) => { + resolve(!error && stdout.trim() === 'mcporter-bun-compile-probe'); + }); + }); + } finally { + await fs.rm(tempDir, { recursive: true, force: true }).catch(() => {}); + } +}