oasis_test_v2 2.2.16 → 2.2.18

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,18 +45,28 @@ 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
@@ -67,7 +86,7 @@ oasis_resolve_bin() {
67
86
  # 还能被找回来,不至于「按 <cmd> 扫 PATH 一个都找不到」。**别删它**,也别据此重新引入自动挪动。
68
87
  while IFS= read -r dir; do
69
88
  candidate="$dir/$cmd_name.oasis-displaced"
70
- if [ -x "$candidate" ] && [ "$(realpath "$candidate" 2>/dev/null)" != "$SELF" ]; then
89
+ if [ -x "$candidate" ] && ! oasis_is_wrapper "$candidate"; then
71
90
  printf -v "$bin_var" '%s' "$candidate"
72
91
  export "$bin_var"
73
92
  return 0