teamsmith 0.3.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/package.json +2 -6
- package/skills/teamsmith/CHANGELOG.md +77 -0
- package/skills/teamsmith/SKILL.md +83 -163
- package/skills/teamsmith/extension/team-inbox-watch.ts +30 -1
- package/skills/teamsmith/extension/team-notify.ts +162 -21
- package/skills/teamsmith/extension/team-reply.ts +105 -0
- package/skills/teamsmith/references/agent-adapters.md +4 -2
- package/skills/teamsmith/references/config.md +21 -12
- package/skills/teamsmith/references/migration.md +47 -3
- package/skills/teamsmith/references/protocol.md +85 -31
- package/skills/teamsmith/references/reminders.md +131 -0
- package/skills/teamsmith/references/troubleshooting.md +26 -8
- package/skills/teamsmith/references/workflows.md +18 -16
- package/skills/teamsmith/scripts/lib/cmd-agents.sh +290 -68
- package/skills/teamsmith/scripts/lib/cmd-config.sh +1 -1
- package/skills/teamsmith/scripts/lib/cmd-project.sh +193 -21
- package/skills/teamsmith/scripts/lib/cmd-remind.sh +103 -0
- package/skills/teamsmith/scripts/lib/cmd-status.sh +177 -21
- package/skills/teamsmith/scripts/lib/cmd-update.sh +7 -4
- package/skills/teamsmith/scripts/lib/cmd-watch.sh +11 -1
- package/skills/teamsmith/scripts/lib/common.sh +50 -6
- package/skills/teamsmith/scripts/lib/outbox.sh +103 -21
- package/skills/teamsmith/scripts/panel/panel.js +1 -1
- package/skills/teamsmith/scripts/panel/src/strings/en.ts +1 -1
- package/skills/teamsmith/scripts/panel/src/strings/zh.ts +1 -1
- package/skills/teamsmith/scripts/remind-store.mjs +529 -0
- package/skills/teamsmith/scripts/replies.mjs +9 -3
- package/skills/teamsmith/scripts/reply-capture.mjs +596 -0
- package/skills/teamsmith/scripts/state-authority.mjs +500 -0
- package/skills/teamsmith/scripts/strings/commands.tsv +2 -1
- package/skills/teamsmith/scripts/strings/help.en.tsv +16 -2
- package/skills/teamsmith/scripts/strings/help.zh.tsv +16 -2
- package/skills/teamsmith/scripts/team +2 -0
- package/skills/teamsmith/templates/AGENTS.section.md.tmpl +68 -123
- package/skills/teamsmith/templates/PROTOCOL.md.tmpl +48 -55
- package/skills/teamsmith/templates/config.sh.tmpl +2 -1
- package/skills/teamsmith/templates/pm-prompt.md.tmpl +126 -119
- package/skills/teamsmith/tests/bg-ledger-harness.mjs +17 -6
- package/skills/teamsmith/tests/bg-ledger.sh +16 -5
- package/skills/teamsmith/tests/checkout-shape-probe.sh +6 -5
- package/skills/teamsmith/tests/delivery-truth.sh +82 -47
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/README.md +71 -23
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/__pycache__/judge-second.cpython-313.pyc +0 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/judge-dirty-ab.py +143 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/judge-second.py +26 -9
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/run-case.sh +92 -20
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +47 -3
- package/skills/teamsmith/tests/fixtures/reply-capture-provider.ts +76 -0
- package/skills/teamsmith/tests/flip-p410-order2.sh +205 -0
- package/skills/teamsmith/tests/frames/README.md +3 -1
- package/skills/teamsmith/tests/gate-guard.sh +20 -4
- package/skills/teamsmith/tests/help-surface.sh +61 -3
- package/skills/teamsmith/tests/install-shape.sh +400 -38
- package/skills/teamsmith/tests/key-replies-pty.sh +197 -21
- package/skills/teamsmith/tests/key-replies.sh +187 -68
- package/skills/teamsmith/tests/ledger-claim.sh +8 -6
- package/skills/teamsmith/tests/lib/box-judge.sh +2 -1
- package/skills/teamsmith/tests/lib/main-team-fingerprint.sh +104 -0
- package/skills/teamsmith/tests/lib/pm-window.sh +127 -0
- package/skills/teamsmith/tests/lib/reply-fixture.sh +7 -19
- package/skills/teamsmith/tests/lib/reply-guard.sh +188 -0
- package/skills/teamsmith/tests/lib/section-calls.pl +171 -0
- package/skills/teamsmith/tests/loop-inventory.tsv +7 -5
- package/skills/teamsmith/tests/meta-suite.sh +215 -0
- package/skills/teamsmith/tests/panel-b3-pty-mouse.py +154 -17
- package/skills/teamsmith/tests/panel-b3.sh +33 -4
- package/skills/teamsmith/tests/panel-choices.sh +11 -7
- package/skills/teamsmith/tests/remind-cli.sh +574 -0
- package/skills/teamsmith/tests/reply-capture-real.mjs +360 -0
- package/skills/teamsmith/tests/reply-capture-real.sh +5 -0
- package/skills/teamsmith/tests/reply-capture.mjs +622 -0
- package/skills/teamsmith/tests/section-paths.tsv +41 -10
- package/skills/teamsmith/tests/section-select.sh +180 -26
- package/skills/teamsmith/tests/smoke.sh +1829 -249
- package/skills/teamsmith/tests/state-authority-node.mjs +42 -0
- package/skills/teamsmith/tests/state-authority.sh +629 -0
- package/skills/teamsmith/tests/task-model-routing.sh +10 -1
- package/skills/teamsmith/tests/team-inbox-watch-harness.mjs +33 -0
- package/skills/teamsmith/tests/team-notify-knock-marker.mjs +91 -0
- package/skills/teamsmith/tests/workflow-entry.sh +123 -3
- package/skills/teamsmith-init/SKILL.md +1 -1
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# remind-cli.sh — P409(change: agent-self-reminder 2.1/2.3)的隔离夹具
|
|
3
|
+
#
|
|
4
|
+
# 证这些事,全部在自己的临时根里:每个仓库先 `git init`,每条命令显式给 `--root` 与
|
|
5
|
+
# `TEAM_STATE_DIR`,`HOME`/`TMPDIR` 指向夹具自己的目录,继承来的 TEAM_* 身份一律清掉。
|
|
6
|
+
#
|
|
7
|
+
# A CLI 面 add(相对/绝对时间、正文逐字节)/ list(派生视图与全文)/ show / cancel(幂等)
|
|
8
|
+
# B 输入拒绝 非法串、不存在的日期、过去时间、无时区、零/负/溢出时长、两种时间、空正文、NUL、
|
|
9
|
+
# 非 UTF-8、未知参数 —— 每条都点名原因且一个字节都不写
|
|
10
|
+
# C key 幂等 同一请求返回原 id 与原 due(不重算)/ 同一 key 的不同请求被拒 / 终结后 key 可复用
|
|
11
|
+
# D 视图派生 手工把快照改成 queued / observed / 到期的 scheduled 之后,list 的计数跟着变;
|
|
12
|
+
# 快照里没有 view / counts 这类第二份真相
|
|
13
|
+
# E 修剪与高水位 终结记录超过上限时最旧的消失、已签发高水位不回退、被修剪的 id 报 history-pruned、
|
|
14
|
+
# 高水位写坏(倒退 / 非整数 / 低于已签发)必须被拒且快照一字不改
|
|
15
|
+
# F 隔离 跑完主项目 `.pi/team` 的非白名单路径零变化(与 §66 共用 tests/lib/main-team-fingerprint.sh)
|
|
16
|
+
#
|
|
17
|
+
# 红侧(`--flip=<id>`,每条都必须能红;不带参数时全跑):
|
|
18
|
+
# --flip=view-stored 把视图存进记录再读回来 → D 的「计数跟着快照变」必须红
|
|
19
|
+
# --flip=no-prune 关掉修剪 → E 的「最旧终结项消失」必须红
|
|
20
|
+
# --flip=highwater-lax 去掉高水位一致性检查 → E 的「写坏高水位必须被拒」必须红
|
|
21
|
+
# --flip=past-time 放过过去时间 → B 的「过去时间必须拒」必须红
|
|
22
|
+
# --flip=key-conflict-gone 活跃 key 的不同请求照旧返回 → C 的「不同请求必须拒」必须红
|
|
23
|
+
# 红侧跑在 scratch 副本上(只复制 state-authority.mjs + remind-store.mjs,与产品同样的 import 关系),
|
|
24
|
+
# 真树与产品文件不动;每条变异都先证明落地,再判它给出的是错误答案。
|
|
25
|
+
#
|
|
26
|
+
# 用法:bash tests/remind-cli.sh [--flip=<id>]…
|
|
27
|
+
# 退出码:0 全绿 / 1 有失败 / 2 参数不认识 / 3 前提缺失(JS 运行时或 flock;可见跳过,不算通过)
|
|
28
|
+
set -uo pipefail
|
|
29
|
+
|
|
30
|
+
HERE="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
31
|
+
SKILL="$(cd -P "$HERE/.." && pwd)"
|
|
32
|
+
TEAM_CLI="$SKILL/scripts/team"
|
|
33
|
+
|
|
34
|
+
FLIPS=()
|
|
35
|
+
for arg in "$@"; do
|
|
36
|
+
case "$arg" in
|
|
37
|
+
--flip=*)
|
|
38
|
+
case "${arg#--flip=}" in
|
|
39
|
+
view-stored|no-prune|highwater-lax|past-time|key-conflict-gone) FLIPS+=("${arg#--flip=}") ;;
|
|
40
|
+
*) printf 'remind-cli:不认识的 --flip 值 [%s]\n' "${arg#--flip=}" >&2; exit 2 ;;
|
|
41
|
+
esac ;;
|
|
42
|
+
-h|--help) sed -n '2,26p' "$0"; exit 0 ;;
|
|
43
|
+
*) printf 'remind-cli:不认识的参数 [%s]\n' "$arg" >&2; exit 2 ;;
|
|
44
|
+
esac
|
|
45
|
+
done
|
|
46
|
+
arm_selected() {
|
|
47
|
+
[ "${#FLIPS[@]}" -eq 0 ] && return 0
|
|
48
|
+
local f; for f in "${FLIPS[@]}"; do [ "$f" = "$1" ] && return 0; done
|
|
49
|
+
return 1
|
|
50
|
+
}
|
|
51
|
+
FLIPS_RUN=""
|
|
52
|
+
|
|
53
|
+
# shellcheck source=lib/tmp-root.sh
|
|
54
|
+
. "$HERE/lib/tmp-root.sh"
|
|
55
|
+
# shellcheck source=lib/main-team-fingerprint.sh
|
|
56
|
+
. "$HERE/lib/main-team-fingerprint.sh"
|
|
57
|
+
|
|
58
|
+
RUNNER="$(team_js_runner)"
|
|
59
|
+
if [ -z "$RUNNER" ]; then
|
|
60
|
+
printf 'remind-cli:前提缺失 —— 没有 JS 运行时;这是可见跳过,不是通过\n' >&2
|
|
61
|
+
exit 3
|
|
62
|
+
fi
|
|
63
|
+
if ! command -v flock >/dev/null 2>&1; then
|
|
64
|
+
printf 'remind-cli:前提缺失 —— 这台机器没有 flock,权威层按设计拒绝工作(可见跳过,不是通过)\n' >&2
|
|
65
|
+
exit 3
|
|
66
|
+
fi
|
|
67
|
+
|
|
68
|
+
ROOT="$(tmp_root_create remind-cli)" || exit 3
|
|
69
|
+
trap 'tmp_root_reap_all' EXIT
|
|
70
|
+
mkdir -p "$ROOT/home" "$ROOT/tmp" "$ROOT/fx" "$ROOT/msg" "$ROOT/out" "$ROOT/script"
|
|
71
|
+
export HOME="$ROOT/home"
|
|
72
|
+
# The fixture's children are stripped again in child_env(); unsetting here keeps this process from
|
|
73
|
+
# writing into the real team's authority by accident.
|
|
74
|
+
unset TEAM_ROOT TEAM_MAIN_ROOT TEAM_PROJECT TEAM_SESSION TEAM_SESSION_FROM TEAM_STATE_DIR TEAM_CONFIG_FILE \
|
|
75
|
+
TEAM_IDENTITY_LOCKED TEAM_IDENTITY_ROOT TEAM_IDENTITY_MAIN_ROOT TEAM_IDENTITY_PROJECT \
|
|
76
|
+
TEAM_IDENTITY_INHERIT_ROOT TEAM_IDENTITY_INHERIT_MAIN_ROOT TEAM_IDENTITY_INHERIT_PROJECT \
|
|
77
|
+
TEAM_IDENTITY_INHERIT_SESSION TEAM_ALLOW_FOREIGN_IDENTITY 2>/dev/null || true
|
|
78
|
+
|
|
79
|
+
PASS=0; FAIL=0
|
|
80
|
+
ok() { printf ' \033[32m✓\033[0m %s\n' "$1"; PASS=$((PASS + 1)); }
|
|
81
|
+
bad() { printf ' \033[31m✗\033[0m %s\n' "$1"; FAIL=$((FAIL + 1)); }
|
|
82
|
+
note() { printf ' %s\n' "$1"; }
|
|
83
|
+
result() {
|
|
84
|
+
printf '\nflip 臂:%s\n' "${FLIPS_RUN:-none}"
|
|
85
|
+
# The result line is a contract with the gate (smoke_inner_summary matches it exactly).
|
|
86
|
+
printf '== remind-cli 结果 == ✓%d ✗%d SKIP0\n' "$PASS" "$FAIL"
|
|
87
|
+
[ "$FAIL" -eq 0 ]
|
|
88
|
+
}
|
|
89
|
+
assert_eq() { [ "$2" = "$3" ] && ok "$1" || bad "$1(期望 [$3],实际 [$2])"; }
|
|
90
|
+
assert_has() { case "$2" in *"$3"*) ok "$1" ;; *) bad "$1(输出里没有 [$3]:$(printf '%s' "$2" | head -2 | tr '\n' '|' | cut -c1-120))" ;; esac; }
|
|
91
|
+
assert_no() { case "$2" in *"$3"*) bad "$1(输出里不该出现 [$3])" ;; *) ok "$1" ;; esac; }
|
|
92
|
+
|
|
93
|
+
# ---------------------------------------------------------------- small JSON helpers (no jq)
|
|
94
|
+
cat > "$ROOT/json-get.mjs" <<'JS'
|
|
95
|
+
import fs from 'node:fs';
|
|
96
|
+
const [file, dotted] = process.argv.slice(2);
|
|
97
|
+
let value = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
98
|
+
for (const key of dotted.split('.')) value = value == null ? undefined : value[key];
|
|
99
|
+
if (value === undefined) process.exit(3);
|
|
100
|
+
process.stdout.write(typeof value === 'string' ? value : JSON.stringify(value));
|
|
101
|
+
JS
|
|
102
|
+
cat > "$ROOT/json-dump.mjs" <<'JS'
|
|
103
|
+
// write one JSON string field out byte for byte (a shell variable would eat trailing newlines)
|
|
104
|
+
import fs from 'node:fs';
|
|
105
|
+
const [file, dotted, out] = process.argv.slice(2);
|
|
106
|
+
let value = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
107
|
+
for (const key of dotted.split('.')) value = value == null ? undefined : value[key];
|
|
108
|
+
if (typeof value !== 'string') process.exit(3);
|
|
109
|
+
fs.writeFileSync(out, value);
|
|
110
|
+
JS
|
|
111
|
+
cat > "$ROOT/snapshot-edit.mjs" <<'JS'
|
|
112
|
+
// Hand-edit a snapshot the way an operator or a later slice 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', fs.readFileSync(script, 'utf8'))(snap);
|
|
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
|
+
jdump() { "$RUNNER" "$ROOT/json-dump.mjs" "$1" "$2" "$3"; }
|
|
123
|
+
snapshot_of() { printf '%s/.pi/team/state/reminders/state.json\n' "$1"; }
|
|
124
|
+
edit_snapshot() { # <repo> <script-file>
|
|
125
|
+
"$RUNNER" "$ROOT/snapshot-edit.mjs" "$(snapshot_of "$1")" "$2"
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
# ---------------------------------------------------------------- fixture repositories
|
|
129
|
+
new_repo() { # <名字> → path(自己的 git 仓库;绝不落在别人的检出里)
|
|
130
|
+
local dir="$ROOT/fx/$1"
|
|
131
|
+
rm -rf "$dir"; mkdir -p "$dir"
|
|
132
|
+
git -C "$dir" init -q || return 1
|
|
133
|
+
git -C "$dir" -c user.email=fixture@example.invalid -c user.name=Fixture commit -q --allow-empty -m fixture || return 1
|
|
134
|
+
printf '%s\n' "$dir"
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
# One place where a child is stripped of inherited identity and given explicit roots.
|
|
138
|
+
child_env() { # <repo> [VAR=VAL…] -- <command…>
|
|
139
|
+
local repo="$1"; shift
|
|
140
|
+
local envs=()
|
|
141
|
+
while [ "$#" -gt 0 ] && [ "$1" != "--" ]; do envs+=("$1"); shift; done
|
|
142
|
+
[ "${1:-}" = "--" ] && shift
|
|
143
|
+
( cd "$repo" && env -u TEAM_ROOT -u TEAM_MAIN_ROOT -u TEAM_PROJECT -u TEAM_SESSION -u TEAM_SESSION_FROM \
|
|
144
|
+
-u TEAM_STATE_DIR -u TEAM_CONFIG_FILE -u TEAM_IDENTITY_LOCKED -u TEAM_IDENTITY_ROOT \
|
|
145
|
+
-u TEAM_IDENTITY_MAIN_ROOT -u TEAM_IDENTITY_PROJECT -u TEAM_IDENTITY_INHERIT_ROOT \
|
|
146
|
+
-u TEAM_IDENTITY_INHERIT_MAIN_ROOT -u TEAM_IDENTITY_INHERIT_PROJECT -u TEAM_IDENTITY_INHERIT_SESSION \
|
|
147
|
+
-u TEAM_ALLOW_FOREIGN_IDENTITY \
|
|
148
|
+
HOME="$ROOT/home" TMPDIR="$ROOT/tmp" TEAM_STATE_DIR="$repo/.pi/team/state" \
|
|
149
|
+
${envs[@]+"${envs[@]}"} "$@" )
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
# run_team <repo> <stdin-file> <out-file> [args…] → RC;stdout+stderr 落 <out-file>
|
|
153
|
+
run_team() {
|
|
154
|
+
local repo="$1" stdin="$2" out="$3"; shift 3
|
|
155
|
+
child_env "$repo" -- bash "$TEAM_CLI" --root "$repo" "$@" <"$stdin" >"$out" 2>&1
|
|
156
|
+
RC=$?
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
# The red sides call the transaction helper exactly as the CLI does (same --cli entry, same lock),
|
|
160
|
+
# from a private two-file copy: the product's own code plus one deliberate defect.
|
|
161
|
+
helper_copy() { # <id> → prints the copied helper path
|
|
162
|
+
local dir="$ROOT/flip/$1"
|
|
163
|
+
rm -rf "$dir"; mkdir -p "$dir"
|
|
164
|
+
cp "$SKILL/scripts/state-authority.mjs" "$dir/state-authority.mjs" || return 1
|
|
165
|
+
cp "$SKILL/scripts/remind-store.mjs" "$dir/remind-store.mjs" || return 1
|
|
166
|
+
printf '%s\n' "$dir/state-authority.mjs"
|
|
167
|
+
}
|
|
168
|
+
run_helper() { # <helper> <repo> <stdin-file> <out-file> [args…] → RC
|
|
169
|
+
local helper="$1" repo="$2" stdin="$3" out="$4"; shift 4
|
|
170
|
+
child_env "$repo" -- "$RUNNER" "$helper" --cli "$repo" "$repo/.pi/team/state" "$@" <"$stdin" >"$out" 2>&1
|
|
171
|
+
RC=$?
|
|
172
|
+
}
|
|
173
|
+
mutate() { # <file> <old> <new> — 必须真的改到(否则这条红侧是橡皮章)
|
|
174
|
+
python3 - "$1" "$2" "$3" <<'PY'
|
|
175
|
+
import sys
|
|
176
|
+
path, old, new = sys.argv[1], sys.argv[2], sys.argv[3]
|
|
177
|
+
s = open(path, encoding="utf-8").read()
|
|
178
|
+
if old not in s:
|
|
179
|
+
sys.exit("mutate: pattern not found in %s" % path)
|
|
180
|
+
open(path, "w", encoding="utf-8").write(s.replace(old, new, 1))
|
|
181
|
+
PY
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
# Message fixtures: everything a shell can eat (two lines, CJK, a percent sign, two trailing newlines —
|
|
185
|
+
# a command substitution would drop those last bytes, so the fixture compares bytes, not variables).
|
|
186
|
+
printf 'first line — 中文 100%%\nsecond line\n\n' > "$ROOT/msg/full.txt"
|
|
187
|
+
FULL_BYTES="$(wc -c < "$ROOT/msg/full.txt" | tr -d ' ')"
|
|
188
|
+
printf 'line one\nline two\n' > "$ROOT/msg/two.txt"
|
|
189
|
+
printf 'probe text\n' > "$ROOT/msg/x.txt"
|
|
190
|
+
: > "$ROOT/msg/empty.txt"
|
|
191
|
+
: > "$ROOT/msg/none"
|
|
192
|
+
printf 'a\000b' > "$ROOT/msg/nul.bin"
|
|
193
|
+
printf 'bad \377 utf8\n' > "$ROOT/msg/bad.bin"
|
|
194
|
+
|
|
195
|
+
# Isolation ledger for the real project's .pi/team (before).
|
|
196
|
+
REAL_MAIN="$(main_team_project_root "$SKILL")"
|
|
197
|
+
main_team_snapshot "${REAL_MAIN:-/nonexistent}/.pi/team" >"$ROOT/real-before.txt"
|
|
198
|
+
|
|
199
|
+
# ---------------------------------------------------------------- A. the CLI surface
|
|
200
|
+
A="$(new_repo A)" || { bad "夹具建不出仓库 A"; result; exit 1; }
|
|
201
|
+
|
|
202
|
+
run_team "$A" "$ROOT/msg/none" "$ROOT/out/a1.txt" remind add --after 2h --message "review the build" --key check
|
|
203
|
+
assert_eq "A add:相对时间建成(rc)" "$RC" "0"
|
|
204
|
+
A_ID="$(sed -n 's/^已创建 \(rem-[^ ]*\) · .*/\1/p' "$ROOT/out/a1.txt")"
|
|
205
|
+
case "$A_ID" in
|
|
206
|
+
rem-*-1) ok "A add:打印稳定 id($A_ID)" ;;
|
|
207
|
+
*) bad "A add:没有打印 rem-<project>-1 形状的 id(拿到 [$A_ID])" ;;
|
|
208
|
+
esac
|
|
209
|
+
assert_has "A add:打印 scheduled 视图" "$(cat "$ROOT/out/a1.txt")" "scheduled"
|
|
210
|
+
A_DUE="$(sed -n 's/^ 到期 \([^(]*\)(.*/\1/p' "$ROOT/out/a1.txt")"
|
|
211
|
+
|
|
212
|
+
run_team "$A" "$ROOT/msg/none" "$ROOT/out/a2.txt" remind list
|
|
213
|
+
assert_eq "A list:rc" "$RC" "0"
|
|
214
|
+
A_LIST="$(cat "$ROOT/out/a2.txt")"
|
|
215
|
+
assert_has "A list:视图计数行在(八种视图全列出)" "$A_LIST" \
|
|
216
|
+
"视图 scheduled=1 derived-due=0 queued=0 intent=0 observed=0 unknown=0 cancelled=0 resolved=0"
|
|
217
|
+
assert_has "A list:正文逐字出现(不截断)" "$A_LIST" "review the build"
|
|
218
|
+
assert_has "A list:到期时间就是创建时打印的那个" "$A_LIST" "$A_DUE"
|
|
219
|
+
|
|
220
|
+
run_team "$A" "$ROOT/msg/full.txt" "$ROOT/out/a3.txt" remind add --at 2099-01-01T00:00:00Z --message-file "$ROOT/msg/full.txt"
|
|
221
|
+
assert_eq "A add --message-file + 绝对时间:建成(rc)" "$RC" "0"
|
|
222
|
+
B_ID="$(sed -n 's/^已创建 \(rem-[^ ]*\) · .*/\1/p' "$ROOT/out/a3.txt")"
|
|
223
|
+
|
|
224
|
+
run_team "$A" "$ROOT/msg/none" "$ROOT/out/a3j.txt" remind show "$B_ID" --json
|
|
225
|
+
assert_eq "A show --json:rc" "$RC" "0"
|
|
226
|
+
if jdump "$ROOT/out/a3j.txt" reminder.message "$ROOT/out/b-msg.txt" \
|
|
227
|
+
&& cmp -s "$ROOT/msg/full.txt" "$ROOT/out/b-msg.txt"; then
|
|
228
|
+
ok "A add --message-file:正文逐字节落盘($FULL_BYTES 字节,含中文、% 与结尾空行)"
|
|
229
|
+
else
|
|
230
|
+
bad "A add --message-file:落盘的正文与文件不同($(wc -c < "$ROOT/out/b-msg.txt" 2>/dev/null || echo 0) 字节 ≠ $FULL_BYTES)"
|
|
231
|
+
fi
|
|
232
|
+
|
|
233
|
+
run_team "$A" "$ROOT/msg/none" "$ROOT/out/a4.txt" remind show "$B_ID"
|
|
234
|
+
SHOW_OUT="$(cat "$ROOT/out/a4.txt")"
|
|
235
|
+
assert_has "A show:正文逐字完整(两行 + 结尾空行)" "$SHOW_OUT" "$(cat "$ROOT/msg/full.txt")"
|
|
236
|
+
assert_has "A show:phase 与视图" "$SHOW_OUT" "phase scheduled"
|
|
237
|
+
assert_has "A show:owner 与来源" "$SHOW_OUT" "owner pm"
|
|
238
|
+
|
|
239
|
+
run_team "$A" "$ROOT/msg/none" "$ROOT/out/a5.txt" remind cancel "$A_ID"
|
|
240
|
+
assert_eq "A cancel:rc" "$RC" "0"
|
|
241
|
+
assert_has "A cancel:说明已取消与原因" "$(cat "$ROOT/out/a5.txt")" "已取消"
|
|
242
|
+
cp "$(snapshot_of "$A")" "$ROOT/out/a-after-cancel.json"
|
|
243
|
+
run_team "$A" "$ROOT/msg/none" "$ROOT/out/a6.txt" remind cancel "$A_ID" --json
|
|
244
|
+
assert_eq "A 再取消:rc(幂等)" "$RC" "0"
|
|
245
|
+
assert_eq "A 再取消:outcome 是 already-cancelled(不假装刚取消)" "$(jfield "$ROOT/out/a6.txt" outcome)" "already-cancelled"
|
|
246
|
+
cmp -s "$ROOT/out/a-after-cancel.json" "$(snapshot_of "$A")" \
|
|
247
|
+
&& ok "A 再取消:快照逐字节不变(幂等不是再写一遍)" \
|
|
248
|
+
|| bad "A 再取消:快照被重写了(幂等臂动了状态)"
|
|
249
|
+
|
|
250
|
+
run_team "$A" "$ROOT/msg/none" "$ROOT/out/a7.txt" remind list
|
|
251
|
+
assert_has "A list:取消后计数跟着变(cancelled=1,只剩 2099 那条 scheduled)" "$(cat "$ROOT/out/a7.txt")" \
|
|
252
|
+
"视图 scheduled=1 derived-due=0 queued=0 intent=0 observed=0 unknown=0 cancelled=1 resolved=0"
|
|
253
|
+
assert_has "A list:取消的那条仍在保留的终结历史里" "$(cat "$ROOT/out/a7.txt")" "另有 1 条已终结"
|
|
254
|
+
|
|
255
|
+
# ---------------------------------------------------------------- B. refusals (each names its reason, writes nothing)
|
|
256
|
+
B="$(new_repo B)" || { bad "夹具建不出仓库 B"; result; exit 1; }
|
|
257
|
+
run_team "$B" "$ROOT/msg/none" "$ROOT/out/b0.txt" remind add --after 2h --message seed
|
|
258
|
+
[ "$RC" = "0" ] || bad "B 夹具:种子提醒没建成($(head -1 "$ROOT/out/b0.txt"))"
|
|
259
|
+
cp "$(snapshot_of "$B")" "$ROOT/out/b-before.json"
|
|
260
|
+
|
|
261
|
+
refuse() { # <label> <expected-fragment> [args…]
|
|
262
|
+
local label="$1" expect="$2"; shift 2
|
|
263
|
+
run_team "$B" "$ROOT/msg/none" "$ROOT/out/b-case.txt" remind add "$@"
|
|
264
|
+
local out; out="$(cat "$ROOT/out/b-case.txt")"
|
|
265
|
+
if [ "$RC" = "1" ] && case "$out" in *"$expect"*) true ;; *) false ;; esac; then
|
|
266
|
+
ok "B $label:拒绝并点名($expect)"
|
|
267
|
+
else
|
|
268
|
+
bad "B $label:没有按预期拒绝(rc=$RC,期望点名 [$expect]:$(printf '%s' "$out" | head -1 | cut -c1-100))"
|
|
269
|
+
fi
|
|
270
|
+
}
|
|
271
|
+
refuse "非法串" "not an RFC 3339" --at "next tuesday" --message x
|
|
272
|
+
refuse "不存在的日期" "not a real calendar date" --at 2026-02-30T09:00:00Z --message x
|
|
273
|
+
refuse "过去时间" "not in the future" --at 2020-01-01T00:00:00Z --message x
|
|
274
|
+
refuse "无时区绝对时间" "has no time zone" --at 2099-01-01T09:00:00 --message x
|
|
275
|
+
refuse "零时长" "is zero" --after 0s --message x
|
|
276
|
+
refuse "负时长" "is negative" --after -5m --message x
|
|
277
|
+
refuse "时长单位错" "not a whole number" --after "20 minutes" --message x
|
|
278
|
+
refuse "时长溢出" "too large" --after 99999999999999999999h --message x
|
|
279
|
+
refuse "两种时间都给" "exactly one" --at 2099-01-01T00:00:00Z --after 2h --message x
|
|
280
|
+
refuse "一种时间都没给" "give one of" --message x
|
|
281
|
+
refuse "空正文" "message is empty" --after 2h --message-file "$ROOT/msg/empty.txt"
|
|
282
|
+
refuse "NUL 正文" "NUL byte" --after 2h --message-file "$ROOT/msg/nul.bin"
|
|
283
|
+
refuse "非 UTF-8 正文" "not valid UTF-8" --after 2h --message-file "$ROOT/msg/bad.bin"
|
|
284
|
+
refuse "key 用了非 ASCII" "outside printable ASCII" --after 2h --message-file "$ROOT/msg/x.txt" --key 有中文
|
|
285
|
+
|
|
286
|
+
run_team "$B" "$ROOT/msg/none" "$ROOT/out/b-flag.txt" remind add --after 2h --message x --frobnicate
|
|
287
|
+
assert_eq "B 未知参数:rc(用法错误)" "$RC" "2"
|
|
288
|
+
assert_has "B 未知参数:点名该参数" "$(cat "$ROOT/out/b-flag.txt")" "--frobnicate"
|
|
289
|
+
run_team "$B" "$ROOT/msg/none" "$ROOT/out/b-id.txt" remind show not-an-id
|
|
290
|
+
assert_eq "B 不认识的 id:rc" "$RC" "1"
|
|
291
|
+
assert_has "B 不认识的 id:点名它不是本项目的提醒 id" "$(cat "$ROOT/out/b-id.txt")" "is not a reminder id of this project"
|
|
292
|
+
cmp -s "$ROOT/out/b-before.json" "$(snapshot_of "$B")" \
|
|
293
|
+
&& ok "B 全部拒绝之后:快照逐字节不变(没有半成品)" \
|
|
294
|
+
|| bad "B 拒绝臂改动了快照"
|
|
295
|
+
|
|
296
|
+
# ---------------------------------------------------------------- C. key idempotency and release
|
|
297
|
+
C="$(new_repo C)" || { bad "夹具建不出仓库 C"; result; exit 1; }
|
|
298
|
+
run_team "$C" "$ROOT/msg/none" "$ROOT/out/c1.txt" remind add --after 2h --message "same text" --key check
|
|
299
|
+
C_ID="$(sed -n 's/^已创建 \(rem-[^ ]*\) · .*/\1/p' "$ROOT/out/c1.txt")"
|
|
300
|
+
C_DUE="$(sed -n 's/^ 到期 \([^(]*\)(.*/\1/p' "$ROOT/out/c1.txt")"
|
|
301
|
+
C_HW="$(jfield "$(snapshot_of "$C")" sequences.reminder)"
|
|
302
|
+
run_team "$C" "$ROOT/msg/none" "$ROOT/out/c2.txt" remind add --after 2h --message "same text" --key check
|
|
303
|
+
assert_eq "C 同一请求重试:rc" "$RC" "0"
|
|
304
|
+
assert_has "C 同一请求重试:说明已存在而不是新建" "$(cat "$ROOT/out/c2.txt")" "已存在 $C_ID"
|
|
305
|
+
C2_DUE="$(sed -n 's/^ 到期 \([^(]*\)(.*/\1/p' "$ROOT/out/c2.txt")"
|
|
306
|
+
assert_eq "C 同一请求重试:due 是第一次那个(不重算)" "$C2_DUE" "$C_DUE"
|
|
307
|
+
assert_eq "C 同一请求重试:没有分配新序号(高水位不动)" "$(jfield "$(snapshot_of "$C")" sequences.reminder)" "$C_HW"
|
|
308
|
+
|
|
309
|
+
run_team "$C" "$ROOT/msg/none" "$ROOT/out/c3.txt" remind add --after 2h --message "other text" --key check
|
|
310
|
+
assert_eq "C 同一 key 的不同请求:rc(必须拒)" "$RC" "1"
|
|
311
|
+
assert_has "C 同一 key 的不同请求:点名冲突与原 id" "$(cat "$ROOT/out/c3.txt")" "already held by $C_ID"
|
|
312
|
+
run_team "$C" "$ROOT/msg/none" "$ROOT/out/c4.txt" remind cancel "$C_ID"
|
|
313
|
+
assert_eq "C 取消:rc" "$RC" "0"
|
|
314
|
+
run_team "$C" "$ROOT/msg/none" "$ROOT/out/c5.txt" remind add --after 3h --message "same text" --key check
|
|
315
|
+
assert_eq "C 终结后复用 key:rc(允许)" "$RC" "0"
|
|
316
|
+
C_NEW="$(sed -n 's/^已创建 \(rem-[^ ]*\) · .*/\1/p' "$ROOT/out/c5.txt")"
|
|
317
|
+
if [ -n "$C_NEW" ] && [ "$C_NEW" != "$C_ID" ]; then
|
|
318
|
+
ok "C 终结后复用 key:得到新 id($C_NEW ≠ $C_ID)"
|
|
319
|
+
else
|
|
320
|
+
bad "C 终结后复用 key:没有新建(拿到 [$C_NEW])"
|
|
321
|
+
fi
|
|
322
|
+
|
|
323
|
+
# ---------------------------------------------------------------- D. views are derived, never stored
|
|
324
|
+
V="$(new_repo V)" || { bad "夹具建不出仓库 V"; result; exit 1; }
|
|
325
|
+
run_team "$V" "$ROOT/msg/none" "$ROOT/out/d1.txt" remind add --after 2h --message "queued one"
|
|
326
|
+
V1="$(sed -n 's/^已创建 \(rem-[^ ]*\) · .*/\1/p' "$ROOT/out/d1.txt")"
|
|
327
|
+
run_team "$V" "$ROOT/msg/none" "$ROOT/out/d2.txt" remind add --after 2h --message "observed one"
|
|
328
|
+
V2="$(sed -n 's/^已创建 \(rem-[^ ]*\) · .*/\1/p' "$ROOT/out/d2.txt")"
|
|
329
|
+
run_team "$V" "$ROOT/msg/none" "$ROOT/out/d3.txt" remind add --after 2h --message "due one"
|
|
330
|
+
V3="$(sed -n 's/^已创建 \(rem-[^ ]*\) · .*/\1/p' "$ROOT/out/d3.txt")"
|
|
331
|
+
|
|
332
|
+
# The snapshot records phases and times; the views must be derived from them on every read.
|
|
333
|
+
cat > "$ROOT/script/d-edit.mjs" <<JS
|
|
334
|
+
const v1 = snap.reminders.find(r => r.id === '$V1'); v1.phase = 'queued'; v1.enqueuedAt = new Date().toISOString();
|
|
335
|
+
const v2 = snap.reminders.find(r => r.id === '$V2'); v2.phase = 'observed'; v2.endedAt = new Date().toISOString();
|
|
336
|
+
const v3 = snap.reminders.find(r => r.id === '$V3'); v3.dueAt = new Date(Date.now() - 60000).toISOString();
|
|
337
|
+
JS
|
|
338
|
+
edit_snapshot "$V" "$ROOT/script/d-edit.mjs"
|
|
339
|
+
run_team "$V" "$ROOT/msg/none" "$ROOT/out/d4.txt" remind list --json
|
|
340
|
+
assert_eq "D 手工改快照后 list --json:rc" "$RC" "0"
|
|
341
|
+
assert_eq "D queued 计数跟着快照变(phase=queued → queued=1)" "$(jfield "$ROOT/out/d4.txt" counts.queued)" "1"
|
|
342
|
+
assert_eq "D observed 计数跟着快照变(phase=observed → observed=1)" "$(jfield "$ROOT/out/d4.txt" counts.observed)" "1"
|
|
343
|
+
assert_eq "D 到期是时钟派生的(过去的 scheduled → derived-due=1)" "$(jfield "$ROOT/out/d4.txt" counts.derived-due)" "1"
|
|
344
|
+
assert_eq "D 到期的那条不再算 scheduled" "$(jfield "$ROOT/out/d4.txt" counts.scheduled)" "0"
|
|
345
|
+
|
|
346
|
+
run_team "$V" "$ROOT/msg/none" "$ROOT/out/d5.txt" remind list
|
|
347
|
+
D_HUMAN="$(cat "$ROOT/out/d5.txt")"
|
|
348
|
+
assert_has "D list 的人读视图:queued 那条还在活跃列表里" "$D_HUMAN" "$V1 · queued"
|
|
349
|
+
assert_has "D list 的人读视图:到期的那条说明在等入队" "$D_HUMAN" "已到期,等 Pulse 入队"
|
|
350
|
+
assert_no "D list 默认不打印终结项(observed 那条)" "$D_HUMAN" "observed one"
|
|
351
|
+
assert_has "D list 默认提示还有终结项(--all 才打印)" "$D_HUMAN" "另有 1 条已终结"
|
|
352
|
+
run_team "$V" "$ROOT/msg/none" "$ROOT/out/d6.txt" remind list --all
|
|
353
|
+
assert_has "D list --all:打印 observed 记录" "$(cat "$ROOT/out/d6.txt")" "$V2 · observed"
|
|
354
|
+
|
|
355
|
+
# The snapshot itself must not carry a second truth: no stored counts / views / per-record view.
|
|
356
|
+
"$RUNNER" -e '
|
|
357
|
+
import fs from "node:fs";
|
|
358
|
+
const snap = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
|
|
359
|
+
const stored = Object.keys(snap).filter(k => ["counts", "views", "active", "derivedDue"].includes(k));
|
|
360
|
+
const perRecord = snap.reminders.flatMap(r => Object.keys(r).filter(k => ["view", "active", "due"].includes(k)));
|
|
361
|
+
process.stdout.write(JSON.stringify({ stored, perRecord }));
|
|
362
|
+
' "$(snapshot_of "$V")" > "$ROOT/out/d-shape.json"
|
|
363
|
+
assert_eq "D 快照里没有第二份真相(无 counts / view / active 字段)" "$(cat "$ROOT/out/d-shape.json")" '{"stored":[],"perRecord":[]}'
|
|
364
|
+
|
|
365
|
+
run_team "$V" "$ROOT/msg/none" "$ROOT/out/d7.txt" remind cancel "$V2" --json
|
|
366
|
+
assert_eq "D 取消已 observed 的记录:rc(不假装成功)" "$RC" "1"
|
|
367
|
+
assert_eq "D 取消已 observed 的记录:refusal 是 already-observed" "$(jfield "$ROOT/out/d7.txt" refusal)" "already-observed"
|
|
368
|
+
|
|
369
|
+
# ---------------------------------------------------------------- E. bounded history and the issued high-water
|
|
370
|
+
P="$(new_repo P)" || { bad "夹具建不出仓库 P"; result; exit 1; }
|
|
371
|
+
run_team "$P" "$ROOT/msg/none" "$ROOT/out/e0.txt" remind add --after 2h --message seed
|
|
372
|
+
[ "$RC" = "0" ] || bad "E 夹具:种子提醒没建成($(head -1 "$ROOT/out/e0.txt"))"
|
|
373
|
+
P_UUID="$(jfield "$(snapshot_of "$P")" project.id)"
|
|
374
|
+
cat > "$ROOT/script/e-fill.mjs" <<'JS'
|
|
375
|
+
snap.reminders = [];
|
|
376
|
+
for (let i = 1; i <= 1050; i++) {
|
|
377
|
+
snap.reminders.push({
|
|
378
|
+
id: 'rem-' + snap.project.id + '-' + i, seq: i, owner: 'pm', source: 'cli', task: null, key: null,
|
|
379
|
+
phase: 'cancelled', createdAt: new Date(Date.now() - (2000 - i) * 60000).toISOString(),
|
|
380
|
+
request: { form: 'after', value: '2h' }, dueAt: new Date(Date.now() - (1500 - i) * 60000).toISOString(),
|
|
381
|
+
message: 'terminal ' + i, endedAt: new Date(Date.now() - (1200 - i) * 60000).toISOString(),
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
snap.sequences.reminder = 1100;
|
|
385
|
+
snap.pruned = 0;
|
|
386
|
+
snap.audit = [];
|
|
387
|
+
JS
|
|
388
|
+
edit_snapshot "$P" "$ROOT/script/e-fill.mjs"
|
|
389
|
+
run_team "$P" "$ROOT/msg/none" "$ROOT/out/e1.txt" remind list --json
|
|
390
|
+
assert_eq "E 修剪前:1050 条终结记录都在(读不修剪)" "$(jfield "$ROOT/out/e1.txt" terminalTotal)" "1050"
|
|
391
|
+
assert_eq "E 修剪前:pruned 0" "$(jfield "$ROOT/out/e1.txt" pruned)" "0"
|
|
392
|
+
|
|
393
|
+
run_team "$P" "$ROOT/msg/none" "$ROOT/out/e2.txt" remind add --after 2h --message "after prune"
|
|
394
|
+
assert_eq "E 修剪:add 仍然成功(rc)" "$RC" "0"
|
|
395
|
+
assert_eq "E 修剪:新 id 用已签发高水位(1100,不回退)" \
|
|
396
|
+
"$(sed -n 's/^已创建 \(rem-[^ ]*\) · .*/\1/p' "$ROOT/out/e2.txt")" "rem-$P_UUID-1100"
|
|
397
|
+
run_team "$P" "$ROOT/msg/none" "$ROOT/out/e3.txt" remind list --all --json
|
|
398
|
+
assert_eq "E 修剪:终结记录被压到上限 1000 条" "$(jfield "$ROOT/out/e3.txt" terminalTotal)" "1000"
|
|
399
|
+
assert_eq "E 修剪:pruned 记下被删的 50 条" "$(jfield "$ROOT/out/e3.txt" pruned)" "50"
|
|
400
|
+
assert_eq "E 修剪:已签发高水位仍是 1100(不因修剪回退)" "$(jfield "$ROOT/out/e3.txt" highWater)" "1100"
|
|
401
|
+
|
|
402
|
+
run_team "$P" "$ROOT/msg/none" "$ROOT/out/e4.txt" remind show "rem-$P_UUID-1" --json
|
|
403
|
+
assert_eq "E 被修剪的 id:rc" "$RC" "1"
|
|
404
|
+
assert_eq "E 被修剪的 id:refusal 是 history-pruned(不是「从未签发」)" "$(jfield "$ROOT/out/e4.txt" refusal)" "history-pruned"
|
|
405
|
+
assert_has "E 被修剪的 id:人读输出说明它离开了保留的历史" "$(jfield "$ROOT/out/e4.txt" reason)" "left the retained history"
|
|
406
|
+
run_team "$P" "$ROOT/msg/none" "$ROOT/out/e5.txt" remind show "rem-$P_UUID-1149"
|
|
407
|
+
assert_eq "E 从未签发的 id:rc" "$RC" "1"
|
|
408
|
+
assert_has "E 从未签发的 id:报从未签发(高水位之外)" "$(cat "$ROOT/out/e5.txt")" "never issued"
|
|
409
|
+
run_team "$P" "$ROOT/msg/none" "$ROOT/out/e6.txt" remind cancel "rem-$P_UUID-1" --json
|
|
410
|
+
assert_eq "E 取消被修剪的 id:rc" "$RC" "1"
|
|
411
|
+
assert_eq "E 取消被修剪的 id:refusal 是 history-pruned" "$(jfield "$ROOT/out/e6.txt" refusal)" "history-pruned"
|
|
412
|
+
|
|
413
|
+
# A high-water that went backwards must be refused, not used: it would turn a pruned identity into a
|
|
414
|
+
# "never issued" one and make an old id look reusable.
|
|
415
|
+
cp "$(snapshot_of "$P")" "$ROOT/out/e-good.json"
|
|
416
|
+
bad_hw() { # <label> <expected-fragment> <script-file>
|
|
417
|
+
local label="$1" expect="$2" script="$3"
|
|
418
|
+
cp "$ROOT/out/e-good.json" "$(snapshot_of "$P")"
|
|
419
|
+
edit_snapshot "$P" "$script"
|
|
420
|
+
local before after
|
|
421
|
+
before="$(sha256sum "$(snapshot_of "$P")" | cut -d' ' -f1)"
|
|
422
|
+
run_team "$P" "$ROOT/msg/none" "$ROOT/out/e-bad.txt" remind list
|
|
423
|
+
local out; out="$(cat "$ROOT/out/e-bad.txt")"
|
|
424
|
+
if [ "$RC" != "0" ] && case "$out" in *"$expect"*) true ;; *) false ;; esac; then
|
|
425
|
+
ok "E 写坏高水位($label):拒绝并点名($expect)"
|
|
426
|
+
else
|
|
427
|
+
bad "E 写坏高水位($label):没有拒绝(rc=$RC:$(printf '%s' "$out" | head -1 | cut -c1-100))"
|
|
428
|
+
fi
|
|
429
|
+
after="$(sha256sum "$(snapshot_of "$P")" | cut -d' ' -f1)"
|
|
430
|
+
[ "$before" = "$after" ] && ok "E 写坏高水位($label):快照一字不改(拒绝不是修复)" \
|
|
431
|
+
|| bad "E 写坏高水位($label):拒绝时仍写了快照"
|
|
432
|
+
}
|
|
433
|
+
printf "snap.sequences.reminder = 3;\n" > "$ROOT/script/bad-hw-3.mjs"
|
|
434
|
+
printf "snap.sequences.reminder = 20; snap.pruned = 50;\n" > "$ROOT/script/bad-hw-pruned.mjs"
|
|
435
|
+
printf "snap.sequences.reminder = 'many';\n" > "$ROOT/script/bad-hw-text.mjs"
|
|
436
|
+
bad_hw "低于已签发记录" "high-water" "$ROOT/script/bad-hw-3.mjs"
|
|
437
|
+
bad_hw "低于已修剪计数" "high-water" "$ROOT/script/bad-hw-pruned.mjs"
|
|
438
|
+
bad_hw "不是整数" "sequence" "$ROOT/script/bad-hw-text.mjs"
|
|
439
|
+
cp "$ROOT/out/e-good.json" "$(snapshot_of "$P")"
|
|
440
|
+
run_team "$P" "$ROOT/msg/none" "$ROOT/out/e7.txt" remind list
|
|
441
|
+
assert_eq "E 恢复合法快照后 list 仍然 rc=0(上述拒绝没把仓库弄坏)" "$RC" "0"
|
|
442
|
+
|
|
443
|
+
# ---------------------------------------------------------------- F. the real project's .pi/team did not move
|
|
444
|
+
main_team_snapshot "${REAL_MAIN:-/nonexistent}/.pi/team" >"$ROOT/real-after.txt"
|
|
445
|
+
F_VIOL="$(main_team_violations "$ROOT/real-before.txt" "$ROOT/real-after.txt")"
|
|
446
|
+
F_MOVED="$(main_team_volatile_changes "$ROOT/real-before.txt" "$ROOT/real-after.txt")"
|
|
447
|
+
if [ -z "$F_VIOL" ]; then
|
|
448
|
+
ok "F 主项目 .pi/team:非白名单路径零变化(同期白名单内 $F_MOVED 个运行时文件在动)"
|
|
449
|
+
else
|
|
450
|
+
bad "F 主项目 .pi/team 出现了非白名单变化($(printf '%s' "$F_VIOL" | tr '\n' ' '))"
|
|
451
|
+
fi
|
|
452
|
+
case "${REAL_MAIN:-}" in
|
|
453
|
+
"") note "本检出没有主工作树,F 只证明没有写到 /nonexistent" ;;
|
|
454
|
+
*) note "F 的证明对象:$REAL_MAIN/.pi/team(非白名单路径逐字节;白名单形状按名字放行)" ;;
|
|
455
|
+
esac
|
|
456
|
+
# F 的登记自检(P411,与 state-authority §11 同一份 lib):元套件的运行记录目录被放行(那次假红的
|
|
457
|
+
# 形状:从 worktree 跑元套件,记录落在主检出),而 state/ 下未登记的子目录仍被点名。任一边松了就红。
|
|
458
|
+
F_SLACK=""
|
|
459
|
+
main_team_volatile "./state/meta-suite/2026-11-04T06-46-57Z.log" || F_SLACK="$F_SLACK meta-suite-未放行"
|
|
460
|
+
main_team_volatile "./state/one-off-writer/x.log" && F_SLACK="$F_SLACK 未登记子目录-被放行"
|
|
461
|
+
assert_eq "F 白名单登记:元套件记录放行、state/ 下未登记的子目录仍被点名(判据没有一处松)" "$F_SLACK" ""
|
|
462
|
+
|
|
463
|
+
# ---------------------------------------------------------------- red sides
|
|
464
|
+
# Each arm: copy the product's own two modules, break exactly one rule, prove the mutation landed,
|
|
465
|
+
# then run the *same scenario* and require the mutated code to give the wrong answer the green
|
|
466
|
+
# assertion rejects.
|
|
467
|
+
flip_prepare() { # <id> <helper>
|
|
468
|
+
local store; store="$(dirname "$2")/remind-store.mjs"
|
|
469
|
+
case "$1" in
|
|
470
|
+
view-stored)
|
|
471
|
+
mutate "$store" " for (const record of records) counts[viewOf(record, nowMs)] = (counts[viewOf(record, nowMs)] ?? 0) + 1;" \
|
|
472
|
+
" for (const record of records) { const v = record.view ?? viewOf(record, nowMs); counts[v] = (counts[v] ?? 0) + 1; }" &&
|
|
473
|
+
mutate "$store" " phase: 'scheduled'," " phase: 'scheduled',
|
|
474
|
+
view: 'scheduled'," ;;
|
|
475
|
+
no-prune) mutate "$store" " pruneHistory(snapshot, nowMs);" " /* pruned by the red side: nothing is compacted */" ;;
|
|
476
|
+
highwater-lax)
|
|
477
|
+
mutate "$store" " if (snapshot.pruned > highWater - 1) {" " if (false) {" &&
|
|
478
|
+
mutate "$store" " if (parsed.seq >= highWater) bad(" " if (false) bad(" ;;
|
|
479
|
+
past-time) mutate "$store" " if (dueMs <= nowMs) {" " if (false) {" ;;
|
|
480
|
+
key-conflict-gone) mutate "$store" " if (!sameRequest(active, candidate)) {" " if (false) {" ;;
|
|
481
|
+
*) return 1 ;;
|
|
482
|
+
esac
|
|
483
|
+
}
|
|
484
|
+
flip_probe() { # <id> <helper>
|
|
485
|
+
local id="$1" helper="$2" repo rid out
|
|
486
|
+
case "$id" in
|
|
487
|
+
view-stored|no-prune|highwater-lax|past-time|key-conflict-gone) repo="$(new_repo "flip-$id")" ;;
|
|
488
|
+
*) return 1 ;;
|
|
489
|
+
esac
|
|
490
|
+
case "$id" in
|
|
491
|
+
view-stored)
|
|
492
|
+
run_helper "$helper" "$repo" "$ROOT/msg/x.txt" "$ROOT/out/p.txt" remind-add --after 2h
|
|
493
|
+
rid="$(sed -n 's/^已创建 \(rem-[^ ]*\) · .*/\1/p' "$ROOT/out/p.txt")"
|
|
494
|
+
printf "snap.reminders.find(r => r.id === '%s').phase = 'queued';\n" "$rid" > "$ROOT/script/p-queued.mjs"
|
|
495
|
+
edit_snapshot "$repo" "$ROOT/script/p-queued.mjs"
|
|
496
|
+
run_helper "$helper" "$repo" "$ROOT/msg/none" "$ROOT/out/p2.txt" remind-list --json
|
|
497
|
+
out="$(jfield "$ROOT/out/p2.txt" counts.queued 2>/dev/null)"
|
|
498
|
+
if [ "$out" = "0" ]; then
|
|
499
|
+
ok "flip(把视图存下来):phase=queued 之后 queued 计数仍是 0 —— D 那条断言会红"
|
|
500
|
+
else
|
|
501
|
+
bad "flip(把视图存下来):计数仍跟着快照变(queued=$out),这条红侧是橡皮章"
|
|
502
|
+
fi ;;
|
|
503
|
+
no-prune)
|
|
504
|
+
cat > "$ROOT/script/p-fill.mjs" <<'JS'
|
|
505
|
+
snap.reminders = [];
|
|
506
|
+
for (let i = 1; i <= 1050; i++) {
|
|
507
|
+
snap.reminders.push({ id: 'rem-' + snap.project.id + '-' + i, seq: i, owner: 'pm', source: 'cli', task: null,
|
|
508
|
+
key: null, phase: 'cancelled', createdAt: new Date().toISOString(), request: { form: 'after', value: '2h' },
|
|
509
|
+
dueAt: new Date().toISOString(), message: 'terminal ' + i, endedAt: new Date().toISOString() });
|
|
510
|
+
}
|
|
511
|
+
snap.sequences.reminder = 1100; snap.pruned = 0;
|
|
512
|
+
JS
|
|
513
|
+
run_helper "$helper" "$repo" "$ROOT/msg/x.txt" "$ROOT/out/p.txt" remind-add --after 2h
|
|
514
|
+
edit_snapshot "$repo" "$ROOT/script/p-fill.mjs"
|
|
515
|
+
run_helper "$helper" "$repo" "$ROOT/msg/x.txt" "$ROOT/out/p2.txt" remind-add --after 2h
|
|
516
|
+
run_helper "$helper" "$repo" "$ROOT/msg/none" "$ROOT/out/p3.txt" remind-list --json
|
|
517
|
+
out="$(jfield "$ROOT/out/p3.txt" terminalTotal 2>/dev/null)"
|
|
518
|
+
if [ "$out" = "1050" ]; then
|
|
519
|
+
ok "flip(关掉修剪):1050 条终结记录一条没删 —— E 的「压到 1000 条」会红"
|
|
520
|
+
else
|
|
521
|
+
bad "flip(关掉修剪):仍然修剪了(terminalTotal=$out),这条红侧是橡皮章"
|
|
522
|
+
fi ;;
|
|
523
|
+
highwater-lax)
|
|
524
|
+
run_helper "$helper" "$repo" "$ROOT/msg/x.txt" "$ROOT/out/p.txt" remind-add --after 2h
|
|
525
|
+
printf "snap.sequences.reminder = 1;\n" > "$ROOT/script/p-hw.mjs"
|
|
526
|
+
edit_snapshot "$repo" "$ROOT/script/p-hw.mjs"
|
|
527
|
+
run_helper "$helper" "$repo" "$ROOT/msg/none" "$ROOT/out/p2.txt" remind-list --json
|
|
528
|
+
if [ "$RC" = "0" ]; then
|
|
529
|
+
ok "flip(去掉高水位检查):高水位倒退的快照被接受 —— E 的「必须拒绝」会红"
|
|
530
|
+
else
|
|
531
|
+
bad "flip(去掉高水位检查):仍然拒绝了(rc=$RC),这条红侧是橡皮章"
|
|
532
|
+
fi ;;
|
|
533
|
+
past-time)
|
|
534
|
+
run_helper "$helper" "$repo" "$ROOT/msg/x.txt" "$ROOT/out/p.txt" remind-add --at 2020-01-01T00:00:00Z
|
|
535
|
+
if [ "$RC" = "0" ]; then
|
|
536
|
+
ok "flip(放过过去时间):过去的 --at 被建成 —— B 的「过去时间必须拒」会红"
|
|
537
|
+
else
|
|
538
|
+
bad "flip(放过过去时间):仍然拒绝了(rc=$RC),这条红侧是橡皮章"
|
|
539
|
+
fi ;;
|
|
540
|
+
key-conflict-gone)
|
|
541
|
+
run_helper "$helper" "$repo" "$ROOT/msg/x.txt" "$ROOT/out/p.txt" remind-add --after 2h --key check
|
|
542
|
+
run_helper "$helper" "$repo" "$ROOT/msg/two.txt" "$ROOT/out/p2.txt" remind-add --after 2h --key check
|
|
543
|
+
if [ "$RC" = "0" ]; then
|
|
544
|
+
ok "flip(活跃 key 的不同请求照旧返回):冲突被吞掉 —— C 的「必须拒」会红"
|
|
545
|
+
else
|
|
546
|
+
bad "flip(活跃 key 的不同请求照旧返回):仍然拒绝了(rc=$RC),这条红侧是橡皮章"
|
|
547
|
+
fi ;;
|
|
548
|
+
esac
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
for flip_id in view-stored no-prune highwater-lax past-time key-conflict-gone; do
|
|
552
|
+
arm_selected "$flip_id" || continue
|
|
553
|
+
FLIPS_RUN="${FLIPS_RUN:+$FLIPS_RUN,}$flip_id"
|
|
554
|
+
if ! helper="$(helper_copy "$flip_id")"; then
|
|
555
|
+
bad "红侧 $flip_id:副本建不出来"
|
|
556
|
+
continue
|
|
557
|
+
fi
|
|
558
|
+
if ! flip_prepare "$flip_id" "$helper" >"$ROOT/out/flip-$flip_id.prep" 2>&1; then
|
|
559
|
+
bad "红侧 $flip_id:变异没落地(夹具缺陷)—— $(head -2 "$ROOT/out/flip-$flip_id.prep" | tr '\n' ' ')"
|
|
560
|
+
rm -rf "$ROOT/flip/$flip_id"
|
|
561
|
+
continue
|
|
562
|
+
fi
|
|
563
|
+
if cmp -s "$helper" "$SKILL/scripts/state-authority.mjs" \
|
|
564
|
+
&& cmp -s "$ROOT/flip/$flip_id/remind-store.mjs" "$SKILL/scripts/remind-store.mjs"; then
|
|
565
|
+
bad "红侧 $flip_id:变异没落地(副本与产品逐字节相同)"
|
|
566
|
+
rm -rf "$ROOT/flip/$flip_id"
|
|
567
|
+
continue
|
|
568
|
+
fi
|
|
569
|
+
ok "红侧 $flip_id:变异已落地(副本不再是产品那一份)"
|
|
570
|
+
flip_probe "$flip_id" "$helper"
|
|
571
|
+
rm -rf "$ROOT/flip/$flip_id"
|
|
572
|
+
done
|
|
573
|
+
|
|
574
|
+
result
|