fix(cli): verify Bun.which() path exists before using on Windows

Bun.which('bun') on Windows CI returns a non-existent path
(C:\Users\runneradmin\.bun\bin\bun.exe), causing all integration
tests to fail. Add existsSync() check to fallback to process.execPath
when the resolved path doesn't exist.

Also fix version-command.test.ts to use process.execPath instead of
hardcoded 'bun' string for cross-platform compatibility.

Fixes 19 failing integration tests on Windows platform.
This commit is contained in:
dongmucat 2026-04-29 16:08:53 +08:00
parent 87dbf2686b
commit 704f2d2af4
2 changed files with 9 additions and 3 deletions

View file

@ -1,6 +1,9 @@
import { existsSync } from 'node:fs'
export async function runCli(args: string[], env: Record<string, string> = {}) {
// Use Bun.which() to find bun in PATH, fallback to current executable
const bunPath = await Bun.which('bun') || process.execPath
// Use Bun.which() to find bun in PATH, but verify it exists
const whichBun = await Bun.which('bun')
const bunPath = (whichBun && existsSync(whichBun)) ? whichBun : process.execPath
const proc = Bun.spawn({
cmd: [bunPath, 'src/index.ts', ...args],

View file

@ -26,8 +26,11 @@ describe('version command', () => {
const dir = await mkdtemp(join(tmpdir(), 'skillhub-node-build-'))
const outfile = join(dir, 'index.js')
await writeFile(join(dir, 'package.json'), JSON.stringify({ type: 'module' }))
// Use process.execPath to ensure we use the current Bun executable
const bunPath = process.execPath
const build = Bun.spawn({
cmd: ['bun', 'build', 'src/index.ts', '--target=node', `--outfile=${outfile}`],
cmd: [bunPath, 'build', 'src/index.ts', '--target=node', `--outfile=${outfile}`],
cwd: new URL('../../', import.meta.url).pathname,
stdout: 'pipe',
stderr: 'pipe'