teamsmith 0.4.3 → 0.4.6

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.
Files changed (44) hide show
  1. package/README.md +4 -4
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +33 -1
  4. package/skills/teamsmith/SKILL.md +1 -1
  5. package/skills/teamsmith/extension/team-bg.ts +7 -8
  6. package/skills/teamsmith/extension/team-inbox-watch.ts +136 -3
  7. package/skills/teamsmith/references/protocol.md +2 -3
  8. package/skills/teamsmith/references/reminders.md +55 -12
  9. package/skills/teamsmith/references/workflows.md +1 -3
  10. package/skills/teamsmith/scripts/lib/cmd-agents.sh +18 -1
  11. package/skills/teamsmith/scripts/lib/cmd-project.sh +12 -9
  12. package/skills/teamsmith/scripts/lib/cmd-remind.sh +49 -10
  13. package/skills/teamsmith/scripts/lib/cmd-update.sh +90 -88
  14. package/skills/teamsmith/scripts/lib/cmd-watch.sh +281 -155
  15. package/skills/teamsmith/scripts/lib/common.sh +74 -14
  16. package/skills/teamsmith/scripts/panel/panel.js +134 -134
  17. package/skills/teamsmith/scripts/panel/src/data.ts +51 -0
  18. package/skills/teamsmith/scripts/panel/src/layout.ts +10 -0
  19. package/skills/teamsmith/scripts/panel/src/main.tsx +27 -0
  20. package/skills/teamsmith/scripts/remind-store.mjs +362 -6
  21. package/skills/teamsmith/scripts/remind-tick.mjs +102 -0
  22. package/skills/teamsmith/scripts/reminder-delivery.mjs +76 -0
  23. package/skills/teamsmith/scripts/reply-capture.mjs +53 -8
  24. package/skills/teamsmith/scripts/state-authority.mjs +265 -17
  25. package/skills/teamsmith/scripts/strings/commands.tsv +3 -3
  26. package/skills/teamsmith/scripts/strings/help.en.tsv +12 -12
  27. package/skills/teamsmith/scripts/strings/help.zh.tsv +12 -12
  28. package/skills/teamsmith/scripts/team +3 -3
  29. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +2 -3
  30. package/skills/teamsmith/templates/pm-prompt.md.tmpl +11 -5
  31. package/skills/teamsmith/tests/death-cause.sh +5 -0
  32. package/skills/teamsmith/tests/help-surface.sh +15 -150
  33. package/skills/teamsmith/tests/isolation-ledger.sh +85 -0
  34. package/skills/teamsmith/tests/lib/main-team-fingerprint.sh +17 -1
  35. package/skills/teamsmith/tests/live-capture-probe.sh +63 -0
  36. package/skills/teamsmith/tests/pulse-nudge-key.sh +5 -0
  37. package/skills/teamsmith/tests/remind-delivery-node.mjs +176 -0
  38. package/skills/teamsmith/tests/remind-delivery.sh +611 -0
  39. package/skills/teamsmith/tests/section-paths.tsv +6 -6
  40. package/skills/teamsmith/tests/smoke.sh +397 -107
  41. package/skills/teamsmith/tests/state-authority.sh +246 -26
  42. package/skills/teamsmith/tests/team-inbox-watch-harness.mjs +58 -8
  43. package/skills/teamsmith/tests/tmux-identity-leak.sh +12 -16
  44. package/skills/teamsmith-init/SKILL.md +1 -1
