@pawlogic/dl 0.4.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dl-npm-update.sh +36 -7
- package/dl.mjs +1 -1
- package/ilands.mjs +1 -1
- package/package.json +1 -1
package/dl-npm-update.sh
CHANGED
|
@@ -16,9 +16,10 @@
|
|
|
16
16
|
# 次,不加缓存白白打满 npm registry。
|
|
17
17
|
#
|
|
18
18
|
# 观测: 每条分支结束 fire-and-forget POST 一条事件到 callback-server
|
|
19
|
-
# $CALLBACK_SERVER_URL/
|
|
20
|
-
#
|
|
19
|
+
# $CALLBACK_SERVER_URL/sandbox-rpc/dl/selfupdate-event,backend 仅转发到 Honeycomb,
|
|
20
|
+
# schema 校验由本脚本端负责。TTL 命中频繁(每个沙箱 5min 内 N 次), 按 1/10 采样上报;
|
|
21
21
|
# 其余分支(install / no_tag / no_npm / lock_skip)全量上报。
|
|
22
|
+
# 鉴权: 复用 $DL_PROXY_TOKEN (沙箱 env, hono-pi-e2b 注入), Authorization Bearer。
|
|
22
23
|
# 上报失败一律 swallow,绝不让观测链阻塞自更新本身。
|
|
23
24
|
|
|
24
25
|
set -u
|
|
@@ -29,11 +30,15 @@ TTL=300
|
|
|
29
30
|
PACKAGE="@pawlogic/dl"
|
|
30
31
|
|
|
31
32
|
# ── 观测上报: fire-and-forget JSON POST,失败 swallow ────────────────────────
|
|
32
|
-
# args: outcome duration_ms
|
|
33
|
+
# args: outcome duration_ms [error_tail_file]
|
|
34
|
+
# error_tail_file 仅 npm_fail 分支传入,读末尾 ~200 字节带上去 —— 之前 npm stderr
|
|
35
|
+
# 全 swallow,根本看不到为什么失败,fleet 升级率 0.24% 都查不到根因。
|
|
33
36
|
report_event() {
|
|
34
37
|
_outcome="$1"
|
|
35
38
|
_dur="${2:-null}"
|
|
39
|
+
_errfile="${3:-}"
|
|
36
40
|
[ -z "${CALLBACK_SERVER_URL:-}" ] && return 0
|
|
41
|
+
[ -z "${DL_PROXY_TOKEN:-}" ] && return 0
|
|
37
42
|
command -v curl >/dev/null 2>&1 || return 0
|
|
38
43
|
_tag="${DL_NPM_DIST_TAG:-unknown}"
|
|
39
44
|
case "$_tag" in
|
|
@@ -45,11 +50,21 @@ report_event() {
|
|
|
45
50
|
if [ -f "$_verfile" ] && command -v node >/dev/null 2>&1; then
|
|
46
51
|
_ver=$(node -e 'try{console.log(require("'"$_verfile"'").version||"")}catch(e){}' 2>/dev/null || echo "")
|
|
47
52
|
fi
|
|
53
|
+
# error_tail: 末尾 200 字节, JSON 不安全字符 (\ " 控制符 / 换行 / tab) 一律压成
|
|
54
|
+
# 单空格; 长度上限挡住 LB 滥用,字符替换让 JSON 不需要复杂 escape。
|
|
55
|
+
_err_json="null"
|
|
56
|
+
if [ -n "$_errfile" ] && [ -f "$_errfile" ]; then
|
|
57
|
+
_err_raw=$(tail -c 200 "$_errfile" 2>/dev/null | tr '\n\r\t\\"' ' ' | tr -d '\000-\037')
|
|
58
|
+
if [ -n "$_err_raw" ]; then
|
|
59
|
+
_err_json="\"$_err_raw\""
|
|
60
|
+
fi
|
|
61
|
+
fi
|
|
48
62
|
# 后台 curl, -m 2 上限 2s; 不解析响应; stderr/stdout 全丢。
|
|
49
63
|
(
|
|
50
|
-
curl -fsS -m 2 -X POST "${CALLBACK_SERVER_URL%/}/
|
|
64
|
+
curl -fsS -m 2 -X POST "${CALLBACK_SERVER_URL%/}/sandbox-rpc/dl/selfupdate-event" \
|
|
51
65
|
-H 'content-type: application/json' \
|
|
52
|
-
-
|
|
66
|
+
-H "authorization: Bearer ${DL_PROXY_TOKEN}" \
|
|
67
|
+
-d "{\"trigger\":\"wrapper\",\"dist_tag\":\"$_tag\",\"outcome\":\"$_outcome\",\"duration_ms\":$_dur,\"installed_version\":\"$_ver\",\"build_short_sha\":null,\"error_tail\":$_err_json}" \
|
|
53
68
|
>/dev/null 2>&1 || true
|
|
54
69
|
) &
|
|
55
70
|
}
|
|
@@ -89,7 +104,16 @@ fi
|
|
|
89
104
|
# flock 不一定有(busybox sh) → mkdir 兜底原子锁。
|
|
90
105
|
run_install() {
|
|
91
106
|
_t0=$(date +%s 2>/dev/null || echo 0)
|
|
92
|
-
|
|
107
|
+
# stderr 写到独立文件 npm_fail 分支带末尾给观测端;stdout 仍丢掉。
|
|
108
|
+
_errlog=$(mktemp 2>/dev/null || echo "/tmp/dl-npm-err.$$")
|
|
109
|
+
# 必须带 --prefix=/home/user/.local 跟 HOME=/home/user,跟 sandbox-template
|
|
110
|
+
# 首次安装那一段对齐 (packages/sandbox-template/scripts/publish-e2b-template.ts
|
|
111
|
+
# 里 wrapper 写法)。沙箱进程 owner 是 user,无 /usr/lib/node_modules 写权限;
|
|
112
|
+
# 不带 prefix → npm 走默认全局路径 → EACCES 1 秒内挂掉, stderr 又被吞 → fleet
|
|
113
|
+
# 自更新 100% 失败但完全黑盒。这是 PR #729 漏掉 prefix 留下的 bug。
|
|
114
|
+
if HOME=/home/user npm install -g --prefix=/home/user/.local \
|
|
115
|
+
--no-audit --no-fund --no-update-notifier \
|
|
116
|
+
"$PACKAGE@$DL_NPM_DIST_TAG" >/dev/null 2>"$_errlog"; then
|
|
93
117
|
_outcome=ok
|
|
94
118
|
else
|
|
95
119
|
_outcome=npm_fail
|
|
@@ -114,7 +138,12 @@ run_install() {
|
|
|
114
138
|
chmod +x /home/user/.local/lib/dl-npm-update.sh 2>/dev/null || true
|
|
115
139
|
fi
|
|
116
140
|
echo "$now" > "$STAMP"
|
|
117
|
-
|
|
141
|
+
if [ "$_outcome" = "npm_fail" ]; then
|
|
142
|
+
report_event "$_outcome" "$_dur_ms" "$_errlog"
|
|
143
|
+
else
|
|
144
|
+
report_event "$_outcome" "$_dur_ms"
|
|
145
|
+
fi
|
|
146
|
+
rm -f "$_errlog" 2>/dev/null || true
|
|
118
147
|
}
|
|
119
148
|
|
|
120
149
|
if command -v flock >/dev/null 2>&1; then
|