teamsmith 0.2.0 → 0.3.1
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/README.md +4 -4
- package/package.json +1 -1
- package/skills/teamsmith/CHANGELOG.md +69 -0
- package/skills/teamsmith/SKILL.md +20 -13
- package/skills/teamsmith/extension/team-inbox-watch.ts +5 -3
- package/skills/teamsmith/extension/team-notify.ts +37 -6
- package/skills/teamsmith/extension/team.ts +438 -0
- package/skills/teamsmith/references/config.md +39 -6
- package/skills/teamsmith/references/migration.md +197 -47
- package/skills/teamsmith/references/protocol.md +201 -30
- package/skills/teamsmith/references/troubleshooting.md +130 -10
- package/skills/teamsmith/references/workflows.md +36 -2
- package/skills/teamsmith/scripts/lib/cmd-agents.sh +318 -23
- package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +2 -2
- package/skills/teamsmith/scripts/lib/cmd-config.sh +349 -67
- package/skills/teamsmith/scripts/lib/cmd-draft.sh +4 -4
- package/skills/teamsmith/scripts/lib/cmd-help.sh +677 -0
- package/skills/teamsmith/scripts/lib/cmd-init.sh +157 -5
- package/skills/teamsmith/scripts/lib/cmd-interrupt.sh +461 -0
- package/skills/teamsmith/scripts/lib/cmd-meeting.sh +2 -25
- package/skills/teamsmith/scripts/lib/cmd-project.sh +30 -103
- package/skills/teamsmith/scripts/lib/cmd-reap.sh +277 -0
- package/skills/teamsmith/scripts/lib/cmd-reply.sh +3 -3
- package/skills/teamsmith/scripts/lib/cmd-review.sh +182 -32
- package/skills/teamsmith/scripts/lib/cmd-status.sh +234 -21
- package/skills/teamsmith/scripts/lib/cmd-update.sh +36 -7
- package/skills/teamsmith/scripts/lib/cmd-watch.sh +564 -46
- package/skills/teamsmith/scripts/lib/common.sh +1004 -245
- package/skills/teamsmith/scripts/lib/gate-lock.sh +582 -0
- package/skills/teamsmith/scripts/panel/draft-send.sh +11 -1
- package/skills/teamsmith/scripts/panel/panel.js +211 -211
- package/skills/teamsmith/scripts/panel/src/App.tsx +58 -21
- package/skills/teamsmith/scripts/panel/src/clipboard.ts +12 -5
- package/skills/teamsmith/scripts/panel/src/compose.ts +6 -3
- package/skills/teamsmith/scripts/panel/src/data.ts +51 -5
- package/skills/teamsmith/scripts/panel/src/layout.ts +209 -69
- package/skills/teamsmith/scripts/panel/src/main.tsx +37 -8
- package/skills/teamsmith/scripts/panel/src/strings/en.ts +39 -29
- package/skills/teamsmith/scripts/panel/src/strings/zh.ts +41 -31
- package/skills/teamsmith/scripts/panel/src/types.ts +28 -3
- package/skills/teamsmith/scripts/replies.mjs +4 -1
- package/skills/teamsmith/scripts/shim/killall +10 -0
- package/skills/teamsmith/scripts/shim/pgrep +10 -0
- package/skills/teamsmith/scripts/shim/pidof +10 -0
- package/skills/teamsmith/scripts/shim/pkill +10 -0
- package/skills/teamsmith/scripts/shim/signal-gate +108 -31
- package/skills/teamsmith/scripts/shim/tmux +18 -0
- package/skills/teamsmith/scripts/strings/commands.tsv +86 -0
- package/skills/teamsmith/scripts/strings/help.en.tsv +503 -0
- package/skills/teamsmith/scripts/strings/help.zh.tsv +489 -0
- package/skills/teamsmith/scripts/team +19 -6
- package/skills/teamsmith/templates/AGENTS.section.md.tmpl +8 -1
- package/skills/teamsmith/templates/config.sh.tmpl +20 -1
- package/skills/teamsmith/templates/pm-prompt.md.tmpl +21 -0
- package/skills/teamsmith/tests/README.md +31 -0
- package/skills/teamsmith/tests/bg-ledger-harness.mjs +464 -40
- package/skills/teamsmith/tests/bg-ledger.sh +168 -10
- package/skills/teamsmith/tests/checkout-shape-probe.sh +83 -54
- package/skills/teamsmith/tests/config-cli.sh +184 -32
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +7 -1
- package/skills/teamsmith/tests/fixtures/p287/lint-good.sh.in +3 -0
- package/skills/teamsmith/tests/fixtures/p287/lint-hardcoded.sh.in +3 -0
- package/skills/teamsmith/tests/fixtures/p287/lint-no-ns.sh.in +3 -0
- package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +18 -6
- package/skills/teamsmith/tests/flip-m33.sh +5 -3
- package/skills/teamsmith/tests/flip-p158.sh +2 -1
- package/skills/teamsmith/tests/flip-p308-skip-not-pass.sh +151 -0
- package/skills/teamsmith/tests/flip-p310-lock.sh +210 -0
- package/skills/teamsmith/tests/flip-p310-socket.sh +125 -0
- package/skills/teamsmith/tests/gate-guard.sh +52 -79
- package/skills/teamsmith/tests/help-surface.sh +1664 -0
- package/skills/teamsmith/tests/install-shape.sh +359 -22
- package/skills/teamsmith/tests/key-replies-pty.sh +9 -10
- package/skills/teamsmith/tests/key-replies-ui.sh +2 -8
- package/skills/teamsmith/tests/key-replies.sh +281 -28
- package/skills/teamsmith/tests/ledger-ban.sh +5 -4
- package/skills/teamsmith/tests/ledger-claim.sh +2 -1
- package/skills/teamsmith/tests/lib/bounded-spin.sh +90 -0
- package/skills/teamsmith/tests/lib/model-policy.sh +4 -0
- package/skills/teamsmith/tests/lib/model-routing-flips.py +51 -0
- package/skills/teamsmith/tests/lib/pty-wait.sh +21 -111
- package/skills/teamsmith/tests/lib/reply-fixture.sh +4 -9
- package/skills/teamsmith/tests/lib/section-guard.sh +316 -164
- package/skills/teamsmith/tests/lib/tmp-root.sh +139 -27
- package/skills/teamsmith/tests/lib/tmux-cap.sh +10 -1
- package/skills/teamsmith/tests/lib/tmux-iso.sh +31 -13
- package/skills/teamsmith/tests/loop-inventory.tsv +83 -77
- package/skills/teamsmith/tests/panel-b2.sh +430 -352
- package/skills/teamsmith/tests/panel-b3-stub.sh +112 -4
- package/skills/teamsmith/tests/panel-b3.sh +314 -62
- package/skills/teamsmith/tests/panel-choices.sh +11 -6
- package/skills/teamsmith/tests/panel-cpu.sh +43 -130
- package/skills/teamsmith/tests/panel-p21.sh +251 -265
- package/skills/teamsmith/tests/panel-snapshots.sh +41 -225
- package/skills/teamsmith/tests/panel-strings.mjs +33 -18
- package/skills/teamsmith/tests/perf.sh +187 -396
- package/skills/teamsmith/tests/routes.sh +440 -117
- package/skills/teamsmith/tests/seat-interrupt.sh +1012 -0
- package/skills/teamsmith/tests/seat-visibility.sh +675 -0
- package/skills/teamsmith/tests/section-guard.sh +13 -102
- package/skills/teamsmith/tests/section-needs-audit.sh +24 -7
- package/skills/teamsmith/tests/section-paths.tsv +32 -18
- package/skills/teamsmith/tests/section-select.sh +371 -19
- package/skills/teamsmith/tests/signal-gate.sh +249 -27
- package/skills/teamsmith/tests/signal-lint-legacy.txt +4 -1
- package/skills/teamsmith/tests/slash-team-e2e.sh +323 -0
- package/skills/teamsmith/tests/slash-team.sh +617 -0
- package/skills/teamsmith/tests/slice-coverage.sh +206 -0
- package/skills/teamsmith/tests/smoke.sh +3595 -788
- package/skills/teamsmith/tests/task-model-routing.sh +530 -15
- package/skills/teamsmith/tests/team-bg-stop.sh +18 -10
- package/skills/teamsmith/tests/tmp-hygiene.sh +782 -45
- package/skills/teamsmith/tests/tmux-identity-leak.sh +773 -0
- package/skills/teamsmith/tests/tmux-lint-legacy.txt +12 -18
- package/skills/teamsmith/tests/upgrade-recipe.sh +537 -0
- package/skills/teamsmith/tests/workflow-entry.sh +207 -0
- package/skills/teamsmith-init/SKILL.md +12 -12
- package/skills/teamsmith-init/references/bootstrap.md +3 -3
- package/skills/teamsmith/tests/flip-glue.sh +0 -162
- package/skills/teamsmith/tests/flip-m12-26c.sh +0 -129
- package/skills/teamsmith/tests/flip-m12.sh +0 -185
- package/skills/teamsmith/tests/flip-m16.sh +0 -166
- package/skills/teamsmith/tests/flip-m17.sh +0 -204
- package/skills/teamsmith/tests/flip-m34.sh +0 -96
- package/skills/teamsmith/tests/flip-m37.sh +0 -185
- package/skills/teamsmith/tests/flip-m4.3.sh +0 -375
- package/skills/teamsmith/tests/flip-m43.sh +0 -128
- package/skills/teamsmith/tests/flip-m45.sh +0 -244
- package/skills/teamsmith/tests/flip-m46.sh +0 -238
- package/skills/teamsmith/tests/flip-m48.sh +0 -304
- package/skills/teamsmith/tests/flip-m6.2.sh +0 -205
- package/skills/teamsmith/tests/flip-m6.3.sh +0 -283
- package/skills/teamsmith/tests/flip-m6.4.sh +0 -267
- package/skills/teamsmith/tests/flip-m6.5.sh +0 -113
- package/skills/teamsmith/tests/flip-m7.1.sh +0 -135
- package/skills/teamsmith/tests/flip-m7.2.sh +0 -321
- package/skills/teamsmith/tests/flip-p144.sh +0 -112
- package/skills/teamsmith/tests/flip-p156.sh +0 -133
- package/skills/teamsmith/tests/flip-p160.sh +0 -182
- package/skills/teamsmith/tests/flip-p171.sh +0 -249
- package/skills/teamsmith/tests/flip-p18.1.sh +0 -95
- package/skills/teamsmith/tests/flip-p20.sh +0 -286
- package/skills/teamsmith/tests/flip-p201.sh +0 -249
- package/skills/teamsmith/tests/flip-p210.sh +0 -239
- package/skills/teamsmith/tests/flip-p211.sh +0 -152
- package/skills/teamsmith/tests/flip-p217.sh +0 -288
- package/skills/teamsmith/tests/flip-p22.sh +0 -123
- package/skills/teamsmith/tests/flip-p23.sh +0 -239
- package/skills/teamsmith/tests/flip-p25.sh +0 -165
- package/skills/teamsmith/tests/flip-p71.sh +0 -184
- package/skills/teamsmith/tests/flip-p72.sh +0 -202
- package/skills/teamsmith/tests/load-experiment.sh +0 -290
- package/skills/teamsmith/tests/panel-cpu-premise.sh +0 -173
- package/skills/teamsmith/tests/panel-flip-m54.sh +0 -207
- package/skills/teamsmith/tests/panel-flip-p123.sh +0 -278
- package/skills/teamsmith/tests/panel-flip-p125.sh +0 -318
- package/skills/teamsmith/tests/panel-flip-p128.sh +0 -259
- package/skills/teamsmith/tests/panel-keyprobe-stub.sh +0 -41
- package/skills/teamsmith/tests/panel-keyprobe.sh +0 -82
- package/skills/teamsmith/tests/panel-knobs.sh +0 -83
- package/skills/teamsmith/tests/section-budgets.tsv +0 -154
- package/skills/teamsmith/tests/team-bg-flip.sh +0 -239
- package/skills/teamsmith/tests/team-inbox-watch-flip.sh +0 -191
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# section-guard.sh — 门禁的**每段自述 +
|
|
2
|
+
# section-guard.sh — 门禁的**每段自述 + 挂住上限 + 现场**(change: gate-section-accounting · 实现:P70;
|
|
3
|
+
# P316 按用户裁定改成「时间只记录、不判定」)
|
|
3
4
|
#
|
|
4
5
|
# 被 `tests/smoke.sh` source(也支持 `bash tests/lib/section-guard.sh --self-test` 自检)。
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
# `#<N> <id> · 用时 <S>s · <✓/✗/SKIP 增量> · ticks <T>`(stdout 与 sections.log 逐字节一致;
|
|
6
|
+
# * 每段开跑前打印 `== #<N> <id> == <ISO-8601>`;结束时打印**唯一**的收口行
|
|
7
|
+
# `#<N> <id> · 参考 用时 <S>s · <✓/✗/SKIP 增量> · ticks <T>`(stdout 与 sections.log 逐字节一致;
|
|
8
8
|
# 增量由 P98 账本经 SG_CLOSE_COUNTS 注入,没有账本时是 `-`);
|
|
9
9
|
# 每段一行进 `<run tmp>/sections.tsv`(`no id start elapsed_s ticks`)。
|
|
10
|
-
# *
|
|
11
|
-
#
|
|
12
|
-
#
|
|
10
|
+
# * 每段只有一个**挂住上限**(默认 1800s,防死等):**cap 秒内没有进度**(心跳里的 ticks 没变)→
|
|
11
|
+
# **停跑**,看门狗打印「段落 #N(id)挂住:已 <cap>s 没有进度(…)」,写现场,然后才发信号。
|
|
12
|
+
# 判据是「有没有动」,不是「跑了多久」:慢但一直在推进的段不会被停(V61 F1)。
|
|
13
13
|
# * 看门狗是**双重 fork**(不进作业表:裸 `wait` 不会被它卡住),只对进程树里的子孙发信号,
|
|
14
14
|
# **绝不** `kill -- -$pgid`(门禁的进程组里有 team review / CI / 启动它的席位)。
|
|
15
|
-
# *
|
|
15
|
+
# * 没有性能判定:机器再慢,只要段在动(ticks / 挂住上限之内)就是绿(D33 + 用户裁定)。
|
|
16
16
|
# * 夹具旋钮只在 `TEAM_SMOKE_FIXTURE=1` 下生效,否则**打印忽略行**(环境不能悄悄拆掉边界)。
|
|
17
17
|
#
|
|
18
18
|
# 现场(trip 时):`${TMPDIR:-/tmp}/.teamsmith-smoke-scene.<pid>/`,点开头、在 run 自己的临时根**之外**
|
|
@@ -20,6 +20,19 @@
|
|
|
20
20
|
|
|
21
21
|
SG_SECTION_GUARD_LIB=1
|
|
22
22
|
|
|
23
|
+
# P287:ns(临时根名字里的项目命名空间)的唯一实现在 scripts/lib/common.sh —— 本库被 smoke 前导段
|
|
24
|
+
# source(tmp-root.sh 已经带进来了),独立跑 --self-test 时自己补一次。
|
|
25
|
+
# P309:库位置可以显式给(`TEAM_SG_SKILL_DIR`)—— 自检的**变异副本**被复制到临时根下运行,它自己
|
|
26
|
+
# 数不出 skill 树在哪;不显式给就会找不到解析器,红侧因此「红错原因」。给了之后仍然只有一处解析实现。
|
|
27
|
+
if ! declare -F team_project_ns >/dev/null 2>&1; then
|
|
28
|
+
_sg_ns_lib="${TEAM_SG_SKILL_DIR:-$(cd -P "$(dirname "${BASH_SOURCE[0]}")/../.." 2>/dev/null && pwd)}/scripts/lib/common.sh"
|
|
29
|
+
[ -f "$_sg_ns_lib" ] && . "$_sg_ns_lib"
|
|
30
|
+
unset _sg_ns_lib
|
|
31
|
+
fi
|
|
32
|
+
if ! declare -F team_tmp_root >/dev/null 2>&1; then
|
|
33
|
+
printf 'section-guard: 缺少解析器 team_tmp_root(scripts/lib/common.sh 没被 source 进来,可给 TEAM_SG_SKILL_DIR)\n' >&2
|
|
34
|
+
fi
|
|
35
|
+
|
|
23
36
|
# ---------------------------------------------------------------- 状态(全部有默认值:smoke 是 set -u)
|
|
24
37
|
SG_ENABLED=0
|
|
25
38
|
SG_ARMED=0
|
|
@@ -27,18 +40,16 @@ SG_TRIPPED=0
|
|
|
27
40
|
SG_SEC_NO=0
|
|
28
41
|
SG_SEC_ID=""
|
|
29
42
|
SG_SEC_START=""
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
SG_BUDGET_SOURCE=""
|
|
43
|
+
SG_HANG_CAP=""
|
|
44
|
+
SG_HANG_CAP_SOURCE=""
|
|
33
45
|
SG_ARMED_EPOCH=0
|
|
34
46
|
SG_ARMED_SECONDS=0
|
|
35
47
|
SG_TICKS=0
|
|
36
48
|
SG_ELAPSED=0
|
|
37
49
|
SG_OWNER_PID="$$"
|
|
38
50
|
SG_OWNER_START=""
|
|
39
|
-
SG_BASE="$
|
|
51
|
+
SG_BASE="$(team_tmp_root)"
|
|
40
52
|
SG_RUN_TMP=""
|
|
41
|
-
SG_BUDGETS=""
|
|
42
53
|
SG_TIMING=""
|
|
43
54
|
SG_LOG=""
|
|
44
55
|
SG_HEARTBEAT=""
|
|
@@ -51,16 +62,21 @@ SG_POLL=1
|
|
|
51
62
|
SG_DESC_GRACE=6
|
|
52
63
|
SG_SUITE_GRACE=2
|
|
53
64
|
SG_PROGRESS_INTERVAL=60
|
|
54
|
-
|
|
65
|
+
SG_HANG_CAP_DEFAULT=1800
|
|
55
66
|
SG_FIXTURE="${TEAM_SMOKE_FIXTURE:-0}"
|
|
56
67
|
SG_STUCK_SECTION=""
|
|
57
|
-
|
|
68
|
+
SG_HANG_CAP_OVERRIDE=""
|
|
58
69
|
SG_FAST="${TEAM_SMOKE_FAST:-0}"
|
|
59
70
|
SG_LOCK_NOTE=""
|
|
60
71
|
SG_CLOSE_COUNTS="" # P98 账本:本段收口行里的 ✓/✗/SKIP 增量(关段前注入;空 → 行里打 `-`)
|
|
61
72
|
|
|
62
73
|
_sg_now() { date +%s; }
|
|
63
74
|
|
|
75
|
+
# P281:心跳文件的路径**只在这里拼一次**(门禁锁的记录要公布它,嵌套运行要靠它找祖辈的武装段)
|
|
76
|
+
section_guard_heartbeat_path() { # [<owner pid>] → <TMPDIR>/.teamsmith-smoke-heartbeat.<pid>
|
|
77
|
+
printf '%s\n' "$(team_tmp_root)/.teamsmith-smoke-heartbeat.${1:-$$}"
|
|
78
|
+
}
|
|
79
|
+
|
|
64
80
|
_sg_proc_start() { # /proc/<pid>/stat 的 starttime:pid 复用安全的判据
|
|
65
81
|
local st; st="$(LC_ALL=C cat "/proc/$1/stat" 2>/dev/null)" || return 1
|
|
66
82
|
st="${st##*\) }"; set -- $st
|
|
@@ -80,9 +96,17 @@ _sg_pid_alive() { # <pid> [<starttime>] → 0 活着且(给了 starttime 时
|
|
|
80
96
|
return 0
|
|
81
97
|
}
|
|
82
98
|
|
|
99
|
+
# P281:僵尸(Z)已经跑完了(只等被 wait 收尸)—— 收尾等待时不能把它当「还活着」(否则白等满宽限)
|
|
100
|
+
_sg_pid_running() { # <pid> → 0 = 存在且不是僵尸
|
|
101
|
+
local pid="${1:-}" st
|
|
102
|
+
case "$pid" in ''|*[!0-9]*) return 1 ;; esac
|
|
103
|
+
st="$(awk '{print $3}' "/proc/$pid/stat" 2>/dev/null || true)"
|
|
104
|
+
[ -n "$st" ] && [ "$st" != "Z" ]
|
|
105
|
+
}
|
|
106
|
+
|
|
83
107
|
# ---------------------------------------------------------------- 初始化
|
|
84
108
|
# section_guard_init <run tmp> [--poll <s>] [--progress <s>] [--suite-grace <s>]
|
|
85
|
-
# [--desc-grace <n>] [--
|
|
109
|
+
# [--desc-grace <n>] [--hang-cap <s>]
|
|
86
110
|
section_guard_init() {
|
|
87
111
|
SG_RUN_TMP="${1:-}"; shift || true
|
|
88
112
|
while [ $# -gt 0 ]; do
|
|
@@ -91,16 +115,15 @@ section_guard_init() {
|
|
|
91
115
|
--progress) SG_PROGRESS_INTERVAL="${2:-60}"; shift 2 ;;
|
|
92
116
|
--suite-grace) SG_SUITE_GRACE="${2:-2}"; shift 2 ;;
|
|
93
117
|
--desc-grace) SG_DESC_GRACE="${2:-6}"; shift 2 ;;
|
|
94
|
-
--
|
|
95
|
-
--budgets) SG_BUDGETS="${2:-}"; shift 2 ;;
|
|
118
|
+
--hang-cap) SG_HANG_CAP_DEFAULT="${2:-1800}"; shift 2 ;;
|
|
96
119
|
*) printf 'section-guard: 不认识的参数 %s\n' "$1" >&2; return 2 ;;
|
|
97
120
|
esac
|
|
98
121
|
done
|
|
99
|
-
SG_BASE="$
|
|
122
|
+
SG_BASE="$(team_tmp_root)"
|
|
100
123
|
SG_FIXTURE="${TEAM_SMOKE_FIXTURE:-0}"
|
|
101
124
|
SG_OWNER_PID="${BASHPID:-$$}"
|
|
102
125
|
SG_OWNER_START="$(_sg_proc_start "$SG_OWNER_PID" 2>/dev/null || true)"
|
|
103
|
-
SG_HEARTBEAT="$
|
|
126
|
+
SG_HEARTBEAT="$(section_guard_heartbeat_path "$SG_OWNER_PID")"
|
|
104
127
|
SG_MARKER="$SG_BASE/.teamsmith-smoke-trip.$SG_OWNER_PID"
|
|
105
128
|
SG_SCENE="$SG_BASE/.teamsmith-smoke-scene.$SG_OWNER_PID"
|
|
106
129
|
SG_STOP="$SG_BASE/.teamsmith-smoke-guard-stop.$SG_OWNER_PID"
|
|
@@ -108,7 +131,6 @@ section_guard_init() {
|
|
|
108
131
|
SG_WATCHDOG_PIDFILE="$SG_BASE/.teamsmith-smoke-guard.pid.$SG_OWNER_PID"
|
|
109
132
|
SG_TIMING="$SG_RUN_TMP/sections.tsv"
|
|
110
133
|
SG_LOG="$SG_RUN_TMP/sections.log"
|
|
111
|
-
[ -n "$SG_BUDGETS" ] || SG_BUDGETS="${SG_SKILL_DIR:-}/tests/section-budgets.tsv"
|
|
112
134
|
_sg_parse_knobs
|
|
113
135
|
if [ ! -s "$SG_TIMING" ]; then
|
|
114
136
|
printf 'no\tid\tstart\telapsed_s\tticks\n' > "$SG_TIMING" 2>/dev/null || true
|
|
@@ -124,23 +146,23 @@ _sg_knob_note() { # <name> <value>:非夹具路径下的忽略行(旋钮不
|
|
|
124
146
|
_sg_parse_knobs() {
|
|
125
147
|
local k v
|
|
126
148
|
SG_STUCK_SECTION=""
|
|
127
|
-
|
|
149
|
+
SG_HANG_CAP_OVERRIDE=""
|
|
128
150
|
SG_POLL="${SG_POLL:-1}"
|
|
129
151
|
SG_PROGRESS_INTERVAL="${SG_PROGRESS_INTERVAL:-60}"
|
|
130
152
|
if [ "${SG_FIXTURE:-0}" = "1" ]; then
|
|
131
153
|
SG_STUCK_SECTION="${TEAM_SMOKE_STUCK_SECTION:-}"
|
|
132
|
-
|
|
154
|
+
SG_HANG_CAP_OVERRIDE="${TEAM_SMOKE_SECTION_HANG_CAP:-}"
|
|
133
155
|
[ -n "${TEAM_SMOKE_PROGRESS_INTERVAL:-}" ] && SG_PROGRESS_INTERVAL="$TEAM_SMOKE_PROGRESS_INTERVAL"
|
|
134
156
|
[ -n "${TEAM_SMOKE_GUARD_POLL:-}" ] && SG_POLL="$TEAM_SMOKE_GUARD_POLL"
|
|
135
157
|
return 0
|
|
136
158
|
fi
|
|
137
|
-
for k in TEAM_SMOKE_STUCK_SECTION
|
|
159
|
+
for k in TEAM_SMOKE_STUCK_SECTION TEAM_SMOKE_SECTION_HANG_CAP TEAM_SMOKE_PROGRESS_INTERVAL TEAM_SMOKE_GUARD_POLL SMOKE_PROGRESS_INTERVAL; do
|
|
138
160
|
case "$k" in
|
|
139
|
-
TEAM_SMOKE_STUCK_SECTION)
|
|
140
|
-
|
|
141
|
-
TEAM_SMOKE_PROGRESS_INTERVAL)
|
|
142
|
-
TEAM_SMOKE_GUARD_POLL)
|
|
143
|
-
SMOKE_PROGRESS_INTERVAL)
|
|
161
|
+
TEAM_SMOKE_STUCK_SECTION) v="${TEAM_SMOKE_STUCK_SECTION:-}" ;;
|
|
162
|
+
TEAM_SMOKE_SECTION_HANG_CAP) v="${TEAM_SMOKE_SECTION_HANG_CAP:-}" ;;
|
|
163
|
+
TEAM_SMOKE_PROGRESS_INTERVAL) v="${TEAM_SMOKE_PROGRESS_INTERVAL:-}" ;;
|
|
164
|
+
TEAM_SMOKE_GUARD_POLL) v="${TEAM_SMOKE_GUARD_POLL:-}" ;;
|
|
165
|
+
SMOKE_PROGRESS_INTERVAL) v="${SMOKE_PROGRESS_INTERVAL:-}" ;;
|
|
144
166
|
esac
|
|
145
167
|
[ -n "$v" ] && _sg_knob_note "$k" "$v"
|
|
146
168
|
done
|
|
@@ -150,35 +172,17 @@ _sg_parse_knobs() {
|
|
|
150
172
|
}
|
|
151
173
|
|
|
152
174
|
# ---------------------------------------------------------------- 预算表
|
|
153
|
-
#
|
|
154
|
-
|
|
155
|
-
local id="$1"
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
' "$SG_BUDGETS" 2>/dev/null || true)"
|
|
162
|
-
fi
|
|
163
|
-
# 行必须在、band 可以是 "-"(没测过),budget 必须是正整数
|
|
164
|
-
case "$row" in
|
|
165
|
-
*$'\t'*) SG_BAND="${row%% *}"; SG_BUDGET="${row##* }" ;;
|
|
166
|
-
*) SG_BAND=""; SG_BUDGET="" ;;
|
|
167
|
-
esac
|
|
168
|
-
case "${SG_BUDGET:-x}" in ''|*[!0-9]*) row="" ;; esac
|
|
169
|
-
if [ -n "$row" ]; then
|
|
170
|
-
SG_BUDGET_SOURCE="table"
|
|
171
|
-
else
|
|
172
|
-
SG_BAND=""
|
|
173
|
-
SG_BUDGET="$SG_DEFAULT_BUDGET"
|
|
174
|
-
SG_BUDGET_SOURCE="default"
|
|
175
|
-
fi
|
|
176
|
-
# 夹具的预算覆盖:只作用于被点名的 stuck 段;没点名就作用于每段(自检/夹具用)
|
|
177
|
-
if [ "${SG_FIXTURE:-0}" = "1" ] && [ -n "$SG_BUDGET_OVERRIDE" ]; then
|
|
178
|
-
case "${SG_BUDGET_OVERRIDE:-x}" in *[!0-9]*) ;; *)
|
|
175
|
+
# section_guard_hang_cap_for <id> → 设置 SG_HANG_CAP / SG_HANG_CAP_SOURCE(常量,防死等;不是性能预算)
|
|
176
|
+
section_guard_hang_cap_for() {
|
|
177
|
+
local id="$1"
|
|
178
|
+
SG_HANG_CAP="$SG_HANG_CAP_DEFAULT"
|
|
179
|
+
SG_HANG_CAP_SOURCE="default"
|
|
180
|
+
# 夹具覆盖:只作用于被点名的 stuck 段;没点名就作用于每段(自检/夹具用)
|
|
181
|
+
if [ "${SG_FIXTURE:-0}" = "1" ] && [ -n "$SG_HANG_CAP_OVERRIDE" ]; then
|
|
182
|
+
case "${SG_HANG_CAP_OVERRIDE:-x}" in *[!0-9]*) ;; *)
|
|
179
183
|
if [ -z "$SG_STUCK_SECTION" ] || _sg_id_matches "$SG_STUCK_SECTION" "$id"; then
|
|
180
|
-
|
|
181
|
-
|
|
184
|
+
SG_HANG_CAP="$SG_HANG_CAP_OVERRIDE"
|
|
185
|
+
SG_HANG_CAP_SOURCE="fixture"
|
|
182
186
|
fi
|
|
183
187
|
;;
|
|
184
188
|
esac
|
|
@@ -203,7 +207,7 @@ section_guard_write_heartbeat() {
|
|
|
203
207
|
fi
|
|
204
208
|
SG_ELAPSED=$(( SECONDS - SG_ARMED_SECONDS ))
|
|
205
209
|
printf '%s|%s|%s|%s|%s|%s\n' \
|
|
206
|
-
"$SG_SEC_NO" "$SG_ARMED_EPOCH" "$
|
|
210
|
+
"$SG_SEC_NO" "$SG_ARMED_EPOCH" "$SG_HANG_CAP" "$SG_ELAPSED" "$SG_TICKS" "$SG_SEC_ID" \
|
|
207
211
|
> "$SG_HEARTBEAT" 2>/dev/null || true
|
|
208
212
|
return 0
|
|
209
213
|
}
|
|
@@ -255,25 +259,7 @@ section_guard_on_term() { # 看门狗对我们的 TERM:trip → exit 2;否
|
|
|
255
259
|
|
|
256
260
|
# ---------------------------------------------------------------- 段落开闭
|
|
257
261
|
_sg_start_line() {
|
|
258
|
-
|
|
259
|
-
case "$SG_BUDGET_SOURCE" in
|
|
260
|
-
default) src="(默认:预算表没有这段)" ;;
|
|
261
|
-
fixture) src="(夹具覆盖)" ;;
|
|
262
|
-
esac
|
|
263
|
-
printf '== #%s %s == %s · 预算 %ss%s' "$SG_SEC_NO" "$SG_SEC_ID" "$SG_SEC_START" "$SG_BUDGET" "$src"
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
# _sg_band_over <elapsed> <band> → 0 当且仅当 band 是数字且 elapsed 超过它(**记录**,不是判定)。
|
|
267
|
-
# band 是小数也必须比 —— 表的 110/112 行是 `0.02 … 44.00`(P108 F2:旧的 `case ''|*[!0-9]*`
|
|
268
|
-
# 整数守卫把带小数点的带全落进空分支,规范承诺的「超过实测带打一行警告」对它们永不可达)。
|
|
269
|
-
# 空 / `-` = 表里没有实测带 → 不比较;非数字(表坏了)由 `section-guard.sh --budget-check` 点名。
|
|
270
|
-
_sg_band_over() {
|
|
271
|
-
local elapsed="$1" band="${2:-}"
|
|
272
|
-
case "$band" in
|
|
273
|
-
''|-) return 1 ;; # 没有实测带(表里写「-」)→ 不比较
|
|
274
|
-
*[!0-9.]*) return 1 ;; # 非数字(表坏了,由 --budget-check 点名)→ 不比较
|
|
275
|
-
esac
|
|
276
|
-
awk -v a="$elapsed" -v b="$band" 'BEGIN { exit !(a + 0 > b + 0) }'
|
|
262
|
+
printf '== #%s %s == %s' "$SG_SEC_NO" "$SG_SEC_ID" "$SG_SEC_START"
|
|
277
263
|
}
|
|
278
264
|
|
|
279
265
|
_sg_close_current() {
|
|
@@ -284,16 +270,15 @@ _sg_close_current() {
|
|
|
284
270
|
SG_ELAPSED="$elapsed" # P98 账本读回:收口行与 sections.tsv 用同一个数,不再各量一次
|
|
285
271
|
counts="${SG_CLOSE_COUNTS:--}"; SG_CLOSE_COUNTS=""
|
|
286
272
|
# 唯一收口行(gate-section-accounting × gate-runtime-budget 的合并形态):P70 的用时/ticks 与
|
|
287
|
-
# P98
|
|
288
|
-
|
|
273
|
+
# P98 账本的增量同形同一行。用时是**参考读数**(P316:时间不参与绿/红)。stdout 与 sections.log
|
|
274
|
+
# 逐字节一致;行不带门禁红标、不缩进。
|
|
275
|
+
printf '\033[2m#%s\033[0m %s · 参考 用时 %ss · %s · ticks %s\n' \
|
|
289
276
|
"$SG_SEC_NO" "$SG_SEC_ID" "$elapsed" "$counts" "$SG_TICKS"
|
|
290
|
-
printf '#%s %s · 用时 %ss · %s · ticks %s\n' \
|
|
277
|
+
printf '#%s %s · 参考 用时 %ss · %s · ticks %s\n' \
|
|
291
278
|
"$SG_SEC_NO" "$SG_SEC_ID" "$elapsed" "$counts" "$SG_TICKS" >> "$SG_LOG" 2>/dev/null || true
|
|
292
279
|
printf '%s\t%s\t%s\t%s\t%s\n' "$SG_SEC_NO" "$SG_SEC_ID" "$SG_SEC_START" "$elapsed" "$SG_TICKS" >> "$SG_TIMING" 2>/dev/null || true
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
"$SG_SEC_NO" "$elapsed" "$SG_BAND"
|
|
296
|
-
fi
|
|
280
|
+
# P281:本段收口后,本夹具登记过的嵌套运行还不许活着(只对自己登记过的 pid 发信号,D37)
|
|
281
|
+
section_guard_check_orphans "${SG_LOCK_NOTE:-}"
|
|
297
282
|
SG_ARMED=0
|
|
298
283
|
SG_SEC_ID=""
|
|
299
284
|
printf 'disarm\n' > "$SG_HEARTBEAT" 2>/dev/null || true
|
|
@@ -317,18 +302,30 @@ section_guard_begin() { # <id>:收上一段 → 开这一段(含夹具注入
|
|
|
317
302
|
SG_ARMED_EPOCH="$(_sg_now)"
|
|
318
303
|
SG_ARMED_SECONDS="$SECONDS"
|
|
319
304
|
SG_TICKS=0
|
|
320
|
-
|
|
305
|
+
section_guard_hang_cap_for "$id"
|
|
321
306
|
SG_ARMED=1
|
|
322
307
|
section_guard_write_heartbeat
|
|
323
308
|
line="$(_sg_start_line)"
|
|
324
309
|
printf '\n\033[1m%s\033[0m\n' "$line"
|
|
325
310
|
printf '%s\n' "$line" >> "$SG_LOG" 2>/dev/null || true
|
|
326
|
-
#
|
|
311
|
+
# 夹具注入:被点名的段落永不返回(挂住上限到点必须点名 + 停跑 + 留现场)
|
|
327
312
|
if [ "${SG_FIXTURE:-0}" = "1" ] && [ -n "$SG_STUCK_SECTION" ] && _sg_id_matches "$SG_STUCK_SECTION" "$id"; then
|
|
328
|
-
printf ' \033[35m[fixture]\033[0m 注入永不返回的段落(%s
|
|
313
|
+
printf ' \033[35m[fixture]\033[0m 注入永不返回的段落(%s,挂住上限 %ss)\n' "$id" "$SG_HANG_CAP"
|
|
329
314
|
local stuck_log="$SG_RUN_TMP/fixture-stuck-$SG_SEC_NO.log"
|
|
330
|
-
printf 'fixture 注入:段落 #%s(%s
|
|
331
|
-
|
|
315
|
+
printf 'fixture 注入:段落 #%s(%s)永不返回(挂住上限 %ss)\n' "$SG_SEC_NO" "$id" "$SG_HANG_CAP" > "$stuck_log" 2>/dev/null || true
|
|
316
|
+
# P313:这个「永不返回」是**夹具造的现场**,不是永不退出的进程。旧形状
|
|
317
|
+
# `bash -c 'trap "" TERM; while :; do date +%s >> $log; sleep 0.2; done'`
|
|
318
|
+
# 在被打断的运行里会永久泄漏(现场:78 个孤儿合计持有 11.98 GB 已删除文件)。现在由
|
|
319
|
+
# lib/bounded-spin.sh 一处实现三条边界:父进程没了就退、到点(挂住上限 + 120s 宽限)就退
|
|
320
|
+
# 并留一行、写目标被删就退。cap 永远大于挂住上限 → 合法运行不会被它截断。
|
|
321
|
+
# 它**响应** TERM(P313 的硬要求:看门/轮询进程不再 `trap "" TERM`)。因此段落 0f 的现场
|
|
322
|
+
# 不会记 `escalation:` —— 段 0f 反过来断言「没有升级」,那条断言就是「有人把忽略 TERM 放回来」
|
|
323
|
+
# 的守卫;「真要升级时现场照写」由自检的 F1 夹具(P110)负责。
|
|
324
|
+
local _sg_spin_lib; _sg_spin_lib="$(_sg_spin_lib_path)"
|
|
325
|
+
local _sg_spin_cap=$(( SG_HANG_CAP + 120 ))
|
|
326
|
+
[ -f "$_sg_spin_lib" ] || printf ' \033[31m✗\033[0m 夹具:缺 %s(心跳循环起不来)\n' "$_sg_spin_lib"
|
|
327
|
+
bash -c 'lib="$1"; shift; . "$lib"; bounded_spin "$@"' _ "$_sg_spin_lib" \
|
|
328
|
+
0.2 "$_sg_spin_cap" "$(( _sg_spin_cap * 64 + 65536 ))" "$stuck_log" "$BASHPID" &
|
|
332
329
|
local child=$!
|
|
333
330
|
command -v tmp_root_track_pid >/dev/null 2>&1 && tmp_root_track_pid "$child" "section-guard-stuck" || true
|
|
334
331
|
wait "$child" 2>/dev/null || true
|
|
@@ -363,7 +360,7 @@ section_guard_arm() {
|
|
|
363
360
|
sleep 0.02
|
|
364
361
|
done
|
|
365
362
|
if [ ! -s "$SG_WATCHDOG_PIDFILE" ]; then
|
|
366
|
-
printf ' \033[31m✗\033[0m section-guard:看门狗没起来(%s)——
|
|
363
|
+
printf ' \033[31m✗\033[0m section-guard:看门狗没起来(%s)—— 本套**没有**挂住上限\n' "$SG_WATCHDOG_PIDFILE"
|
|
367
364
|
fi
|
|
368
365
|
return 0
|
|
369
366
|
}
|
|
@@ -411,26 +408,42 @@ _sg_descendants() { # <pid> <exclude> → 叶子优先
|
|
|
411
408
|
section_guard_watchdog() {
|
|
412
409
|
local me="$BASHPID"
|
|
413
410
|
printf '%s\t%s\n' "$me" "$(_sg_proc_start "$me" 2>/dev/null || true)" > "$SG_WATCHDOG_PIDFILE" 2>/dev/null || true
|
|
414
|
-
local line no armed
|
|
411
|
+
local line no armed cap elapsed ticks id now last_progress=0
|
|
412
|
+
# P316 · V61 F1:停跑的判据是**没有进度**,不是「武装后过了多久」。进度证据就是心跳里已有的 ticks
|
|
413
|
+
# (ok()/bad()/等待轮每轮都会 +1 并重写心跳):ticks 变了就刷新 last_moved。仍在推进的段不会因为
|
|
414
|
+
# 慢而被判成挂住;真卡死的形状(自检的四个 stub、0f 注入段)根本不 tick,照样在 cap 到点时停跑。
|
|
415
|
+
# 不新增进度协议、不新增看门狗:还是这一个循环、这一份心跳。
|
|
416
|
+
local last_ticks="" last_moved=0
|
|
417
|
+
# 这两个状态**按段归属**(P316 · V63 F2):心跳里带段号与武装代次,换段/换代次时必须重置,
|
|
418
|
+
# 否则上一段的 ticks 与 last_moved 会被带进下一段(新段可能一开跑就带着旧基线,或长期不算它自己的进度)。
|
|
419
|
+
# 只重置这两个既有变量:不新增守卫、不新增进度协议、不改心跳格式。
|
|
420
|
+
local seen_sec="" seen_arm=""
|
|
415
421
|
while :; do
|
|
416
422
|
[ -e "$SG_STOP" ] && break
|
|
417
423
|
_sg_pid_alive "$SG_OWNER_PID" "$SG_OWNER_START" || break
|
|
418
424
|
line="$(cat "$SG_HEARTBEAT" 2>/dev/null || true)"
|
|
419
425
|
case "$line" in ''|disarm*) sleep "$SG_POLL"; continue ;; esac
|
|
420
|
-
IFS='|' read -r no armed
|
|
421
|
-
case "${no:-x}${armed:-x}${
|
|
426
|
+
IFS='|' read -r no armed cap elapsed ticks id <<<"$line"
|
|
427
|
+
case "${no:-x}${armed:-x}${cap:-x}" in *[!0-9]*) sleep "$SG_POLL"; continue ;; esac
|
|
422
428
|
now="$(_sg_now)"
|
|
423
429
|
case "${elapsed:-0}" in ''|*[!0-9]*) elapsed=0 ;; esac
|
|
424
|
-
|
|
430
|
+
case "${ticks:-0}" in ''|*[!0-9]*) ticks=0 ;; esac
|
|
431
|
+
# 换段或换武装代次 → 基线跟着换段(同一个变量,重新起算)。
|
|
432
|
+
if [ "$no|$armed" != "$seen_sec|$seen_arm" ]; then
|
|
433
|
+
seen_sec="$no"; seen_arm="$armed"
|
|
434
|
+
last_ticks="$ticks"; last_moved="$now"
|
|
435
|
+
elif [ "$ticks" != "$last_ticks" ]; then
|
|
436
|
+
last_ticks="$ticks"; last_moved="$now"
|
|
437
|
+
fi
|
|
425
438
|
case "${SG_PROGRESS_INTERVAL:-60}" in ''|*[!0-9]*) SG_PROGRESS_INTERVAL=60 ;; esac
|
|
426
439
|
if [ "$SG_PROGRESS_INTERVAL" -gt 0 ] \
|
|
427
440
|
&& [ "$(( now - armed ))" -ge "$SG_PROGRESS_INTERVAL" ] \
|
|
428
441
|
&& [ "$(( now - last_progress ))" -ge "$SG_PROGRESS_INTERVAL" ]; then
|
|
429
|
-
_sg_progress_line "$no" "$id" "$(( now - armed ))" "$
|
|
442
|
+
_sg_progress_line "$no" "$id" "$(( now - armed ))" "$cap"
|
|
430
443
|
last_progress=$now
|
|
431
444
|
fi
|
|
432
|
-
if [ "$(( now -
|
|
433
|
-
_sg_trip "$no" "$id" "$armed" "$
|
|
445
|
+
if [ "$(( now - last_moved ))" -ge "$cap" ]; then
|
|
446
|
+
_sg_trip "$no" "$id" "$armed" "$cap" "$ticks" "$(( now - last_moved ))" "$now"
|
|
434
447
|
break
|
|
435
448
|
fi
|
|
436
449
|
sleep "$SG_POLL"
|
|
@@ -441,23 +454,23 @@ section_guard_watchdog() {
|
|
|
441
454
|
}
|
|
442
455
|
|
|
443
456
|
_sg_progress_line() {
|
|
444
|
-
local no="$1" id="$2" elapsed="$3"
|
|
457
|
+
local no="$1" id="$2" elapsed="$3" cap="$4" slow=""
|
|
445
458
|
slow="$(awk -F'\t' 'NR > 1 && $4 ~ /^[0-9]+$/ { printf "%s\t#%s %s\n", $4, $1, $2 }' "$SG_TIMING" 2>/dev/null \
|
|
446
459
|
| sort -rn 2>/dev/null | head -3 | cut -f2 | tr '\n' ' ' || true)"
|
|
447
|
-
printf ' \033[2m… 段落 #%s(%s)已运行 %ss
|
|
448
|
-
"$no" "$id" "$elapsed" "$
|
|
449
|
-
printf '… 段落 #%s(%s)已运行 %ss
|
|
450
|
-
"$no" "$id" "$elapsed" "$
|
|
460
|
+
printf ' \033[2m… 段落 #%s(%s)已运行 %ss(挂住上限 %ss)%s\033[0m\n' \
|
|
461
|
+
"$no" "$id" "$elapsed" "$cap" "${slow:+;最慢:$slow}"
|
|
462
|
+
printf '… 段落 #%s(%s)已运行 %ss(挂住上限 %ss)%s\n' \
|
|
463
|
+
"$no" "$id" "$elapsed" "$cap" "${slow:+;最慢:$slow}" >> "$SG_LOG" 2>/dev/null || true
|
|
451
464
|
return 0
|
|
452
465
|
}
|
|
453
466
|
|
|
454
|
-
_sg_trip() { # <no> <id> <armed> <
|
|
455
|
-
local no="$1" id="$2" armed="$3"
|
|
467
|
+
_sg_trip() { # <no> <id> <armed> <cap> <ticks> <stalled_for> <now>
|
|
468
|
+
local no="$1" id="$2" armed="$3" cap="$4" ticks="$5" stalled="$6" now="$7"
|
|
456
469
|
local elapsed="$(( now - armed ))" i=0
|
|
457
|
-
printf '\n \033[31m✗\033[0m 段落 #%s(%s
|
|
458
|
-
"$no" "$id" "$
|
|
470
|
+
printf '\n \033[31m✗\033[0m 段落 #%s(%s)挂住:已 %ss 没有进度(挂住上限 %ss;段落已运行 %ss,ticks %s)→ 停跑(exit 2),现场 %s\n' \
|
|
471
|
+
"$no" "$id" "$stalled" "$cap" "$elapsed" "$ticks" "$SG_SCENE"
|
|
459
472
|
: > "$SG_MARKER" 2>/dev/null || true
|
|
460
|
-
_sg_scene_write "$no" "$id" "$
|
|
473
|
+
_sg_scene_write "$no" "$id" "$cap" "$elapsed" "$stalled" "$ticks" "$armed"
|
|
461
474
|
_sg_stop_children "$no"
|
|
462
475
|
# 给套件一个**有界**的机会自己走到安全点退出(exit 2);它不走才 TERM/KILL
|
|
463
476
|
while [ "$i" -lt $(( SG_SUITE_GRACE * 5 )) ]; do
|
|
@@ -497,6 +510,36 @@ _sg_stop_children() { # <no>:只停这个套件进程树里的子孙(不含
|
|
|
497
510
|
return 0
|
|
498
511
|
}
|
|
499
512
|
|
|
513
|
+
# P281(change: gate-lock-hygiene):本夹具登记过的嵌套运行在**生它的那一段收口后**还不许活着。
|
|
514
|
+
# 只对记录里 `ancestor=<本 run 的 pid>` 且 pid 仍活着的条目动手;只对**那个 pid** 发信号(D37:
|
|
515
|
+
# 不按名字、不按进程组)。没有锁路径 / 没有 gate-lock.sh / 没有记录 → 静默不动。
|
|
516
|
+
section_guard_check_orphans() { # <lock>
|
|
517
|
+
local lock="${1:-}" f pid st pids="" n=0 p i alive
|
|
518
|
+
[ -n "$lock" ] || return 0
|
|
519
|
+
command -v gate_lock_record_get >/dev/null 2>&1 || return 0
|
|
520
|
+
for f in "$lock.runs"/*.run; do
|
|
521
|
+
[ -f "$f" ] || continue
|
|
522
|
+
[ "$(gate_lock_record_get "$f" ancestor)" = "$SG_OWNER_PID" ] || continue
|
|
523
|
+
pid="$(gate_lock_record_get "$f" pid)"; st="$(gate_lock_record_get "$f" start)"
|
|
524
|
+
case "$st" in ''|'-') st="" ;; esac
|
|
525
|
+
_sg_pid_alive "$pid" "$st" || continue
|
|
526
|
+
_sg_pid_running "$pid" || continue
|
|
527
|
+
printf ' \033[31m✗\033[0m 嵌套运行在生它的那一段收口后仍活着:pid=%s %s → 只对这个登记过的 pid 发信号收尾\n' \
|
|
528
|
+
"$pid" "$(gate_lock_describe_one "$f")"
|
|
529
|
+
pids="$pids $pid"; n=$((n + 1))
|
|
530
|
+
done
|
|
531
|
+
[ "$n" -eq 0 ] && return 0
|
|
532
|
+
for p in $pids; do kill -TERM "$p" 2>/dev/null || true; done
|
|
533
|
+
for i in $(seq 1 25); do
|
|
534
|
+
alive=0
|
|
535
|
+
for p in $pids; do _sg_pid_running "$p" && alive=1; done
|
|
536
|
+
[ "$alive" -eq 0 ] && break
|
|
537
|
+
sleep 0.2
|
|
538
|
+
done
|
|
539
|
+
for p in $pids; do kill -KILL "$p" 2>/dev/null || true; done
|
|
540
|
+
return 0
|
|
541
|
+
}
|
|
542
|
+
|
|
500
543
|
_sg_recent_files() { # <root> <min_epoch> <max>:窗口内动过的文件,**按 mtime 从新到旧**(有界)
|
|
501
544
|
# 不按 find 的目录顺序:正在被写的那份(挂住段落的夹具日志)必须排在最前,否则 12 个名额会被
|
|
502
545
|
# 窗口里更早、目录顺序靠前的文件占满 —— 2026-09-28 容器实测:0f 现场收进 .git/hooks/*.sample,
|
|
@@ -505,17 +548,17 @@ _sg_recent_files() { # <root> <min_epoch> <max>:窗口内动过的文件,**
|
|
|
505
548
|
| sort -rn | head -n "$3" | cut -f2-
|
|
506
549
|
}
|
|
507
550
|
|
|
508
|
-
_sg_scene_write() { # <no> <id> <
|
|
509
|
-
local no="$1" id="$2"
|
|
551
|
+
_sg_scene_write() { # <no> <id> <cap> <elapsed> <stalled_for> <ticks> <armed>
|
|
552
|
+
local no="$1" id="$2" cap="$3" elapsed="$4" stalled="$5" ticks="$6" armed="$7"
|
|
510
553
|
mkdir -p "$SG_SCENE/logs" 2>/dev/null || return 0
|
|
511
554
|
{
|
|
512
|
-
printf 'section: #%s\nid: %s\
|
|
513
|
-
"$no" "$id" "$
|
|
555
|
+
printf 'section: #%s\nid: %s\ncap: %ss\nelapsed: %ss\nstalled for: %ss\nticks: %s\n' \
|
|
556
|
+
"$no" "$id" "$cap" "$elapsed" "$stalled" "$ticks"
|
|
514
557
|
printf 'watchdog pid: %s\n' "${BASHPID:-?}"
|
|
515
558
|
printf 'suite pid: %s\n' "$SG_OWNER_PID"
|
|
516
559
|
printf 'mode: FAST=%s fixture=%s\n' "${SG_FAST:-0}" "${SG_FIXTURE:-0}"
|
|
517
|
-
printf 'knobs: stuck=%s
|
|
518
|
-
"${SG_STUCK_SECTION:-}" "${
|
|
560
|
+
printf 'knobs: stuck=%s hang_cap_override=%s progress=%s poll=%s\n' \
|
|
561
|
+
"${SG_STUCK_SECTION:-}" "${SG_HANG_CAP_OVERRIDE:-}" "$SG_PROGRESS_INTERVAL" "$SG_POLL"
|
|
519
562
|
printf 'lock: %s\n' "$([ -n "$SG_LOCK_NOTE" ] && printf '%s holder=%s' "$SG_LOCK_NOTE" "$(cat "$SG_LOCK_NOTE.holder" 2>/dev/null || true)" || printf '(无)')"
|
|
520
563
|
printf 'machine: nproc=%s loadavg=%s run_tmp=%s\n' \
|
|
521
564
|
"$(nproc 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || printf '?')" \
|
|
@@ -589,7 +632,7 @@ _sg_selftest_case() { # <name> <shape> <want:0|2|!0> <want_scene:0|1>
|
|
|
589
632
|
local rc=0
|
|
590
633
|
(
|
|
591
634
|
export TMPDIR="$dir"
|
|
592
|
-
section_guard_init "$dir/run-tmp" --poll 0.2 --progress 300 --suite-grace 1 --desc-grace 2 --
|
|
635
|
+
section_guard_init "$dir/run-tmp" --poll 0.2 --progress 300 --suite-grace 1 --desc-grace 2 --hang-cap 2
|
|
593
636
|
section_guard_arm
|
|
594
637
|
section_guard_begin "selftest-$name"
|
|
595
638
|
wait
|
|
@@ -599,8 +642,14 @@ _sg_selftest_case() { # <name> <shape> <want:0|2|!0> <want_scene:0|1>
|
|
|
599
642
|
stubborn) bash -c 'trap "" TERM; while :; do sleep 0.2; done' ;;
|
|
600
643
|
spin) while :; do :; done ;;
|
|
601
644
|
deadspin) trap '' TERM; while :; do :; done ;;
|
|
602
|
-
clean)
|
|
603
|
-
|
|
645
|
+
clean) : ;;
|
|
646
|
+
# P316 · V61 F1:慢但**一直在动**的段。每 0.1s 走一次真实进度路径(section_guard_check,
|
|
647
|
+
# 也就是 ok()/等待轮每轮做的那件事),总时长远超 cap(2s)。旧实现按「武装后经过多久」判,
|
|
648
|
+
# 这一形状会被误判成挂住并停跑;按「cap 内没有进度」判,它必须照常跑完。
|
|
649
|
+
progressing)
|
|
650
|
+
local _n=0
|
|
651
|
+
while [ "$_n" -lt 40 ]; do section_guard_check; sleep 0.1; _n=$((_n + 1)); done
|
|
652
|
+
;;
|
|
604
653
|
esac
|
|
605
654
|
section_guard_check
|
|
606
655
|
section_guard_finish
|
|
@@ -619,7 +668,7 @@ _sg_selftest_case() { # <name> <shape> <want:0|2|!0> <want_scene:0|1>
|
|
|
619
668
|
if [ -n "$scene" ] && [ -s "$scene/summary.txt" ]; then
|
|
620
669
|
st_ok "$name:现场存在且有摘要(${scene#$ST_ROOT/})"
|
|
621
670
|
grep -qF "selftest-$name" "$scene/summary.txt" && st_ok "$name:现场点名该段" || st_bad "$name:现场没点名该段"
|
|
622
|
-
grep -qF '
|
|
671
|
+
grep -qF '挂住' "$dir/out.log" && st_ok "$name:stdout 有一行点名挂住" || st_bad "$name:stdout 没有点名挂住"
|
|
623
672
|
grep -qF 'SECTION_DONE' "$dir/out.log" && st_bad "$name:套件居然跑完了整段" || st_ok "$name:套件没有跑完整段"
|
|
624
673
|
else
|
|
625
674
|
st_bad "$name:没有现场(期望有)"
|
|
@@ -635,18 +684,6 @@ _sg_selftest_case() { # <name> <shape> <want:0|2|!0> <want_scene:0|1>
|
|
|
635
684
|
|| st_bad "$name:run 临时根删掉后现场也丢了"
|
|
636
685
|
fi
|
|
637
686
|
grep -qF 'BARE_WAIT_RETURNED' "$dir/out.log" && st_ok "$name:裸 wait 没被看门狗卡住" || st_bad "$name:裸 wait 没返回"
|
|
638
|
-
if [ "$shape" = "clean" ]; then
|
|
639
|
-
grep -qF '超过实测带' "$dir/out.log" && st_ok "$name:整数 band 超过时打一行警告(记录,不是判定)" \
|
|
640
|
-
|| st_bad "$name:超过实测带没有警告行"
|
|
641
|
-
fi
|
|
642
|
-
if [ "$shape" = "decimal" ]; then
|
|
643
|
-
grep -qF '超过实测带 0.19s' "$dir/out.log" \
|
|
644
|
-
&& st_ok "$name:小数 band(0.19)超过时也打警告(P108 F2)" \
|
|
645
|
-
|| st_bad "$name:小数 band 超过时没有警告行(规范承诺对 110/112 行不可达)"
|
|
646
|
-
grep -qF '这是记录,不是判定' "$dir/out.log" \
|
|
647
|
-
&& st_ok "$name:小数 band 的警告仍是记录、不是判定(D33)" \
|
|
648
|
-
|| st_bad "$name:小数 band 的警告丢了「记录,不是判定」"
|
|
649
|
-
fi
|
|
650
687
|
local i pidfile
|
|
651
688
|
for i in $(seq 1 25); do
|
|
652
689
|
pidfile="$(ls "$dir"/.teamsmith-smoke-guard.pid.* 2>/dev/null | head -1 || true)"
|
|
@@ -712,23 +749,123 @@ _sg_selftest_f1() {
|
|
|
712
749
|
return 0
|
|
713
750
|
}
|
|
714
751
|
|
|
715
|
-
#
|
|
752
|
+
# ---------------------------------------------------------------- P313:心跳循环的三条边界
|
|
753
|
+
# 用**真**父进程造现场(不真留两天):
|
|
754
|
+
# ① 父进程被 KILL -9(来不及通知任何人)→ 心跳必须在 ~3s 内自己退;
|
|
755
|
+
# ② 对心跳直接发 TERM → 必须有界退出;
|
|
756
|
+
# ③ 硬上限:cap=2s、父还活着、没人发 TERM → 到点自己退,日志尾部留一行说明;
|
|
757
|
+
# ④ 写目标被删(夹具的临时根被清理)→ 不再往已删除的文件里写,立即退。
|
|
758
|
+
# 四条都是这个函数自己收尾(变异副本让某条失效时,剩下的进程由这里 KILL —— 夹具自己也不许泄漏)。
|
|
759
|
+
_sg_selftest_orphan() {
|
|
760
|
+
local lib dir log pid n i gone parent hp cp
|
|
761
|
+
lib="$(_sg_spin_lib_path)"
|
|
762
|
+
dir="$ST_ROOT/spin"; mkdir -p "$dir"
|
|
763
|
+
if [ ! -f "$lib" ]; then st_bad "P313:心跳循环的实现不在($lib)"; return 0; fi
|
|
764
|
+
|
|
765
|
+
# ① 父进程没了就退:中间的 bash 起心跳(父 = 它自己)后自旋;我们对它 KILL -9
|
|
766
|
+
log="$dir/parent.log"; : > "$log"
|
|
767
|
+
bash -c '. "$1"; shift; bounded_spin 0.2 30 - "$1" "$$" & echo "$!" > "$2"; sleep 120' _ \
|
|
768
|
+
"$lib" "$log" "$dir/parent.pid" 2>"$dir/parent.err" &
|
|
769
|
+
parent=$!
|
|
770
|
+
for n in $(seq 1 50); do [ -s "$dir/parent.pid" ] && break; sleep 0.1; done
|
|
771
|
+
pid="$(cat "$dir/parent.pid" 2>/dev/null || true)"
|
|
772
|
+
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
|
|
773
|
+
st_ok "P313①:心跳先起来了(pid=$pid)"
|
|
774
|
+
[ "$(grep -c '^[0-9]\{10\}$' "$log" 2>/dev/null || true)" -ge 1 ] \
|
|
775
|
+
&& st_ok "P313①:心跳真的在写(日志里有时间戳)" \
|
|
776
|
+
|| st_bad "P313①:心跳没有写日志(夹具失效)"
|
|
777
|
+
kill -KILL "$parent" 2>/dev/null || true; wait "$parent" 2>/dev/null || true
|
|
778
|
+
gone=0
|
|
779
|
+
for i in $(seq 1 30); do kill -0 "$pid" 2>/dev/null || { gone=1; break; }; sleep 0.1; done
|
|
780
|
+
if [ "$gone" = "1" ]; then
|
|
781
|
+
st_ok "P313①:父进程被 KILL 后心跳自己退了(≤3s)"
|
|
782
|
+
else
|
|
783
|
+
st_bad "P313①:心跳活过了父进程(去掉父进程检查就是这个形状)"
|
|
784
|
+
kill -KILL "$pid" 2>/dev/null || true
|
|
785
|
+
fi
|
|
786
|
+
grep -qF '父进程' "$log" 2>/dev/null && st_ok "P313①:日志里有一行说明原因(父进程已不在)" \
|
|
787
|
+
|| st_bad "P313①:日志里没有说明为什么退"
|
|
788
|
+
else
|
|
789
|
+
st_bad "P313①:心跳没起来(夹具失效)"
|
|
790
|
+
kill -KILL "$parent" 2>/dev/null || true; wait "$parent" 2>/dev/null || true
|
|
791
|
+
fi
|
|
792
|
+
|
|
793
|
+
# ② TERM 就让路:父(本 shell)还活着,直接给心跳发 TERM
|
|
794
|
+
log="$dir/term.log"; : > "$log"
|
|
795
|
+
bash -c '. "$1"; shift; bounded_spin 0.2 30 - "$1" "$2"' _ "$lib" "$log" "$$" 2>"$dir/term.err" &
|
|
796
|
+
hp=$!
|
|
797
|
+
sleep 0.5
|
|
798
|
+
if kill -0 "$hp" 2>/dev/null; then
|
|
799
|
+
kill -TERM "$hp" 2>/dev/null || true
|
|
800
|
+
gone=0
|
|
801
|
+
for i in $(seq 1 30); do kill -0 "$hp" 2>/dev/null || { gone=1; break; }; sleep 0.1; done
|
|
802
|
+
if [ "$gone" = "1" ]; then
|
|
803
|
+
st_ok "P313②:TERM 让心跳退出(≤3s)"
|
|
804
|
+
else
|
|
805
|
+
st_bad "P313②:心跳扛住了 TERM(trap \"\" TERM 就是这个形状)"
|
|
806
|
+
kill -KILL "$hp" 2>/dev/null || true
|
|
807
|
+
fi
|
|
808
|
+
grep -qF '收到 TERM' "$log" 2>/dev/null && st_ok "P313②:日志里有一行点名收到 TERM" \
|
|
809
|
+
|| st_bad "P313②:日志里没有点名 TERM"
|
|
810
|
+
else
|
|
811
|
+
st_bad "P313②:心跳没起来(夹具失效)"
|
|
812
|
+
fi
|
|
813
|
+
wait "$hp" 2>/dev/null || true
|
|
814
|
+
|
|
815
|
+
# ③ 硬上限:2s 到点自己退(父一直活着、没人发信号)
|
|
816
|
+
log="$dir/cap.log"; : > "$log"
|
|
817
|
+
bash -c '. "$1"; shift; bounded_spin 0.2 2 - "$1" "$2"' _ "$lib" "$log" "$$" 2>"$dir/cap.err" &
|
|
818
|
+
cp=$!
|
|
819
|
+
gone=0
|
|
820
|
+
for i in $(seq 1 80); do kill -0 "$cp" 2>/dev/null || { gone=1; break; }; sleep 0.1; done
|
|
821
|
+
if [ "$gone" = "1" ]; then
|
|
822
|
+
st_ok "P313③:到点(2s 上限)自己退"
|
|
823
|
+
else
|
|
824
|
+
st_bad "P313③:到了上限还在跑(硬上限被拿走就是这个形状)"
|
|
825
|
+
kill -KILL "$cp" 2>/dev/null || true
|
|
826
|
+
fi
|
|
827
|
+
grep -qF '到点(最大运行 2s)' "$log" 2>/dev/null && st_ok "P313③:日志里有一行点名上限" \
|
|
828
|
+
|| st_bad "P313③:日志里没有提到点退出"
|
|
829
|
+
wait "$cp" 2>/dev/null || true
|
|
830
|
+
|
|
831
|
+
# ④ 写目标被删:夹具的临时根被清理后不许再往已删除的文件里写
|
|
832
|
+
log="$dir/gone.log"; : > "$log"
|
|
833
|
+
bash -c '. "$1"; shift; bounded_spin 0.2 30 - "$1" "$2"' _ "$lib" "$log" "$$" 2>"$dir/gone.err" &
|
|
834
|
+
cp=$!
|
|
835
|
+
sleep 0.4; rm -f -- "$log"
|
|
836
|
+
gone=0
|
|
837
|
+
for i in $(seq 1 30); do kill -0 "$cp" 2>/dev/null || { gone=1; break; }; sleep 0.1; done
|
|
838
|
+
if [ "$gone" = "1" ]; then
|
|
839
|
+
st_ok "P313④:写目标被删后心跳自己退(不再往已删除的文件里写)"
|
|
840
|
+
else
|
|
841
|
+
st_bad "P313④:写目标已删,心跳还在写(11.98 GB 那个形状)"
|
|
842
|
+
kill -KILL "$cp" 2>/dev/null || true
|
|
843
|
+
fi
|
|
844
|
+
wait "$cp" 2>/dev/null || true
|
|
845
|
+
return 0
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
# 红侧翻转:把实现变异回旧形状(f1 = 「子孙忽略 TERM」措辞)。
|
|
716
849
|
# 这是「破坏实现 → 守卫测试必须红」的前半:变异后的副本由 _sg_selftest_flips 跑。
|
|
717
|
-
|
|
850
|
+
_sg_skill_dir() { # 本库所属的 skill 树(变异副本靠它拿到真正的解析器)
|
|
851
|
+
if [ -n "${TEAM_SG_SKILL_DIR:-}" ]; then printf '%s' "$TEAM_SG_SKILL_DIR"; return 0; fi
|
|
852
|
+
( cd -P "$(dirname "${BASH_SOURCE[0]}")/../.." 2>/dev/null && pwd )
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
# P313:心跳循环的唯一实现(红侧变异副本靠 SG_SPIN_LIB 指到别处;默认是本 skill 树里的那一份)
|
|
856
|
+
_sg_spin_lib_path() {
|
|
857
|
+
if [ -n "${SG_SPIN_LIB:-}" ]; then printf '%s' "$SG_SPIN_LIB"; return 0; fi
|
|
858
|
+
printf '%s' "$(_sg_skill_dir)/tests/lib/bounded-spin.sh"
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
_sg_selftest_mutate() { # <src> <dst> <f1|f3|f4|f5> → 0 = 变异落地
|
|
718
862
|
local src="$1" dst="$2" kind="$3"
|
|
719
863
|
case "$kind" in
|
|
720
|
-
f2) awk '
|
|
721
|
-
/^_sg_band_over\(\) \{/ { inband = 1 }
|
|
722
|
-
inband && /^ case "\$band" in/ {
|
|
723
|
-
print " case \"$band\" in # P110_F2 红侧:旧整数守卫(小数落空分支)"
|
|
724
|
-
print " \047\047|*[!0-9]*) return 1 ;;"
|
|
725
|
-
print " esac"
|
|
726
|
-
skipping = 1; inband = 0; next
|
|
727
|
-
}
|
|
728
|
-
skipping { if ($0 == " esac") skipping = 0; next }
|
|
729
|
-
{ print }
|
|
730
|
-
' "$src" > "$dst" ;;
|
|
731
864
|
f1) sed 's/的 grace 用尽(仍有子孙存活)→ 已/的子孙忽略 TERM → 已/g' "$src" > "$dst" ;;
|
|
865
|
+
# P313:心跳循环的三条边界。变异的是 lib/bounded-spin.sh(一个文件、三条各自可辨的行)。
|
|
866
|
+
f3) sed 's|^ while _bs_parent_alive "\$parent"; do$| while :; do # P313-F3 红侧:父进程检查被拿掉|' "$src" > "$dst" ;;
|
|
867
|
+
f4) sed "s|^ trap '_bs_on_term' TERM$| trap '' TERM # P313-F4 红侧:忽略 TERM|" "$src" > "$dst" ;;
|
|
868
|
+
f5) sed 's|^ if \[ "\$(( SECONDS - t0 ))" -ge "\$cap_s" \]; then _bs_exit "到点(最大运行 \${cap_s}s)"; fi$| : # P313-F5 红侧:硬上限被拿掉|' "$src" > "$dst" ;;
|
|
732
869
|
*) return 1 ;;
|
|
733
870
|
esac
|
|
734
871
|
# 变异必须真的改变文件(拿标记 grep 会被变异代码自身的存在骗过),且副本仍然可解析。
|
|
@@ -739,31 +876,18 @@ _sg_selftest_mutate() { # <src> <dst> <f2|f1> → 0 = 变异落地
|
|
|
739
876
|
}
|
|
740
877
|
|
|
741
878
|
# 两个红侧翻转(只在完整自检里跑;`--self-test <形状>` 只跑形状,避免递归):
|
|
742
|
-
#
|
|
879
|
+
# 两个红侧翻转(只在完整自检里跑;`--self-test <形状>` 只跑形状,避免递归):
|
|
743
880
|
# F1:grace 用尽的归因 —— 变异回「子孙忽略 TERM」→ f1 夹具必须红。
|
|
881
|
+
# (P316:band 小数警告的 F2 红侧随 band 一起退役。)
|
|
744
882
|
# 变异副本跑在自己的私有 TMPDIR 下,跑完连根删掉(失败也不留现场)。
|
|
745
883
|
_sg_selftest_flips() {
|
|
746
884
|
local dir="$ST_ROOT/flips" self mut rc out
|
|
747
885
|
self="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
|
|
748
|
-
mkdir -p "$dir/
|
|
749
|
-
# --- F2 ---
|
|
750
|
-
mut="$dir/f2-legacy-guard.sh"; out="$dir/f2-mutated.log"
|
|
751
|
-
if _sg_selftest_mutate "$self" "$mut" f2; then
|
|
752
|
-
TMPDIR="$dir/f2-tmp" bash "$mut" --self-test decimal >"$out" 2>&1; rc=$?
|
|
753
|
-
[ "$rc" -ne 0 ] && st_ok "F2 红侧:还原成整数守卫 → decimal 夹具红(rc=$rc)" \
|
|
754
|
-
|| st_bad "F2 红侧:还原成整数守卫后 decimal 夹具仍绿(守卫没被证到)"
|
|
755
|
-
grep -qF '超过实测带' "$out" && st_bad "F2 红侧:整数守卫下居然打了「超过实测带」行" \
|
|
756
|
-
|| st_ok "F2 红侧:整数守卫下没有「超过实测带」警告行(规范承诺回到不可达)"
|
|
757
|
-
grep -qF '小数 band 超过时没有警告行' "$out" \
|
|
758
|
-
&& st_ok "F2 红侧:红的是那条夹具断言本身(不是别的原因)" \
|
|
759
|
-
|| st_bad "F2 红侧:红的原因不是「小数 band 没有警告行」"
|
|
760
|
-
else
|
|
761
|
-
st_bad "F2 红侧:变异没落到 _sg_band_over(夹具失效)"
|
|
762
|
-
fi
|
|
886
|
+
mkdir -p "$dir/f1-tmp"
|
|
763
887
|
# --- F1 ---
|
|
764
888
|
mut="$dir/f1-legacy-wording.sh"; out="$dir/f1-mutated.log"
|
|
765
889
|
if _sg_selftest_mutate "$self" "$mut" f1; then
|
|
766
|
-
TMPDIR="$dir/f1-tmp" bash "$mut" --self-test f1 >"$out" 2>&1; rc=$?
|
|
890
|
+
TEAM_SG_SKILL_DIR="$(_sg_skill_dir)" TMPDIR="$dir/f1-tmp" bash "$mut" --self-test f1 >"$out" 2>&1; rc=$?
|
|
767
891
|
[ "$rc" -ne 0 ] && st_ok "F1 红侧:还原成「子孙忽略 TERM」措辞 → f1 夹具红(rc=$rc)" \
|
|
768
892
|
|| st_bad "F1 红侧:还原措辞后 f1 夹具仍绿(归因守卫没被证到)"
|
|
769
893
|
grep -qF '归因仍声称' "$out" \
|
|
@@ -772,6 +896,32 @@ _sg_selftest_flips() {
|
|
|
772
896
|
else
|
|
773
897
|
st_bad "F1 红侧:变异没落到归因措辞(夹具失效)"
|
|
774
898
|
fi
|
|
899
|
+
# --- P313①/②/③:心跳循环的父进程检查 / TERM / 硬上限 ---
|
|
900
|
+
local spin_src mutant
|
|
901
|
+
spin_src="$(_sg_spin_lib_path)"
|
|
902
|
+
if [ -f "$spin_src" ]; then
|
|
903
|
+
local -a _p313_kinds=(f3 f4 f5)
|
|
904
|
+
local -a _p313_want=("P313①:心跳活过了父进程" "P313②:心跳扛住了 TERM" "P313③:到了上限还在跑")
|
|
905
|
+
local _k _want _j
|
|
906
|
+
for _j in 0 1 2; do
|
|
907
|
+
_k="${_p313_kinds[$_j]}"; _want="${_p313_want[$_j]}"
|
|
908
|
+
mkdir -p "$dir/$_k-tmp"
|
|
909
|
+
mutant="$dir/$_k-bounded-spin.sh"; out="$dir/$_k-mutated.log"
|
|
910
|
+
if _sg_selftest_mutate "$spin_src" "$mutant" "$_k"; then
|
|
911
|
+
TEAM_SG_SKILL_DIR="$(_sg_skill_dir)" SG_SPIN_LIB="$mutant" TMPDIR="$dir/$_k-tmp" \
|
|
912
|
+
bash "$self" --self-test orphan >"$out" 2>&1; rc=$?
|
|
913
|
+
[ "$rc" -ne 0 ] && st_ok "P313 $_k 红侧:变异后心跳边界自检红(rc=$rc)" \
|
|
914
|
+
|| st_bad "P313 $_k 红侧:变异后心跳边界自检仍绿(守卫没被证到)"
|
|
915
|
+
grep -qF "$_want" "$out" \
|
|
916
|
+
&& st_ok "P313 $_k 红侧:红的是那条边界断言本身($_want)" \
|
|
917
|
+
|| st_bad "P313 $_k 红侧:红的原因不是「$_want」"
|
|
918
|
+
else
|
|
919
|
+
st_bad "P313 $_k 红侧:变异没落到 bounded-spin.sh(夹具失效)"
|
|
920
|
+
fi
|
|
921
|
+
done
|
|
922
|
+
else
|
|
923
|
+
st_bad "P313 红侧:找不到心跳循环实现($spin_src)"
|
|
924
|
+
fi
|
|
775
925
|
rm -rf -- "$dir" 2>/dev/null || true
|
|
776
926
|
return 0
|
|
777
927
|
}
|
|
@@ -781,7 +931,7 @@ _sg_selftest() {
|
|
|
781
931
|
local only=()
|
|
782
932
|
for arg in "$@"; do
|
|
783
933
|
case "$arg" in
|
|
784
|
-
--help|-h) printf '用法:bash %s --self-test [形状…]\n 形状:clean stuck stubborn spin deadspin
|
|
934
|
+
--help|-h) printf '用法:bash %s --self-test [形状…]\n 形状:clean stuck stubborn spin deadspin orphan f1(不带形状 = 全部 + 红侧翻转)\n' "${BASH_SOURCE[0]}"; return 0 ;;
|
|
785
935
|
-*) printf 'section-guard: 自检不认识的参数 %s\n' "$arg" >&2; return 2 ;;
|
|
786
936
|
*) only+=("$arg"); want_all=0 ;;
|
|
787
937
|
esac
|
|
@@ -790,7 +940,8 @@ _sg_selftest() {
|
|
|
790
940
|
st_ok() { printf ' \033[32m✓\033[0m %s\n' "$1"; PASS=$((PASS + 1)); }
|
|
791
941
|
st_bad() { printf ' \033[31m✗\033[0m %s\n' "$1"; FAIL=$((FAIL + 1)); }
|
|
792
942
|
local ST_ROOT
|
|
793
|
-
|
|
943
|
+
team_tmp_root_prepare >/dev/null 2>&1 || true
|
|
944
|
+
ST_ROOT="$(mktemp -d "$(team_tmp_root)/teamsmith-sg-selftest-$(team_project_ns).XXXXXX" 2>/dev/null)" || {
|
|
794
945
|
printf 'section-guard 自检:建不出临时根\n' >&2; return 3; }
|
|
795
946
|
local pgid_before pgid_after
|
|
796
947
|
pgid_before="$(ps -o pgid= -p "$$" 2>/dev/null | tr -d ' ')"
|
|
@@ -798,20 +949,21 @@ _sg_selftest() {
|
|
|
798
949
|
SG_FIXTURE=1
|
|
799
950
|
TEAM_SMOKE_FIXTURE=1
|
|
800
951
|
if [ "$want_all" = "1" ]; then
|
|
801
|
-
shapes="clean stuck stubborn spin deadspin
|
|
952
|
+
shapes="clean progressing stuck stubborn spin deadspin orphan"
|
|
802
953
|
else
|
|
803
954
|
shapes="${only[*]}"
|
|
804
955
|
fi
|
|
805
956
|
for shape in $shapes; do
|
|
806
957
|
case "$shape" in
|
|
807
958
|
clean) _sg_selftest_case clean clean 0 0 ;;
|
|
959
|
+
progressing) _sg_selftest_case progressing progressing 0 0 ;;
|
|
808
960
|
stuck) _sg_selftest_case stuck stuck 2 1 ;;
|
|
809
961
|
stubborn) _sg_selftest_case stubborn stubborn 2 1 ;;
|
|
810
962
|
spin) _sg_selftest_case spin spin 2 1 ;;
|
|
811
963
|
deadspin) _sg_selftest_case deadspin deadspin '!0' 1 ;;
|
|
812
|
-
|
|
964
|
+
orphan) _sg_selftest_orphan ;;
|
|
813
965
|
f1) _sg_selftest_f1 ;;
|
|
814
|
-
*) st_bad "自检:不认识的形状「$shape」(可用:clean stuck stubborn spin deadspin
|
|
966
|
+
*) st_bad "自检:不认识的形状「$shape」(可用:clean progressing stuck stubborn spin deadspin orphan f1)"; break ;;
|
|
815
967
|
esac
|
|
816
968
|
done
|
|
817
969
|
# 现场尾巴的收集顺序 = mtime 降序,不是 find 的目录顺序(容器实测:目录顺序把挂住的夹具日志
|