teamsmith 0.0.0-stage → 0.1.2
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/LICENSE +21 -0
- package/README.md +158 -2
- package/bin/team.mjs +59 -0
- package/install.sh +94 -0
- package/package.json +37 -4
- package/skills/teamsmith/CHANGELOG.md +763 -0
- package/skills/teamsmith/SKILL.md +312 -0
- package/skills/teamsmith/extension/team-bg.ts +435 -0
- package/skills/teamsmith/extension/team-inbox-watch.ts +1412 -0
- package/skills/teamsmith/extension/team-notify.ts +663 -0
- package/skills/teamsmith/references/agent-adapters.md +643 -0
- package/skills/teamsmith/references/config.md +477 -0
- package/skills/teamsmith/references/meeting.md +124 -0
- package/skills/teamsmith/references/memory.md +133 -0
- package/skills/teamsmith/references/migration.md +227 -0
- package/skills/teamsmith/references/openspec.md +222 -0
- package/skills/teamsmith/references/philosophy.md +95 -0
- package/skills/teamsmith/references/protocol.md +712 -0
- package/skills/teamsmith/references/troubleshooting.md +1384 -0
- package/skills/teamsmith/references/workflows.md +448 -0
- package/skills/teamsmith/scripts/lib/cmd-agents.sh +1709 -0
- package/skills/teamsmith/scripts/lib/cmd-bg.sh +284 -0
- package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +311 -0
- package/skills/teamsmith/scripts/lib/cmd-config.sh +1156 -0
- package/skills/teamsmith/scripts/lib/cmd-death.sh +562 -0
- package/skills/teamsmith/scripts/lib/cmd-docs.sh +149 -0
- package/skills/teamsmith/scripts/lib/cmd-draft.sh +124 -0
- package/skills/teamsmith/scripts/lib/cmd-init.sh +212 -0
- package/skills/teamsmith/scripts/lib/cmd-meeting.sh +904 -0
- package/skills/teamsmith/scripts/lib/cmd-outbox.sh +196 -0
- package/skills/teamsmith/scripts/lib/cmd-project.sh +642 -0
- package/skills/teamsmith/scripts/lib/cmd-review.sh +1393 -0
- package/skills/teamsmith/scripts/lib/cmd-status.sh +1399 -0
- package/skills/teamsmith/scripts/lib/cmd-update.sh +191 -0
- package/skills/teamsmith/scripts/lib/cmd-watch.sh +1681 -0
- package/skills/teamsmith/scripts/lib/common.sh +4964 -0
- package/skills/teamsmith/scripts/lib/draft-entry.sh +51 -0
- package/skills/teamsmith/scripts/lib/outbox.sh +2042 -0
- package/skills/teamsmith/scripts/lib/tmux-argv.sh +165 -0
- package/skills/teamsmith/scripts/monitor.mjs +616 -0
- package/skills/teamsmith/scripts/panel/README.md +192 -0
- package/skills/teamsmith/scripts/panel/build.sh +47 -0
- package/skills/teamsmith/scripts/panel/bun.lock +109 -0
- package/skills/teamsmith/scripts/panel/draft-send.sh +68 -0
- package/skills/teamsmith/scripts/panel/package.json +24 -0
- package/skills/teamsmith/scripts/panel/panel.js +388 -0
- package/skills/teamsmith/scripts/panel/src/App.tsx +2150 -0
- package/skills/teamsmith/scripts/panel/src/clipboard.ts +154 -0
- package/skills/teamsmith/scripts/panel/src/compose.ts +691 -0
- package/skills/teamsmith/scripts/panel/src/data.ts +555 -0
- package/skills/teamsmith/scripts/panel/src/format.ts +50 -0
- package/skills/teamsmith/scripts/panel/src/layout.ts +2562 -0
- package/skills/teamsmith/scripts/panel/src/main.tsx +894 -0
- package/skills/teamsmith/scripts/panel/src/markdown.ts +340 -0
- package/skills/teamsmith/scripts/panel/src/sanitize.ts +42 -0
- package/skills/teamsmith/scripts/panel/src/settings.ts +154 -0
- package/skills/teamsmith/scripts/panel/src/strings/en.ts +416 -0
- package/skills/teamsmith/scripts/panel/src/strings/index.ts +65 -0
- package/skills/teamsmith/scripts/panel/src/strings/types.ts +9 -0
- package/skills/teamsmith/scripts/panel/src/strings/zh.ts +414 -0
- package/skills/teamsmith/scripts/panel/src/theme.ts +116 -0
- package/skills/teamsmith/scripts/panel/src/types.ts +652 -0
- package/skills/teamsmith/scripts/panel/src/width.ts +105 -0
- package/skills/teamsmith/scripts/panel/tsconfig.json +16 -0
- package/skills/teamsmith/scripts/shim/signal-gate +156 -0
- package/skills/teamsmith/scripts/shim/tmux +403 -0
- package/skills/teamsmith/scripts/team +143 -0
- package/skills/teamsmith/templates/AGENTS.section.md.tmpl +147 -0
- package/skills/teamsmith/templates/BOARD.md.tmpl +18 -0
- package/skills/teamsmith/templates/DECISIONS.md.tmpl +22 -0
- package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +25 -0
- package/skills/teamsmith/templates/PROTOCOL.md.tmpl +84 -0
- package/skills/teamsmith/templates/ROADMAP.md.tmpl +29 -0
- package/skills/teamsmith/templates/config.sh.tmpl +106 -0
- package/skills/teamsmith/templates/memory-seed.md.tmpl +46 -0
- package/skills/teamsmith/templates/pm-prompt.md.tmpl +110 -0
- package/skills/teamsmith/templates/report.md.tmpl +36 -0
- package/skills/teamsmith/templates/task.md.tmpl +65 -0
- package/skills/teamsmith/templates/threads-README.md +17 -0
- package/skills/teamsmith/tests/bg-ledger-harness.mjs +682 -0
- package/skills/teamsmith/tests/bg-ledger.sh +307 -0
- package/skills/teamsmith/tests/checkout-shape-probe.sh +800 -0
- package/skills/teamsmith/tests/config-cli.sh +1562 -0
- package/skills/teamsmith/tests/container-tmux.sh +493 -0
- package/skills/teamsmith/tests/coverage-inventory.sh +173 -0
- package/skills/teamsmith/tests/death-cause.sh +564 -0
- package/skills/teamsmith/tests/delivery-truth.sh +1231 -0
- package/skills/teamsmith/tests/fake-tui.py +450 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/README.md +60 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/judge-second.py +139 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/mock-server.py +29 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/observe.ts +20 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/run-case.sh +79 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +175 -0
- package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +229 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/README.md +22 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/dev2.seen +8 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/dev2.wake +9 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/pm-nudges.wake +3 -0
- package/skills/teamsmith/tests/fixtures/signal-lint-cases.txt +40 -0
- package/skills/teamsmith/tests/flip-glue.sh +162 -0
- package/skills/teamsmith/tests/flip-m12-26c.sh +129 -0
- package/skills/teamsmith/tests/flip-m12.sh +185 -0
- package/skills/teamsmith/tests/flip-m16.sh +166 -0
- package/skills/teamsmith/tests/flip-m17.sh +204 -0
- package/skills/teamsmith/tests/flip-m33.sh +284 -0
- package/skills/teamsmith/tests/flip-m34.sh +96 -0
- package/skills/teamsmith/tests/flip-m37.sh +185 -0
- package/skills/teamsmith/tests/flip-m4.3.sh +375 -0
- package/skills/teamsmith/tests/flip-m43.sh +128 -0
- package/skills/teamsmith/tests/flip-m44.sh +262 -0
- package/skills/teamsmith/tests/flip-m45.sh +244 -0
- package/skills/teamsmith/tests/flip-m46.sh +238 -0
- package/skills/teamsmith/tests/flip-m48.sh +304 -0
- package/skills/teamsmith/tests/flip-m6.2.sh +205 -0
- package/skills/teamsmith/tests/flip-m6.3.sh +283 -0
- package/skills/teamsmith/tests/flip-m6.4.sh +267 -0
- package/skills/teamsmith/tests/flip-m6.5.sh +113 -0
- package/skills/teamsmith/tests/flip-m7.1.sh +135 -0
- package/skills/teamsmith/tests/flip-m7.2.sh +321 -0
- package/skills/teamsmith/tests/flip-p144.sh +112 -0
- package/skills/teamsmith/tests/flip-p156.sh +133 -0
- package/skills/teamsmith/tests/flip-p158.sh +301 -0
- package/skills/teamsmith/tests/flip-p160.sh +182 -0
- package/skills/teamsmith/tests/flip-p171.sh +249 -0
- package/skills/teamsmith/tests/flip-p18.1.sh +95 -0
- package/skills/teamsmith/tests/flip-p20.sh +286 -0
- package/skills/teamsmith/tests/flip-p201.sh +249 -0
- package/skills/teamsmith/tests/flip-p210.sh +239 -0
- package/skills/teamsmith/tests/flip-p211.sh +152 -0
- package/skills/teamsmith/tests/flip-p217.sh +288 -0
- package/skills/teamsmith/tests/flip-p22.sh +123 -0
- package/skills/teamsmith/tests/flip-p23.sh +239 -0
- package/skills/teamsmith/tests/flip-p25.sh +165 -0
- package/skills/teamsmith/tests/flip-p71.sh +184 -0
- package/skills/teamsmith/tests/flip-p72.sh +202 -0
- package/skills/teamsmith/tests/frames/README.md +176 -0
- package/skills/teamsmith/tests/frames/p78-conversation-rule-below-box.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-cursor-mid-draft.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-below-cursor-line.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-below-cursor.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-blank-region.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-only.txt +5 -0
- package/skills/teamsmith/tests/frames/p78-spinner-row-below-cursor.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-wider-rule-below-cursor.txt +6 -0
- package/skills/teamsmith/tests/frames/p86-f1-mixed-width-disjoint-box.txt +8 -0
- package/skills/teamsmith/tests/frames/p86-f1-narrower-width-disjoint-box.txt +8 -0
- package/skills/teamsmith/tests/frames/p86-f1-spinner-top-disjoint-box.txt +8 -0
- package/skills/teamsmith/tests/frames/pi-0.85.1-update-banner.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-draft-half-sentence.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-empty-box.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-one-line-draft.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-project-trust-prompt.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.99.2-empty-editor.txt +32 -0
- package/skills/teamsmith/tests/frames/pi-0.99.2-human-draft.txt +32 -0
- package/skills/teamsmith/tests/frames/pi-1.0.0-git-error-in-box.txt +32 -0
- package/skills/teamsmith/tests/gate-guard.sh +112 -0
- package/skills/teamsmith/tests/guard-matrix.sh +233 -0
- package/skills/teamsmith/tests/install-shape.sh +731 -0
- package/skills/teamsmith/tests/ledger-ban.sh +612 -0
- package/skills/teamsmith/tests/lib/box-judge.sh +68 -0
- package/skills/teamsmith/tests/lib/checkout-shape.sh +129 -0
- package/skills/teamsmith/tests/lib/loop-scan.awk +114 -0
- package/skills/teamsmith/tests/lib/pty-wait.sh +676 -0
- package/skills/teamsmith/tests/lib/section-guard.sh +855 -0
- package/skills/teamsmith/tests/lib/shell-lex.pl +261 -0
- package/skills/teamsmith/tests/lib/tmp-root.sh +528 -0
- package/skills/teamsmith/tests/lib/tmux-cap.sh +35 -0
- package/skills/teamsmith/tests/lib/tmux-iso-call-probe.sh +81 -0
- package/skills/teamsmith/tests/lib/tmux-iso-probe.sh +46 -0
- package/skills/teamsmith/tests/lib/tmux-iso.sh +381 -0
- package/skills/teamsmith/tests/load-experiment.sh +290 -0
- package/skills/teamsmith/tests/loop-inventory.tsv +84 -0
- package/skills/teamsmith/tests/panel-b2-slow-stub.sh +19 -0
- package/skills/teamsmith/tests/panel-b2.sh +1183 -0
- package/skills/teamsmith/tests/panel-b3-pty-mouse.py +240 -0
- package/skills/teamsmith/tests/panel-b3-pty-tmux-mouse.py +138 -0
- package/skills/teamsmith/tests/panel-b3-stub.sh +279 -0
- package/skills/teamsmith/tests/panel-b3.sh +1301 -0
- package/skills/teamsmith/tests/panel-choices.sh +572 -0
- package/skills/teamsmith/tests/panel-clipboard-model.ts +187 -0
- package/skills/teamsmith/tests/panel-compose-model.ts +290 -0
- package/skills/teamsmith/tests/panel-contrast.mjs +81 -0
- package/skills/teamsmith/tests/panel-cpu-premise.sh +173 -0
- package/skills/teamsmith/tests/panel-cpu.sh +391 -0
- package/skills/teamsmith/tests/panel-flip-m54.sh +207 -0
- package/skills/teamsmith/tests/panel-flip-p123.sh +278 -0
- package/skills/teamsmith/tests/panel-flip-p125.sh +318 -0
- package/skills/teamsmith/tests/panel-flip-p128.sh +259 -0
- package/skills/teamsmith/tests/panel-keyprobe-pty.py +99 -0
- package/skills/teamsmith/tests/panel-keyprobe-stub.sh +41 -0
- package/skills/teamsmith/tests/panel-keyprobe.sh +82 -0
- package/skills/teamsmith/tests/panel-keyprobe.tsx +116 -0
- package/skills/teamsmith/tests/panel-knobs.sh +83 -0
- package/skills/teamsmith/tests/panel-p21.sh +2181 -0
- package/skills/teamsmith/tests/panel-snapshots.sh +802 -0
- package/skills/teamsmith/tests/panel-strings.mjs +195 -0
- package/skills/teamsmith/tests/perf.sh +740 -0
- package/skills/teamsmith/tests/pm-box-real.sh +350 -0
- package/skills/teamsmith/tests/pulse-nudge-key.sh +563 -0
- package/skills/teamsmith/tests/routes.sh +1652 -0
- package/skills/teamsmith/tests/section-budgets.tsv +150 -0
- package/skills/teamsmith/tests/section-guard.sh +231 -0
- package/skills/teamsmith/tests/section-needs-audit.sh +94 -0
- package/skills/teamsmith/tests/section-paths.tsv +142 -0
- package/skills/teamsmith/tests/section-select.sh +655 -0
- package/skills/teamsmith/tests/signal-gate.sh +366 -0
- package/skills/teamsmith/tests/signal-lint-legacy.txt +14 -0
- package/skills/teamsmith/tests/signal-lint.pl +416 -0
- package/skills/teamsmith/tests/skill-load.mjs +65 -0
- package/skills/teamsmith/tests/smoke.sh +19711 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-120-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-120-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-120.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-160-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-160.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-59-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-59-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-59.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-99-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-99.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-120-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-120-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-120.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-160-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-160.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-59-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-59-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-59.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-99-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-99.txt +32 -0
- package/skills/teamsmith/tests/spec-ledger-refs.tsv +78 -0
- package/skills/teamsmith/tests/spec-refs.sh +826 -0
- package/skills/teamsmith/tests/task-header-model.sh +267 -0
- package/skills/teamsmith/tests/team-bg-flip.sh +239 -0
- package/skills/teamsmith/tests/team-bg-harness.mjs +392 -0
- package/skills/teamsmith/tests/team-bg-stop.sh +434 -0
- package/skills/teamsmith/tests/team-inbox-watch-flip.sh +191 -0
- package/skills/teamsmith/tests/team-inbox-watch-harness.mjs +1559 -0
- package/skills/teamsmith/tests/tmp-hygiene.sh +1190 -0
- package/skills/teamsmith/tests/tmux-lint-legacy.txt +31 -0
- package/skills/teamsmith/tests/tmux-lint.pl +604 -0
- package/skills/teamsmith-init/SKILL.md +100 -0
- package/skills/teamsmith-init/references/bootstrap.md +74 -0
- package/skills/teamsmith-init/templates/bootstrap-prompt.md.tmpl +46 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# P159 · `team bg stop` 夹具(safe-signal-discipline · RA3)
|
|
3
|
+
#
|
|
4
|
+
# bash skills/teamsmith/tests/team-bg-stop.sh [--break=no-identity|no-boundary|no-dir-boundary|read-side-pid-only] [--keep]
|
|
5
|
+
#
|
|
6
|
+
# 证明什么(每条断言都对着 RA3 的 scenario):
|
|
7
|
+
# · 真作业按**记录里的 (pid, 启动时间指纹)** 停掉:组 TERM(leader 是组头 → 组内子孙一起),
|
|
8
|
+
# job 死了、**没有记录过的邻居活着**、`state/bg.log` 留下 stop 行(RA3 的 happy path);
|
|
9
|
+
# · 四种拒绝都**什么都没发**:无记录 3 / 记录畸形 4 / pid 复用(指纹对不上)5 / 用法 2;
|
|
10
|
+
# · 记录只认本项目 state 目录:兄弟 state 目录里的 id 不会被找到,也不会去别处搜进程;
|
|
11
|
+
# · 状态边界(P169 · F1,CRITICAL):id 是平坦名字(路径语义不在语法里)、记录必须是本项目
|
|
12
|
+
# bg 目录里的正规文件 —— 穿越 id 2 / 软链 4 / pgid=0 4 / FIFO 4(读取前就拒,不许挂住),
|
|
13
|
+
# 三种畸形都零信号、邻居全活;反向:本项目自己的正规记录照常收(`job.2-fine` 那种名字不误伤);
|
|
14
|
+
# · 目录边界(P187 · F1',CRITICAL):**bg 目录自身**也必须在项目 state 内 —— `state/bg` 是软链时
|
|
15
|
+
# 读写两侧都拒绝(stop/list 同一条规则),点名 `state/bg` 的解析目标;反向:真目录照常收作业;
|
|
16
|
+
# · 已结束的 leader 不追猎:rc=0 + 明说子孙不会被找(活着的子孙留在原地);
|
|
17
|
+
# · `team bg list` 一行一作业,判定逐行标出(holds/gone/unusable/mismatch);**读面没有自己的
|
|
18
|
+
# 判断**(P195 · F1):list 与 stop 走同一个 team_bg_check_record,不可用的记录标 unusable /
|
|
19
|
+
# mismatch 并打出与 stop **同一句**原因(同一个 TEAM_BG_REASON)。
|
|
20
|
+
#
|
|
21
|
+
# 红侧(默认不跑):`--break=no-identity` 把 cmd-bg.sh 的指纹核对那一行改成 `if false` 的**副本**
|
|
22
|
+
# —— 「pid 复用必须被拒」与「邻居必须活着」必须变红;`--break=no-boundary` 把记录解析器短路的
|
|
23
|
+
# 副本 —— 「穿越 id / 软链记录必须被拒且邻居活着」必须变红;`--break=no-dir-boundary` 把「bg 目录
|
|
24
|
+
# 自身也在项目内」的检查短路的副本 —— 「软链目录必须被拒且邻居活着」必须变红;
|
|
25
|
+
# `--break=read-side-pid-only` 把 **list 的判定**换回旧读法(只看 pid 活着 + 指纹,写面不动)的
|
|
26
|
+
# 副本 —— 「非平坦 id / pgid=0 / 实时组不符」三条形状在 list 里必须重新变成 holds。这是断侧,
|
|
27
|
+
# 用来证明断言不是空转。
|
|
28
|
+
#
|
|
29
|
+
# 纪律:清掉继承的团队身份与 tmux 身份;产物落 tmp_root_create 的私有根;每个作业/邻居都是夹具
|
|
30
|
+
# spawn、pid 记录在案,收尾**只按记录的 pid** 发信号(绝不按名字/模式)。夹具不起 tmux、不进容器。
|
|
31
|
+
set -uo pipefail
|
|
32
|
+
|
|
33
|
+
SELF_DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
34
|
+
SKILL_DIR="$(cd -P "$SELF_DIR/.." && pwd)"
|
|
35
|
+
REPO_ROOT="$(cd -P "$SKILL_DIR/../.." && pwd)"
|
|
36
|
+
# shellcheck source=lib/tmp-root.sh
|
|
37
|
+
. "$SELF_DIR/lib/tmp-root.sh"
|
|
38
|
+
|
|
39
|
+
BREAK=""; KEEP=0
|
|
40
|
+
while [ $# -gt 0 ]; do
|
|
41
|
+
case "$1" in
|
|
42
|
+
--break=*) BREAK="${1#--break=}"; shift ;;
|
|
43
|
+
--keep) KEEP=1; shift ;;
|
|
44
|
+
-h|--help) sed -n '2,30p' "$0"; exit 0 ;;
|
|
45
|
+
*) printf 'team-bg-stop: 未知参数 %s\n' "$1" >&2; exit 2 ;;
|
|
46
|
+
esac
|
|
47
|
+
done
|
|
48
|
+
case "$BREAK" in ''|no-identity|no-boundary|no-dir-boundary|read-side-pid-only) ;; *) printf 'team-bg-stop: --break 只认 no-identity / no-boundary / no-dir-boundary / read-side-pid-only(收到 %s)\n' "$BREAK" >&2; exit 2 ;; esac
|
|
49
|
+
[ "$KEEP" = "1" ] && export TEAM_TMP_KEEP=1
|
|
50
|
+
|
|
51
|
+
# ── 身份隔离:绝不继承调用者的团队/tmux 身份 ─────────────────────────────────────────────────
|
|
52
|
+
for _v in $(env | sed -n 's/^\(TEAM_[A-Za-z0-9_]*\)=.*/\1/p'); do
|
|
53
|
+
case "$_v" in TEAM_TMP_KEEP|TEAM_TMP_RUN_ID|TEAM_TMP_LEDGER) ;; *) unset "$_v" ;; esac
|
|
54
|
+
done
|
|
55
|
+
unset TMUX TMUX_PANE TMUX_TMPDIR 2>/dev/null || true
|
|
56
|
+
|
|
57
|
+
TMP="$(tmp_root_create team-bg-stop)" || exit 3
|
|
58
|
+
FAIL=0; PASS=0; FAILED=""
|
|
59
|
+
ok() { printf ' \033[32m✓\033[0m %s\n' "$1"; PASS=$((PASS + 1)); }
|
|
60
|
+
bad() { printf ' \033[31m✗\033[0m %s\n' "$1"; FAIL=$((FAIL + 1)); FAILED="${FAILED:+$FAILED, }$1"; }
|
|
61
|
+
hdr() { printf '\n== %s ==\n' "$1"; }
|
|
62
|
+
assert_eq() { [ "$2" = "$3" ] && ok "$1" || bad "$1(期望 [$3],实际 [$2])"; }
|
|
63
|
+
assert_has() { case "$2" in *"$3"*) ok "$1" ;; *) bad "$1([$2] 里没有 [$3])" ;; esac; }
|
|
64
|
+
assert_alive() { kill -0 "$2" 2>/dev/null && ok "$1" || bad "$1(pid $2 不在)"; }
|
|
65
|
+
assert_gone() { kill -0 "$2" 2>/dev/null && bad "$1(pid $2 还活着)" || ok "$1"; }
|
|
66
|
+
|
|
67
|
+
# ── 被夹具 spawn 的进程登记(收尾只按这些 pid 发信号)───────────────────────────────────────
|
|
68
|
+
SPAWNED=()
|
|
69
|
+
spawn_group_job() { # <child-pid-file> → leader pid(新会话:pgid == pid);组里再留一个真子孙
|
|
70
|
+
setsid bash -c 'sleep 300 & echo $! > "$1"; wait' _ "$1" >/dev/null 2>&1 &
|
|
71
|
+
printf '%s\n' "$!"
|
|
72
|
+
}
|
|
73
|
+
spawn_neighbour() { # → pid(登记在案、**不写进任何记录**的邻居)
|
|
74
|
+
setsid sleep 300 >/dev/null 2>&1 &
|
|
75
|
+
printf '%s\n' "$!"
|
|
76
|
+
}
|
|
77
|
+
cleanup() {
|
|
78
|
+
local p
|
|
79
|
+
for p in ${SPAWNED[@]+"${SPAWNED[@]}"}; do
|
|
80
|
+
[ -n "$p" ] && kill -KILL "$p" 2>/dev/null || true
|
|
81
|
+
done
|
|
82
|
+
[ "$KEEP" = "1" ] || tmp_root_reap_all
|
|
83
|
+
}
|
|
84
|
+
trap cleanup EXIT
|
|
85
|
+
|
|
86
|
+
# /proc/<pid>/stat 的 comm 之后第 <i> 个词(0 起):i=2 是 pgid(字段 5),i=19 是启动时间(字段 22)
|
|
87
|
+
proc_word() {
|
|
88
|
+
local _stat _rest; local -a _f=()
|
|
89
|
+
_stat="$(cat "/proc/$1/stat" 2>/dev/null)" || return 1
|
|
90
|
+
_rest="${_stat##*)}"; read -r -a _f <<< "$_rest"
|
|
91
|
+
printf '%s\n' "${_f[$2]:-}"
|
|
92
|
+
}
|
|
93
|
+
now_start() { proc_word "$1" 19; }
|
|
94
|
+
|
|
95
|
+
# ── 夹具项目:一个真 git 仓库 + .pi/team/config.sh(state 就在它下面)─────────────────────────
|
|
96
|
+
ROOT="$TMP/repo"; STATE="$ROOT/.pi/team/state"; BGD="$STATE/bg"
|
|
97
|
+
mkdir -p "$ROOT" "$BGD"
|
|
98
|
+
( cd "$ROOT" && git init -q -b main ) >/dev/null 2>&1 || true
|
|
99
|
+
printf 'TEAM_PROJECT="p159-bg-stop"\n' > "$ROOT/.pi/team/config.sh"
|
|
100
|
+
# 兄弟 state 目录:里面也有一个 id 相同的记录 —— 本项目**不许**看见它(RA3 的边界)
|
|
101
|
+
OTHER="$TMP/other"; OTHER_BGD="$OTHER/.pi/team/state/bg"
|
|
102
|
+
mkdir -p "$OTHER_BGD"
|
|
103
|
+
printf 'TEAM_PROJECT="p159-other"\n' > "$OTHER/.pi/team/config.sh"
|
|
104
|
+
|
|
105
|
+
TEAM="$SKILL_DIR/scripts/team"
|
|
106
|
+
if [ -n "$BREAK" ]; then
|
|
107
|
+
# 红侧:scripts/ 的副本 + 只改一处(每个 --break 一个断点)
|
|
108
|
+
MUT="$TMP/skill"; mkdir -p "$MUT"
|
|
109
|
+
cp -a "$SKILL_DIR/scripts" "$MUT/scripts"
|
|
110
|
+
case "$BREAK" in
|
|
111
|
+
no-identity)
|
|
112
|
+
sed -i 's#^ if \[ "\$now_start" != "\$start" \]; then$# if false; then#' "$MUT/scripts/lib/cmd-bg.sh"
|
|
113
|
+
if grep -qx ' if false; then' "$MUT/scripts/lib/cmd-bg.sh"; then
|
|
114
|
+
printf '红侧:cmd-bg.sh 副本的指纹核对已改成 if false(%s)\n' "$MUT/scripts/lib/cmd-bg.sh"
|
|
115
|
+
else
|
|
116
|
+
printf '✗ 红侧不成立:sed 没改到共享判定里的指纹核对那一行\n' >&2; exit 2
|
|
117
|
+
fi ;;
|
|
118
|
+
no-boundary)
|
|
119
|
+
# 把记录解析器短路:不再要求「平坦 id / 本项目 bg 目录里的正规文件 / realpath 仍在目录内」
|
|
120
|
+
sed -i 's#^ local _id="\$1" _d="\$2" _f _dreal _freal$# printf "%s" "$2/$1.job"; return 0#' "$MUT/scripts/lib/cmd-bg.sh"
|
|
121
|
+
if grep -q 'printf "%s" "\$2/\$1.job"; return 0' "$MUT/scripts/lib/cmd-bg.sh"; then
|
|
122
|
+
printf '红侧:cmd-bg.sh 副本的记录边界解析已短路(%s)\n' "$MUT/scripts/lib/cmd-bg.sh"
|
|
123
|
+
else
|
|
124
|
+
printf '✗ 红侧不成立:sed 没改到 team_bg_record_resolve 的第一行\n' >&2; exit 2
|
|
125
|
+
fi ;;
|
|
126
|
+
no-dir-boundary)
|
|
127
|
+
# 把「bg 目录自身也必须在项目 state 内」短路成恒真:软链目录里的记录照常被解析、被停
|
|
128
|
+
sed -i 's#^ local _d="\$1" _sreal _dreal$# printf "%s" "$1"; return 0#' "$MUT/scripts/lib/cmd-bg.sh"
|
|
129
|
+
if grep -q 'printf "%s" "\$1"; return 0' "$MUT/scripts/lib/cmd-bg.sh"; then
|
|
130
|
+
printf '红侧:cmd-bg.sh 副本的 bg 目录边界检查已短路(%s)\n' "$MUT/scripts/lib/cmd-bg.sh"
|
|
131
|
+
else
|
|
132
|
+
printf '✗ 红侧不成立:sed 没改到 team_bg_dir_resolve 的第一行\n' >&2; exit 2
|
|
133
|
+
fi ;;
|
|
134
|
+
read-side-pid-only)
|
|
135
|
+
# 把 **list 的判定**换回旧读法(只要 pid 活着 + 指纹一致就说 holds):写面一个字节不动,
|
|
136
|
+
# 于是「非平坦 id / pgid=0 / 实时组不符」三条形状在 list 里必须重新变成 identity=holds。
|
|
137
|
+
sed -i 's#^ team_bg_check_record "\$id" "\$d" || true$# team_bg_read_side_legacy "$id" "$d"#' "$MUT/scripts/lib/cmd-bg.sh"
|
|
138
|
+
cat >> "$MUT/scripts/lib/cmd-bg.sh" <<'SHADOW'
|
|
139
|
+
|
|
140
|
+
# ── 影子(夹具注入,只存在于副本里):P195 之前 list 自己的读法 —— 只看 pid 活着 + 指纹 ──────
|
|
141
|
+
team_bg_read_side_legacy() { # <id> <bg-dir>
|
|
142
|
+
local _id="$1" _d="$2" _f _pid _pgid _start
|
|
143
|
+
_f="$_d/$_id.job"
|
|
144
|
+
TEAM_BG_VERDICT="unusable"; TEAM_BG_REASON=""
|
|
145
|
+
_pid="$(team_bg_record_get "$_f" pid || true)"
|
|
146
|
+
_pgid="$(team_bg_record_get "$_f" pgid || true)"
|
|
147
|
+
_start="$(team_bg_record_get "$_f" start || true)"
|
|
148
|
+
TEAM_BG_PID="$_pid"; TEAM_BG_PGID="$_pgid"; TEAM_BG_START="$_start"
|
|
149
|
+
TEAM_BG_CMD="$(team_bg_record_get "$_f" cmd || true)"
|
|
150
|
+
case "$_pid" in
|
|
151
|
+
''|*[!0-9]*) TEAM_BG_VERDICT="malformed" ;;
|
|
152
|
+
*)
|
|
153
|
+
if ! team_bg_pid_alive "$_pid"; then TEAM_BG_VERDICT="gone"
|
|
154
|
+
elif [ -n "$_start" ] && [ "$(team_bg_start_of "$_pid")" = "$_start" ]; then TEAM_BG_VERDICT="holds"
|
|
155
|
+
else TEAM_BG_VERDICT="mismatch"
|
|
156
|
+
fi ;;
|
|
157
|
+
esac
|
|
158
|
+
return 0
|
|
159
|
+
}
|
|
160
|
+
SHADOW
|
|
161
|
+
if grep -qF ' team_bg_read_side_legacy "$id" "$d"' "$MUT/scripts/lib/cmd-bg.sh"; then
|
|
162
|
+
printf '红侧:cmd-bg.sh 副本的 list 判定已换回旧读法(只看 pid 活着 + 指纹)(%s)\n' "$MUT/scripts/lib/cmd-bg.sh"
|
|
163
|
+
else
|
|
164
|
+
printf '✗ 红侧不成立:sed 没改到 list 的判定调用行\n' >&2; exit 2
|
|
165
|
+
fi ;;
|
|
166
|
+
esac
|
|
167
|
+
TEAM="$MUT/scripts/team"
|
|
168
|
+
fi
|
|
169
|
+
|
|
170
|
+
write_record() { # <id> <pid> <pgid> <start> [cmd]
|
|
171
|
+
printf 'id=%s\npid=%s\npgid=%s\nstart=%s\ncwd=%s\nlog=%s\ncmd=%s\n' \
|
|
172
|
+
"$1" "$2" "$3" "$4" "$ROOT" "$BGD/$1.log" "${5:-sleep 300}" > "$BGD/$1.job"
|
|
173
|
+
}
|
|
174
|
+
bg() { ( cd "$ROOT" && env -u TEAM_ROOT -u TEAM_MAIN_ROOT -u TEAM_PROJECT -u TEAM_SESSION -u TEAM_STATE_DIR \
|
|
175
|
+
"$TEAM" --root "$ROOT" bg "$@" ) 2>&1; }
|
|
176
|
+
bg_rc() { ( cd "$ROOT" && env -u TEAM_ROOT -u TEAM_MAIN_ROOT -u TEAM_PROJECT -u TEAM_SESSION -u TEAM_STATE_DIR \
|
|
177
|
+
"$TEAM" --root "$ROOT" bg "$@" ) >/dev/null 2>&1; printf '%s\n' "$?"; }
|
|
178
|
+
bg_timeout() { # <秒> <bg 参数…>:给「非正规记录不许挂住」这条腿一个硬上界
|
|
179
|
+
local _t="$1"; shift
|
|
180
|
+
( cd "$ROOT" && env -u TEAM_ROOT -u TEAM_MAIN_ROOT -u TEAM_PROJECT -u TEAM_SESSION -u TEAM_STATE_DIR \
|
|
181
|
+
timeout "$_t" "$TEAM" --root "$ROOT" bg "$@" ) 2>&1
|
|
182
|
+
}
|
|
183
|
+
# 读面断言的小工具(P195):从 list 输出里取一行 / 取原因句,再与写面的诊断逐字比对。
|
|
184
|
+
list_row() { printf '%s\n' "$1" | awk -v id="$2" 'index($0, id " ") == 1 { print; exit }'; }
|
|
185
|
+
stop_reason() { local _l; _l="$(printf '%s\n' "$1" | head -n1)"; printf '%s\n' "${_l#*bg stop: }"; }
|
|
186
|
+
list_reason() { # <list 输出> <id>
|
|
187
|
+
local _l _p="! bg list: $2:"
|
|
188
|
+
_l="$(printf '%s\n' "$1" | grep -F -m1 -- "$_p")"
|
|
189
|
+
printf '%s\n' "${_l#"$_p"}"
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
# ══════════════════════════════════════════════════════════════════════════════════════════════
|
|
193
|
+
hdr "RA3 · 真作业按记录停掉:job 死、邻居活、账本留痕"
|
|
194
|
+
JOB="job1"; CHILD_PID_FILE="$TMP/job1-child.pid"
|
|
195
|
+
JPID="$(spawn_group_job "$CHILD_PID_FILE")"; SPAWNED+=("$JPID")
|
|
196
|
+
NPID="$(spawn_neighbour)"; SPAWNED+=("$NPID")
|
|
197
|
+
sleep 0.3
|
|
198
|
+
JPGID="$(proc_word "$JPID" 2)"; JSTART="$(now_start "$JPID")"
|
|
199
|
+
JCHILD="$(cat "$CHILD_PID_FILE" 2>/dev/null || true)"
|
|
200
|
+
assert_alive "夹具前提:作业 leader 活着" "$JPID"
|
|
201
|
+
assert_eq "夹具前提:leader 是组头(pgid == pid)" "$JPGID" "$JPID"
|
|
202
|
+
assert_alive "夹具前提:组里的子孙也活着" "${JCHILD:-0}"
|
|
203
|
+
assert_alive "夹具前提:邻居活着" "$NPID"
|
|
204
|
+
write_record "$JOB" "$JPID" "$JPGID" "$JSTART" "sleep 300"
|
|
205
|
+
SPAWNED+=("${JCHILD:-0}")
|
|
206
|
+
|
|
207
|
+
LIST="$(bg list)"
|
|
208
|
+
assert_has "list 里作业行标 identity=holds" "$LIST" "identity=holds"
|
|
209
|
+
assert_has "list 行带 pid 与 cmd" "$LIST" "pid=$JPID"
|
|
210
|
+
BEFORE_LOG_LINES="$(wc -l < "$STATE/bg.log" 2>/dev/null | tr -dc '0-9' || true)"
|
|
211
|
+
BEFORE_LOG_LINES="${BEFORE_LOG_LINES:-0}"
|
|
212
|
+
OUT="$(bg stop "$JOB")"; RC=$?
|
|
213
|
+
assert_eq "team bg stop job1 退出 0" "$RC" "0"
|
|
214
|
+
assert_has "输出点名 job/signal/result" "$OUT" "signal=TERM"
|
|
215
|
+
assert_has "输出说 result=stopped" "$OUT" "result=stopped"
|
|
216
|
+
assert_has "输出点名被停的命令" "$OUT" "cmd: sleep 300"
|
|
217
|
+
assert_gone "作业 leader 已被停掉" "$JPID"
|
|
218
|
+
assert_alive "没有记录的邻居仍然活着(只停了记录里的那个)" "$NPID"
|
|
219
|
+
assert_has "state/bg.log 记下 stop 行(job/signal/result)" "$(cat "$STATE/bg.log" 2>/dev/null)" " stop id=$JOB signal=TERM result=stopped "
|
|
220
|
+
AFTER_LOG_LINES="$(wc -l < "$STATE/bg.log" 2>/dev/null | tr -dc '0-9' || true)"
|
|
221
|
+
AFTER_LOG_LINES="${AFTER_LOG_LINES:-0}"
|
|
222
|
+
assert_eq "stop 只追了 1 行账本" "$((AFTER_LOG_LINES - BEFORE_LOG_LINES))" "1"
|
|
223
|
+
sleep 0.3
|
|
224
|
+
|
|
225
|
+
hdr "RA3 · 无记录 → 3,什么都没发"
|
|
226
|
+
OUT="$(bg stop nope)"; RC=$?
|
|
227
|
+
assert_eq "无记录的 id 退出 3" "$RC" "3"
|
|
228
|
+
assert_has "理由点名 state 里的路径" "$OUT" "$BGD/nope.job"
|
|
229
|
+
assert_has "理由说清不按名字/进程树找" "$OUT" "不按名字/命令行/进程树找进程"
|
|
230
|
+
assert_alive "邻居照旧活着" "$NPID"
|
|
231
|
+
|
|
232
|
+
hdr "RA3 · 记录畸形 → 4,什么都没发"
|
|
233
|
+
printf 'id=bad\npid=abc\npgid=1\nstart=1\n' > "$BGD/bad.job"
|
|
234
|
+
OUT="$(bg stop bad)"; RC=$?
|
|
235
|
+
assert_eq "pid 不是数字 → 4" "$RC" "4"
|
|
236
|
+
assert_has "理由点名记录畸形" "$OUT" "记录畸形"
|
|
237
|
+
assert_alive "邻居照旧活着" "$NPID"
|
|
238
|
+
|
|
239
|
+
hdr "RA3 · pid 复用(指纹对不上)→ 5,什么都没发"
|
|
240
|
+
write_record reused "$NPID" "$NPID" "1" "sleep 300"
|
|
241
|
+
OUT="$(bg stop reused)"; RC=$?
|
|
242
|
+
assert_eq "指纹对不上 → 5" "$RC" "5"
|
|
243
|
+
assert_has "理由点名启动时间指纹" "$OUT" "启动时间指纹对不上"
|
|
244
|
+
assert_alive "记录里的 pid 指向的**真进程**没有被误杀" "$NPID"
|
|
245
|
+
|
|
246
|
+
hdr "RA3 · 记录只认本项目 state:兄弟目录里的 id 找不到"
|
|
247
|
+
OTHER_PID="$(spawn_neighbour)"; SPAWNED+=("$OTHER_PID")
|
|
248
|
+
printf 'id=sibling\npid=%s\npgid=%s\nstart=%s\ncwd=%s\nlog=%s\ncmd=sleep 300\n' \
|
|
249
|
+
"$OTHER_PID" "$(proc_word "$OTHER_PID" 2)" "$(now_start "$OTHER_PID")" "$OTHER" "$OTHER_BGD/sibling.log" > "$OTHER_BGD/sibling.job"
|
|
250
|
+
OUT="$(bg stop sibling)"; RC=$?
|
|
251
|
+
assert_eq "兄弟 state 里的 id 在本项目 → 3" "$RC" "3"
|
|
252
|
+
assert_alive "兄弟记录的进程没有被本项目动到" "$OTHER_PID"
|
|
253
|
+
case "$(bg list)" in *sibling*) bad "list 里出现了兄弟 state 目录的作业" ;; *) ok "list 不列兄弟 state 目录的作业" ;; esac
|
|
254
|
+
|
|
255
|
+
hdr "F1 · 记录必须留在本项目里:穿越 id / 软链都拒,邻居活着"
|
|
256
|
+
# ① 邻居的记录 + id 里带路径(PM 的形状):id 不是平坦名字 → 2,记录没有被解析
|
|
257
|
+
OUT_PID="$(spawn_neighbour)"; SPAWNED+=("$OUT_PID")
|
|
258
|
+
printf 'id=outside\npid=%s\npgid=%s\nstart=%s\ncwd=%s\nlog=%s\ncmd=sleep 300\n' \
|
|
259
|
+
"$OUT_PID" "$(proc_word "$OUT_PID" 2)" "$(now_start "$OUT_PID")" "$OTHER" "$OTHER_BGD/outside.log" > "$OTHER_BGD/outside.job"
|
|
260
|
+
TRAV_ID="$(realpath --relative-to="$BGD" "$OTHER_BGD" 2>/dev/null)/outside"
|
|
261
|
+
case "$TRAV_ID" in */*) ok "夹具前提:穿越 id 带路径分隔符($TRAV_ID)" ;; *) bad "夹具前提:没算出带路径的 id" ;; esac
|
|
262
|
+
OUT="$(bg stop "$TRAV_ID")"; RC=$?
|
|
263
|
+
assert_eq "① 路径穿越的 id → 2(id 没有路径语义)" "$RC" "2"
|
|
264
|
+
assert_has "① 诊断点名「平坦名字」" "$OUT" "平坦名字"
|
|
265
|
+
assert_alive "① 邻居记录没有被本项目执行(pid 活着)" "$OUT_PID"
|
|
266
|
+
# ② 软链记录(PM 的形状):bg/ 里一个指向邻居记录的软链 → 4,邻居活着
|
|
267
|
+
LINK_PID="$(spawn_neighbour)"; SPAWNED+=("$LINK_PID")
|
|
268
|
+
printf 'id=linked-target\npid=%s\npgid=%s\nstart=%s\ncwd=%s\nlog=%s\ncmd=sleep 300\n' \
|
|
269
|
+
"$LINK_PID" "$(proc_word "$LINK_PID" 2)" "$(now_start "$LINK_PID")" "$OTHER" "$OTHER_BGD/linked.log" > "$OTHER_BGD/linked.job"
|
|
270
|
+
ln -s "$OTHER_BGD/linked.job" "$BGD/linked.job"
|
|
271
|
+
OUT="$(bg stop linked)"; RC=$?
|
|
272
|
+
assert_eq "② 软链记录 → 4(不是本项目的正规文件)" "$RC" "4"
|
|
273
|
+
assert_has "② 诊断点名「正规记录」" "$OUT" "正规记录"
|
|
274
|
+
assert_alive "② 软链指向的邻居进程没有被误杀" "$LINK_PID"
|
|
275
|
+
LIST_SKIP="$(bg list)"
|
|
276
|
+
if printf '%s\n' "$LIST_SKIP" | grep -q '^linked '; then
|
|
277
|
+
bad "list 列出了软链记录(越界的记录不许出现在本项目视图里)"
|
|
278
|
+
else
|
|
279
|
+
ok "list 不列软链记录(只有跳过告警)"
|
|
280
|
+
fi
|
|
281
|
+
# ③ 反向:本项目自己的正规记录照常收(名字里带 . 与 - 也不误伤)
|
|
282
|
+
FLAT_JOB="job.2-fine"; FLATF="$TMP/flat-child.pid"
|
|
283
|
+
FPID="$(spawn_group_job "$FLATF")"; SPAWNED+=("$FPID")
|
|
284
|
+
sleep 0.3
|
|
285
|
+
write_record "$FLAT_JOB" "$FPID" "$FPID" "$(now_start "$FPID")" "sleep 300"
|
|
286
|
+
OUT="$(bg stop "$FLAT_JOB")"; RC=$?
|
|
287
|
+
assert_eq "③ 平坦名字(含 . 与 -)的正规记录照常收作业 → 0" "$RC" "0"
|
|
288
|
+
assert_has "③ 输出说 result=stopped" "$OUT" "result=stopped"
|
|
289
|
+
assert_gone "③ 作业被停掉" "$FPID"
|
|
290
|
+
|
|
291
|
+
hdr "F2 · 畸形记录一致 fail-closed:pgid=0 与 FIFO 都拒、有界"
|
|
292
|
+
# pgid=0(Linux 的进程组 id 必为正):pid/start 都对,只有 pgid 畸形 → 4,零信号
|
|
293
|
+
write_record zero "$NPID" "0" "$(now_start "$NPID")" "sleep 300"
|
|
294
|
+
OUT="$(bg stop zero)"; RC=$?
|
|
295
|
+
assert_eq "pgid=0 → 4(pid/pgid 必须正整数)" "$RC" "4"
|
|
296
|
+
assert_has "诊断点名 pgid" "$OUT" "pgid"
|
|
297
|
+
assert_alive "记录里的真进程没有被误杀" "$NPID"
|
|
298
|
+
# FIFO 记录:读取之前就要拒(`-f` 且非 FIFO),不许挂住
|
|
299
|
+
mkfifo "$BGD/fifo.job"
|
|
300
|
+
OUT="$(bg_timeout 5 stop fifo)"; RC=$?
|
|
301
|
+
assert_eq "FIFO 记录 → 4(拒绝在读之前,rc 不是 124)" "$RC" "4"
|
|
302
|
+
assert_has "诊断点名「正规记录」" "$OUT" "正规记录"
|
|
303
|
+
case "$(bg list)" in *fifo*) bad "list 列出了 FIFO 记录" ;; *) ok "list 不列 FIFO 记录" ;; esac
|
|
304
|
+
|
|
305
|
+
hdr "P189 · F1:读面与写面同一条规则(list 不许说「成立」,原因句与 stop 逐字相同)"
|
|
306
|
+
# 三条形状**逐字**用第三轮复验的夹具(docs/team/reports/P189-verify/pkg/verify.py §20):
|
|
307
|
+
# ① 记录名/id 带空格(非平坦 id)② pgid=0 ③ 实时进程组与记录不符。
|
|
308
|
+
# 每条都双向:stop 拒绝(2/4/5、零信号、邻居活着)+ list 行不再说 identity=holds + 两边的原因句相同。
|
|
309
|
+
RSTART="$(now_start "$NPID")"
|
|
310
|
+
# ① 非平坦 id(验证者的 `two words` 形状:文件 two words.job + id=two words)
|
|
311
|
+
write_record "two words" "$NPID" "$NPID" "$RSTART" "sleep 300"
|
|
312
|
+
OUT="$(bg stop "two words")"; RC=$?
|
|
313
|
+
assert_eq "① stop 'two words' → 2(非平坦 id)" "$RC" "2"
|
|
314
|
+
assert_alive "① 记录里的真进程没有被误杀" "$NPID"
|
|
315
|
+
LISTV="$(bg list)"; ROW="$(list_row "$LISTV" "two words")"
|
|
316
|
+
case "$ROW" in
|
|
317
|
+
*identity=holds*) bad "① list 对非平坦 id 说了 identity=holds(读面说谎)" ;;
|
|
318
|
+
*identity=unusable*) ok "① list 标 identity=unusable(不再说成立)" ;;
|
|
319
|
+
*) bad "① list 行没有给出不可用判定([$ROW])" ;;
|
|
320
|
+
esac
|
|
321
|
+
assert_eq "① list 与 stop 打的是同一句原因" "$(list_reason "$LISTV" "two words")" "$(stop_reason "$OUT")"
|
|
322
|
+
# ② pgid=0(验证者的 pgid-zero-list 形状)
|
|
323
|
+
write_record pgid-zero-list "$NPID" 0 "$RSTART" "sleep 300"
|
|
324
|
+
OUT="$(bg stop pgid-zero-list)"; RC=$?
|
|
325
|
+
assert_eq "② stop pgid=0 → 4(pid/pgid 必须正整数)" "$RC" "4"
|
|
326
|
+
assert_alive "② 记录里的真进程没有被误杀" "$NPID"
|
|
327
|
+
LISTV="$(bg list)"; ROW="$(list_row "$LISTV" pgid-zero-list)"
|
|
328
|
+
case "$ROW" in
|
|
329
|
+
*identity=holds*) bad "② list 对 pgid=0 说了 identity=holds(读面说谎)" ;;
|
|
330
|
+
*identity=unusable*) ok "② list 标 identity=unusable(不再说成立)" ;;
|
|
331
|
+
*) bad "② list 行没有给出不可用判定([$ROW])" ;;
|
|
332
|
+
esac
|
|
333
|
+
assert_eq "② list 与 stop 打的是同一句原因" "$(list_reason "$LISTV" pgid-zero-list)" "$(stop_reason "$OUT")"
|
|
334
|
+
# ③ 实时进程组与记录不符(验证者的 group-mismatch 形状)
|
|
335
|
+
write_record group-mismatch "$NPID" "$((NPID + 1))" "$RSTART" "sleep 300"
|
|
336
|
+
OUT="$(bg stop group-mismatch)"; RC=$?
|
|
337
|
+
assert_eq "③ stop 实时组不符 → 5(进程组身份对不上)" "$RC" "5"
|
|
338
|
+
assert_alive "③ 记录里的真进程没有被误杀" "$NPID"
|
|
339
|
+
LISTV="$(bg list)"; ROW="$(list_row "$LISTV" group-mismatch)"
|
|
340
|
+
case "$ROW" in
|
|
341
|
+
*identity=holds*) bad "③ list 对实时组不符说了 identity=holds(读面说谎)" ;;
|
|
342
|
+
*identity=mismatch*) ok "③ list 标 identity=mismatch(与写面 rc=5 同一张表)" ;;
|
|
343
|
+
*) bad "③ list 行没有给出身份判定([$ROW])" ;;
|
|
344
|
+
esac
|
|
345
|
+
assert_eq "③ list 与 stop 打的是同一句原因" "$(list_reason "$LISTV" group-mismatch)" "$(stop_reason "$OUT")"
|
|
346
|
+
# ④ 反向(不许误伤):正规记录 → list 仍是 holds 且 stop 照常收
|
|
347
|
+
P195F="$TMP/p195-child.pid"; P195PID="$(spawn_group_job "$P195F")"; SPAWNED+=("$P195PID")
|
|
348
|
+
sleep 0.3
|
|
349
|
+
P195CHILD="$(cat "$P195F" 2>/dev/null || true)"; [ -n "$P195CHILD" ] && SPAWNED+=("$P195CHILD")
|
|
350
|
+
write_record p195-ok "$P195PID" "$P195PID" "$(now_start "$P195PID")" "sleep 300"
|
|
351
|
+
LISTV="$(bg list)"; ROW="$(list_row "$LISTV" p195-ok)"
|
|
352
|
+
case "$ROW" in
|
|
353
|
+
*identity=holds*) ok "④ 反向:正规记录在 list 里仍是 identity=holds" ;;
|
|
354
|
+
*) bad "④ 反向:正规记录没有被标成 holds([$ROW])" ;;
|
|
355
|
+
esac
|
|
356
|
+
OUT="$(bg stop p195-ok)"; RC=$?
|
|
357
|
+
assert_eq "④ 反向:正规记录照常收作业 → 0" "$RC" "0"
|
|
358
|
+
assert_gone "④ 反向:作业被停掉(新判定没有误伤)" "$P195PID"
|
|
359
|
+
|
|
360
|
+
hdr "F1' · bg 目录自身必须在项目内:软链目录读写两侧都拒,兄弟进程活着"
|
|
361
|
+
# 现场(P175 的 finding F1'):state/bg 指到兄弟项目的 bg 目录 —— 记录解析两侧 realpath 一起落到
|
|
362
|
+
# 同一处,「在 bg 目录内」自洽通过。目录这一层单独收口:stop 与 list 同一条规则,都拒绝并点名目标。
|
|
363
|
+
SYM_PID="$(spawn_neighbour)"; SPAWNED+=("$SYM_PID")
|
|
364
|
+
printf 'id=symdir\npid=%s\npgid=%s\nstart=%s\ncwd=%s\nlog=%s\ncmd=sleep 300\n' \
|
|
365
|
+
"$SYM_PID" "$(proc_word "$SYM_PID" 2)" "$(now_start "$SYM_PID")" "$OTHER" "$OTHER_BGD/symdir.log" > "$OTHER_BGD/symdir.job"
|
|
366
|
+
rm -rf "$BGD"; ln -s "$OTHER_BGD" "$BGD"
|
|
367
|
+
assert_eq "夹具前提:state/bg 现在是指向兄弟 bg 目录的软链" "$(readlink "$BGD")" "$OTHER_BGD"
|
|
368
|
+
assert_alive "夹具前提:兄弟记录里的进程活着" "$SYM_PID"
|
|
369
|
+
SYM_LOG_BEFORE="$(wc -l < "$STATE/bg.log" 2>/dev/null | tr -dc '0-9' || true)"; SYM_LOG_BEFORE="${SYM_LOG_BEFORE:-0}"
|
|
370
|
+
OUT="$(bg stop symdir)"; RC=$?
|
|
371
|
+
assert_eq "① 软链 bg 目录里的记录 → 4(目录自身越界)" "$RC" "4"
|
|
372
|
+
assert_has "① 诊断点名 state/bg 的解析目标" "$OUT" "$OTHER_BGD"
|
|
373
|
+
assert_alive "① 兄弟项目的真进程仍然活着(目录越界 → 什么都没发)" "$SYM_PID"
|
|
374
|
+
SYM_LOG_AFTER="$(wc -l < "$STATE/bg.log" 2>/dev/null | tr -dc '0-9' || true)"; SYM_LOG_AFTER="${SYM_LOG_AFTER:-0}"
|
|
375
|
+
assert_eq "① 拒绝没有写账本(没有 stop 行)" "$SYM_LOG_AFTER" "$SYM_LOG_BEFORE"
|
|
376
|
+
OUT="$(bg list)"; RC=$?
|
|
377
|
+
assert_eq "② bg list 同一收口 → 4(不列软链目录里的记录)" "$RC" "4"
|
|
378
|
+
assert_has "② list 的诊断同样点名解析目标" "$OUT" "$OTHER_BGD"
|
|
379
|
+
case "$OUT" in *symdir*) bad "② list 列出了软链目录里的兄弟记录" ;; *) ok "② list 不列软链目录里的记录" ;; esac
|
|
380
|
+
# 反向:恢复真目录 → 照常收作业(新检查不许误伤正常形态)
|
|
381
|
+
rm -f "$BGD"; mkdir -p "$BGD"
|
|
382
|
+
REV_JOB="job.3-rev"; REVF="$TMP/rev-child.pid"
|
|
383
|
+
RPID="$(spawn_group_job "$REVF")"; SPAWNED+=("$RPID")
|
|
384
|
+
sleep 0.3
|
|
385
|
+
write_record "$REV_JOB" "$RPID" "$RPID" "$(now_start "$RPID")" "sleep 300"
|
|
386
|
+
OUT="$(bg stop "$REV_JOB")"; RC=$?
|
|
387
|
+
assert_eq "③ 反向:真目录(非软链)照常收作业 → 0" "$RC" "0"
|
|
388
|
+
assert_has "③ 输出说 result=stopped" "$OUT" "result=stopped"
|
|
389
|
+
assert_gone "③ 作业被停掉" "$RPID"
|
|
390
|
+
|
|
391
|
+
hdr "RA3 · 已结束的 leader:rc=0,不追猎活着的子孙"
|
|
392
|
+
GONE_JOB="gone1"; GCPIDF="$TMP/gone1-child.pid"
|
|
393
|
+
GPID="$(spawn_group_job "$GCPIDF")"; SPAWNED+=("$GPID")
|
|
394
|
+
sleep 0.3
|
|
395
|
+
GCHILD="$(cat "$GCPIDF" 2>/dev/null || true)"; SPAWNED+=("${GCHILD:-0}")
|
|
396
|
+
write_record "$GONE_JOB" "$GPID" "$GPID" "$(now_start "$GPID")" "sleep 300"
|
|
397
|
+
kill -KILL "$GPID" 2>/dev/null || true; sleep 0.2
|
|
398
|
+
assert_gone "夹具前提:leader 已经不在了" "$GPID"
|
|
399
|
+
OUT="$(bg stop "$GONE_JOB")"; RC=$?
|
|
400
|
+
assert_eq "leader 已走 → 0(什么都没发)" "$RC" "0"
|
|
401
|
+
assert_has "明说子孙不会被追猎" "$OUT" "子孙不会被追猎"
|
|
402
|
+
assert_alive "活着的子孙留在原地(本车道不搜索进程)" "${GCHILD:-0}"
|
|
403
|
+
case "$(bg list)" in *"$GONE_JOB"*identity=gone*) ok "list 把这个作业标成 identity=gone" ;; *) bad "list 没有把已走 leader 标成 identity=gone" ;; esac
|
|
404
|
+
|
|
405
|
+
hdr "RA3 · 用法:没有子命令 / stop 缺 id → 2"
|
|
406
|
+
OUT="$(bg 2>&1)"; RC=$?
|
|
407
|
+
assert_eq "team bg 无子命令 → 2" "$RC" "2"
|
|
408
|
+
assert_has "打用法行(点名两个子命令)" "$OUT" "需要一个子命令"
|
|
409
|
+
assert_has "用法行里给出 list" "$OUT" "list | stop"
|
|
410
|
+
OUT="$(bg stop)"; RC=$?
|
|
411
|
+
assert_eq "team bg stop 缺 id → 2" "$RC" "2"
|
|
412
|
+
assert_has "用法行点名 job id 从哪来" "$OUT" "team bg list 看全部"
|
|
413
|
+
|
|
414
|
+
# ══════════════════════════════════════════════════════════════════════════════════════════════
|
|
415
|
+
if [ -n "$BREAK" ]; then
|
|
416
|
+
printf '\n== 红侧(--break=%s)==\n' "$BREAK"
|
|
417
|
+
if [ "$FAIL" -gt 0 ]; then
|
|
418
|
+
printf '红侧成立:%d 条断言变红 —— %s\n' "$FAIL" "$FAILED"
|
|
419
|
+
case "$BREAK" in
|
|
420
|
+
no-identity) printf '(跳过指纹核对后,记录里的 pid 被直接当身份:pid 复用场景不再被拒、邻居被误杀)\n' ;;
|
|
421
|
+
no-boundary) printf '(短路记录边界解析后,穿越 id / 软链记录都能走到邻居的记录并停掉它)\n' ;;
|
|
422
|
+
no-dir-boundary) printf '(短路 bg 目录边界检查后,软链目录里的兄弟记录被接受并真的停掉了兄弟进程)\n' ;;
|
|
423
|
+
read-side-pid-only) printf '(把 list 的判定换回旧读法后,非平坦 id / pgid=0 / 实时组不符 三条形状在 list 里又都变成 identity=holds)\n' ;;
|
|
424
|
+
esac
|
|
425
|
+
exit 1
|
|
426
|
+
fi
|
|
427
|
+
printf '✗ 红侧不成立:动了副本(%s)之后,夹具居然还是绿的\n' "$BREAK"
|
|
428
|
+
exit 1
|
|
429
|
+
fi
|
|
430
|
+
|
|
431
|
+
printf '\n== team-bg-stop 结果 == ✓ %d ✗ %d\n' "$PASS" "$FAIL"
|
|
432
|
+
[ "$FAIL" -eq 0 ] && { printf '\033[32mteam-bg-stop 全绿\033[0m\n'; exit 0; }
|
|
433
|
+
printf '\033[31mteam-bg-stop 有失败项(--keep 保留现场 %s)\033[0m\n' "$TMP"
|
|
434
|
+
exit 1
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# M30 · team-inbox-watch 扩展的翻转复现(红 → 绿)
|
|
3
|
+
#
|
|
4
|
+
# bash skills/teamsmith/tests/team-inbox-watch-flip.sh [--keep]
|
|
5
|
+
# TEAM_FLIP_BASE=<sha> bash skills/teamsmith/tests/team-inbox-watch-flip.sh # 默认 merge-base HEAD main
|
|
6
|
+
#
|
|
7
|
+
# 红(两种,都要有):
|
|
8
|
+
# ① 修复前的树(BASE,M30 之前)没有 extension/team-inbox-watch.ts —— 换道根本不存在,夹具必须报 import 失败;
|
|
9
|
+
# ② 七个定点破坏(每个只改一行):合并成一条 / 唤醒投递方式 / 启动基线 / 注册里的 cwd(发送方的判据)/
|
|
10
|
+
# 预览截断 / shutdown 清场(外加 trim 之后的 offset 对账)—— 每个都必须让夹具里**对应用例**变红。
|
|
11
|
+
# 破坏没生效(sed 没匹配上)= 假红,直接判失败。
|
|
12
|
+
# 绿:当前树的真扩展跑同一套夹具,全绿(TEAM-IW-HARNESS OK)。
|
|
13
|
+
#
|
|
14
|
+
# 只写 /tmp 下的临时目录;不碰调用者所在的仓库/session/tmux(夹具自己清空 TEAM_* 身份并断言
|
|
15
|
+
# 产物落在临时仓库里,另有一条反向守卫对比真实仓库 state/ 的前后快照)。
|
|
16
|
+
set -uo pipefail
|
|
17
|
+
|
|
18
|
+
SELF_DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
19
|
+
SKILL_DIR="$(cd -P "$SELF_DIR/.." && pwd)"
|
|
20
|
+
# P53:临时根的唯一创建者(${TMPDIR:-/tmp} + owned 家族 + 回收)
|
|
21
|
+
. "$SELF_DIR/lib/tmp-root.sh"
|
|
22
|
+
SKILL_EXT="$SKILL_DIR/extension/team-inbox-watch.ts"
|
|
23
|
+
REPO_ROOT="$(git -C "$SKILL_DIR" rev-parse --show-toplevel 2>/dev/null || true)"
|
|
24
|
+
[ -n "$REPO_ROOT" ] || { printf 'team-inbox-watch-flip: 找不到 git 仓库(需要它取修复前的树)\n' >&2; exit 2; }
|
|
25
|
+
|
|
26
|
+
# 能直接跑 .ts 的运行时(与 smoke 的选择顺序一致;没有就响亮退出,不静默跳过)
|
|
27
|
+
RUNNER=""
|
|
28
|
+
if command -v node >/dev/null 2>&1 && node -e 'process.exit(process.features.typescript?0:1)' >/dev/null 2>&1; then
|
|
29
|
+
RUNNER="node"
|
|
30
|
+
elif command -v bun >/dev/null 2>&1 && bun -e '1' >/dev/null 2>&1; then
|
|
31
|
+
RUNNER="bun"
|
|
32
|
+
elif [ -x "$HOME/.bun/bin/bun" ] && "$HOME/.bun/bin/bun" -e '1' >/dev/null 2>&1; then
|
|
33
|
+
RUNNER="$HOME/.bun/bin/bun"
|
|
34
|
+
elif command -v tsx >/dev/null 2>&1; then
|
|
35
|
+
RUNNER="tsx"
|
|
36
|
+
fi
|
|
37
|
+
[ -n "$RUNNER" ] || { printf 'team-inbox-watch-flip: 没有能跑 .ts 的运行时(node 开启类型剥离 / bun / tsx)\n' >&2; exit 2; }
|
|
38
|
+
|
|
39
|
+
BASE="${TEAM_FLIP_BASE:-}"
|
|
40
|
+
if [ -z "$BASE" ]; then
|
|
41
|
+
BASE="$(git -C "$REPO_ROOT" merge-base HEAD main 2>/dev/null || true)"
|
|
42
|
+
fi
|
|
43
|
+
[ -n "$BASE" ] || BASE="$(git -C "$REPO_ROOT" rev-parse --verify -q HEAD^ 2>/dev/null || true)"
|
|
44
|
+
[ -n "$BASE" ] || { printf 'team-inbox-watch-flip: 解析不到修复前的 revision,用 TEAM_FLIP_BASE=<sha> 指定\n' >&2; exit 2; }
|
|
45
|
+
|
|
46
|
+
KEEP=0
|
|
47
|
+
[ "${1:-}" = "--keep" ] && KEEP=1
|
|
48
|
+
[ "${KEEP:-0}" = "1" ] && export TEAM_TMP_KEEP=1
|
|
49
|
+
TMP="$(tmp_root_create flip-m30)" || exit 3
|
|
50
|
+
cleanup() { [ "$KEEP" = "1" ] || tmp_root_reap_all; }
|
|
51
|
+
trap cleanup EXIT
|
|
52
|
+
|
|
53
|
+
FAIL=0
|
|
54
|
+
ok() { printf ' \033[32m✓\033[0m %s\n' "$1"; }
|
|
55
|
+
bad() { printf ' \033[31m✗\033[0m %s\n' "$1"; FAIL=$((FAIL + 1)); }
|
|
56
|
+
hdr() { printf '\n== %s ==\n' "$1"; }
|
|
57
|
+
|
|
58
|
+
HARNESS="$SKILL_DIR/tests/team-inbox-watch-harness.mjs"
|
|
59
|
+
[ -f "$HARNESS" ] || { printf 'team-inbox-watch-flip: 缺夹具 %s\n' "$HARNESS" >&2; exit 2; }
|
|
60
|
+
run_harness() { # <ext.ts> <tag> → 0/1(stdout 落 $TMP/<tag>.log)
|
|
61
|
+
local ext="$1" tag="$2"
|
|
62
|
+
$RUNNER "$HARNESS" "$ext" >"$TMP/$tag.log" 2>&1
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
printf '修复前 revision: %s(%s)\n修复后 skill: %s\n运行时: %s\n' \
|
|
66
|
+
"$BASE" "$(git -C "$REPO_ROOT" log -1 --format=%s "$BASE")" "$SKILL_DIR" "$RUNNER"
|
|
67
|
+
|
|
68
|
+
# ── ① 修复前的树:换道不存在 ────────────────────────────────────────────────
|
|
69
|
+
hdr "红①:修复前的树没有 team-inbox-watch.ts(投递换道不存在)"
|
|
70
|
+
mkdir -p "$TMP/red/ext"
|
|
71
|
+
git -C "$REPO_ROOT" archive "$BASE" skills/teamsmith/extension 2>/dev/null | tar -x -C "$TMP/red"
|
|
72
|
+
RED_EXT="$TMP/red/skills/teamsmith/extension/team-inbox-watch.ts"
|
|
73
|
+
if [ -f "$RED_EXT" ]; then
|
|
74
|
+
bad "$BASE 已经包含 team-inbox-watch.ts(不是修复前的树)——用 TEAM_FLIP_BASE=<修复前的 sha> 指定"
|
|
75
|
+
else
|
|
76
|
+
ok "前提成立:$BASE 的 extension/ 里没有 team-inbox-watch.ts"
|
|
77
|
+
fi
|
|
78
|
+
if run_harness "$RED_EXT" red-base; then
|
|
79
|
+
bad "修复前:夹具竟然全绿(缺失的扩展被当成了通过)"
|
|
80
|
+
else
|
|
81
|
+
ok "修复前:夹具非 0 退出($(grep -m1 'TEAM-IW-CASE FAIL' "$TMP/red-base.log" | sed 's/^TEAM-IW-CASE FAIL //'))"
|
|
82
|
+
fi
|
|
83
|
+
if grep -q 'TEAM-IW-CASE PASS' "$TMP/red-base.log"; then
|
|
84
|
+
bad "修复前:夹具居然跑出了通过用例(import 都失败了不该有)"
|
|
85
|
+
else
|
|
86
|
+
ok "修复前:一个用例都没有通过(import 阶段就红)"
|
|
87
|
+
fi
|
|
88
|
+
|
|
89
|
+
# ── ② 定点破坏:每一行都必须让对应用例变红 ───────────────────────────────────
|
|
90
|
+
hdr "红②:七个定点破坏(每个只改一行,各自必须红在对应用例)"
|
|
91
|
+
mutate_expect_red() { # <tag> <sed 表达式> <必须出现的 FAIL 用例名>
|
|
92
|
+
local tag="$1" expr="$2" want="$3" dir
|
|
93
|
+
dir="$TMP/mut-$tag"
|
|
94
|
+
mkdir -p "$dir"
|
|
95
|
+
cp "$SKILL_EXT" "$dir/team-inbox-watch.ts"
|
|
96
|
+
sed -i "$expr" "$dir/team-inbox-watch.ts"
|
|
97
|
+
if cmp -s "$SKILL_EXT" "$dir/team-inbox-watch.ts"; then
|
|
98
|
+
bad "$tag:定点破坏没生效(sed 表达式没匹配到)——不许把假红当证据"
|
|
99
|
+
return
|
|
100
|
+
fi
|
|
101
|
+
if run_harness "$dir/team-inbox-watch.ts" "$tag"; then
|
|
102
|
+
bad "$tag:破坏后夹具仍然全绿(这条性质没有被守门)"
|
|
103
|
+
elif grep -qF "TEAM-IW-CASE FAIL $want" "$TMP/$tag.log"; then
|
|
104
|
+
ok "$tag:红在「$want」"
|
|
105
|
+
else
|
|
106
|
+
bad "$tag:红了,但不是那条用例(期望 $want):$(grep -m1 'TEAM-IW-CASE FAIL' "$TMP/$tag.log" | sed 's/^TEAM-IW-CASE FAIL //')"
|
|
107
|
+
fi
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
# 合并成一条:同一拍的多行逐条唤醒(刷屏)—— P28 起合并点在 deliverNormal(去重/过期分类之后)那一行
|
|
111
|
+
mutate_expect_red merge-one-wake \
|
|
112
|
+
's/if (res\.lines\.length) deliverNormal(res\.lines)/for (const _l of res.lines) deliverNormal([_l])/' \
|
|
113
|
+
"S3 a burst of three lines produces exactly one wake"
|
|
114
|
+
# 唤醒投递方式:followUp+triggerTurn → nextTurn(排队不唤醒)
|
|
115
|
+
mutate_expect_red wake-mode \
|
|
116
|
+
"s/{ triggerTurn: true, deliverAs: 'followUp' }/{ deliverAs: 'nextTurn' }/" \
|
|
117
|
+
"S2 wake is a custom team-inbox message with triggerTurn+followUp"
|
|
118
|
+
# 启动基线:无基线(offset 从 0 开始)→ 历史行被当成新消息叫一遍
|
|
119
|
+
mutate_expect_red startup-baseline \
|
|
120
|
+
's/return readNewLines(file, 0)\.offset/return 0/' \
|
|
121
|
+
"S5 startup baseline equals the current spool size"
|
|
122
|
+
# 注册里的 cwd:发送方(team_inbox_watch_route)靠它证明监视器属于本项目 —— 少了它判据就只剩 pid
|
|
123
|
+
mutate_expect_red registry-cwd \
|
|
124
|
+
's/^ `cwd=${root}`,$//' \
|
|
125
|
+
"S1 registry carries cwd="
|
|
126
|
+
# 预览截断:唤醒消息带上 payload 全文(指针变正文)
|
|
127
|
+
mutate_expect_red preview-cap \
|
|
128
|
+
"s/return envNum('TEAM_INBOX_WATCH_PREVIEW', DEFAULT_PREVIEW, 16)/return 100000/" \
|
|
129
|
+
"S4 long payload is truncated in the wake (no payload dump)"
|
|
130
|
+
# shutdown 清场:不删注册文件(发送方会一直以为有个活着的监视器)
|
|
131
|
+
mutate_expect_red shutdown-cleanup \
|
|
132
|
+
's/rmSync(reg, { force: true })/void reg/' \
|
|
133
|
+
"S7 shutdown removes the registry file"
|
|
134
|
+
# 裁剪之后的 offset 对账:不对账 → 「size < offset」让下一拍走恢复路径(M43 的 shrink/rescan;
|
|
135
|
+
# P28 起 clamp/repeat 也在那里)——S6 的「裁剪后账本不许出现恢复行」就钉在这一条上
|
|
136
|
+
mutate_expect_red trim-offset \
|
|
137
|
+
's/^ offset = trimmed.*$/ void trimmed/' \
|
|
138
|
+
"S6 the trim is reconciled locally (no spool shrink / rescan / clamp afterwards)"
|
|
139
|
+
|
|
140
|
+
# ── ③ 绿:当前树的真扩展 ─────────────────────────────────────────────────────
|
|
141
|
+
hdr "绿:当前树的真扩展(同一套夹具)"
|
|
142
|
+
if run_harness "$SKILL_EXT" green; then
|
|
143
|
+
ok "绿:夹具全绿($(grep -c 'TEAM-IW-CASE PASS' "$TMP/green.log") 条用例,$(grep -m1 'TEAM-IW-HARNESS' "$TMP/green.log"))"
|
|
144
|
+
else
|
|
145
|
+
bad "绿:当前树的扩展没过夹具"; grep 'TEAM-IW-CASE FAIL' "$TMP/green.log" | sed 's/^/ /'
|
|
146
|
+
fi
|
|
147
|
+
if grep -q 'TEAM-IW-CASE FAIL' "$TMP/green.log"; then
|
|
148
|
+
bad "绿:输出里还有 FAIL 用例"
|
|
149
|
+
else
|
|
150
|
+
ok "绿:没有 FAIL 用例"
|
|
151
|
+
fi
|
|
152
|
+
if grep -q 'reverse guard: the real repo state/ is untouched' "$TMP/green.log"; then
|
|
153
|
+
ok "反向守卫:夹具确认真实仓库 state/ 未被触碰"
|
|
154
|
+
else
|
|
155
|
+
bad "反向守卫:夹具没有跑到真实仓库 state/ 的快照对比"
|
|
156
|
+
fi
|
|
157
|
+
|
|
158
|
+
# ── ④ 真 pi 的加载链(零模型调用):三个 -e 并列 + 坏扩展对照 ────────────────
|
|
159
|
+
hdr "真 pi 加载链:notify + bg + inbox-watch 三个 -e(零模型调用),坏扩展必须让 pi 失败"
|
|
160
|
+
PI_BIN=""
|
|
161
|
+
if command -v pi >/dev/null 2>&1; then PI_BIN="$(command -v pi)"
|
|
162
|
+
elif [ -x "$HOME/.bun/bin/pi" ]; then PI_BIN="$HOME/.bun/bin/pi"; fi
|
|
163
|
+
if [ -z "$PI_BIN" ]; then
|
|
164
|
+
printf ' (跳过:PATH 里没有 pi 可执行文件 —— 这条是集成证据,不是门禁)\n'
|
|
165
|
+
else
|
|
166
|
+
PI_TIMEOUT="${TEAM_IW_PI_TIMEOUT:-30}"
|
|
167
|
+
# 正:三个真扩展都加载,pi 正常跑完(stdin EOF 就退出;rc=0 且没有 Failed to load)
|
|
168
|
+
( sleep 2 ) | timeout "$PI_TIMEOUT" "$PI_BIN" --mode rpc --no-session \
|
|
169
|
+
-e "$SKILL_DIR/extension/team-notify.ts" -e "$SKILL_DIR/extension/team-bg.ts" -e "$SKILL_EXT" >"$TMP/rpc-green.log" 2>&1
|
|
170
|
+
if [ "$?" -eq 0 ] && ! grep -qi 'failed to load' "$TMP/rpc-green.log"; then
|
|
171
|
+
ok "真 pi 接受三个 -e(notify + bg + inbox-watch)且无加载错误"
|
|
172
|
+
else
|
|
173
|
+
bad "真 pi 加载三个扩展失败:$(grep -i 'failed to load' "$TMP/rpc-green.log" | head -1)"
|
|
174
|
+
fi
|
|
175
|
+
# 反:故意抛错的扩展必须让 pi 非 0 退出(证明上面那条不是「pi 根本不看 -e」)
|
|
176
|
+
printf 'export default function () { throw new Error("team-inbox-watch-flip-broken-probe") }\n' > "$TMP/broken-ext.ts"
|
|
177
|
+
( sleep 2 ) | timeout "$PI_TIMEOUT" "$PI_BIN" --mode rpc --no-session -e "$TMP/broken-ext.ts" >"$TMP/rpc-broken.log" 2>&1
|
|
178
|
+
if [ "$?" -ne 0 ] && grep -q 'team-inbox-watch-flip-broken-probe' "$TMP/rpc-broken.log"; then
|
|
179
|
+
ok "坏扩展对照:pi 拒绝加载(rc≠0 且报出被抛的错误)"
|
|
180
|
+
else
|
|
181
|
+
bad "坏扩展对照没红:pi 对加载失败的扩展无反应(上面那条正例就没有证据力)"
|
|
182
|
+
fi
|
|
183
|
+
fi
|
|
184
|
+
|
|
185
|
+
printf '\n'
|
|
186
|
+
if [ "$FAIL" -eq 0 ]; then
|
|
187
|
+
printf '\033[32mteam-inbox-watch-flip:翻转已复现(红① + 红②×7 → 绿)\033[0m\n'
|
|
188
|
+
exit 0
|
|
189
|
+
fi
|
|
190
|
+
printf '\033[31mteam-inbox-watch-flip:没有观察到预期的翻转(%d 条失败)\033[0m\n' "$FAIL"
|
|
191
|
+
exit 1
|