Przeglądaj źródła

【修复,脚本】失败 Issue 门闩按版本边界匹配

check-issue-gate.sh 原用 contains("$VERSION") 匹配标题,0.2.0 会误匹配
0.2.0-rc.1 的失败 Issue 而错误拦截升级。改为与 check-pr-gate.sh /
upgrade-dsh.sh 一致的版本边界正则,并补单测(56/56 通过)。
PJ568 2 miesięcy temu
rodzic
commit
fe73f5f09b
2 zmienionych plików z 20 dodań i 3 usunięć
  1. 12 3
      scripts/check-issue-gate.sh
  2. 8 0
      tests/test-scripts.sh

+ 12 - 3
scripts/check-issue-gate.sh

@@ -25,13 +25,22 @@ GH_BIN="${GH:-gh}"
 GH_TOKEN="${GH_TOKEN:-${GITHUB_TOKEN:-}}"
 export GH_TOKEN
 
-# 列出未关闭的自动升级失败 Issue,标题含目标版本即命中
-# simp: gh 仅输出 JSON,匹配交给 jq(mock 易仿真);查询上限 50 条,按版本去重后远不会触及
+# 列出未关闭的自动升级失败 Issue,标题含目标版本即命中(匹配在下方按版本边界进行)
 #
 # List open auto-upgrade failure Issues; a title containing the target version is a hit
+# (matching below is done at version boundaries)
+# simp: gh 仅输出 JSON,匹配交给 jq(mock 易仿真);查询上限 50 条,按版本去重后远不会触及
+#
 # simp: gh only outputs JSON, matching is delegated to jq (easy to mock); cap of 50 is far above the deduped per-version count
 JSON="$("$GH_BIN" issue list --state open --search 'in:title "[自动升级]"' --json title,number --limit 50 2>/dev/null || true)"
 [ -n "$JSON" ] || { echo 0; exit 0; }
 
-MATCH="$(jq -r '.[] | select(.title | contains("'"$VERSION"'")) | .number' <<<"$JSON" | head -n1)"
+# 版本边界匹配(与 check-pr-gate.sh / upgrade-dsh.sh 同思想):先转义 VERSION 为正则字面量,
+# 再要求前后均非版本字符,避免 0.2.0 误匹配标题中的 0.2.0-rc.1(npm 版本字符集 [0-9A-Za-z.-])
+#
+# Version-boundary match (same idea as check-pr-gate.sh / upgrade-dsh.sh): escape VERSION to a
+# regex literal, then require non-version characters on both sides, so 0.2.0 is never matched as
+# a prefix of 0.2.0-rc.1 in a title (npm version chars [0-9A-Za-z.-])
+ESC="$(printf '%s' "$VERSION" | sed 's/[][\\^$.|*+?()]/\\&/g')"
+MATCH="$(jq -r --arg v "$ESC" '.[] | select(.title | test("(^|[^-0-9A-Za-z.])" + $v + "([^-0-9A-Za-z.]|$)")) | .number' <<<"$JSON" | head -n1)"
 [ -n "$MATCH" ] && echo 1 || echo 0

+ 8 - 0
tests/test-scripts.sh

@@ -212,6 +212,14 @@ GUARD_LOG="$TMP/mock_guard_gate.log" MOCK_LOG="$TMP/mock_guard_gate_gh.log" MOCK
   "$GATE" 0.2.0 > "$TMP/gate_guard.out" 2>&1
 assert_grep "gate:GITHUB_TOKEN 兜底为 GH_TOKEN" "GH_TOKEN=ghp_ci_fallback" "$TMP/mock_guard_gate.log"
 
+# 版本边界:0.2.0 不得匹配 0.2.0-rc.1(与 check-pr-gate.sh 同思想)
+#
+# Version boundary: 0.2.0 must not match 0.2.0-rc.1 (same idea as check-pr-gate.sh)
+GATE_RC='[{"title":"[自动升级] dsh 上游 0.2.0-rc.1 升级流程失败","number":13}]'
+MOCK_LOG="$TMP/mock9.log" MOCK_LIST_OUT="$GATE_RC" GH="$MOCK_GH" \
+  "$GATE" 0.2.0 > "$TMP/gate5.out" 2>&1
+assert_eq "版本前缀不误拦(0.2.0 vs 0.2.0-rc.1)" 0 "$(cat "$TMP/gate5.out")"
+
 echo "== close-stale-issues.sh (mock gh)=="
 CLOSE="$ROOT/scripts/close-stale-issues.sh"
 CLOSE_LIST='[{"title":"[自动升级] dsh 上游 0.1.9 构建冒烟测试失败","number":9},{"title":"[自动升级] dsh 上游 0.2.0 构建冒烟测试失败","number":7}]'