Files
UHD_Media_Tool/scripts/check-compiled-binary.sh
T
rootandClaude Opus 5.5 3f1c6d02f6 fix(sandbox): 子进程环境保留 PATH,编译产物里沙箱任务恢复;编译自检加沙箱启动
清空环境后编译产物在入口按 PATH 解析 --allow-run 失败直接退出,Bangumi 热门、字幕验证码 / 解压等沙箱任务一直报错。

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
2026-10-08 18:08:28 +08:00

27 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
# 编译产物自检(deno task ci 的最后一步):deno compile 的 --exclude-unused-npm 可能漏嵌 npm 包/子路径,
# 开发态与测试全绿但二进制启动即 ERR_MODULE_NOT_FOUND。这里用空环境跑 `--role preflight`:
# 它会先加载完整的服务端模块图(db/任务引擎/全部模块),然后才因缺配置以退出码 2 结束;
# 模块缺失会以退出码 1 + ERR_MODULE_NOT_FOUND 结束。
set -u
bin="${1:-dist/umt-server}"
case "$bin" in /*) ;; *) bin="$PWD/$bin" ;; esac
[ -x "$bin" ] || { echo "check-compiled-binary: 找不到编译产物 $bin(先跑 deno task build)" >&2; exit 1; }
out=$(cd /tmp && env -i PATH="$PATH" "$bin" --role preflight 2>&1)
code=$?
if [ "$code" -eq 2 ] && printf '%s' "$out" | grep -q '配置无效'; then
# 沙箱子进程:与 sandbox/client.ts 同样的环境(只有 PATH)拉起 `--role sandbox`,请求一个不存在的任务,
# 应回一行 {"ok":false,...};入口就崩(如 --allow-run 解析失败)会没有这行
sb=$(cd /tmp && printf '{"job":"__check__","input":null}' | env -i PATH="$PATH" "$bin" --role sandbox 2>&1)
if printf '%s' "$sb" | grep -q '"ok":false'; then
echo "check-compiled-binary: ok(模块图加载完整,沙箱子进程能启动)"
exit 0
fi
echo "check-compiled-binary: 沙箱子进程起不来:" >&2
printf '%s\n' "$sb" >&2
exit 1
fi
echo "check-compiled-binary: 编译产物自检失败(退出码 $code):" >&2
printf '%s\n' "$out" >&2
exit 1