teamsmith 0.4.5 → 0.4.7
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 +6 -6
- package/package.json +1 -1
- package/skills/teamsmith/CHANGELOG.md +37 -1
- package/skills/teamsmith/SKILL.md +32 -23
- package/skills/teamsmith/extension/team-bg.ts +12 -11
- package/skills/teamsmith/extension/team-inbox-watch.ts +149 -5
- package/skills/teamsmith/extension/team-notify.ts +20 -13
- package/skills/teamsmith/extension/team-remind.ts +189 -0
- package/skills/teamsmith/extension/team-reply.ts +4 -7
- package/skills/teamsmith/references/migration.md +101 -0
- package/skills/teamsmith/references/openspec.md +43 -27
- package/skills/teamsmith/references/protocol.md +28 -18
- package/skills/teamsmith/references/reminders.md +133 -98
- package/skills/teamsmith/references/troubleshooting.md +12 -7
- package/skills/teamsmith/references/workflows.md +85 -34
- package/skills/teamsmith/scripts/lib/cmd-agents.sh +28 -5
- package/skills/teamsmith/scripts/lib/cmd-project.sh +100 -15
- package/skills/teamsmith/scripts/lib/cmd-remind.sh +135 -10
- package/skills/teamsmith/scripts/lib/cmd-review.sh +42 -4
- package/skills/teamsmith/scripts/lib/cmd-update.sh +90 -88
- package/skills/teamsmith/scripts/lib/cmd-watch.sh +322 -159
- package/skills/teamsmith/scripts/lib/common.sh +156 -26
- package/skills/teamsmith/scripts/panel/panel.js +182 -182
- package/skills/teamsmith/scripts/panel/src/data.ts +113 -6
- package/skills/teamsmith/scripts/panel/src/layout.ts +26 -4
- package/skills/teamsmith/scripts/panel/src/main.tsx +103 -14
- package/skills/teamsmith/scripts/remind-capability.mjs +261 -0
- package/skills/teamsmith/scripts/remind-store.mjs +404 -17
- package/skills/teamsmith/scripts/remind-tick.mjs +105 -0
- package/skills/teamsmith/scripts/reminder-delivery.mjs +76 -0
- package/skills/teamsmith/scripts/reply-capture.mjs +8 -9
- package/skills/teamsmith/scripts/state-authority.mjs +334 -20
- package/skills/teamsmith/scripts/strings/commands.tsv +3 -3
- package/skills/teamsmith/scripts/strings/help.en.tsv +12 -12
- package/skills/teamsmith/scripts/strings/help.zh.tsv +12 -12
- package/skills/teamsmith/scripts/team +4 -3
- package/skills/teamsmith/templates/AGENTS.section.md.tmpl +13 -11
- package/skills/teamsmith/templates/DECISIONS.md.tmpl +2 -2
- package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +3 -3
- package/skills/teamsmith/templates/PROTOCOL.md.tmpl +19 -14
- package/skills/teamsmith/templates/memory-seed.md.tmpl +2 -2
- package/skills/teamsmith/templates/pm-prompt.md.tmpl +36 -18
- package/skills/teamsmith/templates/report.md.tmpl +33 -0
- package/skills/teamsmith/tests/bg-ledger-harness.mjs +217 -33
- package/skills/teamsmith/tests/bg-ledger.sh +24 -10
- package/skills/teamsmith/tests/checkout-shape-probe.sh +7 -6
- package/skills/teamsmith/tests/death-cause.sh +5 -0
- package/skills/teamsmith/tests/fixtures/remind-adversarial-delay.ts +27 -0
- package/skills/teamsmith/tests/fixtures/remind-tool-provider.ts +65 -0
- package/skills/teamsmith/tests/help-surface.sh +14 -151
- package/skills/teamsmith/tests/isolation-ledger.sh +89 -0
- package/skills/teamsmith/tests/key-replies-ui.sh +53 -0
- package/skills/teamsmith/tests/key-replies.sh +307 -106
- package/skills/teamsmith/tests/lib/main-team-fingerprint.sh +17 -1
- package/skills/teamsmith/tests/lib/routes-pages.sh +243 -0
- package/skills/teamsmith/tests/live-capture-probe.sh +12 -2
- package/skills/teamsmith/tests/loop-inventory.tsv +1 -0
- package/skills/teamsmith/tests/panel-b3-stub.sh +9 -2
- package/skills/teamsmith/tests/pulse-nudge-key.sh +5 -0
- package/skills/teamsmith/tests/remind-adversarial-faults.mjs +163 -0
- package/skills/teamsmith/tests/remind-adversarial-faults.sh +26 -0
- package/skills/teamsmith/tests/remind-adversarial-real.sh +27 -0
- package/skills/teamsmith/tests/remind-cli.sh +108 -3
- package/skills/teamsmith/tests/remind-delivery-node.mjs +189 -0
- package/skills/teamsmith/tests/remind-delivery.sh +699 -0
- package/skills/teamsmith/tests/remind-lifecycle.sh +197 -0
- package/skills/teamsmith/tests/remind-pulse.sh +199 -0
- package/skills/teamsmith/tests/remind-recovery-real.sh +5 -0
- package/skills/teamsmith/tests/remind-recovery-unit.sh +118 -0
- package/skills/teamsmith/tests/remind-tool-node.mjs +159 -0
- package/skills/teamsmith/tests/remind-tool-real.mjs +754 -0
- package/skills/teamsmith/tests/remind-tool-real.sh +5 -0
- package/skills/teamsmith/tests/reply-capture-real.mjs +93 -2
- package/skills/teamsmith/tests/routes.sh +213 -293
- package/skills/teamsmith/tests/section-paths.tsv +14 -12
- package/skills/teamsmith/tests/smoke.sh +876 -130
- package/skills/teamsmith/tests/state-authority.sh +392 -28
- package/skills/teamsmith/tests/team-inbox-watch-harness.mjs +58 -8
- package/skills/teamsmith/tests/tmux-identity-leak.sh +12 -16
- package/skills/teamsmith-init/SKILL.md +5 -5
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/__pycache__/judge-second.cpython-313.pyc +0 -0
|
@@ -7,36 +7,42 @@
|
|
|
7
7
|
# 别的项目的状态根都被拒绝,且拒绝发生在建目录之前。
|
|
8
8
|
# 1.2 版本化快照 + flock 事务:Bash/Node 不同 TMPDIR 并发仍然逐个序号;持锁者被杀后立刻恢复;
|
|
9
9
|
# 损坏 / 不支持版本 / 半个快照是显式失败且一个字节都不改;原子写在被杀写入者下不露半个文件。
|
|
10
|
+
# 1.3 待命:旧 state/standby 只由迁移搬一次(原因/时间保留、代次不加、重复跑不变),读/写全走
|
|
11
|
+
# 统一状态(迁移后旧文件不再是真相),只读路径不写盘,代次每次 on 递增,缺 flock 显式失败。
|
|
10
12
|
#
|
|
11
13
|
# 红侧(各自具名,都用**同一个**判据判定,变异体在 scratch 副本上,产品与工作树不动):
|
|
12
14
|
# --flip=unlocked 把事务助手换成不持锁的直写 → 并发序号断言必须红
|
|
13
15
|
# --flip=version 删掉快照版本检查 → “版本 2 必须被拒”必须红
|
|
14
16
|
# --flip=foreign 删掉外来项目检查 → “别的项目的 .pi/team 必须被拒”必须红
|
|
15
17
|
# --flip=manifest 把隔离清单退回“整段跳过 state/” → “state/ 下的杂散文件必须被报”必须红
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
+
# --flip=standby-ignore 迁移不读旧标记 → “迁移保留原因/时间”必须红
|
|
19
|
+
# --flip=standby-file 读路径退回旧标记文件 → “迁移后旧标记不再是真相”必须红
|
|
20
|
+
# --flip=standby-write 写待命退回 state/standby → “写入后统一状态记下 on”必须红
|
|
21
|
+
# --flip=flock-resolution 解析不再检查执行权限 → “不可执行 flock 必须被拒”必须红
|
|
22
|
+
# 不带 --flip 时八条臂全跑;带一条时只跑那一条,其余臂跳过(跳过即不计入,不是通过)。
|
|
23
|
+
# 用法:bash tests/state-authority.sh [--flip=unlocked|version|foreign|manifest|standby-ignore|standby-file|standby-write|flock-resolution]
|
|
18
24
|
# 退出码:0 全绿 / 1 有失败 / 2 参数不认识 / 3 前提缺失(JS 运行时或 flock;可见跳过,不算通过)
|
|
19
25
|
set -uo pipefail
|
|
20
26
|
|
|
21
27
|
HERE="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
22
28
|
SKILL="$(cd -P "$HERE/.." && pwd)"
|
|
23
29
|
|
|
24
|
-
#
|
|
30
|
+
# 参数面:只接受下列 --flip 值;认不出来就拒绝(静默照跑会把单臂证据当成全套证据)。
|
|
25
31
|
FLIP=""
|
|
26
32
|
flip_err() { printf 'state-authority: %s\n' "$1" >&2; }
|
|
27
33
|
for arg in "$@"; do
|
|
28
34
|
case "$arg" in
|
|
29
|
-
--flip=unlocked|--flip=version|--flip=foreign|--flip=manifest)
|
|
35
|
+
--flip=unlocked|--flip=version|--flip=foreign|--flip=manifest|--flip=standby-ignore|--flip=standby-file|--flip=standby-write|--flip=flock-resolution)
|
|
30
36
|
if [ -n "$FLIP" ] && [ "$FLIP" != "${arg#--flip=}" ]; then
|
|
31
37
|
flip_err "互相冲突的 --flip($FLIP / ${arg#--flip=}):一次只跑一条臂"; exit 2
|
|
32
38
|
fi
|
|
33
39
|
FLIP="${arg#--flip=}" ;;
|
|
34
40
|
--flip=*)
|
|
35
|
-
flip_err "不认识的 --flip 值 [${arg#--flip=}];只接受 unlocked|version|foreign|manifest"; exit 2 ;;
|
|
41
|
+
flip_err "不认识的 --flip 值 [${arg#--flip=}];只接受 unlocked|version|foreign|manifest|standby-ignore|standby-file|standby-write|flock-resolution"; exit 2 ;;
|
|
36
42
|
-h|--help)
|
|
37
|
-
printf 'usage: bash tests/state-authority.sh [--flip=unlocked|version|foreign|manifest]\n'; exit 0 ;;
|
|
43
|
+
printf 'usage: bash tests/state-authority.sh [--flip=unlocked|version|foreign|manifest|standby-ignore|standby-file|standby-write|flock-resolution]\n'; exit 0 ;;
|
|
38
44
|
*)
|
|
39
|
-
flip_err "不认识的参数 [$arg](只接受 --flip=<unlocked|version|foreign|manifest>)"; exit 2 ;;
|
|
45
|
+
flip_err "不认识的参数 [$arg](只接受 --flip=<unlocked|version|foreign|manifest|standby-ignore|standby-file|standby-write|flock-resolution>)"; exit 2 ;;
|
|
40
46
|
esac
|
|
41
47
|
done
|
|
42
48
|
arm_selected() { [ -z "$FLIP" ] || [ "$FLIP" = "$1" ]; }
|
|
@@ -206,7 +212,10 @@ else
|
|
|
206
212
|
fi
|
|
207
213
|
[ ! -e "$ROOT/alt-state" ] && ok "冲突的 override 被拒绝时没有建出第二个权威目录" || bad "冲突的 override 留下了目录 $ROOT/alt-state"
|
|
208
214
|
|
|
209
|
-
|
|
215
|
+
# A caller may deliberately point at another project's state root; the authority must refuse it
|
|
216
|
+
# itself. Mark it as explicit for this invocation so the shell's inherited-value rewrite (P420) does
|
|
217
|
+
# not quietly turn it back into this project's own root before the authority sees it.
|
|
218
|
+
out="$(runchild "$C" TEAM_STATE_DIR="$B/.pi/team/state" TEAM_STATE_DIR_EXPLICIT=1 -- "$PREP; team_authority_state_root" 2>&1)"; rc=$?
|
|
210
219
|
if [ "$rc" -ne 0 ] && case "$out" in *"inside another project's .pi/team"*) true ;; *) false ;; esac; then
|
|
211
220
|
ok "别的项目的 .pi/team 作为状态根:显式拒绝(inside another project's .pi/team)"
|
|
212
221
|
else
|
|
@@ -307,6 +316,7 @@ rm -f "$orphan"
|
|
|
307
316
|
|
|
308
317
|
# ---------------------------------------------------------------- 6. 有界锁失败 + 持锁者被杀
|
|
309
318
|
LOCK="$A_STATE/reminders/authority.lock"
|
|
319
|
+
LOCK_FAIL_BEFORE="$(sha256sum "$A_STATE/reminders/state.json" | cut -d' ' -f1)"
|
|
310
320
|
bash -c 'exec 9>"$1"; flock -x 9; sleep 30' _ "$LOCK" &
|
|
311
321
|
HOLDER=$!
|
|
312
322
|
sleep 0.4
|
|
@@ -323,6 +333,7 @@ if [ "$elapsed_ms" -ge 4500 ] && [ "$elapsed_ms" -le 12000 ]; then
|
|
|
323
333
|
else
|
|
324
334
|
bad "锁等待不是有界的 5s(实测 ${elapsed_ms}ms)"
|
|
325
335
|
fi
|
|
336
|
+
assert_eq_local "真实锁竞争失败后快照一字未改" "$(sha256sum "$A_STATE/reminders/state.json" | cut -d' ' -f1)" "$LOCK_FAIL_BEFORE"
|
|
326
337
|
kill -9 "$HOLDER" 2>/dev/null
|
|
327
338
|
wait "$HOLDER" 2>/dev/null
|
|
328
339
|
start_ns="$(date +%s%N)"
|
|
@@ -436,16 +447,255 @@ else
|
|
|
436
447
|
note "(有残留 .tmp,但它们被忽略;上面已验证读者不受影响)"
|
|
437
448
|
fi
|
|
438
449
|
|
|
439
|
-
# ---------------------------------------------------------------- 9. 1.3
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
450
|
+
# ---------------------------------------------------------------- 9. 待命:唯一写点 + 一次性迁移(1.3)
|
|
451
|
+
# 旧标记的形状:`<时间戳> <原因>`(旧写入者没有原因时写 `-`)。现场由夹具自己造(不碰真项目)。
|
|
452
|
+
sb() { runchild "$1" -- "$PREP; $2"; } # <仓库> <bash 片段(在 PREP 之后)>
|
|
453
|
+
E_STATE="$E/.pi/team/state"
|
|
454
|
+
mkdir -p "$E_STATE"
|
|
455
|
+
MARKER="$E_STATE/standby"
|
|
456
|
+
printf '2026-10-29T10:00:00Z waiting for human\n' >"$MARKER"
|
|
457
|
+
pi_tree() { ( cd "$1" && find .pi -type f 2>/dev/null | sort | while IFS= read -r f; do printf '%s %s\n' "$f" "$(sha256sum "$f" | cut -d' ' -f1)"; done ); }
|
|
458
|
+
|
|
459
|
+
# ① 只读路径认旧标记(升级中的团队不许被读成「没有待命」),且不写盘
|
|
460
|
+
E_BEFORE="$(pi_tree "$E")"
|
|
461
|
+
out="$(sb "$E" 'team_standby_status')"; rc=$?
|
|
462
|
+
assert_eq_local "①a 旧标记还在时 status 读出 on 与原时间/原因(不是「没有待命」)" \
|
|
463
|
+
"$(printf '%s\n' "$out" | sed -n 1p)" "standby: on(自 2026-10-29T10:00:00Z,原因:waiting for human)"
|
|
464
|
+
assert_eq_local "①b status 读 rc" "$rc" "0"
|
|
465
|
+
assert_eq_local "①c 未迁移时如实提示迁移" "$(printf '%s\n' "$out" | sed -n 2p)" \
|
|
466
|
+
"(旧标记还没并入统一状态:跑 team standby migrate 完成迁移)"
|
|
467
|
+
out="$(sb "$E" 'team_in_standby; printf "rc=%s" "$?"')"
|
|
468
|
+
assert_eq_local "①d 巡检/面板读到同一个 on" "$out" "rc=0"
|
|
469
|
+
assert_eq_local "①e 原因原样读出" "$(sb "$E" 'team_standby_reason')" "waiting for human"
|
|
470
|
+
E_AFTER="$(pi_tree "$E")"
|
|
471
|
+
assert_eq_local "①f 只读路径不建定位器、不发布快照(展示路径不写盘)" "$E_AFTER" "$E_BEFORE"
|
|
472
|
+
[ -e "$E/.pi/team/reminder-locator.json" ] && bad "①g 只读路径建出了定位器(展示路径写盘了)" || ok "①g 只读路径没有建定位器"
|
|
473
|
+
|
|
474
|
+
# ② 写待命:旧标记在同一个事务里并被导入,快照发布后才退役(一次搬完)
|
|
475
|
+
out="$(sb "$E" 'team_standby_on "after the upgrade"')"; rc=$?
|
|
476
|
+
E_SNAP="$E_STATE/reminders/state.json"
|
|
477
|
+
assert_eq_local "②a 首次写待命 rc" "$rc" "0"
|
|
478
|
+
[ ! -e "$MARKER" ] && ok "②b 旧标记不再是真相(state/standby 已不在)" || bad "②b 旧标记还立在 state/standby"
|
|
479
|
+
[ -f "$E_STATE/standby.migrated" ] && ok "②c 旧标记改名为 standby.migrated(留证据、不删)" || bad "②c 退役时没有留下 standby.migrated"
|
|
480
|
+
assert_eq_local "②d 写入后统一状态:on" "$(jget "$(cat "$E_SNAP")" standby.on)" "true"
|
|
481
|
+
assert_eq_local "②e 写入后统一状态:代次 1(迁移不占代,on 加一代)" "$(jget "$(cat "$E_SNAP")" standby.generation)" "1"
|
|
482
|
+
assert_eq_local "②f 写入后统一状态:原因就是新给的" "$(jget "$(cat "$E_SNAP")" standby.reason)" "after the upgrade"
|
|
483
|
+
assert_eq_local "②g 统一状态记下迁移已完成" "$(jget "$(cat "$E_SNAP")" standby.migrated)" "true"
|
|
484
|
+
|
|
485
|
+
# ③ 显式迁移:原因/时间保留,代次不加(gen 仍 0)
|
|
486
|
+
I="$(make_repo I)" || { bad "夹具建不出仓库 I"; result; exit 1; }
|
|
487
|
+
I_STATE="$I/.pi/team/state"; I_SNAP="$I_STATE/reminders/state.json"
|
|
488
|
+
mkdir -p "$I_STATE"
|
|
489
|
+
printf '2026-10-30T08:30:00Z human is deciding\n' >"$I_STATE/standby"
|
|
490
|
+
out="$(sb "$I" 'team_standby_migrate')"; rc=$?
|
|
491
|
+
assert_eq_local "③a 显式迁移 rc" "$rc" "0"
|
|
492
|
+
assert_eq_local "③b 迁移后仍是 on,原因与时间都保留" "$(printf '%s\n' "$out" | sed -n 1p)" \
|
|
493
|
+
"standby: on(自 2026-10-30T08:30:00Z,原因:human is deciding)"
|
|
494
|
+
assert_eq_local "③c 迁移不加代次(仍 0)" "$(jget "$(cat "$I_SNAP")" standby.generation)" "0"
|
|
495
|
+
assert_eq_local "③d 迁移后的原因" "$(jget "$(cat "$I_SNAP")" standby.reason)" "human is deciding"
|
|
496
|
+
assert_eq_local "③e 迁移后的时间" "$(jget "$(cat "$I_SNAP")" standby.since)" "2026-10-30T08:30:00Z"
|
|
497
|
+
[ ! -e "$I_STATE/standby" ] && [ -f "$I_STATE/standby.migrated" ] && ok "③f 旧标记已退役" || bad "③f 迁移后旧标记仍立着"
|
|
498
|
+
|
|
499
|
+
# ④ 重复迁移:状态不变、代次不变、不多出第二份证据
|
|
500
|
+
I_H1="$(sha256sum "$I_SNAP" | cut -d' ' -f1)"
|
|
501
|
+
out="$(sb "$I" 'team_standby_migrate')"; rc=$?
|
|
502
|
+
I_H2="$(sha256sum "$I_SNAP" | cut -d' ' -f1)"
|
|
503
|
+
assert_eq_local "④a 重复迁移 rc" "$rc" "0"
|
|
504
|
+
assert_eq_local "④b 重复迁移一个字节都不写(快照哈希不变)" "$I_H2" "$I_H1"
|
|
505
|
+
assert_eq_local "④c 重复迁移提示无需迁移" "$(printf '%s\n' "$out" | sed -n 2p)" "迁移:无需迁移(统一状态已记录待命开启)"
|
|
506
|
+
assert_eq_local "④d 重复迁移没有多出第二份旧标记" "$(find "$I_STATE" -maxdepth 1 -name 'standby.migrated*' | wc -l | tr -d ' ')" "1"
|
|
507
|
+
assert_eq_local "④e 代次仍是 0" "$(jget "$(cat "$I_SNAP")" standby.generation)" "0"
|
|
508
|
+
|
|
509
|
+
# ⑤ 迁移之后:旧文件不再被当成真相(手写一个旧标记,读到的仍是统一状态)
|
|
510
|
+
sb "$I" 'team_standby_off' >/dev/null
|
|
511
|
+
assert_eq_local "⑤a off 之后 status 是 off" "$(sb "$I" 'team_standby_status')" "standby: off"
|
|
512
|
+
printf '2026-11-02T00:00:00Z stale marker from an old writer\n' >"$I_STATE/standby"
|
|
513
|
+
assert_eq_local "⑤b 手写旧标记改不动真相(仍 off)" "$(sb "$I" 'team_standby_status')" "standby: off"
|
|
514
|
+
assert_eq_local "⑤c 巡检也不会被旧标记叫错" "$(sb "$I" 'team_in_standby; printf "rc=%s" "$?"')" "rc=1"
|
|
515
|
+
out="$(sb "$I" 'team_standby_migrate')"
|
|
516
|
+
[ -f "$I_STATE/standby.migrated.1" ] && [ ! -e "$I_STATE/standby" ] && ok "⑤d 残留的旧标记被清掉(改名为 standby.migrated.1,不删)" \
|
|
517
|
+
|| bad "⑤d 残留的旧标记没有被清掉"
|
|
518
|
+
assert_eq_local "⑤e 清残留不改待命状态(仍 off)" "$(sb "$I" 'team_standby_status')" "standby: off"
|
|
519
|
+
assert_eq_local "⑤f 清残留不加代次" "$(jget "$(cat "$I_SNAP")" standby.generation)" "0"
|
|
520
|
+
|
|
521
|
+
# ⑥ 代次语义:每次 on 都是新的一代,off 不动代次、重复 off 不写盘
|
|
522
|
+
J="$(make_repo J)" || { bad "夹具建不出仓库 J"; result; exit 1; }
|
|
523
|
+
J_STATE="$J/.pi/team/state"; J_SNAP="$J_STATE/reminders/state.json"
|
|
524
|
+
sb "$J" 'team_standby_on "first"' >/dev/null
|
|
525
|
+
assert_eq_local "⑥a 第一次 on:代次 1" "$(jget "$(cat "$J_SNAP")" standby.generation)" "1"
|
|
526
|
+
sb "$J" 'team_standby_on "second"' >/dev/null
|
|
527
|
+
assert_eq_local "⑥b 已在待命时再 on:代次 2(代次不重用)" "$(jget "$(cat "$J_SNAP")" standby.generation)" "2"
|
|
528
|
+
assert_eq_local "⑥c 再 on 之后原因是新的" "$(jget "$(cat "$J_SNAP")" standby.reason)" "second"
|
|
529
|
+
sb "$J" 'team_standby_off' >/dev/null
|
|
530
|
+
assert_eq_local "⑥d off 不动代次" "$(jget "$(cat "$J_SNAP")" standby.generation)" "2"
|
|
531
|
+
J_H1="$(sha256sum "$J_SNAP" | cut -d' ' -f1)"
|
|
532
|
+
sb "$J" 'team_standby_off' >/dev/null
|
|
533
|
+
J_H2="$(sha256sum "$J_SNAP" | cut -d' ' -f1)"
|
|
534
|
+
assert_eq_local "⑥e 重复 off 不改状态(快照一字不动)" "$J_H2" "$J_H1"
|
|
535
|
+
sb "$J" 'team_standby_on "third"' >/dev/null
|
|
536
|
+
assert_eq_local "⑥f off 之后 on:代次 3" "$(jget "$(cat "$J_SNAP")" standby.generation)" "3"
|
|
537
|
+
|
|
538
|
+
# ⑦ 没有 flock:显式失败,不静默成功(也不留下半个旧标记)
|
|
539
|
+
L="$(make_repo L)" || { bad "夹具建不出仓库 L"; result; exit 1; }
|
|
540
|
+
L_STATE="$L/.pi/team/state"
|
|
541
|
+
mkdir -p "$L_STATE"
|
|
542
|
+
printf '2026-11-03T00:00:00Z no flock here\n' >"$L_STATE/standby"
|
|
543
|
+
NOFLOCK="$ROOT/flip/noflock-bin"
|
|
544
|
+
if mkdir -p "$NOFLOCK" && for f in /usr/bin/*; do b="${f##*/}"; [ "$b" = flock ] && continue; [ -e "$NOFLOCK/$b" ] || ln -s "$f" "$NOFLOCK/$b"; done; then
|
|
545
|
+
out="$(runchild "$L" NOFLOCK="$NOFLOCK" TEAM_JS_BIN="$RUNNER" -- "$PREP; PATH=\"\$NOFLOCK\" team_standby_on x >/dev/null 2>&1; printf 'rc=%s' \"\$?\"" 2>&1)"
|
|
546
|
+
if [ "$out" = "rc=1" ]; then
|
|
547
|
+
ok "⑦a 缺 flock:写待命退出码是 1(不是静默成功)"
|
|
548
|
+
else
|
|
549
|
+
bad "⑦a 缺 flock 时退出码不对([$out])"
|
|
550
|
+
fi
|
|
551
|
+
out="$(runchild "$L" NOFLOCK="$NOFLOCK" TEAM_JS_BIN="$RUNNER" -- "$PREP; PATH=\"\$NOFLOCK\" team_standby_on x 2>&1; printf ' rc=%s' \"\$?\"" 2>&1)"
|
|
552
|
+
if case "$out" in *"flock unavailable"*) true ;; *) false ;; esac; then
|
|
553
|
+
ok "⑦b 缺 flock:报错点名 flock(安装一个可用的,不落回无锁写)"
|
|
554
|
+
else
|
|
555
|
+
bad "⑦b 缺 flock 的报错没有点名 flock(输出:$(printf '%s' "$out" | tr '\n' '|'))"
|
|
556
|
+
fi
|
|
557
|
+
out="$(runchild "$J" NOFLOCK="$NOFLOCK" TEAM_JS_BIN="$RUNNER" -- "$PREP; PATH=\"\$NOFLOCK\" team_standby_status 2>&1; printf ' rc=%s' \"\$?\"" 2>&1)"
|
|
558
|
+
# 已钉住权威的项目:读要走事务锁,没有 flock 就不能算读过(不静默降级成 off)。
|
|
559
|
+
if case "$out" in *"flock unavailable"*) true ;; *) false ;; esac; then
|
|
560
|
+
ok "⑦c 缺 flock:已钉住的项目读也不静默降级成 off"
|
|
561
|
+
else
|
|
562
|
+
bad "⑦c 缺 flock 时读静默给了个结果(输出:$(printf '%s' "$out" | tr '\n' '|'))"
|
|
563
|
+
fi
|
|
564
|
+
# 未钉住的项目还没有权威快照可读:读只答旧标记(不需要锁),而且不能答成 off。
|
|
565
|
+
out="$(runchild "$L" NOFLOCK="$NOFLOCK" TEAM_JS_BIN="$RUNNER" -- "$PREP; PATH=\"\$NOFLOCK\" team_standby_status 2>&1; printf ' rc=%s' \"\$?\"" 2>&1)"
|
|
566
|
+
if case "$out" in *"standby: on(自 2026-11-03T00:00:00Z,原因:no flock here)"*) true ;; *) false ;; esac; then
|
|
567
|
+
ok "⑦d 缺 flock:未钉住的项目仍从旧标记读出 on(不需要锁,也不答成 off)"
|
|
568
|
+
else
|
|
569
|
+
bad "⑦d 缺 flock 时旧标记没被如实读出(输出:$(printf '%s' "$out" | tr '\n' '|'))"
|
|
570
|
+
fi
|
|
571
|
+
assert_eq_local "⑦e 缺 flock 时旧标记原样未动" "$(cat "$L_STATE/standby")" "2026-11-03T00:00:00Z no flock here"
|
|
572
|
+
[ ! -e "$L/.pi/team/reminder-locator.json" ] && [ ! -e "$L_STATE/reminders" ] && ok "⑦f 缺 flock 时没有建出定位器或快照" \
|
|
573
|
+
|| bad "⑦f 缺 flock 时留下了定位器/快照"
|
|
574
|
+
else
|
|
575
|
+
note "跳过 ⑦(这台机器上造不出没有 flock 的 PATH)"
|
|
576
|
+
fi
|
|
577
|
+
|
|
578
|
+
# ---------------------------------------------------------------- 7b. 不可执行 / 实际 flock 失败(P451 · 1.3.2)
|
|
579
|
+
BADFLOCK="$ROOT/flip/badflock-bin"
|
|
580
|
+
cp -a "$NOFLOCK" "$BADFLOCK"
|
|
581
|
+
printf 'not executable\n' >"$BADFLOCK/flock"
|
|
582
|
+
chmod 0644 "$BADFLOCK/flock"
|
|
583
|
+
M="$(make_repo M)" || { bad "夹具建不出仓库 M"; result; exit 1; }
|
|
584
|
+
M_STATE="$M/.pi/team/state"; mkdir -p "$M_STATE"
|
|
585
|
+
printf '2026-11-12T00:00:00Z bad flock\n' >"$M_STATE/standby"
|
|
586
|
+
out="$(runchild "$M" TEAM_JS_BIN="$RUNNER" BADFLOCK="$BADFLOCK" -- "$PREP; PATH=\"\$BADFLOCK\" team_standby_on x 2>&1; printf ' rc=%s' \"\$?\"" 2>&1)"
|
|
587
|
+
if case "$out" in *"is not an executable regular file"*"rc=1"*) true ;; *) false ;; esac; then
|
|
588
|
+
ok "⑦g 不可执行 flock:点名实际路径与权限问题,写入非零退出"
|
|
589
|
+
else
|
|
590
|
+
bad "⑦g 不可执行 flock 没有明确失败(输出:$(printf '%s' "$out" | tr '\n' '|'))"
|
|
591
|
+
fi
|
|
592
|
+
[ ! -e "$M/.pi/team/reminder-locator.json" ] && [ ! -e "$M_STATE/reminders" ] \
|
|
593
|
+
&& ok "⑦h 不可执行 flock 没有留下定位器或快照" || bad "⑦h 不可执行 flock 留下了半个权威"
|
|
594
|
+
resolution="$(env PATH="$BADFLOCK" "$RUNNER" "$NODE_HELPER" --flock-check)"
|
|
595
|
+
assert_eq_local "⑦i 共享解析器区分不可执行(不是 missing)" "$(printf '%s' "$resolution" | cut -f1-2)" "unusable $BADFLOCK/flock"
|
|
596
|
+
|
|
597
|
+
ENOLCK="$ROOT/flip/enolck-bin"
|
|
598
|
+
cp -a "$NOFLOCK" "$ENOLCK"
|
|
599
|
+
cat >"$ENOLCK/flock" <<'EOF'
|
|
600
|
+
#!/usr/bin/env bash
|
|
601
|
+
if [ "${1:-}" = "--version" ]; then printf 'flock from util-linux fixture\n'; exit 0; fi
|
|
602
|
+
printf '%s\n' "$*" >>"$FLOCK_TEST_LOG"
|
|
603
|
+
printf 'flock: %s: No locks available\n' "${6:-unknown}" >&2
|
|
604
|
+
exit 1
|
|
605
|
+
EOF
|
|
606
|
+
chmod +x "$ENOLCK/flock"
|
|
607
|
+
: >"$ROOT/enolck.calls"
|
|
608
|
+
shown="$(runchild "$J" TEAM_JS_BIN="$RUNNER" ENOLCK="$ENOLCK" -- "$PREP; PATH=\"\$ENOLCK\" team_flock_runner")"
|
|
609
|
+
assert_eq_local "⑦j paths 使用与事务相同的 flock 解析结果" "$shown" "$ENOLCK/flock"
|
|
610
|
+
J_H1="$(sha256sum "$J_SNAP" | cut -d' ' -f1)"
|
|
611
|
+
out="$(runchild "$J" TEAM_JS_BIN="$RUNNER" ENOLCK="$ENOLCK" FLOCK_TEST_LOG="$ROOT/enolck.calls" -- "$PREP; PATH=\"\$ENOLCK\" FLOCK_TEST_LOG=\"\$FLOCK_TEST_LOG\" team_standby_on must-not-write 2>&1; printf ' rc=%s' \"\$?\"" 2>&1)"
|
|
612
|
+
if case "$out" in *"exclusive flock failed at $J_STATE/reminders/authority.lock"*"No locks available"*"no state was written"*"rc=1"*) true ;; *) false ;; esac; then
|
|
613
|
+
ok "⑦k flock 返回 ENOLCK:错误点名真实 authority.lock、文件系统与未写状态"
|
|
614
|
+
else
|
|
615
|
+
bad "⑦k ENOLCK 没有按锁/文件系统失败报告(输出:$(printf '%s' "$out" | tr '\n' '|'))"
|
|
616
|
+
fi
|
|
617
|
+
assert_eq_local "⑦l ENOLCK 后快照一字未改" "$(sha256sum "$J_SNAP" | cut -d' ' -f1)" "$J_H1"
|
|
618
|
+
if grep -q -- "-x -w 5 -E 75 $J_STATE/reminders/authority.lock" "$ROOT/enolck.calls"; then
|
|
619
|
+
ok "⑦m 失败来自实际执行的 flock(参数与真实锁路径已记录),不是伪造成交"
|
|
620
|
+
else
|
|
621
|
+
bad "⑦m 没有执行到真实 flock 调用(日志:$(cat "$ROOT/enolck.calls"))"
|
|
622
|
+
fi
|
|
623
|
+
out="$(runchild "$J" TEAM_JS_BIN="$RUNNER" ENOLCK="$ENOLCK" FLOCK_TEST_LOG="$ROOT/enolck.calls" -- "PATH=\"\$ENOLCK\" FLOCK_TEST_LOG=\"\$FLOCK_TEST_LOG\" bash \"$SKILL/scripts/team\" --root \"$J\" doctor" 2>&1)"; rc=$?
|
|
624
|
+
if [ "$rc" -ne 0 ] && case "$out" in *"真实 authority.lock 加锁失败"*"No locks available"*"不会无锁降级"*) true ;; *) false ;; esac; then
|
|
625
|
+
ok "⑦m2 doctor 对真实 authority.lock 的锁失败给出文件系统修复方式"
|
|
626
|
+
else
|
|
627
|
+
bad "⑦m2 doctor 没诊断真实锁失败(rc=$rc,输出:$(printf '%s' "$out" | grep -A2 -B1 '状态锁 flock' | tr '\n' '|'))"
|
|
628
|
+
fi
|
|
629
|
+
assert_eq_local "⑦m3 doctor 锁探针不改快照" "$(sha256sum "$J_SNAP" | cut -d' ' -f1)" "$J_H1"
|
|
630
|
+
out="$(runchild "$J" -- "bash \"$SKILL/scripts/team\" --root \"$J\" doctor" 2>&1)"
|
|
631
|
+
if case "$out" in *"真实 authority.lock 排他锁可用"*) true ;; *) false ;; esac; then
|
|
632
|
+
ok "⑦m4 恢复真实 flock 后 doctor 探针转绿(同一项目、同一锁文件)"
|
|
633
|
+
else
|
|
634
|
+
bad "⑦m4 恢复后 doctor 锁探针仍不绿(输出:$(printf '%s' "$out" | grep -A2 -B1 '状态锁 flock' | tr '\n' '|'))"
|
|
635
|
+
fi
|
|
636
|
+
|
|
637
|
+
# ---------------------------------------------------------------- 7c. 静止迁移失败与回滚导出(P451 · 1.3.2)
|
|
638
|
+
R="$(make_repo R)" || { bad "夹具建不出仓库 R"; result; exit 1; }
|
|
639
|
+
R_STATE="$R/.pi/team/state"; R_SNAP="$R_STATE/reminders/state.json"
|
|
640
|
+
sb "$R" 'team_authority_init' >/dev/null
|
|
641
|
+
# 合法的旧快照没有 migrated 键;这里只回到那个升级前形状,随后让旧标记无法导入。
|
|
642
|
+
sed -i 's/"migrated":true/"migrated":false/' "$R_SNAP"
|
|
643
|
+
mkdir "$R_STATE/standby"
|
|
644
|
+
R_H1="$(sha256sum "$R_SNAP" | cut -d' ' -f1)"
|
|
645
|
+
out="$(sb "$R" 'team_standby_migrate' 2>&1)"; rc=$?
|
|
646
|
+
if [ "$rc" -ne 0 ] && case "$out" in *"legacy Standby marker is not a regular file"*) true ;; *) false ;; esac; then
|
|
647
|
+
ok "⑦n 静止迁移遇到坏旧标记:显式失败并点名原因"
|
|
648
|
+
else
|
|
649
|
+
bad "⑦n 坏旧标记没有让迁移失败(rc=$rc,输出:$(printf '%s' "$out" | tr '\n' '|'))"
|
|
650
|
+
fi
|
|
651
|
+
assert_eq_local "⑦o 迁移失败后快照保持原状态" "$(sha256sum "$R_SNAP" | cut -d' ' -f1)" "$R_H1"
|
|
652
|
+
[ -d "$R_STATE/standby" ] && [ ! -e "$R_STATE/standby.migrated" ] \
|
|
653
|
+
&& ok "⑦p 迁移失败后旧标记未退役、未伪造迁移完成" || bad "⑦p 迁移失败后旧标记状态变了"
|
|
654
|
+
|
|
655
|
+
U="$(make_repo U)" || { bad "夹具建不出仓库 U"; result; exit 1; }
|
|
656
|
+
U_STATE="$U/.pi/team/state"; U_SNAP="$U_STATE/reminders/state.json"
|
|
657
|
+
sb "$U" 'team_standby_on "rollback export reason"' >/dev/null
|
|
658
|
+
EXPORT="$ROOT/rollback-export"; OLD_CODE="$ROOT/old-code-state"
|
|
659
|
+
mkdir -p "$EXPORT" "$OLD_CODE"
|
|
660
|
+
cp "$U_SNAP" "$EXPORT/state.json"
|
|
661
|
+
# 与 references/migration.md 相同的实际操作:从导出快照重建旧版唯一读取的待命标记。
|
|
662
|
+
"$RUNNER" -e '
|
|
663
|
+
const fs = require("fs");
|
|
664
|
+
const [snapshotFile, markerFile] = process.argv.slice(1);
|
|
665
|
+
const s = JSON.parse(fs.readFileSync(snapshotFile, "utf8"));
|
|
666
|
+
if (!s.standby.migrated) throw new Error("snapshot has not completed Standby migration");
|
|
667
|
+
if (s.standby.on) fs.writeFileSync(markerFile, `${s.standby.since} ${s.standby.reason}\n`);
|
|
668
|
+
' "$EXPORT/state.json" "$OLD_CODE/standby"
|
|
669
|
+
expected_marker="$(jget "$(cat "$EXPORT/state.json")" standby.since) $(jget "$(cat "$EXPORT/state.json")" standby.reason)"
|
|
670
|
+
assert_eq_local "⑦q 回滚导出可重建旧版待命标记" "$(cat "$OLD_CODE/standby")" "$expected_marker"
|
|
671
|
+
mv "$OLD_CODE/standby" "$EXPORT/standby.before-restore-check"
|
|
672
|
+
"$RUNNER" -e '
|
|
673
|
+
const fs = require("fs");
|
|
674
|
+
const [snapshotFile, markerFile] = process.argv.slice(1);
|
|
675
|
+
const s = JSON.parse(fs.readFileSync(snapshotFile, "utf8"));
|
|
676
|
+
if (!s.standby.migrated) throw new Error("snapshot has not completed Standby migration");
|
|
677
|
+
if (s.standby.on) fs.writeFileSync(markerFile, `${s.standby.since} ${s.standby.reason}\n`);
|
|
678
|
+
' "$EXPORT/state.json" "$OLD_CODE/standby"
|
|
679
|
+
if cmp -s "$EXPORT/standby.before-restore-check" "$OLD_CODE/standby"; then
|
|
680
|
+
ok "⑦q2 移走旧标记后可从导出快照逐字节恢复它"
|
|
681
|
+
else
|
|
682
|
+
bad "⑦q2 导出快照不能恢复旧标记"
|
|
683
|
+
fi
|
|
684
|
+
cp "$EXPORT/state.json" "$EXPORT/state.restore-check.json"
|
|
685
|
+
printf 'corrupt restore\n' >>"$EXPORT/state.restore-check.json"
|
|
686
|
+
if cmp -s "$EXPORT/state.json" "$EXPORT/state.restore-check.json"; then
|
|
687
|
+
bad "⑦r 反向改坏:损坏的恢复副本竟与导出原件相同"
|
|
688
|
+
else
|
|
689
|
+
ok "⑦r 反向改坏:恢复副本损坏会被逐字节比较发现"
|
|
690
|
+
fi
|
|
691
|
+
cp "$EXPORT/state.json" "$EXPORT/state.restore-check.json"
|
|
692
|
+
if cmp -s "$EXPORT/state.json" "$EXPORT/state.restore-check.json" \
|
|
693
|
+
&& [ "$(jget "$(cat "$EXPORT/state.restore-check.json")" standby.reason)" = "rollback export reason" ]; then
|
|
694
|
+
ok "⑦s 从导出原件恢复后字节与待命原因都复原"
|
|
695
|
+
else
|
|
696
|
+
bad "⑦s 导出原件无法恢复"
|
|
697
|
+
fi
|
|
698
|
+
[ ! -e "$OLD_CODE/reminders/state.json" ] && ok "⑦t 回滚快照留在旧代码状态路径之外" || bad "⑦t 回滚快照落进了旧代码路径"
|
|
449
699
|
|
|
450
700
|
# ---------------------------------------------------------------- 10. 红侧:同一个判据,改坏实现必须红
|
|
451
701
|
flip_copy() { # <名字> <sed 表达式> —— 变异必须真的改到(否则红侧就是橡皮章)
|
|
@@ -453,6 +703,31 @@ flip_copy() { # <名字> <sed 表达式> —— 变异必须真的改到(否
|
|
|
453
703
|
sed -i "$2" "$ROOT/flip/$1.mjs" || return 1
|
|
454
704
|
! cmp -s "$SKILL/scripts/state-authority.mjs" "$ROOT/flip/$1.mjs"
|
|
455
705
|
}
|
|
706
|
+
# 直接跑 scratch 助手(不经 bash 入口):输出与退出码原样拿来比对。
|
|
707
|
+
flip_helper() { # <helper> <repo> <state> <op> [args…] → 打印输出
|
|
708
|
+
local helper="$1" repo="$2" state="$3"; shift 3
|
|
709
|
+
( cd "$repo" && env -u TEAM_ROOT -u TEAM_MAIN_ROOT -u TEAM_PROJECT -u TEAM_SESSION HOME="$ROOT/home" \
|
|
710
|
+
"$RUNNER" "$helper" --cli "$repo" "$state" "$@" 2>&1 )
|
|
711
|
+
}
|
|
712
|
+
# 10a0. flock 解析退化成「文件存在就算可用」:不可执行诊断必须翻错(P451)
|
|
713
|
+
if arm_selected flock-resolution; then
|
|
714
|
+
FLIPS_RUN="${FLIPS_RUN:+$FLIPS_RUN,}flock-resolution"
|
|
715
|
+
if flip_copy flock-resolution '/fs\.accessSync(file, fs\.constants\.X_OK);/d'; then
|
|
716
|
+
ok "flip 变异已落地:flock 解析不再检查执行权限"
|
|
717
|
+
else
|
|
718
|
+
bad "flip 变异没落地(共享 flock 解析器形状变了)"
|
|
719
|
+
fi
|
|
720
|
+
orig_res="$(env PATH="$BADFLOCK" "$RUNNER" "$NODE_HELPER" --flock-check)"
|
|
721
|
+
mut_res="$(env PATH="$BADFLOCK" "$RUNNER" "$ROOT/flip/flock-resolution.mjs" --flock-check)"
|
|
722
|
+
if [ "$(printf '%s' "$orig_res" | cut -f1)" = "unusable" ] && [ "$(printf '%s' "$mut_res" | cut -f1)" = "ok" ]; then
|
|
723
|
+
ok "flip(不查执行权限):原实现报 unusable,变异体报 ok —— ⑦i 与 paths/doctor 判据会红"
|
|
724
|
+
else
|
|
725
|
+
bad "flip(不查执行权限)没被咬住(原 [$orig_res],变异 [$mut_res])"
|
|
726
|
+
fi
|
|
727
|
+
else
|
|
728
|
+
note "跳过红侧臂 flock-resolution(本次 --flip=${FLIP})"
|
|
729
|
+
fi
|
|
730
|
+
|
|
456
731
|
# 10a. 不持锁的直写:只把生产代码里那条 flock 调用换成直接事务(一行之差,不放大任何窗口)
|
|
457
732
|
if arm_selected unlocked; then
|
|
458
733
|
FLIPS_RUN="${FLIPS_RUN:+$FLIPS_RUN,}unlocked"
|
|
@@ -503,10 +778,6 @@ if flip_copy version 's/if (snapshot.version !== SNAPSHOT_VERSION) fail/if (fals
|
|
|
503
778
|
else
|
|
504
779
|
bad "flip 变异没落地(源码形状变了,夹具需要更新)"
|
|
505
780
|
fi
|
|
506
|
-
flip_helper() { # <helper> <repo> <state> <op> → 打印输出
|
|
507
|
-
( cd "$2" && env -u TEAM_ROOT -u TEAM_MAIN_ROOT -u TEAM_PROJECT -u TEAM_SESSION HOME="$ROOT/home" \
|
|
508
|
-
"$RUNNER" "$1" --cli "$2" "$3" "$4" 2>&1 )
|
|
509
|
-
}
|
|
510
781
|
cp "$A_STATE/reminders/state.json" "$ROOT/state-good.json"
|
|
511
782
|
sed 's/"version":1/"version":2/' "$ROOT/state-good.json" >"$SNAP"
|
|
512
783
|
out="$(flip_helper "$NODE_HELPER" "$A" "$A_STATE" read)"; rc=$?
|
|
@@ -545,6 +816,96 @@ else
|
|
|
545
816
|
note "跳过红侧臂 foreign(本次 --flip=${FLIP})"
|
|
546
817
|
fi
|
|
547
818
|
|
|
819
|
+
# 10e. 待命迁移的三条红臂:迁移必须真的读旧标记、读/写必须真的走统一状态
|
|
820
|
+
if arm_selected standby-ignore; then
|
|
821
|
+
FLIPS_RUN="${FLIPS_RUN:+$FLIPS_RUN,}standby-ignore"
|
|
822
|
+
if flip_copy standby-ignore 's/^function legacyMarker(state) {/function legacyMarker(state) { return null;/'; then
|
|
823
|
+
ok "flip 变异已落地:迁移不再读旧标记"
|
|
824
|
+
else
|
|
825
|
+
bad "flip 变异没落地(源码形状变了,夹具需要更新)"
|
|
826
|
+
fi
|
|
827
|
+
O="$(make_repo O)" || { bad "夹具建不出仓库 O"; result; exit 1; }
|
|
828
|
+
P="$(make_repo P)" || { bad "夹具建不出仓库 P"; result; exit 1; }
|
|
829
|
+
O_STATE="$O/.pi/team/state"; P_STATE="$P/.pi/team/state"
|
|
830
|
+
mkdir -p "$O_STATE" "$P_STATE"
|
|
831
|
+
printf '2026-10-30T08:30:00Z human is deciding\n' >"$O_STATE/standby"
|
|
832
|
+
printf '2026-10-30T08:30:00Z human is deciding\n' >"$P_STATE/standby"
|
|
833
|
+
flip_helper "$NODE_HELPER" "$P" "$P_STATE" standby-import >/dev/null
|
|
834
|
+
mut_out="$(flip_helper "$ROOT/flip/standby-ignore.mjs" "$O" "$O_STATE" standby-import)"
|
|
835
|
+
orig_reason="$(jget "$(cat "$P_STATE/reminders/state.json")" standby.reason)"
|
|
836
|
+
mut_on="$(jget "$(cat "$O_STATE/reminders/state.json")" standby.on)"
|
|
837
|
+
if [ "$orig_reason" = "human is deciding" ] && [ "$mut_on" = "false" ]; then
|
|
838
|
+
ok "flip(忽略旧标记):原实现保留 on+原因,变异体成了 off、原因也没搬进来 —— ③b/③d 会红"
|
|
839
|
+
else
|
|
840
|
+
bad "flip(忽略旧标记)没被咬住(原 reason=[$orig_reason],变异 on=[$mut_on],输出:$(printf '%s' "$mut_out" | tr '\n' '|'))"
|
|
841
|
+
fi
|
|
842
|
+
else
|
|
843
|
+
note "跳过红侧臂 standby-ignore(本次 --flip=${FLIP})"
|
|
844
|
+
fi
|
|
845
|
+
|
|
846
|
+
if arm_selected standby-file; then
|
|
847
|
+
FLIPS_RUN="${FLIPS_RUN:+$FLIPS_RUN,}standby-file"
|
|
848
|
+
if flip_copy standby-file 's/^ if (snapshot.standby.migrated) return { ...snapshot.standby, legacy: false };/ if (false) return { ...snapshot.standby, legacy: false };/'; then
|
|
849
|
+
ok "flip 变异已落地:读路径退回「旧标记总是算数」"
|
|
850
|
+
else
|
|
851
|
+
bad "flip 变异没落地(源码形状变了,夹具需要更新)"
|
|
852
|
+
fi
|
|
853
|
+
Q="$(make_repo Q)" || { bad "夹具建不出仓库 Q"; result; exit 1; }
|
|
854
|
+
Q_STATE="$Q/.pi/team/state"
|
|
855
|
+
runchild "$Q" -- "$PREP; team_standby_on 'x'; team_standby_off" >/dev/null
|
|
856
|
+
printf '2026-11-02T00:00:00Z stale marker\n' >"$Q_STATE/standby"
|
|
857
|
+
orig_on="$(flip_helper "$NODE_HELPER" "$Q" "$Q_STATE" standby-read --print on)"
|
|
858
|
+
mut_on_file="$(flip_helper "$ROOT/flip/standby-file.mjs" "$Q" "$Q_STATE" standby-read --print on)"
|
|
859
|
+
if [ "$orig_on" = "false" ] && [ "$mut_on_file" = "true" ]; then
|
|
860
|
+
ok "flip(读回文件):原实现仍 off,变异体被旧标记改回 on —— ⑤b 会红"
|
|
861
|
+
else
|
|
862
|
+
bad "flip(读回文件)没被咬住(原 [$orig_on],变异 [$mut_on_file])"
|
|
863
|
+
fi
|
|
864
|
+
rm -f "$Q_STATE/standby"
|
|
865
|
+
else
|
|
866
|
+
note "跳过红侧臂 standby-file(本次 --flip=${FLIP})"
|
|
867
|
+
fi
|
|
868
|
+
|
|
869
|
+
if arm_selected standby-write; then
|
|
870
|
+
FLIPS_RUN="${FLIPS_RUN:+$FLIPS_RUN,}standby-write"
|
|
871
|
+
authority_helper_copy "$ROOT/flip/standby-write.mjs"
|
|
872
|
+
python3 - "$ROOT/flip/standby-write.mjs" <<'PYEOF'
|
|
873
|
+
import sys
|
|
874
|
+
path = sys.argv[1]
|
|
875
|
+
text = open(path).read()
|
|
876
|
+
try:
|
|
877
|
+
start = text.index(" case 'standby-on': {")
|
|
878
|
+
end = text.index(" case 'standby-off': {")
|
|
879
|
+
except ValueError:
|
|
880
|
+
sys.stderr.write('state-authority: standby-write 变异没落地(源码形状变了)\n')
|
|
881
|
+
sys.exit(1)
|
|
882
|
+
replacement = """ case 'standby-on': {
|
|
883
|
+
fs.writeFileSync(legacyMarkerFile(state), `${isoSeconds(nowMs)} ${typeof request.reason === 'string' ? request.reason : '-'}\\n`);
|
|
884
|
+
return standbyResult(snapshot, state);
|
|
885
|
+
}
|
|
886
|
+
"""
|
|
887
|
+
open(path, 'w').write(text[:start] + replacement + text[end:])
|
|
888
|
+
PYEOF
|
|
889
|
+
if [ "$?" -eq 0 ] && ! cmp -s "$SKILL/scripts/state-authority.mjs" "$ROOT/flip/standby-write.mjs"; then
|
|
890
|
+
ok "flip 变异已落地:写待命退回写 state/standby"
|
|
891
|
+
else
|
|
892
|
+
bad "flip 变异没落地(源码形状变了,夹具需要更新)"
|
|
893
|
+
fi
|
|
894
|
+
S="$(make_repo S)" || { bad "夹具建不出仓库 S"; result; exit 1; }
|
|
895
|
+
T="$(make_repo T)" || { bad "夹具建不出仓库 T"; result; exit 1; }
|
|
896
|
+
flip_helper "$NODE_HELPER" "$S" "$S/.pi/team/state" standby-on --reason proof >/dev/null
|
|
897
|
+
flip_helper "$ROOT/flip/standby-write.mjs" "$T" "$T/.pi/team/state" standby-on --reason proof >/dev/null
|
|
898
|
+
orig_snap="$(jget "$(cat "$S/.pi/team/state/reminders/state.json" 2>/dev/null)" standby.on 2>/dev/null)"
|
|
899
|
+
mut_snap="$(jget "$(cat "$T/.pi/team/state/reminders/state.json" 2>/dev/null)" standby.on 2>/dev/null)"
|
|
900
|
+
if [ "$orig_snap" = "true" ] && [ "$mut_snap" != "true" ] && [ -f "$T/.pi/team/state/standby" ]; then
|
|
901
|
+
ok "flip(写回文件):原实现的快照记 on,变异体只写了 state/standby(快照里没有 on)—— ②d 会红"
|
|
902
|
+
else
|
|
903
|
+
bad "flip(写回文件)没被咬住(原快照 on=[$orig_snap],变异快照 on=[$mut_snap],旧标记:$( [ -f "$T/.pi/team/state/standby" ] && echo 有 || echo 无))"
|
|
904
|
+
fi
|
|
905
|
+
else
|
|
906
|
+
note "跳过红侧臂 standby-write(本次 --flip=${FLIP})"
|
|
907
|
+
fi
|
|
908
|
+
|
|
548
909
|
# ---------------------------------------------------------------- 11. 事故形状的证明:主项目 .pi/team 没被碰过
|
|
549
910
|
main_team_snapshot "${REAL_MAIN:-/nonexistent}/.pi/team" >"$REAL_AFTER"
|
|
550
911
|
violations="$(main_team_violations "$REAL_BEFORE" "$REAL_AFTER")"
|
|
@@ -556,14 +917,17 @@ else
|
|
|
556
917
|
bad "主项目 .pi/team 出现了非白名单变化($(printf '%s' "$violations" | tr '\n' ' '))"
|
|
557
918
|
printf '%s\n' "$violations" | head -12 | sed 's/^/ /'
|
|
558
919
|
fi
|
|
559
|
-
# 事故形状(2026-10-31
|
|
560
|
-
|
|
561
|
-
|
|
920
|
+
# 事故形状(2026-10-31:夹具往主项目写了提醒与 Standby 状态):这次运行不许在建这些路径上留下任何动作。
|
|
921
|
+
# 判据是「本夹具没动过它」而不是「它不存在」—— 真实团队的 state/standby 在 PM 迁移前本来就在,
|
|
922
|
+
# 迁移之后 .pi/team/reminder-locator.json 与 state/reminders/ 也会是合法的。
|
|
923
|
+
for leaked in ./.pi/team/reminder-locator.json ./.pi/team/reminder-locator.lock ./.pi/team/state/reminders \
|
|
924
|
+
./.pi/team/state/standby ./.pi/team/state/standby.migrated ./reminder-locator.json; do
|
|
562
925
|
[ -n "$REAL_MAIN" ] || break
|
|
563
|
-
|
|
564
|
-
|
|
926
|
+
touched="$(main_team_touched "$REAL_BEFORE" "$REAL_AFTER" "$leaked")"
|
|
927
|
+
if [ -z "$touched" ]; then
|
|
928
|
+
ok "事故形状:这次运行没动主项目的 ${leaked#./}"
|
|
565
929
|
else
|
|
566
|
-
bad "
|
|
930
|
+
bad "事故形状:夹具写了主项目的 ${leaked#./}($(printf '%s' "$touched" | tr '\n' ' '))"
|
|
567
931
|
fi
|
|
568
932
|
done
|
|
569
933
|
note "证明对象:${REAL_MAIN:-(本检出没有主工作树)}/.pi/team(非白名单路径逐字节;白名单形状按名字放行)"
|
|
@@ -350,8 +350,8 @@ if (only('S2')) {
|
|
|
350
350
|
const ok = await waitFor(() => sent.length > before + 0)
|
|
351
351
|
check('S2 a new spool line wakes the session (fs.watch, polling disabled)', ok && sent.length === before + 1,
|
|
352
352
|
`messages=${sent.length - before}`)
|
|
353
|
-
check('S2 wake is a custom team-inbox message with triggerTurn+
|
|
354
|
-
sent.at(-1)?.msg?.customType === 'team-inbox' && sent.at(-1)?.opts?.triggerTurn === true && sent.at(-1)?.opts?.deliverAs === '
|
|
353
|
+
check('S2 wake is a custom team-inbox message with triggerTurn+steer',
|
|
354
|
+
sent.at(-1)?.msg?.customType === 'team-inbox' && sent.at(-1)?.opts?.triggerTurn === true && sent.at(-1)?.opts?.deliverAs === 'steer',
|
|
355
355
|
JSON.stringify({ customType: sent.at(-1)?.msg?.customType, ...(sent.at(-1)?.opts ?? {}) }))
|
|
356
356
|
const body = lastText()
|
|
357
357
|
check('S2 wake is a pointer to the inbox file, not the payload', body.includes('docs/team/inbox/pm.md'), body.split('\n')[0])
|
|
@@ -1037,9 +1037,9 @@ const degradedFiles = () => (existsSync(WATCH_DIR) ? readdirSync(WATCH_DIR).filt
|
|
|
1037
1037
|
check('S23 a forced-failure session still wakes within one poll interval (200 ms)',
|
|
1038
1038
|
woke && sent.length === beforeWake + 1, `messages=${sent.length - beforeWake}`)
|
|
1039
1039
|
const fallbackWake = sent.at(-1)
|
|
1040
|
-
check('S23 the fallback wake keeps the live-watcher shape (customType/triggerTurn/
|
|
1040
|
+
check('S23 the fallback wake keeps the live-watcher shape (customType/triggerTurn/steer)',
|
|
1041
1041
|
fallbackWake?.msg?.customType === 'team-inbox' && fallbackWake?.opts?.triggerTurn === true
|
|
1042
|
-
&& fallbackWake?.opts?.deliverAs === '
|
|
1042
|
+
&& fallbackWake?.opts?.deliverAs === 'steer',
|
|
1043
1043
|
JSON.stringify({ customType: fallbackWake?.msg?.customType, ...(fallbackWake?.opts ?? {}) }))
|
|
1044
1044
|
const fallbackBody = lastText()
|
|
1045
1045
|
check('S23 the fallback wake points at the inbox and truncates the payload',
|
|
@@ -1121,7 +1121,7 @@ if (only('S25j')) {
|
|
|
1121
1121
|
recs.map(r => `${r.kind}${r.fields.seq ? `=${r.fields.seq}` : ''}`).join(' '))
|
|
1122
1122
|
check('S25j every record is ISO-stamped', recs.every(r => /^\d{4}-\d{2}-\d{2}T/.test(r.ts)), recs[0]?.ts ?? '')
|
|
1123
1123
|
check('S25j the wake ledger line names seq and the identities',
|
|
1124
|
-
/ wake n=1 total=1 inbox=pm kinds=say seq=1 ids=\S
|
|
1124
|
+
/ wake n=1 total=1 inbox=pm kinds=say seq=1 ids=\S+ deliver=steer$/.test(ledger().filter(l => / wake n=/.test(l)).at(-1) ?? ''),
|
|
1125
1125
|
ledger().filter(l => / wake n=/.test(l)).at(-1) ?? '(no wake line)')
|
|
1126
1126
|
// 过期行:不写日志记录、不唤醒、只计数
|
|
1127
1127
|
const before = sent.length
|
|
@@ -1221,7 +1221,7 @@ if (only('S25a')) {
|
|
|
1221
1221
|
woke && sent.length === before + 1, `messages=${sent.length - before}`)
|
|
1222
1222
|
const wakeLine = ledger().filter(l => / wake n=/.test(l)).at(-1) ?? ''
|
|
1223
1223
|
check('S25a the ledger records it as recovery with its seq',
|
|
1224
|
-
/ wake n=1 total=1 inbox=pm kinds=say seq=\d+ ids=\S+ recovery n=1$/.test(wakeLine), wakeLine.trim())
|
|
1224
|
+
/ wake n=1 total=1 inbox=pm kinds=say seq=\d+ ids=\S+ deliver=steer recovery n=1$/.test(wakeLine), wakeLine.trim())
|
|
1225
1225
|
check('S25a the recovery is recorded in the journal as sent (at most once from now on)',
|
|
1226
1226
|
journalOf('sent').length === 1, `sent records=${journalOf('sent').length}`)
|
|
1227
1227
|
// 同一批字节再重写一次 —— **跨一次重启**(重启本身也不得再恢复):证明至多一次是由日志
|
|
@@ -1566,9 +1566,9 @@ if (only('S26')) {
|
|
|
1566
1566
|
check('S26 the wake names the delivery journal the identities were recorded in',
|
|
1567
1567
|
body.includes(journalPathOf()) && existsSync(journalPathOf()),
|
|
1568
1568
|
(body.split('\n').find(l => l.includes('Delivery journal')) ?? '(none)').slice(0, 200))
|
|
1569
|
-
check('S26 the wake shape is unchanged (customType/triggerTurn/
|
|
1569
|
+
check('S26 the wake shape is unchanged (customType/triggerTurn/steer)',
|
|
1570
1570
|
sent.at(-1)?.msg?.customType === 'team-inbox' && sent.at(-1)?.opts?.triggerTurn === true
|
|
1571
|
-
&& sent.at(-1)?.opts?.deliverAs === '
|
|
1571
|
+
&& sent.at(-1)?.opts?.deliverAs === 'steer',
|
|
1572
1572
|
JSON.stringify({ customType: sent.at(-1)?.msg?.customType, ...(sent.at(-1)?.opts ?? {}) }))
|
|
1573
1573
|
check('S26 no payload dump: the wake stays a bounded one-line pointer per line',
|
|
1574
1574
|
body.split('\n').filter(l => l.startsWith('- ')).every(l => l.length <= 220), `len=${body.length}`)
|
|
@@ -1578,6 +1578,56 @@ if (only('S26')) {
|
|
|
1578
1578
|
await shutdown()
|
|
1579
1579
|
}
|
|
1580
1580
|
|
|
1581
|
+
// ── S28(P419)· 投递模式按**消息类别**选:通知等 → followUp;含 say 的批 → steer ────────────
|
|
1582
|
+
// 为什么要按类别:`team say` 是 PM 发给席位的**指令**,`followUp` 要等席位把手上这一轮跑完才投,指令就
|
|
1583
|
+
// 只能排在这一轮之后;`steer` 落在本次工具调用结束后、下一次模型请求之前,插得进正在跑的那一轮。通知类
|
|
1584
|
+
// (notify / nudge / knock / draft 回执)不该打断正在跑的一轮,保持 followUp;混批仍然只投一次,用 steer。
|
|
1585
|
+
// 这一组走 100ms 轮询(不依赖 fs.watch 前提),三种前提(真人/机器不可用/强制失败)下都真跑真判。
|
|
1586
|
+
process.env.TEAM_INBOX_WATCH_POLL_MS = '100'
|
|
1587
|
+
if (only('S28')) {
|
|
1588
|
+
await resetState()
|
|
1589
|
+
await sessionStart()
|
|
1590
|
+
const lastOpts = () => sent.at(-1)?.opts ?? {}
|
|
1591
|
+
// (a) 只含通知的批:三类都还是 followUp(只有 triggerTurn 的老形状)
|
|
1592
|
+
for (const kind of ['notify', 'nudge', 'knock']) {
|
|
1593
|
+
const before = sent.length
|
|
1594
|
+
appendWake(kind, 'dev', 'pm', `S28-${kind}-only`)
|
|
1595
|
+
const woke = await waitFor(() => sent.length > before)
|
|
1596
|
+
check(`S28 a ${kind}-only batch is delivered as followUp`,
|
|
1597
|
+
woke && sent.length === before + 1 && lastOpts().deliverAs === 'followUp' && lastOpts().triggerTurn === true,
|
|
1598
|
+
`messages=${sent.length - before} deliverAs=${lastOpts().deliverAs} triggerTurn=${lastOpts().triggerTurn}`)
|
|
1599
|
+
}
|
|
1600
|
+
// (b) 批里只有一条 say:steer(这条红侧是「类别判定被删掉 → 恒 followUp」)
|
|
1601
|
+
{
|
|
1602
|
+
const before = sent.length
|
|
1603
|
+
appendWake('say', 'pm', 'pm', 'S28-say-instruction')
|
|
1604
|
+
const woke = await waitFor(() => sent.length > before)
|
|
1605
|
+
check('S28 a say batch is delivered as steer',
|
|
1606
|
+
woke && sent.length === before + 1 && lastOpts().deliverAs === 'steer' && lastOpts().triggerTurn === true,
|
|
1607
|
+
`messages=${sent.length - before} deliverAs=${lastOpts().deliverAs}`)
|
|
1608
|
+
check('S28 the steer wake still names its line and the inbox file, never the payload in full',
|
|
1609
|
+
lastText().includes('S28-say-instruction') && lastText().includes('docs/team/inbox/pm.md'),
|
|
1610
|
+
lastText().split('\n')[0])
|
|
1611
|
+
}
|
|
1612
|
+
// (c) 混批(一条通知 + 一条指令落在同一拍):只投一次,且用 steer
|
|
1613
|
+
{
|
|
1614
|
+
const before = sent.length
|
|
1615
|
+
appendWake('notify', 'dev', 'pm', 'S28-mixed-notify')
|
|
1616
|
+
appendWake('say', 'pm', 'pm', 'S28-mixed-say')
|
|
1617
|
+
await sleep(500)
|
|
1618
|
+
const body = lastText()
|
|
1619
|
+
const wakeLine = ledger().filter(l => / wake n=/.test(l)).at(-1) ?? ''
|
|
1620
|
+
check('S28 a mixed batch is delivered once and as steer',
|
|
1621
|
+
sent.length === before + 1 && lastOpts().deliverAs === 'steer',
|
|
1622
|
+
`messages=${sent.length - before} deliverAs=${lastOpts().deliverAs}`)
|
|
1623
|
+
check('S28 the mixed wake carries both lines and its ledger names the category decision',
|
|
1624
|
+
body.includes('S28-mixed-notify') && body.includes('S28-mixed-say')
|
|
1625
|
+
&& / wake n=2 total=\d+ inbox=pm kinds=notify,say seq=\d+ ids=\S+ deliver=steer/.test(wakeLine),
|
|
1626
|
+
wakeLine.trim())
|
|
1627
|
+
}
|
|
1628
|
+
await shutdown()
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1581
1631
|
// ── 反向守卫:真实仓库 state/ 未被触碰 ───────────────────────────────────────
|
|
1582
1632
|
{
|
|
1583
1633
|
const after = snapshot(REAL_STATE)
|