teamsmith 0.2.0 → 0.3.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/README.md +4 -4
- package/package.json +1 -1
- package/skills/teamsmith/CHANGELOG.md +28 -0
- package/skills/teamsmith/SKILL.md +14 -7
- 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 +176 -19
- package/skills/teamsmith/references/troubleshooting.md +124 -7
- 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 +175 -30
- package/skills/teamsmith/scripts/lib/cmd-status.sh +226 -17
- 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 +773 -48
- package/skills/teamsmith/scripts/lib/gate-lock.sh +544 -0
- package/skills/teamsmith/scripts/panel/draft-send.sh +11 -1
- package/skills/teamsmith/scripts/panel/panel.js +207 -207
- package/skills/teamsmith/scripts/panel/src/App.tsx +58 -21
- package/skills/teamsmith/scripts/panel/src/clipboard.ts +11 -5
- package/skills/teamsmith/scripts/panel/src/compose.ts +6 -3
- package/skills/teamsmith/scripts/panel/src/data.ts +11 -3
- package/skills/teamsmith/scripts/panel/src/layout.ts +209 -69
- package/skills/teamsmith/scripts/panel/src/main.tsx +33 -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/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/bg-ledger-harness.mjs +464 -40
- package/skills/teamsmith/tests/bg-ledger.sh +168 -10
- package/skills/teamsmith/tests/checkout-shape-probe.sh +3 -1
- package/skills/teamsmith/tests/config-cli.sh +160 -14
- 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-m37.sh +4 -1
- package/skills/teamsmith/tests/flip-m4.3.sh +4 -1
- package/skills/teamsmith/tests/flip-m6.3.sh +4 -1
- package/skills/teamsmith/tests/flip-m6.5.sh +4 -1
- package/skills/teamsmith/tests/flip-m7.2.sh +4 -1
- package/skills/teamsmith/tests/flip-p158.sh +2 -1
- package/skills/teamsmith/tests/flip-p210.sh +4 -1
- package/skills/teamsmith/tests/flip-p217.sh +4 -1
- package/skills/teamsmith/tests/flip-p287-lock.sh +342 -0
- package/skills/teamsmith/tests/flip-p287-name.sh +279 -0
- package/skills/teamsmith/tests/flip-p304-read-side.sh +98 -0
- package/skills/teamsmith/tests/flip-p308-skip-not-pass.sh +151 -0
- package/skills/teamsmith/tests/flip-p309-p162-deep.sh +122 -0
- package/skills/teamsmith/tests/flip-p310-lock.sh +216 -0
- package/skills/teamsmith/tests/flip-p310-socket.sh +125 -0
- package/skills/teamsmith/tests/help-surface.sh +1664 -0
- package/skills/teamsmith/tests/install-shape.sh +279 -20
- package/skills/teamsmith/tests/key-replies-pty.sh +9 -10
- package/skills/teamsmith/tests/key-replies-ui.sh +0 -7
- package/skills/teamsmith/tests/key-replies.sh +240 -1
- 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/reply-fixture.sh +4 -9
- package/skills/teamsmith/tests/lib/section-guard.sh +258 -13
- 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 +59 -47
- package/skills/teamsmith/tests/panel-b2.sh +106 -3
- package/skills/teamsmith/tests/panel-b3-stub.sh +112 -4
- package/skills/teamsmith/tests/panel-b3.sh +175 -19
- package/skills/teamsmith/tests/panel-choices.sh +11 -6
- package/skills/teamsmith/tests/panel-cpu.sh +2 -1
- package/skills/teamsmith/tests/panel-knobs.sh +7 -1
- package/skills/teamsmith/tests/panel-p21.sh +156 -73
- package/skills/teamsmith/tests/panel-snapshots.sh +41 -225
- package/skills/teamsmith/tests/panel-strings.mjs +33 -18
- package/skills/teamsmith/tests/perf.sh +121 -30
- package/skills/teamsmith/tests/routes.sh +327 -93
- package/skills/teamsmith/tests/seat-interrupt.sh +1002 -0
- package/skills/teamsmith/tests/seat-visibility.sh +675 -0
- package/skills/teamsmith/tests/section-budgets.tsv +20 -10
- package/skills/teamsmith/tests/section-guard.sh +6 -1
- package/skills/teamsmith/tests/section-needs-audit.sh +24 -7
- package/skills/teamsmith/tests/section-paths.tsv +19 -13
- package/skills/teamsmith/tests/section-select.sh +8 -1
- package/skills/teamsmith/tests/slash-team-e2e.sh +323 -0
- package/skills/teamsmith/tests/slash-team.sh +617 -0
- package/skills/teamsmith/tests/smoke.sh +2972 -440
- package/skills/teamsmith/tests/task-model-routing.sh +507 -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-init/SKILL.md +12 -12
- package/skills/teamsmith-init/references/bootstrap.md +3 -3
|
@@ -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
|
|
@@ -36,7 +49,7 @@ SG_TICKS=0
|
|
|
36
49
|
SG_ELAPSED=0
|
|
37
50
|
SG_OWNER_PID="$$"
|
|
38
51
|
SG_OWNER_START=""
|
|
39
|
-
SG_BASE="$
|
|
52
|
+
SG_BASE="$(team_tmp_root)"
|
|
40
53
|
SG_RUN_TMP=""
|
|
41
54
|
SG_BUDGETS=""
|
|
42
55
|
SG_TIMING=""
|
|
@@ -58,9 +71,28 @@ SG_BUDGET_OVERRIDE=""
|
|
|
58
71
|
SG_FAST="${TEAM_SMOKE_FAST:-0}"
|
|
59
72
|
SG_LOCK_NOTE=""
|
|
60
73
|
SG_CLOSE_COUNTS="" # P98 账本:本段收口行里的 ✓/✗/SKIP 增量(关段前注入;空 → 行里打 `-`)
|
|
74
|
+
SG_NESTED=0 # P281:本 run 是不是**证明得了祖辈持锁**的嵌套运行(只有嵌套运行才对齐祖辈期限)
|
|
75
|
+
SG_ANCESTOR_HEARTBEAT="" # P281:祖辈公布的心跳文件(读它拿到 armed_epoch + budget)
|
|
61
76
|
|
|
62
77
|
_sg_now() { date +%s; }
|
|
63
78
|
|
|
79
|
+
# P281:心跳文件的路径**只在这里拼一次**(门禁锁的记录要公布它,嵌套运行要靠它找祖辈的武装段)
|
|
80
|
+
section_guard_heartbeat_path() { # [<owner pid>] → <TMPDIR>/.teamsmith-smoke-heartbeat.<pid>
|
|
81
|
+
printf '%s\n' "$(team_tmp_root)/.teamsmith-smoke-heartbeat.${1:-$$}"
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
# P281:祖辈当前武装段的到期时刻(armed_epoch + budget);读不到/未武装 → 空
|
|
85
|
+
_sg_ancestor_deadline() {
|
|
86
|
+
local hb="${SG_ANCESTOR_HEARTBEAT:-}" line no armed budget
|
|
87
|
+
[ -n "$hb" ] && [ -r "$hb" ] || return 1
|
|
88
|
+
line="$(head -1 "$hb" 2>/dev/null || true)"
|
|
89
|
+
case "$line" in ''|disarm*) return 1 ;; esac
|
|
90
|
+
IFS='|' read -r no armed budget _ _ _ <<<"$line"
|
|
91
|
+
case "${armed:-}" in ''|*[!0-9]*) return 1 ;; esac
|
|
92
|
+
case "${budget:-}" in ''|*[!0-9]*) return 1 ;; esac
|
|
93
|
+
printf '%s\n' "$(( armed + budget ))"
|
|
94
|
+
}
|
|
95
|
+
|
|
64
96
|
_sg_proc_start() { # /proc/<pid>/stat 的 starttime:pid 复用安全的判据
|
|
65
97
|
local st; st="$(LC_ALL=C cat "/proc/$1/stat" 2>/dev/null)" || return 1
|
|
66
98
|
st="${st##*\) }"; set -- $st
|
|
@@ -80,6 +112,14 @@ _sg_pid_alive() { # <pid> [<starttime>] → 0 活着且(给了 starttime 时
|
|
|
80
112
|
return 0
|
|
81
113
|
}
|
|
82
114
|
|
|
115
|
+
# P281:僵尸(Z)已经跑完了(只等被 wait 收尸)—— 收尾等待时不能把它当「还活着」(否则白等满宽限)
|
|
116
|
+
_sg_pid_running() { # <pid> → 0 = 存在且不是僵尸
|
|
117
|
+
local pid="${1:-}" st
|
|
118
|
+
case "$pid" in ''|*[!0-9]*) return 1 ;; esac
|
|
119
|
+
st="$(awk '{print $3}' "/proc/$pid/stat" 2>/dev/null || true)"
|
|
120
|
+
[ -n "$st" ] && [ "$st" != "Z" ]
|
|
121
|
+
}
|
|
122
|
+
|
|
83
123
|
# ---------------------------------------------------------------- 初始化
|
|
84
124
|
# section_guard_init <run tmp> [--poll <s>] [--progress <s>] [--suite-grace <s>]
|
|
85
125
|
# [--desc-grace <n>] [--default-budget <s>] [--budgets <file>]
|
|
@@ -96,11 +136,11 @@ section_guard_init() {
|
|
|
96
136
|
*) printf 'section-guard: 不认识的参数 %s\n' "$1" >&2; return 2 ;;
|
|
97
137
|
esac
|
|
98
138
|
done
|
|
99
|
-
SG_BASE="$
|
|
139
|
+
SG_BASE="$(team_tmp_root)"
|
|
100
140
|
SG_FIXTURE="${TEAM_SMOKE_FIXTURE:-0}"
|
|
101
141
|
SG_OWNER_PID="${BASHPID:-$$}"
|
|
102
142
|
SG_OWNER_START="$(_sg_proc_start "$SG_OWNER_PID" 2>/dev/null || true)"
|
|
103
|
-
SG_HEARTBEAT="$
|
|
143
|
+
SG_HEARTBEAT="$(section_guard_heartbeat_path "$SG_OWNER_PID")"
|
|
104
144
|
SG_MARKER="$SG_BASE/.teamsmith-smoke-trip.$SG_OWNER_PID"
|
|
105
145
|
SG_SCENE="$SG_BASE/.teamsmith-smoke-scene.$SG_OWNER_PID"
|
|
106
146
|
SG_STOP="$SG_BASE/.teamsmith-smoke-guard-stop.$SG_OWNER_PID"
|
|
@@ -257,8 +297,13 @@ section_guard_on_term() { # 看门狗对我们的 TERM:trip → exit 2;否
|
|
|
257
297
|
_sg_start_line() {
|
|
258
298
|
local src=""
|
|
259
299
|
case "$SG_BUDGET_SOURCE" in
|
|
260
|
-
default)
|
|
261
|
-
fixture)
|
|
300
|
+
default) src="(默认:预算表没有这段)" ;;
|
|
301
|
+
fixture) src="(夹具覆盖)" ;;
|
|
302
|
+
ancestor) src="(嵌套运行:对齐祖辈剩余预算)" ;;
|
|
303
|
+
# 返修轮次 1 · F1:读不到祖辈公布的 heartbeat → 退回自己的表预算。退回必须**可见**,
|
|
304
|
+
# 不许无声占着(V43 的 F1:旧实现只把环境变量当来源,环境一清就静默退回)。
|
|
305
|
+
nested-fallback) src="(嵌套运行:没有可读的祖辈心跳 → 按本段预算)" ;;
|
|
306
|
+
fixture-nested-fallback) src="(夹具覆盖;嵌套运行:没有可读的祖辈心跳 → 按本段预算)" ;;
|
|
262
307
|
esac
|
|
263
308
|
printf '== #%s %s == %s · 预算 %ss%s' "$SG_SEC_NO" "$SG_SEC_ID" "$SG_SEC_START" "$SG_BUDGET" "$src"
|
|
264
309
|
}
|
|
@@ -294,6 +339,8 @@ _sg_close_current() {
|
|
|
294
339
|
printf ' \033[33m⚠\033[0m #%s 用时 %ss,超过实测带 %ss(这是记录,不是判定)\n' \
|
|
295
340
|
"$SG_SEC_NO" "$elapsed" "$SG_BAND"
|
|
296
341
|
fi
|
|
342
|
+
# P281:本段收口后,本夹具登记过的嵌套运行还不许活着(只对自己登记过的 pid 发信号,D37)
|
|
343
|
+
section_guard_check_orphans "${SG_LOCK_NOTE:-}"
|
|
297
344
|
SG_ARMED=0
|
|
298
345
|
SG_SEC_ID=""
|
|
299
346
|
printf 'disarm\n' > "$SG_HEARTBEAT" 2>/dev/null || true
|
|
@@ -318,6 +365,23 @@ section_guard_begin() { # <id>:收上一段 → 开这一段(含夹具注入
|
|
|
318
365
|
SG_ARMED_SECONDS="$SECONDS"
|
|
319
366
|
SG_TICKS=0
|
|
320
367
|
section_guard_budget_for "$id"
|
|
368
|
+
# P281:嵌套运行的期限 = min(自己的表预算, 祖辈武装段的剩余)。到点走**既有** trip 路径
|
|
369
|
+
# (点名段号 + 预算 + 实际、写现场、停跑)——不许无声占着(EXP2 那次 1h16m 的形状)。
|
|
370
|
+
if [ "${SG_NESTED:-0}" = "1" ]; then
|
|
371
|
+
local adl rem
|
|
372
|
+
adl="$(_sg_ancestor_deadline 2>/dev/null || true)"
|
|
373
|
+
if [ -n "$adl" ]; then
|
|
374
|
+
rem=$(( adl - $(_sg_now) ))
|
|
375
|
+
[ "$rem" -lt 0 ] && rem=0
|
|
376
|
+
if [ "$rem" -lt "$SG_BUDGET" ]; then SG_BUDGET="$rem"; SG_BUDGET_SOURCE="ancestor"; fi
|
|
377
|
+
else
|
|
378
|
+
# F1:祖辈心跳读不到 → 退回**自己的**表预算,但必须可见(开跑行的来源里说清楚)。
|
|
379
|
+
case "${SG_BUDGET_SOURCE:-default}" in
|
|
380
|
+
fixture) SG_BUDGET_SOURCE="fixture-nested-fallback" ;;
|
|
381
|
+
*) SG_BUDGET_SOURCE="nested-fallback" ;;
|
|
382
|
+
esac
|
|
383
|
+
fi
|
|
384
|
+
fi
|
|
321
385
|
SG_ARMED=1
|
|
322
386
|
section_guard_write_heartbeat
|
|
323
387
|
line="$(_sg_start_line)"
|
|
@@ -328,7 +392,19 @@ section_guard_begin() { # <id>:收上一段 → 开这一段(含夹具注入
|
|
|
328
392
|
printf ' \033[35m[fixture]\033[0m 注入永不返回的段落(%s,预算 %ss)\n' "$id" "$SG_BUDGET"
|
|
329
393
|
local stuck_log="$SG_RUN_TMP/fixture-stuck-$SG_SEC_NO.log"
|
|
330
394
|
printf 'fixture 注入:段落 #%s(%s)永不返回(预算 %ss)\n' "$SG_SEC_NO" "$id" "$SG_BUDGET" > "$stuck_log" 2>/dev/null || true
|
|
331
|
-
|
|
395
|
+
# P313:这个「永不返回」是**夹具造的现场**,不是永不退出的进程。旧形状
|
|
396
|
+
# `bash -c 'trap "" TERM; while :; do date +%s >> $log; sleep 0.2; done'`
|
|
397
|
+
# 在被打断的运行里会永久泄漏(现场:78 个孤儿合计持有 11.98 GB 已删除文件)。现在由
|
|
398
|
+
# lib/bounded-spin.sh 一处实现三条边界:父进程没了就退、到点(段落预算 + 120s 宽限)就退
|
|
399
|
+
# 并留一行、写目标被删就退。cap 永远大于段落预算 → 合法运行不会被它截断。
|
|
400
|
+
# 它**响应** TERM(P313 的硬要求:看门/轮询进程不再 `trap "" TERM`)。因此段落 0f 的现场
|
|
401
|
+
# 不会记 `escalation:` —— 段 0f 反过来断言「没有升级」,那条断言就是「有人把忽略 TERM 放回来」
|
|
402
|
+
# 的守卫;「真要升级时现场照写」由自检的 F1 夹具(P110)负责。
|
|
403
|
+
local _sg_spin_lib; _sg_spin_lib="$(_sg_spin_lib_path)"
|
|
404
|
+
local _sg_spin_cap=$(( SG_BUDGET + 120 ))
|
|
405
|
+
[ -f "$_sg_spin_lib" ] || printf ' \033[31m✗\033[0m 夹具:缺 %s(心跳循环起不来)\n' "$_sg_spin_lib"
|
|
406
|
+
bash -c 'lib="$1"; shift; . "$lib"; bounded_spin "$@"' _ "$_sg_spin_lib" \
|
|
407
|
+
0.2 "$_sg_spin_cap" "$(( _sg_spin_cap * 64 + 65536 ))" "$stuck_log" "$BASHPID" &
|
|
332
408
|
local child=$!
|
|
333
409
|
command -v tmp_root_track_pid >/dev/null 2>&1 && tmp_root_track_pid "$child" "section-guard-stuck" || true
|
|
334
410
|
wait "$child" 2>/dev/null || true
|
|
@@ -497,6 +573,36 @@ _sg_stop_children() { # <no>:只停这个套件进程树里的子孙(不含
|
|
|
497
573
|
return 0
|
|
498
574
|
}
|
|
499
575
|
|
|
576
|
+
# P281(change: gate-lock-hygiene):本夹具登记过的嵌套运行在**生它的那一段收口后**还不许活着。
|
|
577
|
+
# 只对记录里 `ancestor=<本 run 的 pid>` 且 pid 仍活着的条目动手;只对**那个 pid** 发信号(D37:
|
|
578
|
+
# 不按名字、不按进程组)。没有锁路径 / 没有 gate-lock.sh / 没有记录 → 静默不动。
|
|
579
|
+
section_guard_check_orphans() { # <lock>
|
|
580
|
+
local lock="${1:-}" f pid st pids="" n=0 p i alive
|
|
581
|
+
[ -n "$lock" ] || return 0
|
|
582
|
+
command -v gate_lock_record_get >/dev/null 2>&1 || return 0
|
|
583
|
+
for f in "$lock.runs"/*.run; do
|
|
584
|
+
[ -f "$f" ] || continue
|
|
585
|
+
[ "$(gate_lock_record_get "$f" ancestor)" = "$SG_OWNER_PID" ] || continue
|
|
586
|
+
pid="$(gate_lock_record_get "$f" pid)"; st="$(gate_lock_record_get "$f" start)"
|
|
587
|
+
case "$st" in ''|'-') st="" ;; esac
|
|
588
|
+
_sg_pid_alive "$pid" "$st" || continue
|
|
589
|
+
_sg_pid_running "$pid" || continue
|
|
590
|
+
printf ' \033[31m✗\033[0m 嵌套运行在生它的那一段收口后仍活着:pid=%s %s → 只对这个登记过的 pid 发信号收尾\n' \
|
|
591
|
+
"$pid" "$(gate_lock_describe_one "$f")"
|
|
592
|
+
pids="$pids $pid"; n=$((n + 1))
|
|
593
|
+
done
|
|
594
|
+
[ "$n" -eq 0 ] && return 0
|
|
595
|
+
for p in $pids; do kill -TERM "$p" 2>/dev/null || true; done
|
|
596
|
+
for i in $(seq 1 25); do
|
|
597
|
+
alive=0
|
|
598
|
+
for p in $pids; do _sg_pid_running "$p" && alive=1; done
|
|
599
|
+
[ "$alive" -eq 0 ] && break
|
|
600
|
+
sleep 0.2
|
|
601
|
+
done
|
|
602
|
+
for p in $pids; do kill -KILL "$p" 2>/dev/null || true; done
|
|
603
|
+
return 0
|
|
604
|
+
}
|
|
605
|
+
|
|
500
606
|
_sg_recent_files() { # <root> <min_epoch> <max>:窗口内动过的文件,**按 mtime 从新到旧**(有界)
|
|
501
607
|
# 不按 find 的目录顺序:正在被写的那份(挂住段落的夹具日志)必须排在最前,否则 12 个名额会被
|
|
502
608
|
# 窗口里更早、目录顺序靠前的文件占满 —— 2026-09-28 容器实测:0f 现场收进 .git/hooks/*.sample,
|
|
@@ -712,9 +818,116 @@ _sg_selftest_f1() {
|
|
|
712
818
|
return 0
|
|
713
819
|
}
|
|
714
820
|
|
|
821
|
+
# ---------------------------------------------------------------- P313:心跳循环的三条边界
|
|
822
|
+
# 用**真**父进程造现场(不真留两天):
|
|
823
|
+
# ① 父进程被 KILL -9(来不及通知任何人)→ 心跳必须在 ~3s 内自己退;
|
|
824
|
+
# ② 对心跳直接发 TERM → 必须有界退出;
|
|
825
|
+
# ③ 硬上限:cap=2s、父还活着、没人发 TERM → 到点自己退,日志尾部留一行说明;
|
|
826
|
+
# ④ 写目标被删(夹具的临时根被清理)→ 不再往已删除的文件里写,立即退。
|
|
827
|
+
# 四条都是这个函数自己收尾(变异副本让某条失效时,剩下的进程由这里 KILL —— 夹具自己也不许泄漏)。
|
|
828
|
+
_sg_selftest_orphan() {
|
|
829
|
+
local lib dir log pid n i gone parent hp cp
|
|
830
|
+
lib="$(_sg_spin_lib_path)"
|
|
831
|
+
dir="$ST_ROOT/spin"; mkdir -p "$dir"
|
|
832
|
+
if [ ! -f "$lib" ]; then st_bad "P313:心跳循环的实现不在($lib)"; return 0; fi
|
|
833
|
+
|
|
834
|
+
# ① 父进程没了就退:中间的 bash 起心跳(父 = 它自己)后自旋;我们对它 KILL -9
|
|
835
|
+
log="$dir/parent.log"; : > "$log"
|
|
836
|
+
bash -c '. "$1"; shift; bounded_spin 0.2 30 - "$1" "$$" & echo "$!" > "$2"; sleep 120' _ \
|
|
837
|
+
"$lib" "$log" "$dir/parent.pid" 2>"$dir/parent.err" &
|
|
838
|
+
parent=$!
|
|
839
|
+
for n in $(seq 1 50); do [ -s "$dir/parent.pid" ] && break; sleep 0.1; done
|
|
840
|
+
pid="$(cat "$dir/parent.pid" 2>/dev/null || true)"
|
|
841
|
+
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
|
|
842
|
+
st_ok "P313①:心跳先起来了(pid=$pid)"
|
|
843
|
+
[ "$(grep -c '^[0-9]\{10\}$' "$log" 2>/dev/null || true)" -ge 1 ] \
|
|
844
|
+
&& st_ok "P313①:心跳真的在写(日志里有时间戳)" \
|
|
845
|
+
|| st_bad "P313①:心跳没有写日志(夹具失效)"
|
|
846
|
+
kill -KILL "$parent" 2>/dev/null || true; wait "$parent" 2>/dev/null || true
|
|
847
|
+
gone=0
|
|
848
|
+
for i in $(seq 1 30); do kill -0 "$pid" 2>/dev/null || { gone=1; break; }; sleep 0.1; done
|
|
849
|
+
if [ "$gone" = "1" ]; then
|
|
850
|
+
st_ok "P313①:父进程被 KILL 后心跳自己退了(≤3s)"
|
|
851
|
+
else
|
|
852
|
+
st_bad "P313①:心跳活过了父进程(去掉父进程检查就是这个形状)"
|
|
853
|
+
kill -KILL "$pid" 2>/dev/null || true
|
|
854
|
+
fi
|
|
855
|
+
grep -qF '父进程' "$log" 2>/dev/null && st_ok "P313①:日志里有一行说明原因(父进程已不在)" \
|
|
856
|
+
|| st_bad "P313①:日志里没有说明为什么退"
|
|
857
|
+
else
|
|
858
|
+
st_bad "P313①:心跳没起来(夹具失效)"
|
|
859
|
+
kill -KILL "$parent" 2>/dev/null || true; wait "$parent" 2>/dev/null || true
|
|
860
|
+
fi
|
|
861
|
+
|
|
862
|
+
# ② TERM 就让路:父(本 shell)还活着,直接给心跳发 TERM
|
|
863
|
+
log="$dir/term.log"; : > "$log"
|
|
864
|
+
bash -c '. "$1"; shift; bounded_spin 0.2 30 - "$1" "$2"' _ "$lib" "$log" "$$" 2>"$dir/term.err" &
|
|
865
|
+
hp=$!
|
|
866
|
+
sleep 0.5
|
|
867
|
+
if kill -0 "$hp" 2>/dev/null; then
|
|
868
|
+
kill -TERM "$hp" 2>/dev/null || true
|
|
869
|
+
gone=0
|
|
870
|
+
for i in $(seq 1 30); do kill -0 "$hp" 2>/dev/null || { gone=1; break; }; sleep 0.1; done
|
|
871
|
+
if [ "$gone" = "1" ]; then
|
|
872
|
+
st_ok "P313②:TERM 让心跳退出(≤3s)"
|
|
873
|
+
else
|
|
874
|
+
st_bad "P313②:心跳扛住了 TERM(trap \"\" TERM 就是这个形状)"
|
|
875
|
+
kill -KILL "$hp" 2>/dev/null || true
|
|
876
|
+
fi
|
|
877
|
+
grep -qF '收到 TERM' "$log" 2>/dev/null && st_ok "P313②:日志里有一行点名收到 TERM" \
|
|
878
|
+
|| st_bad "P313②:日志里没有点名 TERM"
|
|
879
|
+
else
|
|
880
|
+
st_bad "P313②:心跳没起来(夹具失效)"
|
|
881
|
+
fi
|
|
882
|
+
wait "$hp" 2>/dev/null || true
|
|
883
|
+
|
|
884
|
+
# ③ 硬上限:2s 到点自己退(父一直活着、没人发信号)
|
|
885
|
+
log="$dir/cap.log"; : > "$log"
|
|
886
|
+
bash -c '. "$1"; shift; bounded_spin 0.2 2 - "$1" "$2"' _ "$lib" "$log" "$$" 2>"$dir/cap.err" &
|
|
887
|
+
cp=$!
|
|
888
|
+
gone=0
|
|
889
|
+
for i in $(seq 1 80); do kill -0 "$cp" 2>/dev/null || { gone=1; break; }; sleep 0.1; done
|
|
890
|
+
if [ "$gone" = "1" ]; then
|
|
891
|
+
st_ok "P313③:到点(2s 上限)自己退"
|
|
892
|
+
else
|
|
893
|
+
st_bad "P313③:到了上限还在跑(硬上限被拿走就是这个形状)"
|
|
894
|
+
kill -KILL "$cp" 2>/dev/null || true
|
|
895
|
+
fi
|
|
896
|
+
grep -qF '到点(最大运行 2s)' "$log" 2>/dev/null && st_ok "P313③:日志里有一行点名上限" \
|
|
897
|
+
|| st_bad "P313③:日志里没有提到点退出"
|
|
898
|
+
wait "$cp" 2>/dev/null || true
|
|
899
|
+
|
|
900
|
+
# ④ 写目标被删:夹具的临时根被清理后不许再往已删除的文件里写
|
|
901
|
+
log="$dir/gone.log"; : > "$log"
|
|
902
|
+
bash -c '. "$1"; shift; bounded_spin 0.2 30 - "$1" "$2"' _ "$lib" "$log" "$$" 2>"$dir/gone.err" &
|
|
903
|
+
cp=$!
|
|
904
|
+
sleep 0.4; rm -f -- "$log"
|
|
905
|
+
gone=0
|
|
906
|
+
for i in $(seq 1 30); do kill -0 "$cp" 2>/dev/null || { gone=1; break; }; sleep 0.1; done
|
|
907
|
+
if [ "$gone" = "1" ]; then
|
|
908
|
+
st_ok "P313④:写目标被删后心跳自己退(不再往已删除的文件里写)"
|
|
909
|
+
else
|
|
910
|
+
st_bad "P313④:写目标已删,心跳还在写(11.98 GB 那个形状)"
|
|
911
|
+
kill -KILL "$cp" 2>/dev/null || true
|
|
912
|
+
fi
|
|
913
|
+
wait "$cp" 2>/dev/null || true
|
|
914
|
+
return 0
|
|
915
|
+
}
|
|
916
|
+
|
|
715
917
|
# 红侧翻转:把实现变异回旧形状(f2 = 整数守卫;f1 = 「子孙忽略 TERM」措辞)。
|
|
716
918
|
# 这是「破坏实现 → 守卫测试必须红」的前半:变异后的副本由 _sg_selftest_flips 跑。
|
|
717
|
-
|
|
919
|
+
_sg_skill_dir() { # 本库所属的 skill 树(变异副本靠它拿到真正的解析器)
|
|
920
|
+
if [ -n "${TEAM_SG_SKILL_DIR:-}" ]; then printf '%s' "$TEAM_SG_SKILL_DIR"; return 0; fi
|
|
921
|
+
( cd -P "$(dirname "${BASH_SOURCE[0]}")/../.." 2>/dev/null && pwd )
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
# P313:心跳循环的唯一实现(红侧变异副本靠 SG_SPIN_LIB 指到别处;默认是本 skill 树里的那一份)
|
|
925
|
+
_sg_spin_lib_path() {
|
|
926
|
+
if [ -n "${SG_SPIN_LIB:-}" ]; then printf '%s' "$SG_SPIN_LIB"; return 0; fi
|
|
927
|
+
printf '%s' "$(_sg_skill_dir)/tests/lib/bounded-spin.sh"
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
_sg_selftest_mutate() { # <src> <dst> <f2|f1|f3|f4|f5> → 0 = 变异落地
|
|
718
931
|
local src="$1" dst="$2" kind="$3"
|
|
719
932
|
case "$kind" in
|
|
720
933
|
f2) awk '
|
|
@@ -729,6 +942,10 @@ _sg_selftest_mutate() { # <src> <dst> <f2|f1> → 0 = 变异落地
|
|
|
729
942
|
{ print }
|
|
730
943
|
' "$src" > "$dst" ;;
|
|
731
944
|
f1) sed 's/的 grace 用尽(仍有子孙存活)→ 已/的子孙忽略 TERM → 已/g' "$src" > "$dst" ;;
|
|
945
|
+
# P313:心跳循环的三条边界。变异的是 lib/bounded-spin.sh(一个文件、三条各自可辨的行)。
|
|
946
|
+
f3) sed 's|^ while _bs_parent_alive "\$parent"; do$| while :; do # P313-F3 红侧:父进程检查被拿掉|' "$src" > "$dst" ;;
|
|
947
|
+
f4) sed "s|^ trap '_bs_on_term' TERM$| trap '' TERM # P313-F4 红侧:忽略 TERM|" "$src" > "$dst" ;;
|
|
948
|
+
f5) sed 's|^ if \[ "\$(( SECONDS - t0 ))" -ge "\$cap_s" \]; then _bs_exit "到点(最大运行 \${cap_s}s)"; fi$| : # P313-F5 红侧:硬上限被拿掉|' "$src" > "$dst" ;;
|
|
732
949
|
*) return 1 ;;
|
|
733
950
|
esac
|
|
734
951
|
# 变异必须真的改变文件(拿标记 grep 会被变异代码自身的存在骗过),且副本仍然可解析。
|
|
@@ -749,7 +966,7 @@ _sg_selftest_flips() {
|
|
|
749
966
|
# --- F2 ---
|
|
750
967
|
mut="$dir/f2-legacy-guard.sh"; out="$dir/f2-mutated.log"
|
|
751
968
|
if _sg_selftest_mutate "$self" "$mut" f2; then
|
|
752
|
-
TMPDIR="$dir/f2-tmp" bash "$mut" --self-test decimal >"$out" 2>&1; rc=$?
|
|
969
|
+
TEAM_SG_SKILL_DIR="$(_sg_skill_dir)" TMPDIR="$dir/f2-tmp" bash "$mut" --self-test decimal >"$out" 2>&1; rc=$?
|
|
753
970
|
[ "$rc" -ne 0 ] && st_ok "F2 红侧:还原成整数守卫 → decimal 夹具红(rc=$rc)" \
|
|
754
971
|
|| st_bad "F2 红侧:还原成整数守卫后 decimal 夹具仍绿(守卫没被证到)"
|
|
755
972
|
grep -qF '超过实测带' "$out" && st_bad "F2 红侧:整数守卫下居然打了「超过实测带」行" \
|
|
@@ -763,7 +980,7 @@ _sg_selftest_flips() {
|
|
|
763
980
|
# --- F1 ---
|
|
764
981
|
mut="$dir/f1-legacy-wording.sh"; out="$dir/f1-mutated.log"
|
|
765
982
|
if _sg_selftest_mutate "$self" "$mut" f1; then
|
|
766
|
-
TMPDIR="$dir/f1-tmp" bash "$mut" --self-test f1 >"$out" 2>&1; rc=$?
|
|
983
|
+
TEAM_SG_SKILL_DIR="$(_sg_skill_dir)" TMPDIR="$dir/f1-tmp" bash "$mut" --self-test f1 >"$out" 2>&1; rc=$?
|
|
767
984
|
[ "$rc" -ne 0 ] && st_ok "F1 红侧:还原成「子孙忽略 TERM」措辞 → f1 夹具红(rc=$rc)" \
|
|
768
985
|
|| st_bad "F1 红侧:还原措辞后 f1 夹具仍绿(归因守卫没被证到)"
|
|
769
986
|
grep -qF '归因仍声称' "$out" \
|
|
@@ -772,6 +989,32 @@ _sg_selftest_flips() {
|
|
|
772
989
|
else
|
|
773
990
|
st_bad "F1 红侧:变异没落到归因措辞(夹具失效)"
|
|
774
991
|
fi
|
|
992
|
+
# --- P313①/②/③:心跳循环的父进程检查 / TERM / 硬上限 ---
|
|
993
|
+
local spin_src mutant
|
|
994
|
+
spin_src="$(_sg_spin_lib_path)"
|
|
995
|
+
if [ -f "$spin_src" ]; then
|
|
996
|
+
local -a _p313_kinds=(f3 f4 f5)
|
|
997
|
+
local -a _p313_want=("P313①:心跳活过了父进程" "P313②:心跳扛住了 TERM" "P313③:到了上限还在跑")
|
|
998
|
+
local _k _want _j
|
|
999
|
+
for _j in 0 1 2; do
|
|
1000
|
+
_k="${_p313_kinds[$_j]}"; _want="${_p313_want[$_j]}"
|
|
1001
|
+
mkdir -p "$dir/$_k-tmp"
|
|
1002
|
+
mutant="$dir/$_k-bounded-spin.sh"; out="$dir/$_k-mutated.log"
|
|
1003
|
+
if _sg_selftest_mutate "$spin_src" "$mutant" "$_k"; then
|
|
1004
|
+
TEAM_SG_SKILL_DIR="$(_sg_skill_dir)" SG_SPIN_LIB="$mutant" TMPDIR="$dir/$_k-tmp" \
|
|
1005
|
+
bash "$self" --self-test orphan >"$out" 2>&1; rc=$?
|
|
1006
|
+
[ "$rc" -ne 0 ] && st_ok "P313 $_k 红侧:变异后心跳边界自检红(rc=$rc)" \
|
|
1007
|
+
|| st_bad "P313 $_k 红侧:变异后心跳边界自检仍绿(守卫没被证到)"
|
|
1008
|
+
grep -qF "$_want" "$out" \
|
|
1009
|
+
&& st_ok "P313 $_k 红侧:红的是那条边界断言本身($_want)" \
|
|
1010
|
+
|| st_bad "P313 $_k 红侧:红的原因不是「$_want」"
|
|
1011
|
+
else
|
|
1012
|
+
st_bad "P313 $_k 红侧:变异没落到 bounded-spin.sh(夹具失效)"
|
|
1013
|
+
fi
|
|
1014
|
+
done
|
|
1015
|
+
else
|
|
1016
|
+
st_bad "P313 红侧:找不到心跳循环实现($spin_src)"
|
|
1017
|
+
fi
|
|
775
1018
|
rm -rf -- "$dir" 2>/dev/null || true
|
|
776
1019
|
return 0
|
|
777
1020
|
}
|
|
@@ -781,7 +1024,7 @@ _sg_selftest() {
|
|
|
781
1024
|
local only=()
|
|
782
1025
|
for arg in "$@"; do
|
|
783
1026
|
case "$arg" in
|
|
784
|
-
--help|-h) printf '用法:bash %s --self-test [形状…]\n 形状:clean stuck stubborn spin deadspin decimal f1(不带形状 = 全部 + 红侧翻转)\n' "${BASH_SOURCE[0]}"; return 0 ;;
|
|
1027
|
+
--help|-h) printf '用法:bash %s --self-test [形状…]\n 形状:clean stuck stubborn spin deadspin decimal orphan f1(不带形状 = 全部 + 红侧翻转)\n' "${BASH_SOURCE[0]}"; return 0 ;;
|
|
785
1028
|
-*) printf 'section-guard: 自检不认识的参数 %s\n' "$arg" >&2; return 2 ;;
|
|
786
1029
|
*) only+=("$arg"); want_all=0 ;;
|
|
787
1030
|
esac
|
|
@@ -790,7 +1033,8 @@ _sg_selftest() {
|
|
|
790
1033
|
st_ok() { printf ' \033[32m✓\033[0m %s\n' "$1"; PASS=$((PASS + 1)); }
|
|
791
1034
|
st_bad() { printf ' \033[31m✗\033[0m %s\n' "$1"; FAIL=$((FAIL + 1)); }
|
|
792
1035
|
local ST_ROOT
|
|
793
|
-
|
|
1036
|
+
team_tmp_root_prepare >/dev/null 2>&1 || true
|
|
1037
|
+
ST_ROOT="$(mktemp -d "$(team_tmp_root)/teamsmith-sg-selftest-$(team_project_ns).XXXXXX" 2>/dev/null)" || {
|
|
794
1038
|
printf 'section-guard 自检:建不出临时根\n' >&2; return 3; }
|
|
795
1039
|
local pgid_before pgid_after
|
|
796
1040
|
pgid_before="$(ps -o pgid= -p "$$" 2>/dev/null | tr -d ' ')"
|
|
@@ -798,7 +1042,7 @@ _sg_selftest() {
|
|
|
798
1042
|
SG_FIXTURE=1
|
|
799
1043
|
TEAM_SMOKE_FIXTURE=1
|
|
800
1044
|
if [ "$want_all" = "1" ]; then
|
|
801
|
-
shapes="clean stuck stubborn spin deadspin decimal"
|
|
1045
|
+
shapes="clean stuck stubborn spin deadspin decimal orphan"
|
|
802
1046
|
else
|
|
803
1047
|
shapes="${only[*]}"
|
|
804
1048
|
fi
|
|
@@ -810,8 +1054,9 @@ _sg_selftest() {
|
|
|
810
1054
|
spin) _sg_selftest_case spin spin 2 1 ;;
|
|
811
1055
|
deadspin) _sg_selftest_case deadspin deadspin '!0' 1 ;;
|
|
812
1056
|
decimal) _sg_selftest_case decimal decimal 0 0 ;;
|
|
1057
|
+
orphan) _sg_selftest_orphan ;;
|
|
813
1058
|
f1) _sg_selftest_f1 ;;
|
|
814
|
-
*) st_bad "自检:不认识的形状「$shape」(可用:clean stuck stubborn spin deadspin decimal f1)"; break ;;
|
|
1059
|
+
*) st_bad "自检:不认识的形状「$shape」(可用:clean stuck stubborn spin deadspin decimal orphan f1)"; break ;;
|
|
815
1060
|
esac
|
|
816
1061
|
done
|
|
817
1062
|
# 现场尾巴的收集顺序 = mtime 降序,不是 find 的目录顺序(容器实测:目录顺序把挂住的夹具日志
|