teamsmith 0.4.6 → 0.4.8
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 +35 -0
- package/skills/teamsmith/SKILL.md +43 -30
- package/skills/teamsmith/extension/team-bg.ts +5 -3
- package/skills/teamsmith/extension/team-inbox-watch.ts +14 -3
- 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/config.md +11 -12
- package/skills/teamsmith/references/migration.md +101 -0
- package/skills/teamsmith/references/openspec.md +43 -27
- package/skills/teamsmith/references/protocol.md +26 -15
- package/skills/teamsmith/references/reminders.md +153 -161
- package/skills/teamsmith/references/troubleshooting.md +12 -7
- package/skills/teamsmith/references/workflows.md +84 -31
- package/skills/teamsmith/scripts/lib/cmd-agents.sh +10 -4
- package/skills/teamsmith/scripts/lib/cmd-project.sh +88 -6
- package/skills/teamsmith/scripts/lib/cmd-remind.sh +88 -2
- package/skills/teamsmith/scripts/lib/cmd-review.sh +61 -35
- package/skills/teamsmith/scripts/lib/cmd-watch.sh +48 -11
- package/skills/teamsmith/scripts/lib/common.sh +83 -13
- package/skills/teamsmith/scripts/panel/README.md +35 -33
- package/skills/teamsmith/scripts/panel/panel.js +217 -199
- package/skills/teamsmith/scripts/panel/src/App.tsx +221 -66
- package/skills/teamsmith/scripts/panel/src/data.ts +71 -15
- package/skills/teamsmith/scripts/panel/src/layout.ts +159 -310
- package/skills/teamsmith/scripts/panel/src/main.tsx +83 -21
- package/skills/teamsmith/scripts/panel/src/project-settings.ts +46 -0
- package/skills/teamsmith/scripts/panel/src/strings/en.ts +71 -205
- package/skills/teamsmith/scripts/panel/src/strings/index.ts +3 -5
- package/skills/teamsmith/scripts/panel/src/strings/zh.ts +72 -204
- package/skills/teamsmith/scripts/panel/src/types.ts +23 -4
- package/skills/teamsmith/scripts/remind-capability.mjs +261 -0
- package/skills/teamsmith/scripts/remind-store.mjs +55 -24
- package/skills/teamsmith/scripts/remind-tick.mjs +5 -2
- package/skills/teamsmith/scripts/reply-capture.mjs +8 -9
- package/skills/teamsmith/scripts/state-authority.mjs +72 -6
- package/skills/teamsmith/scripts/strings/commands.tsv +1 -1
- package/skills/teamsmith/scripts/team +1 -0
- package/skills/teamsmith/templates/AGENTS.section.md.tmpl +18 -8
- 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 +41 -25
- 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/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 +78 -12
- package/skills/teamsmith/tests/install-shape.sh +7 -7
- package/skills/teamsmith/tests/isolation-ledger.sh +6 -2
- package/skills/teamsmith/tests/key-replies-ui.sh +64 -5
- package/skills/teamsmith/tests/key-replies.sh +307 -106
- package/skills/teamsmith/tests/lib/main-team-fingerprint.sh +2 -0
- package/skills/teamsmith/tests/lib/model-routing-boundary.sh +255 -90
- package/skills/teamsmith/tests/lib/model-routing-expansion.sh +181 -61
- package/skills/teamsmith/tests/lib/model-routing-roles.sh +125 -67
- package/skills/teamsmith/tests/lib/reply-fixture.sh +14 -9
- package/skills/teamsmith/tests/lib/routes-pages.sh +243 -0
- package/skills/teamsmith/tests/lib/tmp-root.sh +1 -1
- package/skills/teamsmith/tests/loop-inventory.tsv +3 -0
- package/skills/teamsmith/tests/panel-b2.sh +91 -31
- package/skills/teamsmith/tests/panel-b3-stub.sh +9 -2
- package/skills/teamsmith/tests/panel-p21.sh +607 -1162
- package/skills/teamsmith/tests/panel-strings.mjs +21 -113
- package/skills/teamsmith/tests/remind-adversarial-faults.mjs +190 -0
- package/skills/teamsmith/tests/remind-adversarial-faults.sh +78 -0
- package/skills/teamsmith/tests/remind-adversarial-real.sh +28 -0
- package/skills/teamsmith/tests/remind-cli.sh +108 -3
- package/skills/teamsmith/tests/remind-delivery-node.mjs +13 -0
- package/skills/teamsmith/tests/remind-delivery.sh +123 -35
- 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 +801 -0
- package/skills/teamsmith/tests/remind-tool-real.sh +180 -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 +19 -17
- package/skills/teamsmith/tests/smoke.sh +583 -133
- package/skills/teamsmith/tests/state-authority.sh +152 -8
- package/skills/teamsmith/tests/task-model-routing.sh +57 -26
- package/skills/teamsmith/tests/tmp-hygiene.sh +1 -1
- package/skills/teamsmith-init/SKILL.md +5 -5
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/__pycache__/judge-second.cpython-313.pyc +0 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# P443 · both real Pulse shapes: due admission during a long patrol, coalesced recovery and child reaping.
|
|
3
|
+
set -uo pipefail
|
|
4
|
+
FLIP_CLEANUP=0
|
|
5
|
+
case "${1:-}" in
|
|
6
|
+
'') ;;
|
|
7
|
+
--flip=cleanup) FLIP_CLEANUP=1 ;;
|
|
8
|
+
*) printf 'remind-pulse:不认识的参数 [%s]\n' "$1" >&2; exit 2 ;;
|
|
9
|
+
esac
|
|
10
|
+
HERE="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
11
|
+
SKILL="$(cd -P "$HERE/.." && pwd)"
|
|
12
|
+
# shellcheck source=lib/tmp-root.sh
|
|
13
|
+
. "$HERE/lib/tmp-root.sh"
|
|
14
|
+
# shellcheck source=lib/main-team-fingerprint.sh
|
|
15
|
+
. "$HERE/lib/main-team-fingerprint.sh"
|
|
16
|
+
ROOT="$(tmp_root_create remind-pulse)" || exit 3
|
|
17
|
+
# The private root is already unique; a one-letter socket name keeps the full AF_UNIX path below 107 bytes.
|
|
18
|
+
SOCK="s"
|
|
19
|
+
cleanup() {
|
|
20
|
+
TMUX_TMPDIR="$ROOT/tmux" tmux -L "$SOCK" -f /dev/null kill-server 2>/dev/null
|
|
21
|
+
tmp_root_reap_all
|
|
22
|
+
}
|
|
23
|
+
trap cleanup EXIT
|
|
24
|
+
mkdir -p "$ROOT/home" "$ROOT/tmp" "$ROOT/tmux" "$ROOT/out" "$ROOT/bin"
|
|
25
|
+
export HOME="$ROOT/home" TMPDIR="$ROOT/tmp"
|
|
26
|
+
unset TEAM_ROOT TEAM_MAIN_ROOT TEAM_PROJECT TEAM_SESSION TEAM_SESSION_FROM TEAM_STATE_DIR TEAM_CONFIG_FILE TMUX TMUX_PANE 2>/dev/null || true
|
|
27
|
+
PASS=0; FAIL=0; W1_FAILURES=0
|
|
28
|
+
ok() { printf ' \033[32m✓\033[0m %s\n' "$1"; PASS=$((PASS+1)); }
|
|
29
|
+
bad() { printf ' \033[31m✗\033[0m %s\n' "$1"; FAIL=$((FAIL+1)); }
|
|
30
|
+
assert_eq() { [ "$2" = "$3" ] && ok "$1" || bad "$1(期望 [$3],实际 [$2])"; }
|
|
31
|
+
assert_has() { case "$2" in *"$3"*) ok "$1" ;; *) bad "$1(缺 [$3])" ;; esac; }
|
|
32
|
+
w1_assert_eq() { if [ "$2" = "$3" ]; then ok "$1"; else W1_FAILURES=$((W1_FAILURES+1)); bad "$1(期望 [$3],实际 [$2])"; fi; }
|
|
33
|
+
new_repo() { local d="$ROOT/$1"; mkdir -p "$d/.pi/team/state" "$d/docs/team"; git -C "$d" init -q; cat > "$d/.pi/team/config.sh" <<EOF
|
|
34
|
+
TEAM_PROJECT='p443-$1'
|
|
35
|
+
TEAM_SESSION='p443-$1'
|
|
36
|
+
TEAM_PM_WINDOW='pm'
|
|
37
|
+
TEAM_AGENTS='dev'
|
|
38
|
+
TEAM_DOCS_DIR='docs/team'
|
|
39
|
+
TEAM_WORKTREES_DIR='.worktrees'
|
|
40
|
+
TEAM_PM_MODEL='fixture/controlled'
|
|
41
|
+
TEAM_TASK_MODELS='code=fixture/controlled'
|
|
42
|
+
TEAM_PULSE_REBUILD_TMUX=0
|
|
43
|
+
TEAM_PULSE_MAX_RESTARTS=5
|
|
44
|
+
TEAM_PULSE_INTERVAL=2
|
|
45
|
+
TEAM_REMIND_TICK_SECS=1
|
|
46
|
+
EOF
|
|
47
|
+
printf '%s\n' "$d"; }
|
|
48
|
+
team() { local repo="$1"; shift; (cd "$repo" && env -u TEAM_ROOT -u TEAM_MAIN_ROOT -u TEAM_PROJECT -u TEAM_SESSION -u TEAM_STATE_DIR -u TEAM_CONFIG_FILE -u TMUX -u TMUX_PANE HOME="$ROOT/home" TMPDIR="$ROOT/tmp" bash "$SKILL/scripts/team" --root "$repo" "$@"); }
|
|
49
|
+
add_due() { local repo="$1" text="$2"; team "$repo" remind add --after 2s --message "$text" > "$ROOT/out/add-$3.txt" 2>&1 || return 1; }
|
|
50
|
+
wait_file() { local file="$1" tries="${2:-200}"; while [ "$tries" -gt 0 ]; do [ -s "$file" ] && return 0; sleep 0.1; tries=$((tries-1)); done; return 1; }
|
|
51
|
+
queued_at() { node -e 'const s=require(process.argv[1]);const r=s.reminders.find(x=>x.phase==="queued"||x.phase==="intent"||x.phase==="observed");if(!r)process.exit(3);process.stdout.write(String(Date.parse(r.queuedAt)))' "$1/.pi/team/state/reminders/state.json"; }
|
|
52
|
+
check_order() { # <label> <repo> <patrol-log> <recovery-log>
|
|
53
|
+
local label="$1" repo="$2" plog="$3" rlog="$4" q
|
|
54
|
+
q="$(queued_at "$repo")" || { bad "$label 没有 queued 记录"; return; }
|
|
55
|
+
Q="$q" LABEL="$label" node - "$plog" "$rlog" <<'JS'
|
|
56
|
+
const fs = require('fs');
|
|
57
|
+
const label = process.env.LABEL, q = Number(process.env.Q);
|
|
58
|
+
const lines = fs.readFileSync(process.argv[2], 'utf8').trim().split('\n').filter(Boolean);
|
|
59
|
+
let active = false, overlap = false, firstBegin = 0, firstEnd = 0, secondBegin = 0;
|
|
60
|
+
for (const line of lines) {
|
|
61
|
+
const [kind, raw] = line.split(' '), at = Number(raw);
|
|
62
|
+
if (kind === 'PATROL_BEGIN') {
|
|
63
|
+
if (active) overlap = true;
|
|
64
|
+
if (!firstBegin) firstBegin = at; else if (!secondBegin) secondBegin = at;
|
|
65
|
+
active = true;
|
|
66
|
+
}
|
|
67
|
+
if (kind === 'PATROL_END') { if (!firstEnd) firstEnd = at; active = false; }
|
|
68
|
+
}
|
|
69
|
+
const recoveryAt = fs.statSync(process.argv[3]).mtimeMs;
|
|
70
|
+
if (!firstBegin || !firstEnd || q < firstBegin || q > firstEnd) {
|
|
71
|
+
console.log(`FAIL ${label}: due ${q} was not admitted inside first patrol ${firstBegin}..${firstEnd}`); process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
if (overlap) { console.log(`FAIL ${label}: a second full patrol overlapped the first`); process.exit(1); }
|
|
74
|
+
if (recoveryAt < firstEnd || (secondBegin && recoveryAt > secondBegin + 250)) {
|
|
75
|
+
console.log(`FAIL ${label}: recovery ${recoveryAt} was not the coalesced recheck after patrol ${firstEnd} (second ${secondBegin})`); process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
console.log(`PASS ${label}: due queued during long patrol; one recovery followed before the next patrol`);
|
|
78
|
+
JS
|
|
79
|
+
RC=$?; assert_eq "$label 长巡检中入队且不重叠、结束后一次恢复" "$RC" '0'
|
|
80
|
+
}
|
|
81
|
+
check_reaped() { # <label> <patrol-log>
|
|
82
|
+
local label="$1" log="$2" pid alive=0
|
|
83
|
+
while read -r kind pid rest; do
|
|
84
|
+
case "$kind" in PATROL_BEGIN|PATROL_SLEEP)
|
|
85
|
+
if kill -0 "$pid" 2>/dev/null; then alive=$((alive+1)); fi ;;
|
|
86
|
+
esac
|
|
87
|
+
done < "$log"
|
|
88
|
+
assert_eq "$label 停止后巡检与其外部子进程都已回收" "$alive" '0'
|
|
89
|
+
}
|
|
90
|
+
check_loop_children_reaped() { # <pid-file>:停止前由循环自己登记的全部直接子进程
|
|
91
|
+
local file="$1" pid alive=0
|
|
92
|
+
while read -r pid; do
|
|
93
|
+
[[ "$pid" =~ ^[0-9]+$ ]] || continue
|
|
94
|
+
if kill -0 "$pid" 2>/dev/null; then alive=$((alive+1)); fi
|
|
95
|
+
done < "$file"
|
|
96
|
+
w1_assert_eq 'headless 停止前登记的循环子进程全部消失' "$alive" '0'
|
|
97
|
+
}
|
|
98
|
+
REAL_MAIN="$(main_team_project_root "$SKILL")"
|
|
99
|
+
main_team_snapshot "${REAL_MAIN:-/nonexistent}/.pi/team" > "$ROOT/real-before.txt"
|
|
100
|
+
|
|
101
|
+
# A · actual `team watch` headless loop. Only the patrol body is slowed/instrumented in a scratch copy.
|
|
102
|
+
H="$(new_repo headless)"; cp -a "$SKILL" "$ROOT/headless-skill"
|
|
103
|
+
python3 - "$ROOT/headless-skill/scripts/lib/cmd-watch.sh" <<'PY'
|
|
104
|
+
import sys
|
|
105
|
+
p = sys.argv[1]; s = open(p).read(); old = 'team_watch_once() {'
|
|
106
|
+
new = '''team_watch_once() {
|
|
107
|
+
printf 'PATROL_BEGIN %s %s\\n' "$(date +%s%3N)" "$BASHPID" >> "$TEAM_STATE_DIR/patrol-fixture.log"
|
|
108
|
+
sleep 4 & local fixture_sleep=$!
|
|
109
|
+
printf 'PATROL_SLEEP %s\\n' "$fixture_sleep" >> "$TEAM_STATE_DIR/patrol-fixture.log"
|
|
110
|
+
wait "$fixture_sleep"
|
|
111
|
+
printf 'PATROL_END %s\\n' "$(date +%s%3N)" >> "$TEAM_STATE_DIR/patrol-fixture.log"
|
|
112
|
+
}
|
|
113
|
+
team_watch_once_real_unused() {'''
|
|
114
|
+
assert s.count(old) == 1
|
|
115
|
+
open(p, 'w').write(s.replace(old, new, 1))
|
|
116
|
+
PY
|
|
117
|
+
if [ "$FLIP_CLEANUP" = "1" ]; then
|
|
118
|
+
# 恢复 V151 的旧清理:在 set -e 下,第一个非零 kill/wait 会跳过锁和剩余子进程。
|
|
119
|
+
python3 - "$ROOT/headless-skill/scripts/lib/cmd-watch.sh" <<'PY'
|
|
120
|
+
import sys
|
|
121
|
+
p = sys.argv[1]; s = open(p).read()
|
|
122
|
+
s = s.replace('kill "$child" 2>/dev/null || true', 'kill "$child" 2>/dev/null')
|
|
123
|
+
s = s.replace('kill "$pid" 2>/dev/null || true', 'kill "$pid" 2>/dev/null')
|
|
124
|
+
s = s.replace('wait "$pid" 2>/dev/null || true', 'wait "$pid" 2>/dev/null')
|
|
125
|
+
open(p, 'w').write(s)
|
|
126
|
+
PY
|
|
127
|
+
fi
|
|
128
|
+
add_due "$H" 'headless due during patrol' headless || bad 'headless 提醒创建失败'
|
|
129
|
+
(cd "$H" && exec env -u TEAM_ROOT -u TEAM_MAIN_ROOT -u TEAM_PROJECT -u TEAM_SESSION -u TEAM_STATE_DIR -u TEAM_CONFIG_FILE -u TMUX -u TMUX_PANE \
|
|
130
|
+
HOME="$ROOT/home" TMPDIR="$ROOT/tmp" TMUX_TMPDIR="$ROOT/tmux" TEAM_STATE_DIR="$H/.pi/team/state" TEAM_PULSE_INTERVAL=2 TEAM_REMIND_TICK_SECS=1 \
|
|
131
|
+
bash "$ROOT/headless-skill/scripts/team" --root "$H" watch > "$ROOT/out/headless.log" 2>&1) & HPID=$!
|
|
132
|
+
wait_file "$H/.pi/team/state/reminders.log" 200 || bad 'headless 没等到到期入队/恢复日志'
|
|
133
|
+
for i in $(seq 1 100); do N=0; [ ! -f "$H/.pi/team/state/patrol-fixture.log" ] || N="$(grep -c '^PATROL_BEGIN' "$H/.pi/team/state/patrol-fixture.log" || true)"; if [ "${N:-0}" -ge 2 ]; then cp "$H/.pi/team/state/reminders.log" "$ROOT/out/headless-recovery-before-second.log"; break; fi; sleep 0.1; done
|
|
134
|
+
for i in $(seq 1 100); do
|
|
135
|
+
ps -o pid=,args= --ppid "$HPID" > "$ROOT/out/headless-loop-children-full.txt"
|
|
136
|
+
awk '$2 == "sleep" && $3 == "1" { print $1 }' "$ROOT/out/headless-loop-children-full.txt" > "$ROOT/out/headless-loop-children.txt"
|
|
137
|
+
[ -s "$ROOT/out/headless-loop-children.txt" ] && break
|
|
138
|
+
sleep 0.1
|
|
139
|
+
done
|
|
140
|
+
[ -s "$ROOT/out/headless-loop-children.txt" ] && ok 'headless 停止前登记了循环自己的 sleep 子进程' || w1_assert_eq 'headless 停止前必须登记循环 sleep 子进程' missing registered
|
|
141
|
+
kill -TERM "$HPID" 2>/dev/null; wait "$HPID"; HRC=$?
|
|
142
|
+
assert_eq 'headless 由 TERM 正常收口' "$HRC" '143'
|
|
143
|
+
[ ! -e "$H/.pi/team/state/watchdog.pid" ] && ok 'headless 停止后 watchdog.pid 不存在' || w1_assert_eq 'headless 停止后 watchdog.pid 不存在' present absent
|
|
144
|
+
check_loop_children_reaped "$ROOT/out/headless-loop-children.txt"
|
|
145
|
+
check_order headless "$H" "$H/.pi/team/state/patrol-fixture.log" "$H/.pi/team/state/reminders.log"
|
|
146
|
+
assert_eq 'headless 第一次长巡检与第二次巡检之间恰有一次恢复' "$(grep -c 'result=missing-window' "$ROOT/out/headless-recovery-before-second.log")" '1'
|
|
147
|
+
check_reaped headless "$H/.pi/team/state/patrol-fixture.log"
|
|
148
|
+
|
|
149
|
+
if [ "$FLIP_CLEANUP" = "1" ]; then
|
|
150
|
+
printf '\n== remind-pulse flip cleanup:旧清理应留下锁或循环子进程 == W1 failures=%d\n' "$W1_FAILURES"
|
|
151
|
+
[ "$W1_FAILURES" -gt 0 ]
|
|
152
|
+
exit $?
|
|
153
|
+
fi
|
|
154
|
+
|
|
155
|
+
# B · actual console bundle and scheduler. A stub supplies panel data and a four-second patrol;
|
|
156
|
+
# due admission still uses the production authority and recovery goes through the production internal entry shape.
|
|
157
|
+
C="$(new_repo console)"; mkdir -p "$ROOT/console-bin"
|
|
158
|
+
cp "$SKILL/scripts/remind-tick.mjs" "$SKILL/scripts/state-authority.mjs" "$SKILL/scripts/remind-store.mjs" "$ROOT/console-bin/"
|
|
159
|
+
cat > "$ROOT/console-bin/team" <<'SH'
|
|
160
|
+
#!/usr/bin/env bash
|
|
161
|
+
set -uo pipefail
|
|
162
|
+
case " $* " in
|
|
163
|
+
*' watch --once '*)
|
|
164
|
+
printf 'PATROL_BEGIN %s %s\n' "$(date +%s%3N)" "$BASHPID" >> "$P443_PULSE_LOG"
|
|
165
|
+
sleep 4 & fixture_sleep=$!
|
|
166
|
+
printf 'PATROL_SLEEP %s\n' "$fixture_sleep" >> "$P443_PULSE_LOG"
|
|
167
|
+
wait "$fixture_sleep"
|
|
168
|
+
printf 'PATROL_END %s\n' "$(date +%s%3N)" >> "$P443_PULSE_LOG" ;;
|
|
169
|
+
*' __remind-recover '*)
|
|
170
|
+
printf 'RECOVERY %s\n' "$(date +%s%3N)" >> "$P443_RECOVERY_LOG" ;;
|
|
171
|
+
*) exec bash "$P443_PANEL_STUB" "$@" ;;
|
|
172
|
+
esac
|
|
173
|
+
SH
|
|
174
|
+
chmod +x "$ROOT/console-bin/team"
|
|
175
|
+
add_due "$C" 'console due during patrol' console || bad 'console 提醒创建失败'
|
|
176
|
+
cat > "$ROOT/console-run.sh" <<EOF
|
|
177
|
+
#!/usr/bin/env bash
|
|
178
|
+
export HOME='$ROOT/home' TMPDIR='$ROOT/tmp' P443_PULSE_LOG='$C/.pi/team/state/patrol-fixture.log'
|
|
179
|
+
export P443_RECOVERY_LOG='$C/.pi/team/state/recovery-fixture.log' P443_PANEL_STUB='$SKILL/tests/panel-b3-stub.sh'
|
|
180
|
+
export TEAM_REMIND_TICK_SECS=1 TEAM_MONITOR_REFRESH=1
|
|
181
|
+
exec node '$SKILL/scripts/panel/panel.js' --root '$C' --team-cli '$ROOT/console-bin/team' --ui tui --interval 1 --tick-every 1 --tick-log '$C/.pi/team/state/watchdog.tick.log'
|
|
182
|
+
EOF
|
|
183
|
+
chmod +x "$ROOT/console-run.sh"
|
|
184
|
+
TMUX_TMPDIR="$ROOT/tmux" tmux -L "$SOCK" -f /dev/null new-session -d -s p443-console -n pulse "bash $ROOT/console-run.sh"
|
|
185
|
+
CPID="$(TMUX_TMPDIR="$ROOT/tmux" tmux -L "$SOCK" -f /dev/null display-message -p -t p443-console:pulse '#{pane_pid}')"
|
|
186
|
+
wait_file "$C/.pi/team/state/recovery-fixture.log" 200 || bad 'console 没等到第一次合并恢复'
|
|
187
|
+
for i in $(seq 1 100); do N=0; [ ! -f "$C/.pi/team/state/patrol-fixture.log" ] || N="$(grep -c '^PATROL_BEGIN' "$C/.pi/team/state/patrol-fixture.log" || true)"; [ "${N:-0}" -ge 2 ] && break; sleep 0.1; done
|
|
188
|
+
sleep 1
|
|
189
|
+
kill -TERM "$CPID" 2>/dev/null
|
|
190
|
+
for i in $(seq 1 50); do kill -0 "$CPID" 2>/dev/null || break; sleep 0.1; done
|
|
191
|
+
if kill -0 "$CPID" 2>/dev/null; then bad 'console SIGTERM 后仍未退出'; else ok 'console SIGTERM 后退出并执行清理'; fi
|
|
192
|
+
check_order console "$C" "$C/.pi/team/state/patrol-fixture.log" "$C/.pi/team/state/recovery-fixture.log"
|
|
193
|
+
check_reaped console "$C/.pi/team/state/patrol-fixture.log"
|
|
194
|
+
|
|
195
|
+
main_team_snapshot "${REAL_MAIN:-/nonexistent}/.pi/team" > "$ROOT/real-after.txt"
|
|
196
|
+
VIOL="$(main_team_violations "$ROOT/real-before.txt" "$ROOT/real-after.txt")"
|
|
197
|
+
[ -z "$VIOL" ] && ok '两种 Pulse 夹具均未写主项目状态' || bad "主项目状态被写入:$VIOL"
|
|
198
|
+
printf '\n== remind-pulse 结果 == ✓%d ✗%d SKIP0\n' "$PASS" "$FAIL"
|
|
199
|
+
[ "$FAIL" -eq 0 ]
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# P443: stopped-PM recovery and immediate tool withdrawal in private real Pi/tmux + controlled model.
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
TESTS="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
5
|
+
exec node "$TESTS/remind-tool-real.mjs" --select=recovery,withdrawal "$@"
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# P443 · prompt-free launch shape and recovery refusal matrix (no live team, tmux or model).
|
|
3
|
+
set -uo pipefail
|
|
4
|
+
HERE="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
5
|
+
SKILL="$(cd -P "$HERE/.." && pwd)"
|
|
6
|
+
# shellcheck source=lib/tmp-root.sh
|
|
7
|
+
. "$HERE/lib/tmp-root.sh"
|
|
8
|
+
ROOT="$(tmp_root_create remind-recovery-unit)" || exit 3
|
|
9
|
+
trap 'tmp_root_reap_all' EXIT
|
|
10
|
+
mkdir -p "$ROOT/home" "$ROOT/tmp" "$ROOT/repo/.pi/team/state" "$ROOT/repo/docs/team"
|
|
11
|
+
export HOME="$ROOT/home" TMPDIR="$ROOT/tmp"
|
|
12
|
+
REPO="$ROOT/repo" STATE="$REPO/.pi/team/state"
|
|
13
|
+
git -C "$REPO" init -q
|
|
14
|
+
cat > "$REPO/.pi/team/config.sh" <<EOF
|
|
15
|
+
TEAM_PROJECT='p443-unit'
|
|
16
|
+
TEAM_SESSION='p443-unit'
|
|
17
|
+
TEAM_PM_WINDOW='pm'
|
|
18
|
+
TEAM_PM_MODEL='fixture/controlled'
|
|
19
|
+
TEAM_TASK_MODELS='code=fixture/controlled'
|
|
20
|
+
TEAM_PM_EXTRA_PI_ARGS=''
|
|
21
|
+
TEAM_PM_RESUME_ARGS=''
|
|
22
|
+
TEAM_PULSE_REBUILD_TMUX=0
|
|
23
|
+
TEAM_PULSE_MAX_RESTARTS=5
|
|
24
|
+
EOF
|
|
25
|
+
PASS=0; FAIL=0
|
|
26
|
+
ok() { printf ' \033[32m✓\033[0m %s\n' "$1"; PASS=$((PASS+1)); }
|
|
27
|
+
bad() { printf ' \033[31m✗\033[0m %s\n' "$1"; FAIL=$((FAIL+1)); }
|
|
28
|
+
assert_has() { case "$2" in *"$3"*) ok "$1" ;; *) bad "$1(缺 [$3])" ;; esac; }
|
|
29
|
+
assert_no() { case "$2" in *"$3"*) bad "$1(不该有 [$3])" ;; *) ok "$1" ;; esac; }
|
|
30
|
+
assert_eq() { [ "$2" = "$3" ] && ok "$1" || bad "$1(期望 [$3],实际 [$2])"; }
|
|
31
|
+
|
|
32
|
+
# Render the real commands with the same config loader used by team up.
|
|
33
|
+
cd "$REPO" && env -u TEAM_ROOT -u TEAM_MAIN_ROOT -u TEAM_PROJECT -u TEAM_SESSION -u TEAM_STATE_DIR -u TEAM_CONFIG_FILE \
|
|
34
|
+
bash -c 'source "$1/scripts/lib/common.sh"; source "$1/scripts/lib/cmd-config.sh"; team_load_config; team_pm_launch_cmd "$2/pm-prompt.md" "$2/pm.pid.spawn"' _ "$SKILL" "$STATE" > "$ROOT/normal.launch"
|
|
35
|
+
cd "$REPO" && env -u TEAM_ROOT -u TEAM_MAIN_ROOT -u TEAM_PROJECT -u TEAM_SESSION -u TEAM_STATE_DIR -u TEAM_CONFIG_FILE \
|
|
36
|
+
bash -c 'source "$1/scripts/lib/common.sh"; source "$1/scripts/lib/cmd-config.sh"; team_load_config; TEAM_REMINDER_ONLY_RECOVERY=1 team_pm_launch_cmd "" "$2/pm.pid.spawn"' _ "$SKILL" "$STATE" > "$ROOT/reminder.launch"
|
|
37
|
+
NORMAL="$(cat "$ROOT/normal.launch")"; REMINDER="$(cat "$ROOT/reminder.launch")"
|
|
38
|
+
assert_has '普通 PM 启动仍带通用提示文件' "$NORMAL" "@$STATE/pm-prompt.md"
|
|
39
|
+
assert_no 'Reminder-only 启动不带 @pm-prompt' "$REMINDER" '@'
|
|
40
|
+
assert_no 'Reminder-only 启动不引用替代初始提示文件' "$REMINDER" 'pm-prompt'
|
|
41
|
+
assert_has 'Reminder-only 保留通常 -c 续跑参数' "$REMINDER" ' -c '
|
|
42
|
+
assert_has 'Reminder-only 保留 inbox watcher 扩展' "$REMINDER" 'extension/team-inbox-watch.ts'
|
|
43
|
+
assert_has 'Reminder-only 保留 PM Reminder 工具扩展' "$REMINDER" 'extension/team-remind.ts'
|
|
44
|
+
assert_has 'Reminder-only 给 watcher 明确的恢复标记' "$REMINDER" 'TEAM_REMINDER_ONLY_RECOVERY=1'
|
|
45
|
+
assert_has '普通启动会清掉继承的恢复标记' "$NORMAL" 'unset TEAM_ROOT TEAM_MAIN_ROOT TEAM_PROJECT TEAM_SESSION TEAM_SESSION_FROM TEAM_CONFIG_FILE TEAM_REMINDER_ONLY_RECOVERY'
|
|
46
|
+
|
|
47
|
+
# Recovery decisions use the real function; only PM/tmux evidence and the final spawn are controlled.
|
|
48
|
+
cd "$REPO" && env -u TEAM_ROOT -u TEAM_MAIN_ROOT -u TEAM_PROJECT -u TEAM_SESSION -u TEAM_STATE_DIR -u TEAM_CONFIG_FILE \
|
|
49
|
+
bash -c '
|
|
50
|
+
set -eu
|
|
51
|
+
source "$1/scripts/lib/common.sh"; source "$1/scripts/lib/cmd-config.sh"; source "$1/scripts/lib/cmd-remind.sh"; team_load_config
|
|
52
|
+
TEAM_SKILL_DIR="$1"; SKILL_PATH="$1"
|
|
53
|
+
team_remind_due_tick() { TEAM_REMIND_RECOVERY_REQUIRED=1; }
|
|
54
|
+
team_pm_evidence() { printf "controlled-evidence"; }
|
|
55
|
+
team_capacity_line() { printf "ram=ok swap=ok"; }
|
|
56
|
+
team_pm_recorded_pid() { printf "4242"; }
|
|
57
|
+
team_pm_attempt_record() { printf "attempt\n" >> "$TEAM_STATE_DIR/calls"; }
|
|
58
|
+
team_pm_restart_record() { printf "restart\n" >> "$TEAM_STATE_DIR/calls"; }
|
|
59
|
+
team_pm_start() {
|
|
60
|
+
printf "start reminder=%s\n" "${TEAM_REMINDER_ONLY_RECOVERY:-0}" >> "$TEAM_STATE_DIR/calls"
|
|
61
|
+
TEAM_PM_START_OUTCOME="${CONTROL_OUTCOME:-started}"
|
|
62
|
+
[ "$TEAM_PM_START_OUTCOME" != "failed" ]
|
|
63
|
+
}
|
|
64
|
+
reset_case() {
|
|
65
|
+
rm -f "$TEAM_STATE_DIR/calls" "$TEAM_STATE_DIR/reminders.log"
|
|
66
|
+
TEAM_PM_CMD=""; TEAM_PULSE_REBUILD_TMUX=0; CONTROL_OUTCOME=started; TEAM_SKILL_DIR="$SKILL_PATH"
|
|
67
|
+
team_pm_identity_guard() { return 0; }
|
|
68
|
+
team_pm_restart_allowed() { return 0; }
|
|
69
|
+
}
|
|
70
|
+
run_case() {
|
|
71
|
+
local name="$1" expected="$2" starts="$3" restarts="$4"
|
|
72
|
+
reset_case
|
|
73
|
+
case "$name" in
|
|
74
|
+
running) team_pm_state() { printf "running:4242"; } ;;
|
|
75
|
+
starting) team_pm_state() { printf "starting:2s"; } ;;
|
|
76
|
+
quota) team_pm_state() { printf "idle:bash"; }; team_pm_restart_allowed() { return 1; } ;;
|
|
77
|
+
identity) team_pm_state() { printf "idle:bash"; }; team_pm_identity_guard() { return 1; } ;;
|
|
78
|
+
adapter) team_pm_state() { printf "idle:bash"; }; TEAM_PM_CMD="custom {prompt}" ;;
|
|
79
|
+
missing-extension) team_pm_state() { printf "idle:bash"; }; TEAM_SKILL_DIR="/nonexistent" ;;
|
|
80
|
+
missing-window) team_pm_state() { printf "missing"; } ;;
|
|
81
|
+
started|already-starting|failed) team_pm_state() { printf "idle:bash"; } ;;
|
|
82
|
+
esac
|
|
83
|
+
[ "$name" = already-starting ] && CONTROL_OUTCOME=already-starting
|
|
84
|
+
[ "$name" = failed ] && CONTROL_OUTCOME=failed
|
|
85
|
+
team_remind_recovery > "$TEAM_STATE_DIR/result"
|
|
86
|
+
local got starts_actual restarts_actual
|
|
87
|
+
got="$(cat "$TEAM_STATE_DIR/result")"
|
|
88
|
+
starts_actual=0; restarts_actual=0
|
|
89
|
+
if [ -f "$TEAM_STATE_DIR/calls" ]; then
|
|
90
|
+
starts_actual="$(grep -c "^start " "$TEAM_STATE_DIR/calls" || true)"
|
|
91
|
+
restarts_actual="$(grep -c "^restart" "$TEAM_STATE_DIR/calls" || true)"
|
|
92
|
+
fi
|
|
93
|
+
case "$got" in *"result=$expected"*) printf "PASS recovery $name\n" ;; *) printf "FAIL recovery $name expected=$expected got=$got\n"; return 1 ;; esac
|
|
94
|
+
[ "$starts_actual" = "$starts" ] && [ "$restarts_actual" = "$restarts" ] || { printf "FAIL recovery $name starts=$starts_actual restarts=$restarts_actual\n"; return 1; }
|
|
95
|
+
}
|
|
96
|
+
run_case running running 0 0
|
|
97
|
+
run_case starting starting 0 0
|
|
98
|
+
run_case quota quota-refused 0 0
|
|
99
|
+
run_case identity identity-refused 0 0
|
|
100
|
+
run_case adapter unsupported-adapter 0 0
|
|
101
|
+
run_case missing-extension missing-extension 0 0
|
|
102
|
+
run_case missing-window missing-window 0 0
|
|
103
|
+
run_case started started 1 1
|
|
104
|
+
run_case already-starting already-starting 1 0
|
|
105
|
+
run_case failed start-failed 1 0
|
|
106
|
+
[ "$(sed -n "s/^start reminder=//p" "$TEAM_STATE_DIR/calls")" = 1 ] || { printf "FAIL reminder marker did not reach team_pm_start\n"; exit 1; }
|
|
107
|
+
printf "PASS recovery marker reaches the one prompt-free start\n"
|
|
108
|
+
' _ "$SKILL" > "$ROOT/matrix.log" 2>&1
|
|
109
|
+
RC=$?
|
|
110
|
+
cat "$ROOT/matrix.log"
|
|
111
|
+
assert_eq '恢复拒绝矩阵与真实启动结果全部符合' "$RC" '0'
|
|
112
|
+
for expected in 'PASS recovery running' 'PASS recovery starting' 'PASS recovery quota' 'PASS recovery identity' \
|
|
113
|
+
'PASS recovery adapter' 'PASS recovery missing-extension' 'PASS recovery missing-window' \
|
|
114
|
+
'PASS recovery started' 'PASS recovery already-starting' 'PASS recovery failed' 'PASS recovery marker reaches'; do
|
|
115
|
+
assert_has "矩阵含 $expected" "$(cat "$ROOT/matrix.log")" "$expected"
|
|
116
|
+
done
|
|
117
|
+
printf '\n== remind-recovery-unit 结果 == ✓%d ✗%d SKIP0\n' "$PASS" "$FAIL"
|
|
118
|
+
[ "$FAIL" -eq 0 ]
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// P442: invalid PM contexts stop before Reminder state; full authority input survives unchanged.
|
|
3
|
+
// Real Pi/tmux evidence lives in remind-tool-real.mjs. This file supplies the fast zero-I/O and flip arms.
|
|
4
|
+
import assert from 'node:assert/strict'
|
|
5
|
+
import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
6
|
+
import { dirname, join, resolve } from 'node:path'
|
|
7
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
8
|
+
import { spawnSync } from 'node:child_process'
|
|
9
|
+
|
|
10
|
+
const tests = dirname(fileURLToPath(import.meta.url)), skill = dirname(tests)
|
|
11
|
+
const root = mkdtempSync('/var/tmp/p442-tool-node-')
|
|
12
|
+
const repo = join(root, 'repo'), state = join(repo, '.pi/team/state'), config = join(repo, '.pi/team/config.sh')
|
|
13
|
+
const snapshot = join(state, 'reminders/state.json')
|
|
14
|
+
const env = { ...process.env, HOME: join(root, 'home'), TMPDIR: root,
|
|
15
|
+
TEAM_ROOT: repo, TEAM_MAIN_ROOT: repo, TEAM_STATE_DIR: state, TEAM_CONFIG_FILE: config,
|
|
16
|
+
TEAM_PM_WINDOW: 'pm', TEAM_SESSION: 'p442-node' }
|
|
17
|
+
let passed = 0
|
|
18
|
+
const pass = name => { passed++; console.log(`PASS ${name}`) }
|
|
19
|
+
const command = (bin, args, cwd = repo) => {
|
|
20
|
+
const result = spawnSync(bin, args, { cwd, env, encoding: 'utf8' })
|
|
21
|
+
assert.equal(result.status, 0, `${bin} ${args.join(' ')}: ${result.stderr}`)
|
|
22
|
+
}
|
|
23
|
+
const context = cwd => ({ cwd, sessionManager: { getSessionId: () => 'ordinary-session', getSessionFile: () => join(root, 'ordinary.jsonl') } })
|
|
24
|
+
async function loadExtension(base) {
|
|
25
|
+
const tools = [], handlers = {}
|
|
26
|
+
let activeTools = ['read', 'team_remind']
|
|
27
|
+
const pi = {
|
|
28
|
+
registerTool: definition => { tools.push(definition); if (definition.exposure === 'direct' && !activeTools.includes(definition.name)) activeTools.push(definition.name) },
|
|
29
|
+
getActiveTools: () => activeTools.slice(),
|
|
30
|
+
setActiveTools: names => { activeTools = names.slice() },
|
|
31
|
+
on: (name, fn) => { (handlers[name] ||= []).push(fn) },
|
|
32
|
+
}
|
|
33
|
+
const factory = (await import(pathToFileURL(join(base, 'extension/team-remind.ts')).href)).default
|
|
34
|
+
await factory(pi)
|
|
35
|
+
return { tools, handlers, active: () => activeTools.slice() }
|
|
36
|
+
}
|
|
37
|
+
const actionInput = action => action === 'add' ? { action, after: '1h', message: 'must not be written' }
|
|
38
|
+
: action === 'list' ? { action } : { action, id: 'rem-00000000-0000-0000-0000-000000000000-1' }
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
for (const path of [state, dirname(config), join(root, 'home')]) mkdirSync(path, { recursive: true })
|
|
42
|
+
writeFileSync(config, "TEAM_PROJECT='p442-node'\nTEAM_SESSION='p442-node'\nTEAM_PM_WINDOW='pm'\nTEAM_PM_MODEL='p442/controlled'\nTEAM_TASK_MODELS='code=p442/controlled'\n")
|
|
43
|
+
command('git', ['init', '-q', '-b', 'main'])
|
|
44
|
+
const worker = join(root, 'worker')
|
|
45
|
+
writeFileSync(join(repo, 'README'), 'fixture')
|
|
46
|
+
command('git', ['add', 'README'])
|
|
47
|
+
command('git', ['-c', 'user.name=fixture', '-c', 'user.email=fixture@example.invalid', 'commit', '-qm', 'fixture'])
|
|
48
|
+
command('git', ['worktree', 'add', '-q', '--detach', worker, 'HEAD'])
|
|
49
|
+
|
|
50
|
+
const host = await loadExtension(skill)
|
|
51
|
+
assert.equal(host.tools.at(-1).exposure, 'hidden')
|
|
52
|
+
for (const [name, cwd, reason] of [['ordinary', repo, 'startup'], ['worker', worker, 'startup'], ['forged', repo, 'reload']]) {
|
|
53
|
+
if (reason === 'reload') await host.handlers.session_start[0]({ reason: 'reload' }, context(cwd))
|
|
54
|
+
else await host.handlers.session_start[0]({ reason: 'startup' }, context(cwd))
|
|
55
|
+
assert.equal(host.tools.at(-1).exposure, 'hidden', `${name}: tool must be hidden`)
|
|
56
|
+
assert(!host.active().includes('team_remind'), `${name}: active tool list withdrew team_remind`)
|
|
57
|
+
for (const action of ['add', 'list', 'show', 'cancel']) {
|
|
58
|
+
await assert.rejects(host.tools.at(-1).execute('call', actionInput(action), undefined, undefined, context(cwd)), /refused|not a verified/, `${name}/${action}`)
|
|
59
|
+
assert(!existsSync(snapshot), `${name}/${action}: no Reminder snapshot may be read or created`)
|
|
60
|
+
}
|
|
61
|
+
pass(`${name}: hidden and all four actions refuse with zero Reminder state`)
|
|
62
|
+
}
|
|
63
|
+
const schema = host.tools.at(-1).parameters
|
|
64
|
+
for (const forbidden of ['project', 'owner', 'state', 'statePath', 'recipient', 'source']) assert(!Object.hasOwn(schema.properties, forbidden))
|
|
65
|
+
pass('tool schema has no caller-selected project/owner/state/recipient/source')
|
|
66
|
+
|
|
67
|
+
// Deliberate defect: bypass only execute's PM check. The same invalid context now writes, proving the
|
|
68
|
+
// zero-state assertions above have teeth. The scratch copy contains only the modules this extension loads.
|
|
69
|
+
const flipped = join(root, 'flipped-skill')
|
|
70
|
+
for (const relative of ['extension/team-remind.ts', 'scripts/remind-capability.mjs', 'scripts/reply-capture.mjs',
|
|
71
|
+
'scripts/replies.mjs', 'scripts/state-authority.mjs', 'scripts/remind-store.mjs']) {
|
|
72
|
+
mkdirSync(dirname(join(flipped, relative)), { recursive: true }); cpSync(join(skill, relative), join(flipped, relative))
|
|
73
|
+
}
|
|
74
|
+
const extensionPath = join(flipped, 'extension/team-remind.ts')
|
|
75
|
+
const original = readFileSync(extensionPath, 'utf8'), anchor = 'const identity = verify(ctx)'
|
|
76
|
+
assert.equal(original.split(anchor).length, 2)
|
|
77
|
+
writeFileSync(extensionPath, original.replace(anchor,
|
|
78
|
+
"const identity = { root: ctx.cwd, state: join(ctx.cwd, '.pi/team/state'), config: join(ctx.cwd, '.pi/team/config.sh') }"))
|
|
79
|
+
const badHost = await loadExtension(flipped)
|
|
80
|
+
await badHost.handlers.session_start[0]({ reason: 'startup' }, context(repo))
|
|
81
|
+
const badResult = await badHost.tools.at(-1).execute('call', actionInput('add'), undefined, undefined, context(repo))
|
|
82
|
+
assert.equal(badResult.details.ok, true)
|
|
83
|
+
assert(existsSync(snapshot), 'the identity-check mutation must really write in the invalid context')
|
|
84
|
+
pass('flip: removing execute identity proof turns the same invalid add into a write')
|
|
85
|
+
|
|
86
|
+
// Direct authority presentation: no key means independent IDs; a 64 KiB body and its final newline survive.
|
|
87
|
+
rmSync(snapshot, { force: true })
|
|
88
|
+
const capability = await import(pathToFileURL(join(skill, 'scripts/remind-capability.mjs')).href)
|
|
89
|
+
const assertConfigValues = module => {
|
|
90
|
+
const parse = (value, key = 'TEAM_SESSION') => module.configValue(`${key}=${value}\n`, key)
|
|
91
|
+
assert.equal(parse('"p442-node" # tmux session name'), 'p442-node', 'default generated quoted value with trailing comment')
|
|
92
|
+
assert.equal(parse('"p442#node" # hash inside quotes'), 'p442#node', 'quoted # belongs to the value')
|
|
93
|
+
assert.equal(parse("'p442#node'\t# hash inside quotes"), 'p442#node', 'single-quoted # belongs to the value')
|
|
94
|
+
assert.equal(parse('p442-node # tmux session name'), 'p442-node', 'unquoted value loses its whitespace-delimited comment')
|
|
95
|
+
assert.equal(parse('p442#node'), 'p442#node', 'unquoted # without preceding whitespace belongs to the value')
|
|
96
|
+
}
|
|
97
|
+
assertConfigValues(capability)
|
|
98
|
+
pass('config: default comments, quoted hashes and unquoted values parse by behavior')
|
|
99
|
+
|
|
100
|
+
const legacyParser = `export function configValue(text, key) {
|
|
101
|
+
const match = new RegExp(\`^\\\\s*(?:export\\\\s+)?\${key}=(.*)\\\\s*$\`, 'm').exec(text)
|
|
102
|
+
if (!match) return null
|
|
103
|
+
const raw = match[1].trim()
|
|
104
|
+
if ((raw.startsWith("'") && raw.endsWith("'")) || (raw.startsWith('"') && raw.endsWith('"'))) return raw.slice(1, -1)
|
|
105
|
+
return raw
|
|
106
|
+
}`
|
|
107
|
+
const currentParser = readFileSync(join(skill, 'scripts/remind-capability.mjs'), 'utf8').match(/export function configValue\(text, key\) \{[\s\S]*?\n\}/)?.[0]
|
|
108
|
+
assert(currentParser, 'locate the current configValue for the legacy flip')
|
|
109
|
+
const legacyPath = join(root, 'legacy-config.mjs')
|
|
110
|
+
writeFileSync(legacyPath, readFileSync(join(skill, 'scripts/remind-capability.mjs'), 'utf8')
|
|
111
|
+
.replace(currentParser, () => legacyParser)
|
|
112
|
+
.replace("'./reply-capture.mjs'", JSON.stringify(pathToFileURL(join(skill, 'scripts/reply-capture.mjs')).href)))
|
|
113
|
+
const legacy = await import(pathToFileURL(legacyPath).href)
|
|
114
|
+
let legacyFailure
|
|
115
|
+
try { assertConfigValues(legacy) } catch (e) { legacyFailure = e }
|
|
116
|
+
assert.match(legacyFailure?.message ?? '', /default generated quoted value with trailing comment/,
|
|
117
|
+
'restoring the old parser must turn the named default-config assertion red')
|
|
118
|
+
console.log(`EXPECTED RED configValue: ${legacyFailure.message.split('\n')[0]}`)
|
|
119
|
+
pass('flip: restoring old configValue turns the named default-config assertion red')
|
|
120
|
+
|
|
121
|
+
const identity = { root: repo, state, config }
|
|
122
|
+
const capabilityRecord = generation => ({ generation, extensionVersion: 'fixture', status: 'registered', exposure: 'direct' })
|
|
123
|
+
capability.publishRemindCapability(identity, capabilityRecord('before-remove'))
|
|
124
|
+
capability.removeRemindCapability(identity, 'before-remove')
|
|
125
|
+
assert(!existsSync(join(state, 'remind-tool/current.json')), 'matching shutdown removes capability evidence')
|
|
126
|
+
capability.publishRemindCapability(identity, capabilityRecord('after-remove'))
|
|
127
|
+
assert.equal(JSON.parse(readFileSync(join(state, 'remind-tool/current.json'), 'utf8')).generation, 'after-remove',
|
|
128
|
+
'a new session can immediately publish after removal without inheriting a held lock')
|
|
129
|
+
const large = `${'x'.repeat(64 * 1024)}\n`
|
|
130
|
+
const first = await capability.runReminderAuthority({ identity, skill, action: 'add', params: { after: '1h', message: large } })
|
|
131
|
+
const second = await capability.runReminderAuthority({ identity, skill, action: 'add', params: { after: '1h', message: large } })
|
|
132
|
+
assert(first.reminder.id !== second.reminder.id)
|
|
133
|
+
assert.equal(first.reminder.source, 'pm-tool')
|
|
134
|
+
assert.equal(first.reminder.message, large)
|
|
135
|
+
const listed = await capability.runReminderAuthority({ identity, skill, action: 'list', params: {} })
|
|
136
|
+
assert.equal(listed.active.find(item => item.id === first.reminder.id).message, large)
|
|
137
|
+
const shown = await capability.runReminderAuthority({ identity, skill, action: 'show', params: { id: first.reminder.id } })
|
|
138
|
+
assert.equal(shown.reminder.message, large)
|
|
139
|
+
const cancelled = await capability.runReminderAuthority({ identity, skill, action: 'cancel', params: { id: first.reminder.id } })
|
|
140
|
+
assert.equal(cancelled.outcome, 'cancelled')
|
|
141
|
+
pass('authority: full text and capability removal followed immediately by a new registration')
|
|
142
|
+
|
|
143
|
+
const truncating = join(root, 'truncating.mjs')
|
|
144
|
+
const capabilitySource = readFileSync(join(skill, 'scripts/remind-capability.mjs'), 'utf8')
|
|
145
|
+
.replace("'./reply-capture.mjs'", JSON.stringify(pathToFileURL(join(skill, 'scripts/reply-capture.mjs')).href))
|
|
146
|
+
const truncateAnchor = "input = Buffer.from(params.message, 'utf8')"
|
|
147
|
+
assert.equal(capabilitySource.split(truncateAnchor).length, 2)
|
|
148
|
+
writeFileSync(truncating, capabilitySource.replace(truncateAnchor,
|
|
149
|
+
"params = { ...params, message: params.message.slice(0, 65536) };\n input = Buffer.from(params.message, 'utf8')"))
|
|
150
|
+
const badCapability = await import(pathToFileURL(truncating).href)
|
|
151
|
+
const truncated = await badCapability.runReminderAuthority({ identity, skill, action: 'add', params: { after: '1h', message: large } })
|
|
152
|
+
assert.equal(truncated.reminder.message.length, 65536)
|
|
153
|
+
assert(!truncated.reminder.message.endsWith('\n'))
|
|
154
|
+
pass('flip: truncating the tool input loses the final newline and is caught by the full-text assertions')
|
|
155
|
+
|
|
156
|
+
console.log(`remind-tool-node: passed=${passed} failed=0`)
|
|
157
|
+
} finally {
|
|
158
|
+
rmSync(root, { recursive: true, force: true })
|
|
159
|
+
}
|