fix(spawn): 稳定子进程 cwd 并统一错误映射#254
Closed
jlovec wants to merge 1 commit into
Closed
Conversation
This was referenced Mar 6, 2026
| return { | ||
| command: process.execPath, | ||
| args: [entrypoint, ...args] | ||
| args: ['--cwd', projectRoot, entrypoint, ...args] |
There was a problem hiding this comment.
[MAJOR] 运行时 cwd 被强制为项目根目录,可能破坏会话工作目录
Why this is a problem: 这里新增的 --cwd projectRoot 会覆盖 spawnHappyCLI 传入的 cwd(runner 启动会话时依赖该 cwd),导致 bun 开发模式下 CLI 进程 process.cwd() 固定为项目根目录,实际会话可能在错误目录启动。
Suggested fix:
// allow caller to preserve intended session cwd when needed
export function getHappyCliCommand(args: string[], workingDir?: string): HappyCliCommand {
...
if (isBunRuntime) {
const bunCwd = workingDir ?? projectRoot;
return {
command: process.execPath,
args: ['--cwd', bunCwd, entrypoint, ...args]
};
}
}
// spawnHappyCLI
const desiredCwd = typeof options.cwd === 'string' ? options.cwd : undefined;
const { command, args: spawnArgs } = getHappyCliCommand(args, desiredCwd);There was a problem hiding this comment.
Findings
- [MAJOR] Bun 子进程
--cwd projectRoot会覆盖spawnHappyCLI的目标 cwd,开发模式下可能导致会话在错误目录启动cli/src/utils/spawnHappyCLI.ts:70
Suggested fix:// allow caller to preserve intended session cwd when needed export function getHappyCliCommand(args: string[], workingDir?: string): HappyCliCommand { ... if (isBunRuntime) { const bunCwd = workingDir ?? projectRoot; return { command: process.execPath, args: ['--cwd', bunCwd, entrypoint, ...args] }; } } // spawnHappyCLI const desiredCwd = typeof options.cwd === 'string' ? options.cwd : undefined; const { command, args: spawnArgs } = getHappyCliCommand(args, desiredCwd);
Summary
- 发现 1 个潜在回归(开发模式会话 cwd 被固定为项目根目录)。
Testing
- Not run (automation)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
新建会话时,前端可能收到
Unexpected spawn result,根因是 CLI 子进程在容器/特定 cwd 下路径解析不稳定,以及 Hub 侧对部分 spawn 错误形态缺少归一化。变更说明
--cwd projectRoot,稳定路径解析行为。error字段与目录审批请求形态,统一返回可消费错误。影响范围
验证
Unexpected spawn result。