From 87dbf2686b2c71bb94ab4fa71ccf319898b8c67d Mon Sep 17 00:00:00 2001 From: dongmucat <1127093059@qq.com> Date: Wed, 29 Apr 2026 16:03:09 +0800 Subject: [PATCH] fix(cli): resolve Windows CI test failures across three platform issues - Use Bun.which() with process.execPath fallback in run-cli helper to resolve bun executable on Windows (fixes 22 integration tests) - Normalize paths in credentials-store test for Windows backslash compat - Use shell: true on Windows in updater spawn for proper exe resolution --- cli/src/platform/updater.ts | 21 ++++++++++++------- cli/test/helpers/run-cli.ts | 5 ++++- .../unit/stores/credentials-store.test.ts | 3 ++- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/cli/src/platform/updater.ts b/cli/src/platform/updater.ts index d1a087bd..862d4288 100644 --- a/cli/src/platform/updater.ts +++ b/cli/src/platform/updater.ts @@ -1,4 +1,5 @@ import { spawn } from 'node:child_process' +import type { ChildProcess, SpawnOptions } from 'node:child_process' export interface UpdaterRunResult { success: boolean @@ -15,18 +16,22 @@ export async function runUpdateCommand(command: string): Promise((resolve) => { - const proc = spawn(executable, args, { stdio: ['ignore', 'pipe', 'pipe'] }) + const proc: ChildProcess = spawn(program, args, spawnOptions) const chunks: Buffer[] = [] - proc.stdout.on('data', chunk => chunks.push(Buffer.from(chunk))) - proc.stderr.on('data', chunk => chunks.push(Buffer.from(chunk))) - proc.on('error', error => resolve({ success: false, output: error.message })) - proc.on('close', code => resolve({ + proc.stdout?.on('data', (chunk: Buffer) => chunks.push(Buffer.from(chunk))) + proc.stderr?.on('data', (chunk: Buffer) => chunks.push(Buffer.from(chunk))) + proc.on('error', (error: Error) => resolve({ success: false, output: error.message })) + proc.on('close', (code: number | null) => resolve({ success: code === 0, output: Buffer.concat(chunks).toString('utf-8') })) diff --git a/cli/test/helpers/run-cli.ts b/cli/test/helpers/run-cli.ts index a21916c1..82c08945 100644 --- a/cli/test/helpers/run-cli.ts +++ b/cli/test/helpers/run-cli.ts @@ -1,6 +1,9 @@ export async function runCli(args: string[], env: Record = {}) { + // Use Bun.which() to find bun in PATH, fallback to current executable + const bunPath = await Bun.which('bun') || process.execPath + const proc = Bun.spawn({ - cmd: ['bun', 'src/index.ts', ...args], + cmd: [bunPath, 'src/index.ts', ...args], cwd: new URL('../../', import.meta.url).pathname, env: { ...process.env, ...env }, stdout: 'pipe', diff --git a/cli/test/unit/stores/credentials-store.test.ts b/cli/test/unit/stores/credentials-store.test.ts index ae416dd0..6ab7da53 100644 --- a/cli/test/unit/stores/credentials-store.test.ts +++ b/cli/test/unit/stores/credentials-store.test.ts @@ -1,4 +1,5 @@ import { describe, expect, test } from 'bun:test' +import { normalize } from 'path' import { createTempHome } from '../../helpers/temp-env' import { CredentialsStore } from '../../../src/stores/credentials-store' @@ -8,7 +9,7 @@ describe('CredentialsStore', () => { const store = new CredentialsStore(env.home) await store.setToken('https://registry.example.com', 'sk_test') expect(await store.getToken('https://registry.example.com')).toBe('sk_test') - expect(store.path).toBe(`${env.home}/.skillhub/credentials.json`) + expect(normalize(store.path)).toBe(normalize(`${env.home}/.skillhub/credentials.json`)) expect(await Bun.file(`${env.cwd}/credentials.json`).exists()).toBe(false) }) })