fix(code-executor): 修复 Windows 宿主到 Container workspace 的路径兼容性 - #251
fix(code-executor): 修复 Windows 宿主到 Container workspace 的路径兼容性#2512021210507 wants to merge 4 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #251 +/- ##
==========================================
Coverage ? 87.86169%
==========================================
Files ? 482
Lines ? 45204
Branches ? 0
==========================================
Hits ? 39717
Misses ? 5487
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
AI Code Review基于我对 发现的问题🚨 Critical
|
| cmd_str = (f"parent='{_container_parent(dst)}'; " | ||
| f"[ -e \"$parent\" ] || mkdir -p \"$parent\"; " | ||
| f"cp -a '{container_src}' '{dst}'") | ||
|
|
There was a problem hiding this comment.
_stage_workspace_input 中 dst 未做 POSIX 归一化
dst(即 dst_abs)直接拼进 ln -sfn '{src}' '{dst}' / cp -a '{src}' '{dst}',src 与 parent 已归一化但 dst 本身未归一化。Windows 宿主上 ws.path 或 spec.dst 含反斜杠时,命令在 bash 中会被错误解释为转义/拼接,导致链接/拷贝目标错误或失败,与本 PR 消除反斜杠的目标自相矛盾。建议对 dst 同样复用 _container_path/_container_parent 做归一化后再插入命令。
| @@ -552,14 +565,14 @@ async def _stage_host_input(self, ws: WorkspaceInfo, host: str, dst: str, mode: | |||
| if self.config.inputs_host_base: | |||
There was a problem hiding this comment.
_stage_host_input 中 dst 同样未归一化
link/copy 分支里 '{dst}' 直接取自 dst_abs,而 parent 已用 _container_parent(dst) 归一化,同根因遗漏。若 dst_abs 含反斜杠,mkdir -p 可能成功但 ln -sfn 目标路径错误。建议统一对 dst 做 POSIX 归一化。
AI Code Review发现的问题
|
|
我已阅读CLA文件,特此签署CLA |
|
I have read the CLA Document and I hereby sign the CLA |
|
recheck |
AI Code Review基于我对 diff 及相关上下文的全面分析,以下是我的审查结果: 发现的问题🚨 严重
|
| if not raw_path: | ||
| if allow_current: | ||
| return "" | ||
| raise ValueError("container relative path must not be empty") |
There was a problem hiding this comment.
_container_relative_path 路径逃逸检测存在缺口
_stage_workspace_input 接收的 dst 为 _container_path(ws.path, dst_rel) 拼出的绝对路径,_container_path 不再校验逃逸,若 dst 含 .. 仍可越界创建软链。建议在 _stage_workspace_input 对 dst 再次做 _container_relative_path 校验或强制以 ws.path 为根做 relative_to 断言。
概述
修复 Windows 宿主机运行 Docker Container workspace 时的路径兼容性和清理稳定性问题。
Container 内部运行的是 Linux,但 SDK 原先在构造 Container workspace 路径时使用宿主机
pathlib.Path。在 Windows 上会生成\,随后被传入 Linux Container 的 shell 命令和文件 stage 路径,可能导致 workspace、Skill 或输入文件路径不正确。修改内容
PurePosixPath统一构造 Container 内部路径,确保始终使用/。_container置为None,使析构期或重复清理成为无操作。finally阶段可完成清理。验证
使用仓库
.venv执行:结果:126 passed。
结果:零违规。
范围
本 PR 仅修复共享
CodeExecutorworkspace runtime:不包含自动代码评审 Agent 示例、Skill、数据库或规则逻辑。
该问题在验证自动代码评审 Agent 的 Windows + Container 路径时发现。
关联 #92