@@ -0,0 +1,611 @@
1
+ #!/usr/bin/env bash
2
+ # remind-delivery.sh — P423(change: agent-self-reminder 3.1/3.2 · 4.1)的隔离夹具
3
+ #
4
+ # 它证的是「叫醒这条线」:到点入队 → 冻结一批 → 一条完整消息 → 匹配的回执 → 至多一次退待命 →
5
+ # 重启补发 / 不重发。全部在自己的临时根里(每个仓库先 git init、显式 --root 与 TEAM_STATE_DIR、
6
+ # HOME/TMPDIR 指向夹具自己的目录、继承来的 TEAM_* 与 tmux 身份一律清掉)。
7
+ #
8
+ # A 到期入队 不到点不入队;到点的只入一次(重复巡检不加第二条);取消的项不入队;
9
+ # overdue 的两种形状(到期早于本巡检实例 / 入队滞后超 30s),正常轮询延迟不标 overdue
10
+ # B 冻结批次 按入队顺序最多 8 条冻结成一批;已有一批在飞时拒绝再冻(不重复送);
11
+ # 5 秒间隔;成员记录带批次 id
12
+ # C 观察与待命 匹配的回执 → observed + 花掉唯一 right + 自动退当前代次 + 一条点名全部 id/来源的审计;
13
+ # 手动已 off → already-off;更新的代次 → 保留并报 ambiguous;重复事件不产生第二次 off;
14
+ # nonce/会话不符 → 拒绝且不消耗 right
15
+ # D 未送达 queued / intent / failed-unknown 都不清待命;只有真回执才清
16
+ # E 失败与确认 API 拒绝 → unknown(可见、不重发、attempts 记账);unknown 挡住下一批;
17
+ # resolve 必须显式 --ack-unknown;确认后成员 resolved、right 烧掉、下一批可以再冻
18
+ # F 重启恢复 queued 在新进程里照样被冻结送出;intent 超过 60s → unknown 且不重发;
19
+ # observed/resolved 不会被重新入队或重发
20
+ # G 投递面 reminderContent/details/matchesObservation 的契约 + 真扩展(假 Pi 宿主):一批一条
21
+ # followUp 消息、先 intent 后发、匹配事件观察一次、重复事件无效、shutdown 后不再发
22
+ # H 隔离 跑完主项目 `.pi/team` 的非白名单路径零变化(与 §66/§67 共用同一份判据)
23
+ #
24
+ # 红侧(`--flip=<id>`,每条都必须能红;不带参数时全跑):
25
+ # --flip=admit-any 入队不看到期时间 → A 的「不到点不入队」必须红
26
+ # --flip=intent-multi 不看已有一批在飞 → B 的「拒绝再冻」必须红
27
+ # --flip=observe-nogen 观察不再核对待命代次 → C 的「更新代次必须保留」必须红
28
+ # --flip=off-on-queue 入队就把待命关掉 → D 的「未送达不得清待命」必须红
29
+ # --flip=unknown-resend unknown 不再挡住下一批 → E 的「unknown 挡住下一批」必须红
30
+ # 红侧跑在 scratch 副本上(只复制 state-authority.mjs + remind-store.mjs,import 关系与产品相同),
31
+ # 真树与产品文件不动;每条变异都先证明落地,再判它给出的是错误答案。
32
+ #
33
+ # 用法:bash tests/remind-delivery.sh [--flip=<id>]…
34
+ # 退出码:0 全绿 / 1 有失败 / 2 参数不认识 / 3 前提缺失(JS 运行时或 flock;可见跳过,不算通过)
35
+ set -uo pipefail
36
+
37
+ HERE="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
38
+ SKILL="$(cd -P "$HERE/.." && pwd)"
39
+ TEAM_CLI="$SKILL/scripts/team"
40
+
41
+ FLIPS=()
42
+ for arg in "$@"; do
43
+ case "$arg" in
44
+ --flip=*)
45
+ case "${arg#--flip=}" in
46
+ admit-any|intent-multi|observe-nogen|off-on-queue|unknown-resend) FLIPS+=("${arg#--flip=}") ;;
47
+ *) printf 'remind-delivery:不认识的 --flip 值 [%s]\n' "${arg#--flip=}" >&2; exit 2 ;;
48
+ esac ;;
49
+ -h|--help) sed -n '2,33p' "$0"; exit 0 ;;
50
+ *) printf 'remind-delivery:不认识的参数 [%s]\n' "$arg" >&2; exit 2 ;;
51
+ esac
52
+ done
53
+ arm_selected() {
54
+ [ "${#FLIPS[@]}" -eq 0 ] && return 0
55
+ local f; for f in "${FLIPS[@]}"; do [ "$f" = "$1" ] && return 0; done
56
+ return 1
57
+ }
58
+ FLIPS_RUN=""
59
+
60
+ # shellcheck source=lib/tmp-root.sh
61
+ . "$HERE/lib/tmp-root.sh"
62
+ # shellcheck source=lib/main-team-fingerprint.sh
63
+ . "$HERE/lib/main-team-fingerprint.sh"
64
+
65
+ RUNNER="$(team_js_runner)"
66
+ if [ -z "$RUNNER" ]; then
67
+ printf 'remind-delivery:前提缺失 —— 没有 JS 运行时;这是可见跳过,不是通过\n' >&2
68
+ exit 3
69
+ fi
70
+ if ! command -v flock >/dev/null 2>&1; then
71
+ printf 'remind-delivery:前提缺失 —— 这台机器没有 flock,权威层按设计拒绝工作(可见跳过,不是通过)\n' >&2
72
+ exit 3
73
+ fi
74
+
75
+ ROOT="$(tmp_root_create remind-delivery)" || exit 3
76
+ trap 'tmp_root_reap_all' EXIT
77
+ mkdir -p "$ROOT/home" "$ROOT/tmp" "$ROOT/fx" "$ROOT/out" "$ROOT/script"
78
+ export HOME="$ROOT/home"
79
+ unset TEAM_ROOT TEAM_MAIN_ROOT TEAM_PROJECT TEAM_SESSION TEAM_SESSION_FROM TEAM_STATE_DIR TEAM_CONFIG_FILE \
80
+ TEAM_IDENTITY_LOCKED TEAM_IDENTITY_ROOT TEAM_IDENTITY_MAIN_ROOT TEAM_IDENTITY_PROJECT \
81
+ TEAM_IDENTITY_INHERIT_ROOT TEAM_IDENTITY_INHERIT_MAIN_ROOT TEAM_IDENTITY_INHERIT_PROJECT \
82
+ TEAM_IDENTITY_INHERIT_SESSION TEAM_ALLOW_FOREIGN_IDENTITY TMUX TMUX_PANE \
83
+ TEAM_INBOX_WATCH_TARGET TEAM_REMIND_POLL_MS 2>/dev/null || true
84
+
85
+ PASS=0; FAIL=0
86
+ ok() { printf ' \033[32m✓\033[0m %s\n' "$1"; PASS=$((PASS + 1)); }
87
+ bad() { printf ' \033[31m✗\033[0m %s\n' "$1"; FAIL=$((FAIL + 1)); }
88
+ note() { printf ' %s\n' "$1"; }
89
+ result() {
90
+ printf '\nflip 臂:%s\n' "${FLIPS_RUN:-none}"
91
+ printf '== remind-delivery 结果 == ✓%d ✗%d SKIP0\n' "$PASS" "$FAIL"
92
+ [ "$FAIL" -eq 0 ]
93
+ }
94
+ assert_eq() { [ "$2" = "$3" ] && ok "$1" || bad "$1(期望 [$3],实际 [$2])"; }
95
+ assert_has() { case "$2" in *"$3"*) ok "$1" ;; *) bad "$1(输出里没有 [$3]:$(printf '%s' "$2" | head -2 | tr '\n' '|' | cut -c1-140))" ;; esac; }
96
+ assert_no() { case "$2" in *"$3"*) bad "$1(输出里不该出现 [$3])" ;; *) ok "$1" ;; esac; }
97
+
98
+ # ---------------------------------------------------------------- small JSON helpers (no jq)
99
+ cat > "$ROOT/json-get.mjs" <<'JS'
100
+ import fs from 'node:fs';
101
+ const [file, dotted] = process.argv.slice(2);
102
+ let value = JSON.parse(fs.readFileSync(file, 'utf8'));
103
+ for (const key of dotted.split('.')) {
104
+ if (value == null) { value = undefined; break; }
105
+ if (Array.isArray(value) && /^-[0-9]+$/.test(key)) value = value[value.length + Number(key)];
106
+ else value = value[key];
107
+ }
108
+ if (value === undefined) process.exit(3);
109
+ process.stdout.write(typeof value === 'string' ? value : JSON.stringify(value));
110
+ JS
111
+ cat > "$ROOT/snapshot-edit.mjs" <<'JS'
112
+ // Hand-edit a snapshot the way an operator or a later process would. The fixture owns the repository,
113
+ // so editing the state file directly is legitimate preparation, not a second implementation.
114
+ import fs from 'node:fs';
115
+ const [file, script] = process.argv.slice(2);
116
+ const snap = JSON.parse(fs.readFileSync(file, 'utf8'));
117
+ new Function('snap', 'iso', fs.readFileSync(script, 'utf8'))(snap, ms => new Date(ms).toISOString());
118
+ fs.writeFileSync(file + '.edit', JSON.stringify(snap) + '\n');
119
+ fs.renameSync(file + '.edit', file);
120
+ JS
121
+ jfield() { "$RUNNER" "$ROOT/json-get.mjs" "$1" "$2"; }
122
+ snapshot_of() { printf '%s/.pi/team/state/reminders/state.json\n' "$1"; }
123
+ edit_snapshot() { # <repo> <script-file>
124
+ "$RUNNER" "$ROOT/snapshot-edit.mjs" "$(snapshot_of "$1")" "$2"
125
+ }
126
+
127
+ # ---------------------------------------------------------------- fixture repositories
128
+ new_repo() { # <名字> → path(自己的 git 仓库;绝不落在别人的检出里)
129
+ local dir="$ROOT/fx/$1"
130
+ rm -rf "$dir"; mkdir -p "$dir"
131
+ git -C "$dir" init -q || return 1
132
+ git -C "$dir" -c user.email=fixture@example.invalid -c user.name=Fixture commit -q --allow-empty -m fixture || return 1
133
+ printf '%s\n' "$dir"
134
+ }
135
+
136
+ # One place where a child is stripped of inherited identity and given explicit roots.
137
+ child_env() { # <repo> [VAR=VAL…] -- <command…>
138
+ local repo="$1"; shift
139
+ local envs=()
140
+ while [ "$#" -gt 0 ] && [ "$1" != "--" ]; do envs+=("$1"); shift; done
141
+ [ "${1:-}" = "--" ] && shift
142
+ ( cd "$repo" && env -u TEAM_ROOT -u TEAM_MAIN_ROOT -u TEAM_PROJECT -u TEAM_SESSION -u TEAM_SESSION_FROM \
143
+ -u TEAM_STATE_DIR -u TEAM_CONFIG_FILE -u TEAM_IDENTITY_LOCKED -u TEAM_IDENTITY_ROOT \
144
+ -u TEAM_IDENTITY_MAIN_ROOT -u TEAM_IDENTITY_PROJECT -u TEAM_IDENTITY_INHERIT_ROOT \
145
+ -u TEAM_IDENTITY_INHERIT_MAIN_ROOT -u TEAM_IDENTITY_INHERIT_PROJECT -u TEAM_IDENTITY_INHERIT_SESSION \
146
+ -u TEAM_ALLOW_FOREIGN_IDENTITY -u TMUX -u TMUX_PANE \
147
+ HOME="$ROOT/home" TMPDIR="$ROOT/tmp" TEAM_STATE_DIR="$repo/.pi/team/state" \
148
+ ${envs[@]+"${envs[@]}"} "$@" )
149
+ }
150
+
151
+ run_team() { # <repo> <out> [args…] → RC;stdout+stderr 落 <out>
152
+ local repo="$1" out="$2"; shift 2
153
+ child_env "$repo" -- bash "$TEAM_CLI" --root "$repo" "$@" </dev/null >"$out" 2>&1
154
+ RC=$?
155
+ }
156
+
157
+ authority() { # <repo> <out> [helper args…] → RC(产品助手;stdin 恒为 /dev/null)
158
+ local repo="$1" out="$2"; shift 2
159
+ child_env "$repo" -- "$RUNNER" "$SKILL/scripts/state-authority.mjs" --cli "$repo" "$repo/.pi/team/state" "$@" \
160
+ </dev/null >"$out" 2>&1
161
+ RC=$?
162
+ }
163
+
164
+ tick() { # <repo> <pulse-started> <out> [extra env…] → RC(巡检的轻量到期检查)
165
+ local repo="$1" started="$2" out="$3"; shift 3
166
+ child_env "$repo" "$@" -- "$RUNNER" "$SKILL/scripts/remind-tick.mjs" --root "$repo" \
167
+ --state-dir "$repo/.pi/team/state" --pulse-started "$started" --json </dev/null >"$out" 2>&1
168
+ RC=$?
169
+ }
170
+
171
+ add_due() { # <repo> <message> [key] → 打印 id(先按 CLI 建一条 30s 后的,再由夹具把 due 改到过去)
172
+ local repo="$1" msg="$2" key="${3:-}" id
173
+ local args=(remind add --after 30s --message "$msg")
174
+ [ -n "$key" ] && args+=(--key "$key")
175
+ run_team "$repo" "$ROOT/out/add.txt" "${args[@]}"
176
+ [ "$RC" -eq 0 ] || { printf 'ADD-FAILED\n'; return 1; }
177
+ id="$(sed -n 's/^已创建 \(rem-[^ ]*\).*/\1/p' "$ROOT/out/add.txt" | head -1)"
178
+ [ -n "$id" ] || { printf 'ADD-NO-ID\n'; return 1; }
179
+ cat > "$ROOT/script/due.js" <<'JS'
180
+ for (const record of snap.reminders) {
181
+ if (record.phase === 'scheduled') record.dueAt = iso(Date.now() - 1000);
182
+ }
183
+ JS
184
+ edit_snapshot "$repo" "$ROOT/script/due.js"
185
+ printf '%s\n' "$id"
186
+ }
187
+
188
+ iso_now() { date -u +%Y-%m-%dT%H:%M:%SZ; }
189
+ iso_shift() { # <秒数(负=过去)>
190
+ date -u -d "@$(( $(date +%s) + $1 ))" +%Y-%m-%dT%H:%M:%SZ
191
+ }
192
+
193
+ # The red sides run the transaction helper exactly as the CLI does, from a private two-file copy:
194
+ # the product's own code plus one deliberate defect.
195
+ helper_copy() { # <id> → prints the copied helper path
196
+ local dir="$ROOT/flip/$1"
197
+ rm -rf "$dir"; mkdir -p "$dir"
198
+ cp "$SKILL/scripts/state-authority.mjs" "$dir/state-authority.mjs" || return 1
199
+ cp "$SKILL/scripts/remind-store.mjs" "$dir/remind-store.mjs" || return 1
200
+ printf '%s\n' "$dir/state-authority.mjs"
201
+ }
202
+ run_helper() { # <helper> <repo> <out> [args…] → RC
203
+ local helper="$1" repo="$2" out="$3"; shift 3
204
+ child_env "$repo" -- "$RUNNER" "$helper" --cli "$repo" "$repo/.pi/team/state" "$@" </dev/null >"$out" 2>&1
205
+ RC=$?
206
+ }
207
+ mutate() { # <file> <old> <new> — 必须真的改到(否则这条红侧是橡皮章)
208
+ python3 - "$1" "$2" "$3" <<'PY'
209
+ import sys
210
+ path, old, new = sys.argv[1], sys.argv[2], sys.argv[3]
211
+ s = open(path, encoding="utf-8").read()
212
+ if old not in s:
213
+ sys.exit("mutate: pattern not found in %s" % path)
214
+ open(path, "w", encoding="utf-8").write(s.replace(old, new, 1))
215
+ PY
216
+ }
217
+
218
+ # Isolation ledger for the real project's .pi/team (before).
219
+ REAL_MAIN="$(main_team_project_root "$SKILL")"
220
+ main_team_snapshot "${REAL_MAIN:-/nonexistent}/.pi/team" >"$ROOT/real-before.txt"
221
+
222
+ # ---------------------------------------------------------------- A. 到期入队
223
+ A="$(new_repo A)" || { bad "夹具建不出仓库 A"; result; exit 1; }
224
+ SA="$(snapshot_of "$A")"
225
+ NOTE_MSG='到点提醒正文 first line 100%
226
+ second line'
227
+ A1="$(add_due "$A" "$NOTE_MSG")"
228
+ if [ "${A1#rem-}" = "$A1" ]; then
229
+ bad "A 建不出一条到点提醒($A1)"; grep -a . "$ROOT/out/add.txt" | head -3 | sed 's/^/ /'
230
+ else
231
+ ok "A 夹具建出到点提醒 $A1"
232
+ fi
233
+ # 不到点 ≠ 入队:先把 due 放回未来,跑一拍,必须一条都不入队
234
+ cat > "$ROOT/script/future.js" <<'JS'
235
+ for (const record of snap.reminders) if (record.phase === 'scheduled') record.dueAt = iso(Date.now() + 120000);
236
+ JS
237
+ edit_snapshot "$A" "$ROOT/script/future.js"
238
+ tick "$A" "$(iso_now)" "$ROOT/out/tick.txt"
239
+ assert_has "A 不到点:tick 正常结束" "$(cat "$ROOT/out/tick.txt")" '"admitted":[]'
240
+ assert_eq "A 不到点:记录仍是 scheduled" "$(jfield "$SA" 'reminders.0.phase')" "scheduled"
241
+ # 到点:入队一次
242
+ cat > "$ROOT/script/due-now.js" <<'JS'
243
+ for (const record of snap.reminders) if (record.phase === 'scheduled') record.dueAt = iso(Date.now() - 1000);
244
+ JS
245
+ edit_snapshot "$A" "$ROOT/script/due-now.js"
246
+ tick "$A" "$(iso_shift -10)" "$ROOT/out/tick.txt"
247
+ assert_has "A 到点:tick 把它入队" "$(cat "$ROOT/out/tick.txt")" '"admitted":["'"$A1"'"'
248
+ assert_eq "A 到点:记录变成 queued" "$(jfield "$SA" 'reminders.0.phase')" "queued"
249
+ QUEUE_SEQ="$(jfield "$SA" 'reminders.0.queueSeq')"
250
+ assert_eq "A 正常轮询延迟不标 overdue(due 晚于本巡检实例起点)" "$(jfield "$SA" 'reminders.0.overdue')" "false"
251
+ tick "$A" "$(iso_shift -10)" "$ROOT/out/tick.txt"
252
+ assert_eq "A 重复巡检不产生第二条队列记录(queueSeq 不变)" "$(jfield "$SA" 'reminders.0.queueSeq')" "$QUEUE_SEQ"
253
+ assert_eq "A 重复巡检不重复入队(admitted 为空)" "$(jfield "$ROOT/out/tick.txt" 'admitted.length')" "0"
254
+
255
+ # 取消的项不入队:另一条提醒先取消,再让它到点
256
+ A2="$(add_due "$A" 'cancel me' cancel-me)"
257
+ run_team "$A" "$ROOT/out/cancel.txt" remind cancel "$A2"
258
+ assert_has "A 可取消尚未冻结的提醒" "$(cat "$ROOT/out/cancel.txt")" "已取消"
259
+ tick "$A" "$(iso_shift -10)" "$ROOT/out/tick.txt"
260
+ assert_eq "A 取消的项不入队(phase 仍是 cancelled)" "$(jfield "$SA" "reminders.1.phase")" "cancelled"
261
+ assert_no "A 取消的项不出现在入队结果里" "$(cat "$ROOT/out/tick.txt")" "$A2"
262
+
263
+ # overdue:due 早于本巡检实例起点 = 补发
264
+ B="$(new_repo B)"; SB="$(snapshot_of "$B")"
265
+ B1="$(add_due "$B" 'overdue by restart')"
266
+ tick "$B" "$(iso_shift 5)" "$ROOT/out/tick.txt"
267
+ assert_eq "A 到期早于本巡检实例起点 → overdue" "$(jfield "$SB" 'reminders.0.overdue')" "true"
268
+ assert_has "A overdue 的 id 被点名" "$(cat "$ROOT/out/tick.txt")" '"overdue":["'"$B1"'"'
269
+
270
+ # 入队滞后超过 30 秒 → overdue(正常轮询延迟不标)
271
+ C="$(new_repo C)"; SC="$(snapshot_of "$C")"
272
+ add_due "$C" 'late admission' >/dev/null
273
+ cat > "$ROOT/script/late.js" <<'JS'
274
+ for (const record of snap.reminders) if (record.phase === 'scheduled') record.dueAt = iso(Date.now() - 45000);
275
+ JS
276
+ edit_snapshot "$C" "$ROOT/script/late.js"
277
+ tick "$C" "$(iso_shift -60)" "$ROOT/out/tick.txt"
278
+ assert_eq "A 入队滞后 45s → overdue" "$(jfield "$SC" 'reminders.0.overdue')" "true"
279
+
280
+ # ---------------------------------------------------------------- B. 冻结批次
281
+ D="$(new_repo D)"; SD="$(snapshot_of "$D")"
282
+ D1="$(add_due "$D" 'batch member one' one)"
283
+ D2="$(add_due "$D" 'batch member two' two)"
284
+ tick "$D" "$(iso_shift -10)" "$ROOT/out/tick.txt"
285
+ authority "$D" "$ROOT/out/intent.txt" remind-intent --session sess-D --pid 111
286
+ assert_has "B 一批冻结成功" "$(cat "$ROOT/out/intent.txt")" '"action":"send"'
287
+ assert_has "B 正文逐字进批次(第一行)" "$(cat "$ROOT/out/intent.txt")" 'batch member one'
288
+ assert_has "B 正文逐字进批次(第二行)" "$(cat "$ROOT/out/intent.txt")" 'batch member two'
289
+ assert_eq "B 两条成员都进入同一批" "$(jfield "$ROOT/out/intent.txt" 'batch.members.length')" "2"
290
+ assert_eq "B 成员记录带批次 id" "$(jfield "$SD" 'reminders.0.batchId')" "$(jfield "$ROOT/out/intent.txt" 'batch.id')"
291
+ assert_eq "B 批次绑定了当时的待命状态(off)" "$(jfield "$ROOT/out/intent.txt" 'batch.generation')" 'off'
292
+ authority "$D" "$ROOT/out/intent2.txt" remind-intent --session sess-D --pid 111
293
+ assert_eq "B 已有一批在飞:第二次冻结被拒(wait,不产生第二批)" "$(jfield "$ROOT/out/intent2.txt" 'action')" "wait"
294
+ assert_eq "B 快照里只有一批" "$(jfield "$SD" 'batches.length')" "1"
295
+ # 8 条上限:一个批次最多 8 个成员(第 9 条留到下一批)
296
+ E="$(new_repo E)"; SE="$(snapshot_of "$E")"
297
+ for i in 1 2 3 4 5 6 7 8 9; do add_due "$E" "cap member $i" "cap$i" >/dev/null; done
298
+ tick "$E" "$(iso_shift -10)" "$ROOT/out/tick.txt"
299
+ authority "$E" "$ROOT/out/intent.txt" remind-intent --session sess-E --pid 222
300
+ assert_eq "B 单批最多 8 条" "$(jfield "$ROOT/out/intent.txt" 'batch.members.length')" "8"
301
+ assert_eq "B 第 9 条仍是 queued(留给下一批)" "$(jfield "$SE" 'reminders.8.phase')" "queued"
302
+ # 5 秒间隔:刚冻结完立刻再冻(先确认上一批已离开 outstanding)
303
+ authority "$E" "$ROOT/out/obs.txt" remind-observe --id "$(jfield "$ROOT/out/intent.txt" 'batch.id')" \
304
+ --nonce "$(jfield "$ROOT/out/intent.txt" 'batch.nonce')" --session sess-E
305
+ authority "$E" "$ROOT/out/intent2.txt" remind-intent --session sess-E --pid 222
306
+ assert_eq "B 5 秒内不再提交下一批(spacing)" "$(jfield "$ROOT/out/intent2.txt" 'action')" "spacing"
307
+
308
+ # ---------------------------------------------------------------- C. 观察与待命
309
+ F="$(new_repo F)"; SF="$(snapshot_of "$F")"
310
+ add_due "$F" 'standby wake' wake >/dev/null
311
+ authority "$F" "$ROOT/out/sb.txt" standby-on --reason "user away" --json
312
+ assert_eq "C 待命开了(代次 1)" "$(jfield "$ROOT/out/sb.txt" 'generation')" "1"
313
+ tick "$F" "$(iso_shift -10)" "$ROOT/out/tick.txt"
314
+ authority "$F" "$ROOT/out/intent.txt" remind-intent --session sess-F --pid 333
315
+ FB="$(jfield "$ROOT/out/intent.txt" 'batch.id')"; FN="$(jfield "$ROOT/out/intent.txt" 'batch.nonce')"
316
+ assert_eq "C 意图绑定当前代次 1" "$(jfield "$ROOT/out/intent.txt" 'batch.generation')" "1"
317
+ authority "$F" "$ROOT/out/bad.txt" remind-observe --id "$FB" --nonce "wrong" --session sess-F
318
+ assert_eq "C nonce 不符:拒绝且不消耗 right" "$(jfield "$ROOT/out/bad.txt" 'refusal')" "nonce-mismatch"
319
+ assert_eq "C nonce 不符后 right 仍未花" "$(jfield "$SF" 'batches.0.right')" "unspent"
320
+ authority "$F" "$ROOT/out/bad.txt" remind-observe --id "$FB" --nonce "$FN" --session other
321
+ assert_eq "C 会话不符:拒绝" "$(jfield "$ROOT/out/bad.txt" 'refusal')" "session-mismatch"
322
+ authority "$F" "$ROOT/out/obs.txt" remind-observe --id "$FB" --nonce "$FN" --session sess-F
323
+ assert_has "C 匹配事件 → observed" "$(cat "$ROOT/out/obs.txt")" '"outcome":"observed"'
324
+ assert_has "C 观察原子地自动退代次 1" "$(cat "$ROOT/out/obs.txt")" '"standby":"auto-off"'
325
+ assert_eq "C 待命已关" "$(jfield "$SF" 'standby.on')" "false"
326
+ assert_eq "C right 已花(wake)" "$(jfield "$SF" 'batches.0.rightSpentBy')" "wake"
327
+ assert_eq "C 审计一条、点名批次" "$(jfield "$SF" 'audit.-1.batch')" "$FB"
328
+ assert_eq "C 审计带每个提醒 id" "$(jfield "$SF" 'audit.-1.ids.length')" "1"
329
+ assert_eq "C 审计带来源" "$(jfield "$SF" 'audit.-1.sources.0')" "cli"
330
+ authority "$F" "$ROOT/out/obs.txt" remind-observe --id "$FB" --nonce "$FN" --session sess-F
331
+ assert_has "C 重复事件 → duplicate(不再退待命)" "$(cat "$ROOT/out/obs.txt")" '"outcome":"duplicate"'
332
+ assert_eq "C 重复事件不产生第二条观察审计" \
333
+ "$(node -e 'const s=require("'"$SF"'");console.log(s.audit.filter(a=>a.op==="remind-observed").length)')" "1"
334
+
335
+ # 手动已 off:观察只记 already-off,不虚构自动退出
336
+ G="$(new_repo G)"; SG="$(snapshot_of "$G")"
337
+ add_due "$G" 'manual off' >/dev/null
338
+ authority "$G" "$ROOT/out/sb.txt" standby-on --reason "x" --json >/dev/null
339
+ tick "$G" "$(iso_shift -10)" "$ROOT/out/tick.txt"
340
+ authority "$G" "$ROOT/out/intent.txt" remind-intent --session sess-G --pid 444
341
+ authority "$G" "$ROOT/out/sb.txt" standby-off >/dev/null
342
+ authority "$G" "$ROOT/out/obs.txt" remind-observe --id "$(jfield "$ROOT/out/intent.txt" 'batch.id')" \
343
+ --nonce "$(jfield "$ROOT/out/intent.txt" 'batch.nonce')" --session sess-G
344
+ assert_has "C 手动已关 → already-off(不虚构自动退出)" "$(cat "$ROOT/out/obs.txt")" '"standby":"already-off"'
345
+
346
+ # 更新的代次:保留,报 ambiguous
347
+ H="$(new_repo H)"; SH="$(snapshot_of "$H")"
348
+ add_due "$H" 'newer generation' >/dev/null
349
+ authority "$H" "$ROOT/out/sb.txt" standby-on --reason "g1" --json >/dev/null
350
+ tick "$H" "$(iso_shift -10)" "$ROOT/out/tick.txt"
351
+ authority "$H" "$ROOT/out/intent.txt" remind-intent --session sess-H --pid 555
352
+ authority "$H" "$ROOT/out/sb.txt" standby-off >/dev/null
353
+ authority "$H" "$ROOT/out/sb.txt" standby-on --reason "g2" --json >/dev/null
354
+ assert_eq "C 现在的代次是 2" "$(jfield "$ROOT/out/sb.txt" 'generation')" "2"
355
+ authority "$H" "$ROOT/out/obs.txt" remind-observe --id "$(jfield "$ROOT/out/intent.txt" 'batch.id')" \
356
+ --nonce "$(jfield "$ROOT/out/intent.txt" 'batch.nonce')" --session sess-H
357
+ assert_has "C 更新代次 → 保留并报 generation-ambiguous" "$(cat "$ROOT/out/obs.txt")" '"standby":"generation-ambiguous"'
358
+ assert_eq "C 更新代次没有被清掉" "$(jfield "$SH" 'standby.on')" "true"
359
+ assert_eq "C 更新代次仍是 2" "$(jfield "$SH" 'standby.generation')" "2"
360
+
361
+ # ---------------------------------------------------------------- D. 未送达不清待命
362
+ I="$(new_repo I)"; SI="$(snapshot_of "$I")"
363
+ add_due "$I" 'not delivered yet' >/dev/null
364
+ authority "$I" "$ROOT/out/sb.txt" standby-on --reason "D" --json >/dev/null
365
+ tick "$I" "$(iso_shift -10)" "$ROOT/out/tick.txt"
366
+ assert_eq "D 只是入队:待命还开着" "$(jfield "$SI" 'standby.on')" "true"
367
+ authority "$I" "$ROOT/out/intent.txt" remind-intent --session sess-I --pid 666
368
+ assert_eq "D 冻结成批次:待命还开着" "$(jfield "$SI" 'standby.on')" "true"
369
+ authority "$I" "$ROOT/out/fail.txt" remind-fail --id "$(jfield "$ROOT/out/intent.txt" 'batch.id')" \
370
+ --nonce "$(jfield "$ROOT/out/intent.txt" 'batch.nonce')" --reason "session API refused"
371
+ assert_eq "D 投递失败:待命还开着(unknown 不等于送达)" "$(jfield "$SI" 'standby.on')" "true"
372
+ assert_eq "D 失败后成员是 unknown" "$(jfield "$SI" 'reminders.0.phase')" "unknown"
373
+
374
+ # ---------------------------------------------------------------- E. 失败与确认
375
+ assert_eq "E 失败后 attempts=2(一次 intent + 一次失败)" "$(jfield "$SI" 'batches.0.attempts')" "2"
376
+ assert_has "E 失败原因可见" "$(jfield "$SI" 'batches.0.lastError')" "session API refused"
377
+ assert_eq "E 失败不冒充成功:right 仍未花" "$(jfield "$SI" 'batches.0.right')" "unspent"
378
+ authority "$I" "$ROOT/out/intent2.txt" remind-intent --session sess-I --pid 666
379
+ assert_eq "E unknown 挡住下一批(wait)" "$(jfield "$ROOT/out/intent2.txt" 'action')" "wait"
380
+ run_team "$I" "$ROOT/out/resolve.txt" remind resolve "$(jfield "$SI" 'batches.0.id')"
381
+ assert_eq "E resolve 不给 --ack-unknown → 拒绝(rc=2)" "$RC" "2"
382
+ assert_has "E resolve 拒绝时点名 --ack-unknown" "$(cat "$ROOT/out/resolve.txt")" "--ack-unknown"
383
+ assert_eq "E 拒绝后批次仍是 unknown(没有动手)" "$(jfield "$SI" 'batches.0.phase')" "unknown"
384
+ run_team "$I" "$ROOT/out/resolve.txt" remind resolve "$(jfield "$SI" 'batches.0.id')" --ack-unknown
385
+ assert_has "E 显式确认 → resolved" "$(cat "$ROOT/out/resolve.txt")" "已确认未知批次"
386
+ assert_eq "E 成员一起关闭" "$(jfield "$SI" 'reminders.0.phase')" "resolved"
387
+ assert_eq "E right 由确认烧掉" "$(jfield "$SI" 'batches.0.rightSpentBy')" "resolve"
388
+ assert_eq "E 确认不声称送达(没有 remind-observed)" \
389
+ "$(node -e 'const s=require("'"$SI"'");console.log(s.audit.filter(a=>a.op==="remind-observed").length)')" "0"
390
+ # 确认后下一批可以再冻结(把上一批的 intentAt 放到 5 秒外,不睡)
391
+ cat > "$ROOT/script/space.js" <<'JS'
392
+ for (const batch of snap.batches) batch.intentAt = iso(Date.now() - 10000);
393
+ JS
394
+ edit_snapshot "$I" "$ROOT/script/space.js"
395
+ add_due "$I" 'after resolve' >/dev/null
396
+ tick "$I" "$(iso_shift -10)" "$ROOT/out/tick.txt"
397
+ authority "$I" "$ROOT/out/intent3.txt" remind-intent --session sess-I --pid 666
398
+ assert_eq "E 确认之后可以冻结下一批" "$(jfield "$ROOT/out/intent3.txt" 'action')" "send"
399
+ assert_no "E 新批次不含已确认的那一条" "$(cat "$ROOT/out/intent3.txt")" 'not delivered yet'
400
+
401
+ # ---------------------------------------------------------------- F. 重启恢复
402
+ J="$(new_repo J)"; SJ="$(snapshot_of "$J")"
403
+ J1="$(add_due "$J" 'restart catch-up')"
404
+ tick "$J" "$(iso_shift -10)" "$ROOT/out/tick.txt"
405
+ assert_eq "F 巡检进程退出后记录仍是 queued" "$(jfield "$SJ" 'reminders.0.phase')" "queued"
406
+ # 新进程(= 重启)照样把它冻结送出
407
+ authority "$J" "$ROOT/out/intent.txt" remind-intent --session sess-J --pid 777
408
+ assert_eq "F 重启后 queued 被冻结成批次" "$(jfield "$ROOT/out/intent.txt" 'action')" "send"
409
+ assert_has "F 正文仍是原文" "$(cat "$ROOT/out/intent.txt")" 'restart catch-up'
410
+ authority "$J" "$ROOT/out/obs.txt" remind-observe --id "$(jfield "$ROOT/out/intent.txt" 'batch.id')" \
411
+ --nonce "$(jfield "$ROOT/out/intent.txt" 'batch.nonce')" --session sess-J
412
+ tick "$J" "$(iso_shift -10)" "$ROOT/out/tick.txt"
413
+ assert_eq "F 已送达的不再入队(admitted 为空)" "$(jfield "$ROOT/out/tick.txt" 'admitted.length')" "0"
414
+ assert_eq "F 已送达记录仍是 observed" "$(jfield "$SJ" 'reminders.0.phase')" "observed"
415
+
416
+ # intent 超过 60s → unknown,且不重发
417
+ K="$(new_repo K)"; SK2="$(snapshot_of "$K")"
418
+ K1="$(add_due "$K" 'lost after intent')"
419
+ tick "$K" "$(iso_shift -10)" "$ROOT/out/tick.txt"
420
+ authority "$K" "$ROOT/out/intent.txt" remind-intent --session sess-K --pid 888
421
+ KB="$(jfield "$ROOT/out/intent.txt" 'batch.id')"
422
+ cat > "$ROOT/script/stale.js" <<'JS'
423
+ for (const batch of snap.batches) if (batch.phase === 'intent') batch.intentAt = iso(Date.now() - 120000);
424
+ for (const record of snap.reminders) if (record.phase === 'intent') record.intentAt = iso(Date.now() - 120000);
425
+ JS
426
+ edit_snapshot "$K" "$ROOT/script/stale.js"
427
+ tick "$K" "$(iso_shift -10)" "$ROOT/out/tick.txt"
428
+ assert_eq "F 过期 intent 被清成 unknown" "$(jfield "$SK2" 'batches.0.phase')" "unknown"
429
+ assert_eq "F unknown 的成员也变成 unknown" "$(jfield "$SK2" 'reminders.0.phase')" "unknown"
430
+ assert_has "F 巡检把这次清点点名" "$(cat "$ROOT/out/tick.txt")" "$KB"
431
+ authority "$K" "$ROOT/out/intent2.txt" remind-intent --session sess-K --pid 888
432
+ assert_eq "F unknown 不会被自动重发(wait)" "$(jfield "$ROOT/out/intent2.txt" 'action')" "wait"
433
+ assert_eq "F 没有产生第二批" "$(jfield "$SK2" 'batches.length')" "1"
434
+ assert_eq "F 成员仍挂着原批次 id(不是新的投递)" "$(jfield "$SK2" 'reminders.0.batchId')" "$KB"
435
+
436
+ # ---------------------------------------------------------------- G. 投递面(模块 + 真扩展,假 Pi 宿主)
437
+ L="$(new_repo L)"; SL="$(snapshot_of "$L")"
438
+ # The watcher derives its project from git + a project config file (the same rule the real install has);
439
+ # a fixture repository needs that one file before it can register a session at all.
440
+ mkdir -p "$L/.pi/team"
441
+ printf 'TEAM_PROJECT="rmd-fixture"\nTEAM_SESSION="team"\nTEAM_PM_WINDOW="pm"\nTEAM_DOCS_DIR="docs/team"\n' > "$L/.pi/team/config.sh"
442
+ add_due "$L" 'watcher reminder text' >/dev/null
443
+ authority "$L" "$ROOT/out/sb.txt" standby-on --reason "G" --json >/dev/null
444
+ tick "$L" "$(iso_shift -10)" "$ROOT/out/tick.txt"
445
+ DRIVER="$SKILL/tests/remind-delivery-node.mjs"
446
+ for group in content match; do
447
+ child_env "$L" -- "$RUNNER" "$DRIVER" "$SKILL" "$L" "$group" >"$ROOT/out/node-$group.txt" 2>&1
448
+ RC=$?
449
+ if [ "$RC" -eq 0 ]; then
450
+ ok "G ${group}:$(grep -c '^RD PASS' "$ROOT/out/node-$group.txt") 条契约成立($(grep -a '结果' "$ROOT/out/node-$group.txt" | tail -1))"
451
+ else
452
+ bad "G ${group}:Node 契约组红(rc=$RC)"
453
+ grep -a '^RD FAIL' "$ROOT/out/node-$group.txt" | head -5 | sed 's/^/ /'
454
+ fi
455
+ done
456
+ child_env "$L" TEAM_INBOX_WATCH_TARGET=team:pm TEAM_REMIND_POLL_MS=200 -- \
457
+ "$RUNNER" "$DRIVER" "$SKILL" "$L" watcher >"$ROOT/out/node-watcher.txt" 2>&1
458
+ RC=$?
459
+ if [ "$RC" -eq 0 ]; then
460
+ ok "G watcher:真扩展在假 Pi 宿主上把一批送出去并观察到回执($(grep -a '结果' "$ROOT/out/node-watcher.txt" | tail -1))"
461
+ else
462
+ bad "G watcher:扩展的投递契约红(rc=$RC)"
463
+ grep -a '^RD FAIL' "$ROOT/out/node-watcher.txt" | head -8 | sed 's/^/ /'
464
+ fi
465
+ assert_has "G watcher 结束后待命按规则退出" "$(jfield "$SL" 'standby.on')" "false"
466
+ assert_eq "G 只有一批" "$(jfield "$SL" 'batches.length')" "1"
467
+
468
+ # ---------------------------------------------------------------- H. 隔离
469
+ main_team_snapshot "${REAL_MAIN:-/nonexistent}/.pi/team" >"$ROOT/real-after.txt"
470
+ H_VIOL="$(main_team_violations "$ROOT/real-before.txt" "$ROOT/real-after.txt")"
471
+ H_MOVED="$(main_team_volatile_changes "$ROOT/real-before.txt" "$ROOT/real-after.txt")"
472
+ if [ -z "$H_VIOL" ]; then
473
+ ok "H 主项目 .pi/team:非白名单路径零变化(同期白名单内 $H_MOVED 个运行时文件在动)"
474
+ else
475
+ bad "H 主项目 .pi/team 出现了非白名单变化($(printf '%s' "$H_VIOL" | tr '\n' ' '))"
476
+ fi
477
+ H_SLACK=""
478
+ main_team_volatile "./state/meta-suite/2026-11-04T06-46-57Z.log" || H_SLACK="$H_SLACK meta-suite-未放行"
479
+ main_team_volatile "./state/one-off-writer/x.log" && H_SLACK="$H_SLACK 未登记子目录-被放行"
480
+ assert_eq "H 白名单登记:元套件记录放行、state/ 下未登记的子目录仍被点名(判据没有一处松)" "$H_SLACK" ""
481
+
482
+ # ---------------------------------------------------------------- 红侧(scratch 副本)
483
+ run_flips() {
484
+ local repo dir helper
485
+ repo="$(new_repo FLIP)" || { bad "红侧夹具仓库建不出来"; return 0; }
486
+
487
+ if arm_selected admit-any; then
488
+ helper="$(helper_copy admit-any)"
489
+ # The admit filter, not peekReminders' one-line probe (the same predicate appears in both).
490
+ mutate "$(dirname "$helper")/remind-store.mjs" \
491
+ "const due = snapshot.reminders
492
+ .filter(record => record.phase === 'scheduled' && Number.isFinite(msOf(record.dueAt)) && msOf(record.dueAt) <= nowMs)" \
493
+ "const due = snapshot.reminders
494
+ .filter(record => record.phase === 'scheduled')"
495
+ dir="$(dirname "$helper")"
496
+ if grep -qF ".filter(record => record.phase === 'scheduled')" "$dir/remind-store.mjs"; then
497
+ ok "红侧 admit-any:变异已落地(副本不再是产品那一份)"
498
+ else
499
+ bad "红侧 admit-any:变异没落地"
500
+ fi
501
+ FLIPS_RUN="${FLIPS_RUN:+$FLIPS_RUN,}admit-any"
502
+ add_due "$repo" 'not due yet' >/dev/null
503
+ cat > "$ROOT/script/future2.js" <<'JS'
504
+ for (const record of snap.reminders) if (record.phase === 'scheduled') record.dueAt = iso(Date.now() + 300000);
505
+ JS
506
+ edit_snapshot "$repo" "$ROOT/script/future2.js"
507
+ run_helper "$helper" "$repo" "$ROOT/out/flip.txt" remind-admit --pulse-started "$(iso_now)"
508
+ if [ "$(jfield "$ROOT/out/flip.txt" 'admitted.length')" != "0" ]; then
509
+ ok "flip(入队不看到期时间):不到点的提醒也入了队 —— A 的「不到点不入队」会红"
510
+ else
511
+ bad "flip(入队不看到期时间):变异没有改变答案(红侧无效)"
512
+ fi
513
+ fi
514
+
515
+ if arm_selected intent-multi; then
516
+ helper="$(helper_copy intent-multi)"
517
+ mutate "$(dirname "$helper")/remind-store.mjs" \
518
+ "return snapshot.batches.find(batch => batch.phase === 'intent' || batch.phase === 'unknown') ?? null;" \
519
+ "return null;"
520
+ ok "红侧 intent-multi:变异已落地(副本不再是产品那一份)"
521
+ FLIPS_RUN="${FLIPS_RUN:+$FLIPS_RUN,}intent-multi"
522
+ repo="$(new_repo FLIP2)"
523
+ for i in 1 2 3 4 5 6 7 8 9; do add_due "$repo" "flip member $i" "fm$i" >/dev/null; done
524
+ run_helper "$helper" "$repo" "$ROOT/out/flip.txt" remind-admit --pulse-started "$(iso_shift -10)"
525
+ run_helper "$helper" "$repo" "$ROOT/out/f1.txt" remind-intent --session s --pid 1
526
+ # Move the first batch out of the 5-second spacing window, so the ONLY thing that could stop the
527
+ # second freeze is the outstanding-batch rule the mutation removed.
528
+ cat > "$ROOT/script/space3.js" <<'JS'
529
+ for (const batch of snap.batches) batch.intentAt = iso(Date.now() - 10000);
530
+ JS
531
+ edit_snapshot "$repo" "$ROOT/script/space3.js"
532
+ run_helper "$helper" "$repo" "$ROOT/out/f2.txt" remind-intent --session s --pid 1
533
+ if [ "$(jfield "$ROOT/out/f2.txt" 'action')" = "send" ]; then
534
+ ok "flip(不看已有一批在飞):同一批被冻了两次 —— B 的「拒绝再冻」会红"
535
+ else
536
+ bad "flip(不看已有一批在飞):变异没有改变答案(红侧无效)"
537
+ fi
538
+ fi
539
+
540
+ if arm_selected observe-nogen; then
541
+ helper="$(helper_copy observe-nogen)"
542
+ mutate "$(dirname "$helper")/remind-store.mjs" \
543
+ "else if (snapshot.standby.generation === batch.generation) {" \
544
+ "else if (true) {"
545
+ ok "红侧 observe-nogen:变异已落地(副本不再是产品那一份)"
546
+ FLIPS_RUN="${FLIPS_RUN:+$FLIPS_RUN,}observe-nogen"
547
+ repo="$(new_repo FLIP3)"
548
+ add_due "$repo" 'flip standby' >/dev/null
549
+ run_helper "$helper" "$repo" "$ROOT/out/f.txt" standby-on --reason g1
550
+ run_helper "$helper" "$repo" "$ROOT/out/f.txt" remind-admit --pulse-started "$(iso_shift -10)"
551
+ run_helper "$helper" "$repo" "$ROOT/out/f1.txt" remind-intent --session s --pid 1
552
+ run_helper "$helper" "$repo" "$ROOT/out/f.txt" standby-off
553
+ run_helper "$helper" "$repo" "$ROOT/out/f.txt" standby-on --reason g2
554
+ run_helper "$helper" "$repo" "$ROOT/out/f2.txt" remind-observe --id "$(jfield "$ROOT/out/f1.txt" 'batch.id')" \
555
+ --nonce "$(jfield "$ROOT/out/f1.txt" 'batch.nonce')" --session s
556
+ if [ "$(jfield "$ROOT/out/f2.txt" 'standby')" = "auto-off" ]; then
557
+ ok "flip(观察不核对代次):新代次被清掉 —— C 的「更新代次必须保留」会红"
558
+ else
559
+ bad "flip(观察不核对代次):变异没有改变答案(红侧无效)"
560
+ fi
561
+ fi
562
+
563
+ if arm_selected off-on-queue; then
564
+ helper="$(helper_copy off-on-queue)"
565
+ mutate "$(dirname "$helper")/remind-store.mjs" \
566
+ " admitted.push(record.id);" \
567
+ " admitted.push(record.id);
568
+ snapshot.standby = { on: false, generation: snapshot.standby.generation, reason: null, since: iso(nowMs), migrated: true };"
569
+ ok "红侧 off-on-queue:变异已落地(副本不再是产品那一份)"
570
+ FLIPS_RUN="${FLIPS_RUN:+$FLIPS_RUN,}off-on-queue"
571
+ repo="$(new_repo FLIP4)"
572
+ add_due "$repo" 'flip queue off' >/dev/null
573
+ run_helper "$helper" "$repo" "$ROOT/out/f.txt" standby-on --reason x
574
+ run_helper "$helper" "$repo" "$ROOT/out/f.txt" remind-admit --pulse-started "$(iso_shift -10)"
575
+ if [ "$(run_helper "$helper" "$repo" "$ROOT/out/f2.txt" standby-read --print on; cat "$ROOT/out/f2.txt")" = "false" ]; then
576
+ ok "flip(入队就关待命):只是入队就把待命清了 —— D 的「未送达不得清待命」会红"
577
+ else
578
+ bad "flip(入队就关待命):变异没有改变答案(红侧无效)"
579
+ fi
580
+ fi
581
+
582
+ if arm_selected unknown-resend; then
583
+ helper="$(helper_copy unknown-resend)"
584
+ mutate "$(dirname "$helper")/remind-store.mjs" \
585
+ "return snapshot.batches.find(batch => batch.phase === 'intent' || batch.phase === 'unknown') ?? null;" \
586
+ "return snapshot.batches.find(batch => batch.phase === 'intent') ?? null;"
587
+ ok "红侧 unknown-resend:变异已落地(副本不再是产品那一份)"
588
+ FLIPS_RUN="${FLIPS_RUN:+$FLIPS_RUN,}unknown-resend"
589
+ repo="$(new_repo FLIP5)"
590
+ add_due "$repo" 'flip unknown' >/dev/null
591
+ run_helper "$helper" "$repo" "$ROOT/out/f.txt" remind-admit --pulse-started "$(iso_shift -10)"
592
+ run_helper "$helper" "$repo" "$ROOT/out/f1.txt" remind-intent --session s --pid 1
593
+ run_helper "$helper" "$repo" "$ROOT/out/f.txt" remind-fail --id "$(jfield "$ROOT/out/f1.txt" 'batch.id')" \
594
+ --nonce "$(jfield "$ROOT/out/f1.txt" 'batch.nonce')" --reason "refused"
595
+ cat > "$ROOT/script/space2.js" <<'JS'
596
+ for (const batch of snap.batches) batch.intentAt = iso(Date.now() - 10000);
597
+ JS
598
+ edit_snapshot "$repo" "$ROOT/script/space2.js"
599
+ add_due "$repo" 'flip next batch' >/dev/null
600
+ run_helper "$helper" "$repo" "$ROOT/out/f.txt" remind-admit --pulse-started "$(iso_shift -10)"
601
+ run_helper "$helper" "$repo" "$ROOT/out/f2.txt" remind-intent --session s --pid 1
602
+ if [ "$(jfield "$ROOT/out/f2.txt" 'action')" = "send" ]; then
603
+ ok "flip(unknown 不再挡住下一批):无法证实送达的一批被绕过去重发 —— E 的「unknown 挡住下一批」会红"
604
+ else
605
+ bad "flip(unknown 不再挡住下一批):变异没有改变答案(红侧无效)"
606
+ fi
607
+ fi
608
+ }
609
+ run_flips
610
+
611
+ result