Files
deta-agent-plugins/scripts/verify-runtime-provision.sh
T
ringo 3ab20c23b0
CI / contract (push) Has been cancelled
feat(runtime): 领域服务运行时随插件分发 + 启动器自动供给(修 P0:同事机器无开发检出就起不来)
根因:启动器的运行时解析第三顺位是开发检出 ~/Dev/ant/ant-copilot,同事机器没有该目录 → 插件装上、MCP 起不来;而私有 registry 匿名读返回 401,走 npm 安装等于要求每台机器都配 Gitea token。

改法:① 打包产物随插件分发(plugins/<产品>/runtime/,3.96MB 自包含单文件 + manifest 记录来源版本/提交/大小/sha256);② 启动器每次拉起比对 sha256,缺失或被改动即从插件包安装到 ~/.deta/runtime(首次启动零操作、升级自动同步);③ 新增 deta install-runtime(显式安装 + 补装可选依赖 @resvg/resvg-js + 装完立刻做一次真实 MCP 握手自证),status/doctor 显示运行时来源与预览图依赖状态;④ 契约校验加 E6:运行时包必须自洽(sha256/字节数/manifest.pluginVersion 与插件版本一致),拦住“升版本忘重跑 sync-runtime”。

实测:全新 HOME(模拟同事机器、无开发检出、无凭据)下供给探针 10/10 通过 —— 首次启动自动安装、启动行指向沙箱运行时、install-runtime 握手 39 个工具、重复安装幂等、运行时被改动自动修复、插件包缺运行时两处都给打包缺陷指引;已装副本 0.3.14 独立验证(含 npm 自动补装 @resvg 2 包)。studio 0.3.14 / writer 0.1.5。
2026-09-20 16:40:33 +08:00

62 lines
3.8 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 探针:运行时供给(模拟同事机器 —— 全新 HOME、无开发检出、无凭据、无 token)
#
# 背景:私有 registry 匿名读 401,运行时因此**随插件包分发**(plugins/<产品>/runtime/),
# 由启动器在首次启动时自动安装到 $HOME/.deta/runtime。本探针断言这条链路的五件事:
# ① 首次启动自动安装(用户零操作)
# ② install-runtime 自证(真实 MCP 握手 + 工具数)
# ③ 幂等(重复安装不重复拷贝)
# ④ 插件包缺运行时 → 报错清楚且指向打包缺陷(不是让用户去配环境)
# ⑤ 运行时被改动/截断 → 下次启动自动修复
#
# 用法:bash scripts/verify-runtime-provision.sh [插件名,缺省 studio]
set -u
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
PROFILE="${1:-studio}"
PLUGIN="$ROOT/plugins/$PROFILE"
FRESH="$(mktemp -d /tmp/deta-runtime-probe.XXXXXX)"
pass=0
fail=0
ok() { printf ' PASS %s\n' "$1"; pass=$((pass + 1)); }
no() { printf ' FAIL %s\n' "$1"; fail=$((fail + 1)); }
[ -d "$PLUGIN" ] || { echo "插件不存在:$PLUGIN"; exit 2; }
echo "== 沙箱 HOME=${FRESH}(插件=${PROFILE})"
# ① 首次启动:启动器应自行从插件包安装运行时
OUT="$(HOME="$FRESH" bash "$PLUGIN/bin/deta-mcp.sh" --profile "$PROFILE" < /dev/null 2>&1 || true)"
if printf '%s' "$OUT" | grep -q "已从插件包安装运行时到"; then ok "首次启动自动安装运行时"; else no "未看到自动安装提示"; fi
if printf '%s' "$OUT" | grep -q "运行时=${FRESH}/.deta/runtime"; then ok "启动行指向沙箱运行时"; else no "启动行运行时不对:$(printf '%s' "$OUT" | grep -o '运行时=[^ ]*' | head -1)"; fi
if [ -f "$FRESH/.deta/runtime/dist/deta-mcp.mjs" ]; then ok "运行时文件已落地"; else no "运行时文件缺失"; fi
if [ -f "$FRESH/.deta/runtime/manifest.json" ]; then ok "manifest 随装(可溯源)"; else no "manifest 缺失"; fi
if printf '%s' "$OUT" | grep -q "@resvg/resvg-js"; then ok "缺可选依赖时有明确提示"; else no "未提示可选依赖缺失"; fi
# ② install-runtime:显式安装 + 真实 MCP 握手自证
CLI_OUT="$(HOME="$FRESH" node "$PLUGIN/bin/deta-cli.mjs" install-runtime --no-resvg 2>&1 || true)"
if printf '%s' "$CLI_OUT" | grep -q "MCP 握手通过"; then
ok "install-runtime 握手通过($(printf '%s' "$CLI_OUT" | grep -o '[0-9]\+ 个工具' | head -1))"
else
no "install-runtime 握手失败:$(printf '%s' "$CLI_OUT" | tail -2)"
fi
if printf '%s' "$CLI_OUT" | grep -q "已是最新"; then ok "重复安装幂等(未重复拷贝)"; else no "未识别为已是最新"; fi
# ③ 运行时被改动 → 下次启动自动修复
printf 'corrupted' >> "$FRESH/.deta/runtime/dist/deta-mcp.mjs"
OUT2="$(HOME="$FRESH" bash "$PLUGIN/bin/deta-mcp.sh" --profile "$PROFILE" < /dev/null 2>&1 || true)"
if printf '%s' "$OUT2" | grep -q "已从插件包安装运行时到"; then ok "运行时被改动后自动修复"; else no "未自动修复被改动的运行时"; fi
# ④ 插件包缺运行时(模拟打包缺陷)→ 两处都要给可执行指引
BAD="$FRESH/bad-plugin"
mkdir -p "$BAD"
cp -R "$PLUGIN/bin" "$BAD/bin"
cp -R "$PLUGIN/.codex-plugin" "$BAD/.codex-plugin"
BAD_OUT="$(HOME="$FRESH/bad-home" bash "$BAD/bin/deta-mcp.sh" --profile "$PROFILE" < /dev/null 2>&1 || true)"
if printf '%s' "$BAD_OUT" | grep -q "未找到领域服务运行时"; then ok "缺运行时启动报错清楚"; else no "缺运行时报错不明确"; fi
BAD_CLI="$(HOME="$FRESH/bad-home" node "$BAD/bin/deta-cli.mjs" install-runtime --no-resvg 2>&1 || true)"
if printf '%s' "$BAD_CLI" | grep -q "插件包内没有运行时"; then ok "install-runtime 指出这是打包缺陷"; else no "install-runtime 对缺运行时的指引不对"; fi
echo
echo "结果:${pass} 通过 / ${fail} 失败"
rm -rf "$FRESH"
[ "$fail" -eq 0 ]