fix(cli): use fileURLToPath for cross-platform cwd path compatibility

The issue was that new URL().pathname returns Unix-style paths on Windows
(e.g., /D:/a/skillhub/...) which Bun.spawn() cannot resolve correctly.
Using fileURLToPath() converts the URL to a proper platform-specific path.

Changes:
- cli/test/helpers/run-cli.ts: use fileURLToPath for cwd
- cli/test/integration/version-command.test.ts: same fix for build spawn
This commit is contained in:
dongmucat 2026-04-29 16:13:50 +08:00
parent 704f2d2af4
commit 43a201c8d5
2 changed files with 4 additions and 2 deletions

View file

@ -1,4 +1,5 @@
import { existsSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
export async function runCli(args: string[], env: Record<string, string> = {}) {
// Use Bun.which() to find bun in PATH, but verify it exists
@ -7,7 +8,7 @@ export async function runCli(args: string[], env: Record<string, string> = {}) {
const proc = Bun.spawn({
cmd: [bunPath, 'src/index.ts', ...args],
cwd: new URL('../../', import.meta.url).pathname,
cwd: fileURLToPath(new URL('../../', import.meta.url)),
env: { ...process.env, ...env },
stdout: 'pipe',
stderr: 'pipe'

View file

@ -2,6 +2,7 @@ import { describe, expect, test } from 'bun:test'
import { mkdtemp, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { runCli } from '../helpers/run-cli'
describe('version command', () => {
@ -31,7 +32,7 @@ describe('version command', () => {
const bunPath = process.execPath
const build = Bun.spawn({
cmd: [bunPath, 'build', 'src/index.ts', '--target=node', `--outfile=${outfile}`],
cwd: new URL('../../', import.meta.url).pathname,
cwd: fileURLToPath(new URL('../../', import.meta.url)),
stdout: 'pipe',
stderr: 'pipe'
})