oasis_test_v2 2.2.15 → 2.2.17

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.
@@ -17,6 +17,18 @@
17
17
 
18
18
  set -euo pipefail
19
19
 
20
+ # 这个候选是不是一个 oasis wrapper?
21
+ #
22
+ # 判据与 TS 侧的 `isOasisWrapperPath` **同一条**:解析到底之后路径以 `/wrapper.sh` 结尾。
23
+ # 所有连接器的 wrapper 都是「以 commandName 之名软链到 <connector>/wrapper.sh」,
24
+ # 所以这一条既认得出自己、也认得出**别的会话/别的部署根** stage 出来的那些。
25
+ oasis_is_wrapper() {
26
+ case "$(realpath "$1" 2>/dev/null)" in
27
+ */wrapper.sh) return 0 ;;
28
+ *) return 1 ;;
29
+ esac
30
+ }
31
+
20
32
  # Resolve the real binary path (avoid recursion into self).
21
33
  # If ${OASIS_BIN_VAR} is already set (injected by inject()), use it — unless it points
22
34
  # back at this very wrapper. Otherwise scan PATH for the first executable that isn't us.
@@ -24,9 +36,6 @@ oasis_resolve_bin() {
24
36
  local bin_var="${OASIS_BIN_VAR:?OASIS_BIN_VAR must be set}"
25
37
  local cmd_name="${OASIS_CMD_NAME:?OASIS_CMD_NAME must be set}"
26
38
 
27
- local SELF
28
- SELF="$(realpath "$0" 2>/dev/null || echo "$0")"
29
-
30
39
  # If already set by inject() AND executable on THIS machine, skip the PATH scan —
31
40
  # but **only if it isn't this wrapper itself**.
32
41
  #
@@ -36,33 +45,48 @@ oasis_resolve_bin() {
36
45
  # 触发更新就会把 /tmp/oasis-conn-* 带进去)。于是 GH_BIN 指向 wrapper 自己 →
37
46
  # 这里的快路径直接 return → 后面 exec "$GH_BIN" 就是无限递归调用自身。
38
47
  # 症状还特别误导:递归被 oasis_check_available 拦下,报的是「cli is upgrading」。
39
- if [ -n "${!bin_var:-}" ] && [ -x "${!bin_var:-}" ] \
40
- && [ "$(realpath "${!bin_var}" 2>/dev/null)" != "$SELF" ]; then
48
+ # 判据是「是不是 wrapper」,不是「是不是**我**」:daemon PATH 被污染时,
49
+ # inject() 解出来的可能是**另一个**会话的 wrapper,信了照样递归。
50
+ if [ -n "${!bin_var:-}" ] && [ -x "${!bin_var:-}" ] && ! oasis_is_wrapper "${!bin_var}"; then
41
51
  return 0
42
52
  fi
43
53
  # 空 / 不可执行 / 指向自己:清掉,让下面的 PATH 扫描重新填。
44
54
  unset "$bin_var" 2>/dev/null || true
45
55
 
46
- # Fallback: scan PATH for real binary (skip self to avoid recursion)
56
+ # Fallback: scan PATH —— **跳过所有 oasis wrapper,不只是自己**。
57
+ #
58
+ # ⚠ 把 `oasis_is_wrapper` 换回 `!= "$SELF"` 会炸机(2026-09-11 两次实测,进程数冲到
59
+ # 1.1 万、load 391)。同一台机器上常常同时挂着**多个** staged wrapper 目录
60
+ # (不同会话、不同部署根),它们各自是**不同的 wrapper.sh 文件**,realpath 互不相等;
61
+ # 只比 `$0` 的话,A 把 B 当「真 CLI」exec 过去,B 再把 A 当真 CLI,
62
+ # 叠上 `oasis_check_available` 的 `--version` 自检,每跳再 fork 一次 → 指数级。
63
+ #
64
+ # 平时看不出来,是因为 inject() 会把 LARK_BIN/GH_BIN 直接设好、走上面那条快路径,
65
+ # 根本不扫 PATH。那个绝对路径**一旦失效**(文件被挪走/升级换名)就立刻掉进这里。
47
66
  local candidate
48
67
  while IFS= read -r dir; do
49
68
  candidate="$dir/$cmd_name"
50
- if [ -x "$candidate" ] && [ "$(realpath "$candidate" 2>/dev/null)" != "$SELF" ]; then
69
+ if [ -x "$candidate" ] && ! oasis_is_wrapper "$candidate"; then
51
70
  printf -v "$bin_var" '%s' "$candidate"
52
71
  export "$bin_var"
53
72
  return 0
54
73
  fi
55
74
  done <<< "$(echo "$PATH" | tr ':' '\n')"
56
75
 
57
- # 最后一档:被「挪开遮挡」挪走的那个原件(<cmd>.oasis-displaced)。
76
+ # 最后一档:名为 <cmd>.oasis-displaced 的原件。
77
+ #
78
+ # ⚠ 这一档现在是**善后用的**,不是常态路径。2026-09-11 短暂上线过一版「派单时自动把
79
+ # $HOME/.local/bin/<cmd> 改名挪走」(node-daemon 2.2.15),当天就回退了——挪走会让**已在
80
+ # 跑的会话**里 inject() 解出来的 LARK_BIN/GH_BIN 失效,回落去扫 PATH,而扫 PATH 会选中
81
+ # 同机**另一个** staged wrapper(不同会话/部署根,realpath 不等于 $0 所以跳不过),
82
+ # 两个 wrapper 互相把对方当真 CLI,叠上下面的 --version 自检后指数级 fork
83
+ # (实测 1.1 万进程、load 391)。
58
84
  #
59
- # 为什么非有不可:clearLoginShellShadow() 会把 $HOME/.local/bin/<cmd> 改名挪走
60
- # (理由见那个函数的注释)。如果这台机器上**真实 CLI 只有那一份**——没装到
61
- # ~/.oasis/connector-tools/bin——那么上面按 <cmd> 扫 PATH 会一个都找不到,
62
- # 挪走遮挡反而把 CLI 弄没了。改名而不是删除,就是为了这一档能把它捡回来。
85
+ # 那一版可能已经在某些节点上留下了 <cmd>.oasis-displaced。这一档保证那些机器上的真 CLI
86
+ # 还能被找回来,不至于「按 <cmd> 扫 PATH 一个都找不到」。**别删它**,也别据此重新引入自动挪动。
63
87
  while IFS= read -r dir; do
64
88
  candidate="$dir/$cmd_name.oasis-displaced"
65
- if [ -x "$candidate" ] && [ "$(realpath "$candidate" 2>/dev/null)" != "$SELF" ]; then
89
+ if [ -x "$candidate" ] && ! oasis_is_wrapper "$candidate"; then
66
90
  printf -v "$bin_var" '%s' "$candidate"
67
91
  export "$bin_var"
68
92
  return 0