teamsmith 0.0.0-stage → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +158 -2
  3. package/bin/team.mjs +59 -0
  4. package/install.sh +94 -0
  5. package/package.json +37 -4
  6. package/skills/teamsmith/CHANGELOG.md +763 -0
  7. package/skills/teamsmith/SKILL.md +312 -0
  8. package/skills/teamsmith/extension/team-bg.ts +435 -0
  9. package/skills/teamsmith/extension/team-inbox-watch.ts +1412 -0
  10. package/skills/teamsmith/extension/team-notify.ts +663 -0
  11. package/skills/teamsmith/references/agent-adapters.md +643 -0
  12. package/skills/teamsmith/references/config.md +477 -0
  13. package/skills/teamsmith/references/meeting.md +124 -0
  14. package/skills/teamsmith/references/memory.md +133 -0
  15. package/skills/teamsmith/references/migration.md +227 -0
  16. package/skills/teamsmith/references/openspec.md +222 -0
  17. package/skills/teamsmith/references/philosophy.md +95 -0
  18. package/skills/teamsmith/references/protocol.md +712 -0
  19. package/skills/teamsmith/references/troubleshooting.md +1384 -0
  20. package/skills/teamsmith/references/workflows.md +448 -0
  21. package/skills/teamsmith/scripts/lib/cmd-agents.sh +1709 -0
  22. package/skills/teamsmith/scripts/lib/cmd-bg.sh +284 -0
  23. package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +311 -0
  24. package/skills/teamsmith/scripts/lib/cmd-config.sh +1156 -0
  25. package/skills/teamsmith/scripts/lib/cmd-death.sh +562 -0
  26. package/skills/teamsmith/scripts/lib/cmd-docs.sh +149 -0
  27. package/skills/teamsmith/scripts/lib/cmd-draft.sh +124 -0
  28. package/skills/teamsmith/scripts/lib/cmd-init.sh +212 -0
  29. package/skills/teamsmith/scripts/lib/cmd-meeting.sh +904 -0
  30. package/skills/teamsmith/scripts/lib/cmd-outbox.sh +196 -0
  31. package/skills/teamsmith/scripts/lib/cmd-project.sh +642 -0
  32. package/skills/teamsmith/scripts/lib/cmd-review.sh +1393 -0
  33. package/skills/teamsmith/scripts/lib/cmd-status.sh +1399 -0
  34. package/skills/teamsmith/scripts/lib/cmd-update.sh +191 -0
  35. package/skills/teamsmith/scripts/lib/cmd-watch.sh +1681 -0
  36. package/skills/teamsmith/scripts/lib/common.sh +4964 -0
  37. package/skills/teamsmith/scripts/lib/draft-entry.sh +51 -0
  38. package/skills/teamsmith/scripts/lib/outbox.sh +2042 -0
  39. package/skills/teamsmith/scripts/lib/tmux-argv.sh +165 -0
  40. package/skills/teamsmith/scripts/monitor.mjs +616 -0
  41. package/skills/teamsmith/scripts/panel/README.md +192 -0
  42. package/skills/teamsmith/scripts/panel/build.sh +47 -0
  43. package/skills/teamsmith/scripts/panel/bun.lock +109 -0
  44. package/skills/teamsmith/scripts/panel/draft-send.sh +68 -0
  45. package/skills/teamsmith/scripts/panel/package.json +24 -0
  46. package/skills/teamsmith/scripts/panel/panel.js +388 -0
  47. package/skills/teamsmith/scripts/panel/src/App.tsx +2150 -0
  48. package/skills/teamsmith/scripts/panel/src/clipboard.ts +154 -0
  49. package/skills/teamsmith/scripts/panel/src/compose.ts +691 -0
  50. package/skills/teamsmith/scripts/panel/src/data.ts +555 -0
  51. package/skills/teamsmith/scripts/panel/src/format.ts +50 -0
  52. package/skills/teamsmith/scripts/panel/src/layout.ts +2562 -0
  53. package/skills/teamsmith/scripts/panel/src/main.tsx +894 -0
  54. package/skills/teamsmith/scripts/panel/src/markdown.ts +340 -0
  55. package/skills/teamsmith/scripts/panel/src/sanitize.ts +42 -0
  56. package/skills/teamsmith/scripts/panel/src/settings.ts +154 -0
  57. package/skills/teamsmith/scripts/panel/src/strings/en.ts +416 -0
  58. package/skills/teamsmith/scripts/panel/src/strings/index.ts +65 -0
  59. package/skills/teamsmith/scripts/panel/src/strings/types.ts +9 -0
  60. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +414 -0
  61. package/skills/teamsmith/scripts/panel/src/theme.ts +116 -0
  62. package/skills/teamsmith/scripts/panel/src/types.ts +652 -0
  63. package/skills/teamsmith/scripts/panel/src/width.ts +105 -0
  64. package/skills/teamsmith/scripts/panel/tsconfig.json +16 -0
  65. package/skills/teamsmith/scripts/shim/signal-gate +156 -0
  66. package/skills/teamsmith/scripts/shim/tmux +403 -0
  67. package/skills/teamsmith/scripts/team +143 -0
  68. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +147 -0
  69. package/skills/teamsmith/templates/BOARD.md.tmpl +18 -0
  70. package/skills/teamsmith/templates/DECISIONS.md.tmpl +22 -0
  71. package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +25 -0
  72. package/skills/teamsmith/templates/PROTOCOL.md.tmpl +84 -0
  73. package/skills/teamsmith/templates/ROADMAP.md.tmpl +29 -0
  74. package/skills/teamsmith/templates/config.sh.tmpl +106 -0
  75. package/skills/teamsmith/templates/memory-seed.md.tmpl +46 -0
  76. package/skills/teamsmith/templates/pm-prompt.md.tmpl +110 -0
  77. package/skills/teamsmith/templates/report.md.tmpl +36 -0
  78. package/skills/teamsmith/templates/task.md.tmpl +65 -0
  79. package/skills/teamsmith/templates/threads-README.md +17 -0
  80. package/skills/teamsmith/tests/bg-ledger-harness.mjs +682 -0
  81. package/skills/teamsmith/tests/bg-ledger.sh +307 -0
  82. package/skills/teamsmith/tests/checkout-shape-probe.sh +800 -0
  83. package/skills/teamsmith/tests/config-cli.sh +1562 -0
  84. package/skills/teamsmith/tests/container-tmux.sh +493 -0
  85. package/skills/teamsmith/tests/coverage-inventory.sh +173 -0
  86. package/skills/teamsmith/tests/death-cause.sh +564 -0
  87. package/skills/teamsmith/tests/delivery-truth.sh +1231 -0
  88. package/skills/teamsmith/tests/fake-tui.py +450 -0
  89. package/skills/teamsmith/tests/fixtures/delivery-truth-real/README.md +60 -0
  90. package/skills/teamsmith/tests/fixtures/delivery-truth-real/judge-second.py +139 -0
  91. package/skills/teamsmith/tests/fixtures/delivery-truth-real/mock-server.py +29 -0
  92. package/skills/teamsmith/tests/fixtures/delivery-truth-real/observe.ts +20 -0
  93. package/skills/teamsmith/tests/fixtures/delivery-truth-real/run-case.sh +79 -0
  94. package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +175 -0
  95. package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +229 -0
  96. package/skills/teamsmith/tests/fixtures/p71-incident/README.md +22 -0
  97. package/skills/teamsmith/tests/fixtures/p71-incident/dev2.seen +8 -0
  98. package/skills/teamsmith/tests/fixtures/p71-incident/dev2.wake +9 -0
  99. package/skills/teamsmith/tests/fixtures/p71-incident/pm-nudges.wake +3 -0
  100. package/skills/teamsmith/tests/fixtures/signal-lint-cases.txt +40 -0
  101. package/skills/teamsmith/tests/flip-glue.sh +162 -0
  102. package/skills/teamsmith/tests/flip-m12-26c.sh +129 -0
  103. package/skills/teamsmith/tests/flip-m12.sh +185 -0
  104. package/skills/teamsmith/tests/flip-m16.sh +166 -0
  105. package/skills/teamsmith/tests/flip-m17.sh +204 -0
  106. package/skills/teamsmith/tests/flip-m33.sh +284 -0
  107. package/skills/teamsmith/tests/flip-m34.sh +96 -0
  108. package/skills/teamsmith/tests/flip-m37.sh +185 -0
  109. package/skills/teamsmith/tests/flip-m4.3.sh +375 -0
  110. package/skills/teamsmith/tests/flip-m43.sh +128 -0
  111. package/skills/teamsmith/tests/flip-m44.sh +262 -0
  112. package/skills/teamsmith/tests/flip-m45.sh +244 -0
  113. package/skills/teamsmith/tests/flip-m46.sh +238 -0
  114. package/skills/teamsmith/tests/flip-m48.sh +304 -0
  115. package/skills/teamsmith/tests/flip-m6.2.sh +205 -0
  116. package/skills/teamsmith/tests/flip-m6.3.sh +283 -0
  117. package/skills/teamsmith/tests/flip-m6.4.sh +267 -0
  118. package/skills/teamsmith/tests/flip-m6.5.sh +113 -0
  119. package/skills/teamsmith/tests/flip-m7.1.sh +135 -0
  120. package/skills/teamsmith/tests/flip-m7.2.sh +321 -0
  121. package/skills/teamsmith/tests/flip-p144.sh +112 -0
  122. package/skills/teamsmith/tests/flip-p156.sh +133 -0
  123. package/skills/teamsmith/tests/flip-p158.sh +301 -0
  124. package/skills/teamsmith/tests/flip-p160.sh +182 -0
  125. package/skills/teamsmith/tests/flip-p171.sh +249 -0
  126. package/skills/teamsmith/tests/flip-p18.1.sh +95 -0
  127. package/skills/teamsmith/tests/flip-p20.sh +286 -0
  128. package/skills/teamsmith/tests/flip-p201.sh +249 -0
  129. package/skills/teamsmith/tests/flip-p210.sh +239 -0
  130. package/skills/teamsmith/tests/flip-p211.sh +152 -0
  131. package/skills/teamsmith/tests/flip-p217.sh +288 -0
  132. package/skills/teamsmith/tests/flip-p22.sh +123 -0
  133. package/skills/teamsmith/tests/flip-p23.sh +239 -0
  134. package/skills/teamsmith/tests/flip-p25.sh +165 -0
  135. package/skills/teamsmith/tests/flip-p71.sh +184 -0
  136. package/skills/teamsmith/tests/flip-p72.sh +202 -0
  137. package/skills/teamsmith/tests/frames/README.md +176 -0
  138. package/skills/teamsmith/tests/frames/p78-conversation-rule-below-box.txt +6 -0
  139. package/skills/teamsmith/tests/frames/p78-cursor-mid-draft.txt +6 -0
  140. package/skills/teamsmith/tests/frames/p78-draft-rule-below-cursor-line.txt +6 -0
  141. package/skills/teamsmith/tests/frames/p78-draft-rule-below-cursor.txt +6 -0
  142. package/skills/teamsmith/tests/frames/p78-draft-rule-blank-region.txt +6 -0
  143. package/skills/teamsmith/tests/frames/p78-draft-rule-only.txt +5 -0
  144. package/skills/teamsmith/tests/frames/p78-spinner-row-below-cursor.txt +6 -0
  145. package/skills/teamsmith/tests/frames/p78-wider-rule-below-cursor.txt +6 -0
  146. package/skills/teamsmith/tests/frames/p86-f1-mixed-width-disjoint-box.txt +8 -0
  147. package/skills/teamsmith/tests/frames/p86-f1-narrower-width-disjoint-box.txt +8 -0
  148. package/skills/teamsmith/tests/frames/p86-f1-spinner-top-disjoint-box.txt +8 -0
  149. package/skills/teamsmith/tests/frames/pi-0.85.1-update-banner.txt +30 -0
  150. package/skills/teamsmith/tests/frames/pi-0.87.0-draft-half-sentence.txt +30 -0
  151. package/skills/teamsmith/tests/frames/pi-0.87.0-empty-box.txt +30 -0
  152. package/skills/teamsmith/tests/frames/pi-0.87.0-one-line-draft.txt +30 -0
  153. package/skills/teamsmith/tests/frames/pi-0.87.0-project-trust-prompt.txt +30 -0
  154. package/skills/teamsmith/tests/frames/pi-0.99.2-empty-editor.txt +32 -0
  155. package/skills/teamsmith/tests/frames/pi-0.99.2-human-draft.txt +32 -0
  156. package/skills/teamsmith/tests/frames/pi-1.0.0-git-error-in-box.txt +32 -0
  157. package/skills/teamsmith/tests/gate-guard.sh +112 -0
  158. package/skills/teamsmith/tests/guard-matrix.sh +233 -0
  159. package/skills/teamsmith/tests/install-shape.sh +731 -0
  160. package/skills/teamsmith/tests/ledger-ban.sh +612 -0
  161. package/skills/teamsmith/tests/lib/box-judge.sh +68 -0
  162. package/skills/teamsmith/tests/lib/checkout-shape.sh +129 -0
  163. package/skills/teamsmith/tests/lib/loop-scan.awk +114 -0
  164. package/skills/teamsmith/tests/lib/pty-wait.sh +676 -0
  165. package/skills/teamsmith/tests/lib/section-guard.sh +855 -0
  166. package/skills/teamsmith/tests/lib/shell-lex.pl +261 -0
  167. package/skills/teamsmith/tests/lib/tmp-root.sh +528 -0
  168. package/skills/teamsmith/tests/lib/tmux-cap.sh +35 -0
  169. package/skills/teamsmith/tests/lib/tmux-iso-call-probe.sh +81 -0
  170. package/skills/teamsmith/tests/lib/tmux-iso-probe.sh +46 -0
  171. package/skills/teamsmith/tests/lib/tmux-iso.sh +381 -0
  172. package/skills/teamsmith/tests/load-experiment.sh +290 -0
  173. package/skills/teamsmith/tests/loop-inventory.tsv +84 -0
  174. package/skills/teamsmith/tests/panel-b2-slow-stub.sh +19 -0
  175. package/skills/teamsmith/tests/panel-b2.sh +1183 -0
  176. package/skills/teamsmith/tests/panel-b3-pty-mouse.py +240 -0
  177. package/skills/teamsmith/tests/panel-b3-pty-tmux-mouse.py +138 -0
  178. package/skills/teamsmith/tests/panel-b3-stub.sh +279 -0
  179. package/skills/teamsmith/tests/panel-b3.sh +1301 -0
  180. package/skills/teamsmith/tests/panel-choices.sh +572 -0
  181. package/skills/teamsmith/tests/panel-clipboard-model.ts +187 -0
  182. package/skills/teamsmith/tests/panel-compose-model.ts +290 -0
  183. package/skills/teamsmith/tests/panel-contrast.mjs +81 -0
  184. package/skills/teamsmith/tests/panel-cpu-premise.sh +173 -0
  185. package/skills/teamsmith/tests/panel-cpu.sh +391 -0
  186. package/skills/teamsmith/tests/panel-flip-m54.sh +207 -0
  187. package/skills/teamsmith/tests/panel-flip-p123.sh +278 -0
  188. package/skills/teamsmith/tests/panel-flip-p125.sh +318 -0
  189. package/skills/teamsmith/tests/panel-flip-p128.sh +259 -0
  190. package/skills/teamsmith/tests/panel-keyprobe-pty.py +99 -0
  191. package/skills/teamsmith/tests/panel-keyprobe-stub.sh +41 -0
  192. package/skills/teamsmith/tests/panel-keyprobe.sh +82 -0
  193. package/skills/teamsmith/tests/panel-keyprobe.tsx +116 -0
  194. package/skills/teamsmith/tests/panel-knobs.sh +83 -0
  195. package/skills/teamsmith/tests/panel-p21.sh +2181 -0
  196. package/skills/teamsmith/tests/panel-snapshots.sh +802 -0
  197. package/skills/teamsmith/tests/panel-strings.mjs +195 -0
  198. package/skills/teamsmith/tests/perf.sh +740 -0
  199. package/skills/teamsmith/tests/pm-box-real.sh +350 -0
  200. package/skills/teamsmith/tests/pulse-nudge-key.sh +563 -0
  201. package/skills/teamsmith/tests/routes.sh +1652 -0
  202. package/skills/teamsmith/tests/section-budgets.tsv +150 -0
  203. package/skills/teamsmith/tests/section-guard.sh +231 -0
  204. package/skills/teamsmith/tests/section-needs-audit.sh +94 -0
  205. package/skills/teamsmith/tests/section-paths.tsv +142 -0
  206. package/skills/teamsmith/tests/section-select.sh +655 -0
  207. package/skills/teamsmith/tests/signal-gate.sh +366 -0
  208. package/skills/teamsmith/tests/signal-lint-legacy.txt +14 -0
  209. package/skills/teamsmith/tests/signal-lint.pl +416 -0
  210. package/skills/teamsmith/tests/skill-load.mjs +65 -0
  211. package/skills/teamsmith/tests/smoke.sh +19711 -0
  212. package/skills/teamsmith/tests/snapshots/zh-dark-120-detail.txt +32 -0
  213. package/skills/teamsmith/tests/snapshots/zh-dark-120-p4.txt +32 -0
  214. package/skills/teamsmith/tests/snapshots/zh-dark-120.txt +32 -0
  215. package/skills/teamsmith/tests/snapshots/zh-dark-160-p4.txt +32 -0
  216. package/skills/teamsmith/tests/snapshots/zh-dark-160.txt +32 -0
  217. package/skills/teamsmith/tests/snapshots/zh-dark-59-detail.txt +32 -0
  218. package/skills/teamsmith/tests/snapshots/zh-dark-59-p4.txt +32 -0
  219. package/skills/teamsmith/tests/snapshots/zh-dark-59.txt +32 -0
  220. package/skills/teamsmith/tests/snapshots/zh-dark-99-p4.txt +32 -0
  221. package/skills/teamsmith/tests/snapshots/zh-dark-99.txt +32 -0
  222. package/skills/teamsmith/tests/snapshots/zh-light-120-detail.txt +32 -0
  223. package/skills/teamsmith/tests/snapshots/zh-light-120-p4.txt +32 -0
  224. package/skills/teamsmith/tests/snapshots/zh-light-120.txt +32 -0
  225. package/skills/teamsmith/tests/snapshots/zh-light-160-p4.txt +32 -0
  226. package/skills/teamsmith/tests/snapshots/zh-light-160.txt +32 -0
  227. package/skills/teamsmith/tests/snapshots/zh-light-59-detail.txt +32 -0
  228. package/skills/teamsmith/tests/snapshots/zh-light-59-p4.txt +32 -0
  229. package/skills/teamsmith/tests/snapshots/zh-light-59.txt +32 -0
  230. package/skills/teamsmith/tests/snapshots/zh-light-99-p4.txt +32 -0
  231. package/skills/teamsmith/tests/snapshots/zh-light-99.txt +32 -0
  232. package/skills/teamsmith/tests/spec-ledger-refs.tsv +78 -0
  233. package/skills/teamsmith/tests/spec-refs.sh +826 -0
  234. package/skills/teamsmith/tests/task-header-model.sh +267 -0
  235. package/skills/teamsmith/tests/team-bg-flip.sh +239 -0
  236. package/skills/teamsmith/tests/team-bg-harness.mjs +392 -0
  237. package/skills/teamsmith/tests/team-bg-stop.sh +434 -0
  238. package/skills/teamsmith/tests/team-inbox-watch-flip.sh +191 -0
  239. package/skills/teamsmith/tests/team-inbox-watch-harness.mjs +1559 -0
  240. package/skills/teamsmith/tests/tmp-hygiene.sh +1190 -0
  241. package/skills/teamsmith/tests/tmux-lint-legacy.txt +31 -0
  242. package/skills/teamsmith/tests/tmux-lint.pl +604 -0
  243. package/skills/teamsmith-init/SKILL.md +100 -0
  244. package/skills/teamsmith-init/references/bootstrap.md +74 -0
  245. package/skills/teamsmith-init/templates/bootstrap-prompt.md.tmpl +46 -0
@@ -0,0 +1,1301 @@
1
+ #!/usr/bin/env bash
2
+ # Console-surface fixtures (pulse-console B3, P14): the pty/tmux proofs for tasks.md items
3
+ # 4.1 pages/panel-page, 4.3 the queue list and full view, 5.1 settings/panel.conf, 5.2 resize,
4
+ # 6.2 language switch, 6.3 SGR mouse (direct pty + the tmux chain), 7.1 the q collapse.
5
+ #
6
+ # bash skills/teamsmith/tests/panel-b3.sh # every scenario
7
+ # bash skills/teamsmith/tests/panel-b3.sh pages settings # selected scenarios
8
+ # TEAM_B3_KEEP=1 bash skills/teamsmith/tests/panel-b3.sh # keep the fixture directory
9
+ #
10
+ # Every scenario runs in a private tmux server (`-L p14b3-$$`) and a fresh fixture project; the
11
+ # data path is the deterministic `panel-b3-stub.sh`, so assertions never depend on this repo.
12
+ # Exit: 0 every selected scenario green, 1 at least one assertion failed, 3 setup failure.
13
+ #
14
+ # Fixture knob (only under TEAM_SMOKE_FIXTURE=1; otherwise printed as ignored):
15
+ # TEAM_B3_SLOW_JS=<可执行的 JS runner> 控制台首帧真的晚到(P68 的 recipe B):它是通过产品自己的
16
+ # `TEAM_JS_BIN` 缝生效的(`team pulse up` → `team monitor` → `team_js_runner` → exec runner)。
17
+ # collapse 场景是首帧晚到的作用域,所以不用 TEAM_B3_PANEL:那条路只影响夹具自己 start_panel 起的
18
+ # 面板,而 collapse 跑的是产品自己的 `team pulse up`(读 skill 树里的 bundle)。runner 应该在
19
+ # `--version` 上直通(`team_require_js_runtime` 的探测不该被拖慢),只在真正启动面板的调用上延迟。
20
+ set -uo pipefail
21
+
22
+ # ── identity isolation (must be first): never inherit the caller's team identity ────────────────
23
+ _slow_js_arg="${TEAM_B3_SLOW_JS:-}"
24
+ _smoke_fixture_arg="${TEAM_SMOKE_FIXTURE:-0}"
25
+ unset TEAM_ROOT TEAM_MAIN_ROOT TEAM_ROOT_SOURCE TEAM_ROOT_WAS TEAM_PROJECT TEAM_SESSION TEAM_SESSION_FROM \
26
+ TEAM_PM_WINDOW TEAM_AGENTS TEAM_DOCS_DIR TEAM_WORKTREES_DIR TEAM_GATES TEAM_VCS TEAM_CONFIG_FILE \
27
+ TEAM_ALLOW_FOREIGN_SESSION TEAM_PULSE_WINDOW TEAM_WATCH_WINDOW TEAM_STATE_DIR TEAM_JS_BIN \
28
+ TEAM_MONITOR_REFRESH TEAM_MONITOR_UI TEAM_MONITOR_ACTIVITY TEAM_AGENT_LOG_GLOB TEAM_PULSE_INTERVAL \
29
+ TEAM_WATCH_INTERVAL 2>/dev/null || true
30
+ # P68 注入缝(仅夹具模式 + 可执行):把产品自己的 TEAM_JS_BIN 指向慢启动的 runner。
31
+ if [ -n "$_slow_js_arg" ]; then
32
+ if [ "$_smoke_fixture_arg" = "1" ] && [ -x "$_slow_js_arg" ]; then
33
+ export TEAM_JS_BIN="$_slow_js_arg"
34
+ else
35
+ printf 'panel-b3: 忽略 TEAM_B3_SLOW_JS=%s(只有 TEAM_SMOKE_FIXTURE=1 且指向可执行文件时才生效)\n' \
36
+ "$_slow_js_arg" >&2
37
+ fi
38
+ fi
39
+
40
+ here="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
41
+ # P53:临时根的唯一创建者(${TMPDIR:-/tmp} + owned 家族 + 回收)
42
+ . "$here/lib/tmp-root.sh"
43
+ # P162:破坏性调用(kill-server/kill-session/kill-window)动手前先证明私有 socket 生效
44
+ . "$here/lib/tmux-iso.sh"
45
+ # P68/fixture-waits-for-landed-reads:控制台自己的状态(首帧标题、日志、capacity.log 行数)也要等数据态,
46
+ # 不再是固定 sleep + 单次采样。复用 P48 的等待引擎(settled frame / 轮数 / 上界 / 归因),不另造一套。
47
+ . "$here/lib/pty-wait.sh"
48
+ tree="${TEAM_B3_TREE:-$(cd -P "$here/../../.." && pwd)}"
49
+ skill="$tree/skills/teamsmith"
50
+ panel="${TEAM_B3_PANEL:-$skill/scripts/panel/panel.js}"
51
+ stub="$here/panel-b3-stub.sh"
52
+ pty_direct="$here/panel-b3-pty-mouse.py"
53
+ pty_tmux="$here/panel-b3-pty-tmux-mouse.py"
54
+
55
+ js="${TEAM_B3_JS:-$(command -v node || true)}"
56
+ [ -n "$js" ] || js="$(command -v bun || true)"
57
+ sock="p14b3-$$"
58
+ sess="p14b3-$$"
59
+ keep="${TEAM_B3_KEEP:-0}"
60
+ [ "$keep" = "1" ] && export TEAM_TMP_KEEP=1
61
+ tmp="$(tmp_root_create panel-b3)" || exit 3
62
+ PASS=0
63
+ FAIL=0
64
+ ROOT=""
65
+ current=""
66
+
67
+ cleanup() {
68
+ [ "${BASHPID:-$$}" = "$$" ] || return 0
69
+ # P162:收尾先证明私有 socket 生效(不成立就拒绝;cleanup 里不许 exit)
70
+ tmux_iso_guard_soft "panel-b3" "收尾:私有 server" --tmpdir "${TMUX_TMPDIR:-}" --sock-name "$sock" \
71
+ && tmux -L "$sock" kill-server 2>/dev/null || true
72
+ rm -f "${TMUX_TMPDIR:-/tmp}/tmux-$(id -u)/$sock" 2>/dev/null || true
73
+ if [ "$keep" = "1" ]; then
74
+ printf '\n保留夹具目录:%s\n' "$tmp"
75
+ else
76
+ tmp_root_reap_all
77
+ fi
78
+ }
79
+ trap cleanup EXIT
80
+
81
+ section() { printf '\n\033[1m== %s ==\033[0m\n' "$1"; }
82
+ ok() { printf ' \033[32m✓\033[0m %s\n' "$1"; PASS=$((PASS + 1)); }
83
+ bad() { printf ' \033[31m✗\033[0m %s\n' "$1"; FAIL=$((FAIL + 1)); }
84
+ assert_eq() { [ "$2" = "$3" ] && ok "$1" || bad "$1(期望 [$3],实际 [$2])"; }
85
+ assert_has() { grep -qF -- "$2" "$1" 2>/dev/null && ok "$3" || bad "$3($1 里找不到 [$2])"; }
86
+ assert_not() { grep -qF -- "$2" "$1" 2>/dev/null && bad "$3(不该出现 [$2])" || ok "$3"; }
87
+ assert_match() { grep -qE -- "$2" "$1" 2>/dev/null && ok "$3" || bad "$3($1 里没有匹配 [$2])"; }
88
+ cond_skip() { printf ' \033[33mSKIP(条件不满足)\033[0m %s\n' "$1${2:+ —— $2}"; }
89
+
90
+ # ---------------------------------------------------------------- P68 数据态等待
91
+ # fixture-waits-for-landed-reads:控制台自己的状态(首帧标题、工具写的日志、capacity.log 的行数)在断言
92
+ # 之前先观察到,不再用固定 sleep + 单次采样。每一条都守 pty-wait.sh 的纪律:计数轮 + 上界 + 耗尽时一行
93
+ # 归因(等待名 / 轮数 / 最后读数)。上界是失败探测器,不是性能阈值(D33):慢但落在界内的写入必须绿。
94
+ # 实测带(P52 F2):收紧前的 5s/6s 固定窗口在负载主机上 6 次红 4 次;安静机上首帧 <1s、
95
+ # pulse up 的日志在窗口起来后 <1s 内写完、capacity.log 的周期配置成 2s —— 下面的上界都是这个带的 4-7 倍。
96
+ b3_cap_pane="panel" # 稳定帧等待捕哪个窗口;collapse 场景在自己的作用域里把它指到 pulse
97
+ pty_cap() { tmux -L "$sock" capture-pane -p -t "$sess:${b3_cap_pane:-panel}" -S -400 2>/dev/null; }
98
+ pty_keys() { keys "$@"; }
99
+ pty_pane_state() { tmux -L "$sock" list-panes -t "$sess:${b3_cap_pane:-panel}" -F '#{pane_dead}:#{pane_dead_status}' 2>/dev/null | head -1; }
100
+
101
+ # 等控制台自己的标题(`teamsmith pulse`)在稳定帧上。上界 75 轮基础视界(轮询 0.4s + 稳定确认 0.25s;
102
+ # 实测每轮 ~0.43s → 约 32s,静态场景不延长)。带宽与推导:安静机上首帧 <1s;旧形状的固定窗口是 5s,
103
+ # P52 F2 在负载主机上 6 次红 4 次(首帧落在 5s 之后);确定性的注入(JS runner 晚 8s)实测标题在第
104
+ # 43-44 轮(~19s)落地(runner 在路径上付了两次:monitor 的 spawn + activity 读的 monitor.mjs),75 轮
105
+ # ≈ 1.7× 实测慢端。rc:0 绿 / 1 红(M59 现场)/ 3 可见 SKIP(场景仍在绘制,机器维度)。
106
+ # 夹具旋钮:B3_CONSOLE_ITERS 覆盖上界(只在测带宽时用;默认 75)。
107
+ wait_console() { # <outfile> <label>
108
+ B3_FRAME_ITERS="${B3_CONSOLE_ITERS:-75}" wait_frame "$1" "$2" 'teamsmith pulse'
109
+ }
110
+
111
+ # 把 pty-wait 的 rc 翻成夹具的断言:0 → ✓;3 → 可见 SKIP(机器,不算通过也不算失败,D33);其它 → ✗。
112
+ b3_wait_verdict() { # <rc> <ok text> <bad text>
113
+ case "$1" in
114
+ 0) ok "$2" ;;
115
+ 3) cond_skip "$2" "机器读数超前提(等待耗尽但场景仍在绘制,D33 的可见 SKIP)" ;;
116
+ *) bad "$3" ;;
117
+ esac
118
+ }
119
+
120
+ # 等面板帧满足 needle... 后把捕获写到 <outfile>(needle 以 `!` 开头表示必须缺席)。
121
+ wait_frame() { # <outfile> <label> <needle...>
122
+ local _out="$1" _label="$2"; shift 2
123
+ local PTY_WAIT_ITERS="${B3_FRAME_ITERS:-30}" PTY_WAIT_PAUSE=0.4 PTY_SETTLE_PAUSE=0.25
124
+ pty_wait_frame "$_out" "$_label" "$@"
125
+ }
126
+
127
+ # P68:固定 sleep + 单次 cap_has/cap_not 的替代(稳定帧上等到 needle 再断言;耗尽按 D33 分派)。
128
+ wait_cap_has() { # <file name> <needle> <message>
129
+ local f="$tmp/$current/$1" needle="$2" msg="$3"
130
+ if wait_frame "$f" "$msg" "$needle"; then
131
+ assert_has "$f" "$needle" "$msg"
132
+ else
133
+ b3_wait_verdict $? "$msg" "$msg(稳定帧里没等到 [$needle])"
134
+ fi
135
+ }
136
+ wait_cap_not() { # <file name> <needle> <message>
137
+ local f="$tmp/$current/$1" needle="$2" msg="$3"
138
+ if wait_frame "$f" "$msg" "!$needle"; then
139
+ assert_not "$f" "$needle" "$msg"
140
+ else
141
+ b3_wait_verdict $? "$msg" "$msg(稳定帧里 [$needle] 一直没消失)"
142
+ fi
143
+ }
144
+
145
+ # 等一个由工具自己写的文件里出现 <needle>(例如 `pulse up` 的日志点名窗口):20 轮 × 0.5s = 10s。
146
+ wait_file_has() { # <file> <needle> <label>
147
+ local file="$1" needle="$2" label="$3" i=1
148
+ while [ "$i" -le "${B3_FILE_ITERS:-20}" ]; do
149
+ grep -qF -- "$needle" "$file" 2>/dev/null && return 0
150
+ sleep 0.5
151
+ i=$((i + 1))
152
+ done
153
+ printf ' \033[33m·\033[0m 等待超时:%s(%s 轮/%s;%s 里缺 [%s],最后两行:%s)\n' \
154
+ "$label" "$((i - 1))" "${B3_FILE_ITERS:-20}" "$file" "$needle" \
155
+ "$(tail -2 "$file" 2>/dev/null | tr '\n' ';')" >&2
156
+ return 1
157
+ }
158
+
159
+ # 等窗格里的进程参数命中 <needle>(q 收起后窗口里应换成 --headless 巡检循环):30 轮 × 0.5s = 15s。
160
+ wait_pane_args() { # <pane> <needle> <label>
161
+ local pane="$1" needle="$2" label="$3" i=1 pid args
162
+ while [ "$i" -le "${B3_ARGS_ITERS:-30}" ]; do
163
+ pid="$(tmux -L "$sock" list-panes -t "$sess:$pane" -F '#{pane_pid}' 2>/dev/null | head -1)"
164
+ args="$(ps -o args= -p "${pid:-0}" 2>/dev/null || true)"
165
+ if [ -n "$args" ] && printf '%s' "$args" | grep -qF -- "$needle"; then return 0; fi
166
+ sleep 0.5
167
+ i=$((i + 1))
168
+ done
169
+ printf ' \033[33m·\033[0m 等待超时:%s(%s 轮/%s;窗格进程参数里缺 [%s],最后读到 [%s])\n' \
170
+ "$label" "$((i - 1))" "${B3_ARGS_ITERS:-30}" "$needle" "${args:-(无)}" >&2
171
+ return 1
172
+ }
173
+
174
+ # 等 capacity.log 的行数真的长过 <floor>(巡检还在跑的正证据):30 轮 × 0.5s = 15s;成功时打印行数。
175
+ wait_capacity_growth() { # <file> <floor> <label>
176
+ local file="$1" floor="$2" label="$3" i=1 c=0
177
+ while [ "$i" -le "${B3_CAP_ITERS:-30}" ]; do
178
+ c="$(grep -c . "$file" 2>/dev/null || echo 0)"
179
+ if [ "${c:-0}" -gt "$floor" ]; then printf '%s\n' "$c"; return 0; fi
180
+ sleep 0.5
181
+ i=$((i + 1))
182
+ done
183
+ printf ' \033[33m·\033[0m 等待超时:%s(%s 轮/%s;%s 的行数停在 %s,没长过 %s)\n' \
184
+ "$label" "$((i - 1))" "${B3_CAP_ITERS:-30}" "$file" "${c:-?}" "$floor" >&2
185
+ return 1
186
+ }
187
+
188
+ if ! command -v tmux >/dev/null 2>&1; then
189
+ printf 'panel-b3: tmux is required (the fixtures drive real panes)\n' >&2
190
+ exit 3
191
+ fi
192
+ if ! command -v python3 >/dev/null 2>&1; then
193
+ printf 'panel-b3: python3 is required (the pty drivers)\n' >&2
194
+ exit 3
195
+ fi
196
+ if [ -z "$js" ]; then
197
+ printf 'panel-b3: no node/bun runtime for the console bundle\n' >&2
198
+ exit 3
199
+ fi
200
+ [ -f "$panel" ] || { printf 'panel-b3: no bundle at %s\n' "$panel" >&2; exit 3; }
201
+ [ -f "$stub" ] || { printf 'panel-b3: no stub at %s\n' "$stub" >&2; exit 3; }
202
+
203
+ # ---------------------------------------------------------------- fixture plumbing
204
+ server_up() { # <name> → fresh project + private tmux session
205
+ current="$1"
206
+ ROOT="$tmp/$1/root"
207
+ mkdir -p "$ROOT"
208
+ ( cd "$ROOT" && git init -q -b main && git config user.email b3@teamsmith && git config user.name b3 \
209
+ && echo "# $1" > README.md && git add -A && git commit -qm init ) >/dev/null 2>&1
210
+ mkdir -p "$ROOT/docs/team" "$ROOT/.pi/team/state"
211
+ # P162:重启前的 kill-server 也要先证明私有 socket 生效(不成立 → 硬停,绝不静默回退)
212
+ tmux_iso_require "panel-b3" "重起私有 server 前的 kill-server" --tmpdir "${TMUX_TMPDIR:-}" --sock-name "$sock"
213
+ tmux -L "$sock" kill-server 2>/dev/null || true
214
+ rm -f "${TMUX_TMPDIR:-/tmp}/tmux-$(id -u)/$sock" 2>/dev/null || true
215
+ ( cd "$ROOT" && bash "$skill/scripts/team" init --session "$sess" --agents "dev verify" --vcs local \
216
+ --gates "true" --docs docs/team ) >"$tmp/$1/init.log" 2>&1 \
217
+ || { printf 'panel-b3: team init failed\n' >&2; tail -3 "$tmp/$1/init.log" >&2; exit 3; }
218
+ mkdir -p "$ROOT/.pi/team/state" "$ROOT/docs/team"
219
+ tmux -L "$sock" new-session -d -s "$sess" -x 120 -y 32 -n bootstrap -c "$ROOT" 'sleep 900'
220
+ tmux -L "$sock" set -g window-size manual 2>/dev/null || true
221
+ state="$ROOT/.pi/team/state"
222
+ }
223
+
224
+ start_panel() { # [extra env assignments] [panel args...]
225
+ local extra="${1:-}"
226
+ [ $# -gt 0 ] && shift
227
+ tmux -L "$sock" kill-window -t "$sess:panel" 2>/dev/null || true
228
+ tmux -L "$sock" new-window -d -t "$sess" -n panel -c "$ROOT" \
229
+ "TEAM_JS_BIN=$(printf '%q' "$js") $extra exec '$js' '$panel' --root '$ROOT' --state-dir '$state' \
230
+ --team-cli '$stub' --no-pulse --interval 1 ${*:-}"
231
+ wait_panel
232
+ }
233
+
234
+ wait_panel() {
235
+ local i
236
+ for i in $(seq 1 60); do
237
+ if tmux -L "$sock" capture-pane -p -t "$sess:panel" 2>/dev/null | grep -qF 'teamsmith pulse'; then
238
+ sleep 0.4
239
+ return 0
240
+ fi
241
+ sleep 0.25
242
+ done
243
+ printf 'panel-b3: the console pane never rendered (%s)\n' "$current" >&2
244
+ tmux -L "$sock" capture-pane -p -t "$sess:panel" 2>/dev/null | tail -5 >&2
245
+ return 1
246
+ }
247
+
248
+ cap() { tmux -L "$sock" capture-pane -p -t "$sess:panel" -S -400 2>/dev/null; }
249
+ cap_to() { cap > "$tmp/$current/${1:-cap}.txt"; }
250
+ cap_has() { local f="$tmp/$current/${2:-cap}.txt"; cap >"$f"; assert_has "$f" "$1" "捕获里有 [$1]"; }
251
+ cap_not() { local f="$tmp/$current/${2:-cap}.txt"; cap >"$f"; assert_not "$f" "$1" "捕获里没有 [$1]"; }
252
+ keys() { tmux -L "$sock" send-keys -t "$sess:panel" "$@" 2>/dev/null; }
253
+ conf() { printf '%s/panel.conf' "$state"; }
254
+ page_file() { printf '%s/panel-page' "$state"; }
255
+ conf_set() { mkdir -p "$state"; printf '%s\n' "$@" > "$(conf)"; }
256
+ page_of() { cat "$(page_file)" 2>/dev/null | tr -d '\n'; }
257
+ conf_of() { cat "$(conf)" 2>/dev/null || true; }
258
+ hash_state() { ( cd "$ROOT" && find .pi/team/state -type f | sort | while IFS= read -r f; do printf '%s ' "$f"; md5sum "$f" | cut -d' ' -f1; done ) | md5sum; }
259
+
260
+
261
+ # The action kinds present in a `--snapshot --targets` dump (comma-separated, sorted).
262
+ kinds_of() { # <file>
263
+ python3 - "$1" <<'PYT'
264
+ import json, sys
265
+
266
+ try:
267
+ data = json.load(open(sys.argv[1]))
268
+ except Exception as e:
269
+ print(f"<unreadable: {e}>")
270
+ else:
271
+ print(",".join(sorted({t["action"]["kind"] for t in data})))
272
+ PYT
273
+ }
274
+
275
+ # Which card id sits under the focus cursor (the board page's `›`), or `-` when there is none.
276
+ focused_id() { # <capture file>
277
+ python3 - "$1" <<'PYF'
278
+ import re, sys
279
+
280
+ rows = [re.sub(r"\x1b\[[0-9;]*m", "", l.rstrip("\n")) for l in open(sys.argv[1], encoding="utf-8")]
281
+ ids = []
282
+ for r in rows:
283
+ if "›" not in r:
284
+ continue
285
+ hit = re.search(r"›[^A-Za-z0-9]*([A-Za-z]+[0-9][0-9-]*)", r)
286
+ if hit:
287
+ ids.append(hit.group(1))
288
+ print(ids[0] if len(ids) == 1 else (",".join(ids) if ids else "-"))
289
+ PYF
290
+ }
291
+ # The whole row that carries the focus cursor: two rows may share an id (M48), so the title — not
292
+ # the id — is what tells the focused one apart. One cursor glyph must mean exactly one row; two
293
+ # cursors is a defect of its own, so the file never contains a row text in that case (a substring
294
+ # assertion must not be able to pass on two lit rows).
295
+ focused_row() { # <capture file>
296
+ python3 - "$1" <<'PYR'
297
+ import re, sys
298
+
299
+ rows = [re.sub(r"\x1b\[[0-9;]*m", "", l.rstrip("\n")) for l in open(sys.argv[1], encoding="utf-8")]
300
+ hits = [r.strip() for r in rows if "›" in r]
301
+ if len(hits) == 1:
302
+ print(hits[0])
303
+ elif hits:
304
+ print(f"AMBIGUOUS-CURSOR:{len(hits)}")
305
+ else:
306
+ print("-")
307
+ PYR
308
+ }
309
+ # The ids visible in the lane whose column contains <col> (1-based display column).
310
+ lane_ids() { # <capture file> <col>
311
+ python3 - "$1" "$2" <<'PYL'
312
+ import re, sys
313
+
314
+ WIDE = [(0x1100,0x115f),(0x2e80,0x303e),(0x3041,0x33ff),(0x3400,0x4dbf),(0x4e00,0x9fff),(0xa000,0xa4cf),(0xac00,0xd7a3),(0xf900,0xfaff),(0xfe10,0xfe19),(0xfe30,0xfe6f),(0xff00,0xff60),(0xffe0,0xffe6)]
315
+
316
+ def cells(text):
317
+ out = []
318
+ for ch in text:
319
+ out.append(ch)
320
+ if any(a <= ord(ch) <= b for a, b in WIDE):
321
+ out.append("")
322
+ return out
323
+
324
+ rows = [re.sub(r"\x1b\[[0-9;]*m", "", l.rstrip("\n")) for l in open(sys.argv[1], encoding="utf-8")]
325
+ col = int(sys.argv[2])
326
+ ids = []
327
+ for r in rows:
328
+ c = cells(r)
329
+ win = "".join(c[col - 1 : col + 20]) if col - 1 < len(c) else ""
330
+ hit = re.search(r"([A-Za-z]+[0-9][0-9-]*)", win)
331
+ if hit:
332
+ ids.append(hit.group(1))
333
+ print(",".join(ids))
334
+ PYL
335
+ }
336
+
337
+ # ---------------------------------------------------------------- scenarios
338
+
339
+ scn_pages() {
340
+ section "pages · 三页 + panel-page 记忆(4.1)"
341
+ server_up pages
342
+ start_panel
343
+ cap_has "项目进度" p1.txt
344
+ cap_has "代理" p1.txt
345
+ keys 2
346
+ wait_cap_has p2.txt "任务看板" "捕获里有 [任务看板]"
347
+ wait_cap_has p2.txt "活动变更" "捕获里有 [活动变更]"
348
+ assert_eq "按 2 后 panel-page=2" "$(page_of)" "2"
349
+ # The compose line opens from every page (B2's requirement, kept by the console).
350
+ keys m
351
+ wait_cap_has p2-compose.txt "Enter 发送" "捕获里有 [Enter 发送]"
352
+ keys Escape
353
+ sleep 0.3
354
+ keys 3
355
+ wait_cap_has p3.txt "延后队列" "捕获里有 [延后队列]"
356
+ # P20/B6 改名:消息页说「往来」,不再说「线程」(目录/命令/英文 term 不变)。
357
+ wait_cap_has p3-inbox "收件箱与往来" "捕获里有 [收件箱与往来]"
358
+ if wait_frame "$tmp/$current/p3-inbox.txt" "消息页计数行(往来,无线程)" '收件箱' '往来' '!线程'; then
359
+ assert_not "$tmp/$current/p3-inbox.txt" "线程" "捕获里没有 [线程]"
360
+ assert_match "$tmp/$current/p3-inbox.txt" '收件箱 [0-9]+ 条 · 往来 [0-9]+ 条' "消息页计数行用「往来」"
361
+ else
362
+ b3_wait_verdict $? "捕获里没有 [线程]" "消息页计数行没有在预算内落定"
363
+ fi
364
+ assert_eq "按 3 后 panel-page=3" "$(page_of)" "3"
365
+ keys m
366
+ wait_cap_has p3-compose.txt "Enter 发送" "捕获里有 [Enter 发送]"
367
+ keys Escape
368
+ sleep 0.3
369
+ # Relaunch: the page is restored (no key sent).
370
+ start_panel
371
+ cap_has "延后队列" p3-relaunch.txt
372
+ assert_eq "重启后打开上次的页(panel-page=3)" "$(page_of)" "3"
373
+ keys 1
374
+ wait_cap_has p1-again.txt "项目进度" "捕获里有 [项目进度]"
375
+ assert_eq "按 1 回总览" "$(page_of)" "1"
376
+ }
377
+
378
+ scn_settings() {
379
+ section "settings · 设置浮层 + panel.conf(5.1/6.2)"
380
+ server_up settings
381
+ conf_set "lang=zh" "page=1" "activity=1" "mouse=1" "density=comfortable" "theme=auto"
382
+ start_panel
383
+ keys ,
384
+ wait_cap_has overlay.txt "设置" "捕获里有 [设置]"
385
+ # The selected row is language: Enter switches zh -> en and it applies on the next frame.
386
+ keys Enter
387
+ wait_cap_has lang-en.txt "language" "捕获里有 [language]"
388
+ wait_file_has "$(conf)" "lang=en" "语言切换写进 panel.conf" || bad "语言偏好没有在预算内落盘"
389
+ assert_has "$(conf)" "lang=en" "切换语言写进 panel.conf"
390
+ # Down three rows to the mouse preference and toggle it off.
391
+ keys Down Down Down
392
+ sleep 0.3
393
+ keys Enter
394
+ wait_file_has "$(conf)" "mouse=0" "鼠标开关写进 panel.conf" || bad "鼠标偏好没有在预算内落盘"
395
+ assert_has "$(conf)" "mouse=0" "鼠标开关写进 panel.conf"
396
+ keys Down
397
+ sleep 0.2
398
+ keys Enter
399
+ wait_file_has "$(conf)" "density=compact" "密度开关写进 panel.conf" || bad "密度偏好没有在预算内落盘"
400
+ assert_has "$(conf)" "density=compact" "密度开关写进 panel.conf"
401
+ keys ,
402
+ wait_cap_not overlay-closed.txt "设置" "捕获里没有 [设置]"
403
+ # Relaunch keeps the preferences (English + the overlay values).
404
+ start_panel
405
+ cap_has "progress" relaunch.txt
406
+ assert_match "$(conf)" '^lang=en$' "重启后语言偏好仍在"
407
+ # defaultPage cycles over the four pages and wraps (P18/B2 left the cycle over three: 4 fell
408
+ # through to 5 and the next launch reset the page silently — fixed and pinned in B3).
409
+ keys ,
410
+ sleep 0.6
411
+ keys Down
412
+ sleep 0.3
413
+ local cyc
414
+ for cyc in 2 3 4 1; do
415
+ keys Enter
416
+ wait_file_has "$(conf)" "page=$cyc" "defaultPage 循环到 $cyc" || bad "defaultPage 没有在预算内循环到 $cyc"
417
+ assert_eq "defaultPage 循环到 $cyc(四页 + 回绕)" "$(sed -n 's/^page=//p' "$(conf)" | tr -d '\n')" "$cyc"
418
+ done
419
+ keys Escape
420
+ sleep 0.4
421
+ }
422
+
423
+ scn_conf() {
424
+ section "settings · 坏/缺 panel.conf 走默认,机读出口不受影响(5.1)"
425
+ server_up conf
426
+ local -a cap_env=(TEAM_MEMINFO_FILE="$tmp/meminfo" TEAM_SWAPFILE_PATH="$tmp/swaps")
427
+ printf 'MemTotal: 1000000 kB\nMemAvailable: 4040000 kB\nSwapFree: 0 kB\n' > "$tmp/meminfo"
428
+ printf 'Filename Type Size Used Priority\n' > "$tmp/swaps"
429
+ ( cd "$ROOT" && env "${cap_env[@]}" bash "$skill/scripts/team" monitor --print --width 120 --height 20 ) >"$tmp/$current/print-a.txt" 2>/dev/null
430
+ mkdir -p "$state"; printf '\000\001garbage\377\n' > "$(conf)"
431
+ ( cd "$ROOT" && env "${cap_env[@]}" bash "$skill/scripts/team" monitor --print --width 120 --height 20 ) >"$tmp/$current/print-b.txt" 2>/dev/null
432
+ RC=$?
433
+ assert_eq "坏 panel.conf 下 --print 退出 0" "$RC" "0"
434
+ norm() { sed -E 's/[0-9]{2}:[0-9]{2}:[0-9]{2}/TIME/' "$1"; }
435
+ if diff <(norm "$tmp/$current/print-a.txt") <(norm "$tmp/$current/print-b.txt") >/dev/null; then
436
+ ok "坏 panel.conf 与无 panel.conf 的 --print 逐字一致(除时间戳)"
437
+ else
438
+ bad "坏 panel.conf 改变了 --print 的内容"; diff <(norm "$tmp/$current/print-a.txt") <(norm "$tmp/$current/print-b.txt") | head -4
439
+ fi
440
+ # The TUI falls back to the defaults (zh).
441
+ start_panel
442
+ cap_has "项目进度" tui-defaults.txt
443
+ }
444
+
445
+ scn_queue() {
446
+ section "queue · 队列列表 + 全文只读(4.3)"
447
+ server_up queue
448
+ local ob="$state/outbox"
449
+ mkdir -p "$ob/held"
450
+ printf 'kind: notify\ntarget: pm\n---\n第一行\n第二行\n' > "$ob/1758000000000-001-pm.msg"
451
+ printf 'kind: say\ntarget: pm\n---\n排队中的第二条\n' > "$ob/1758000001000-002-pm.msg"
452
+ printf 'kind: notify\ntarget: pm\n---\n被扣住的副本\n' > "$ob/held/1757990000000-003-pm.msg"
453
+ local before after
454
+ before="$(hash_state)"
455
+ start_panel
456
+ keys 3
457
+ wait_cap_has queue-list.txt "延后队列 2" "捕获里有 [延后队列 2]"
458
+ wait_cap_has queue-list.txt "1758000001000-002-pm.msg" "捕获里有 [1758000001000-002-pm.msg]"
459
+ wait_cap_has queue-list.txt "滞留" "捕获里有 [滞留]"
460
+ wait_cap_has queue-list.txt "扣住原因:draft-raced" "捕获里有 [扣住原因:draft-raced]"
461
+ keys Enter
462
+ wait_cap_has queue-view.txt "条目全文" "捕获里有 [条目全文]"
463
+ cap_has "第一行" queue-view.txt
464
+ cap_has "第二行" queue-view.txt
465
+ keys Escape
466
+ wait_cap_has queue-back.txt "延后队列 2" "捕获里有 [延后队列 2]"
467
+ after="$(hash_state)"
468
+ # The page/conf files are the console's own; the queue must be byte-identical.
469
+ local qbefore qafter
470
+ qbefore="$(cd "$ROOT" && find .pi/team/state/outbox -type f | sort | xargs -r md5sum | md5sum)"
471
+ keys 1
472
+ sleep 0.8
473
+ qafter="$(cd "$ROOT" && find .pi/team/state/outbox -type f | sort | xargs -r md5sum | md5sum)"
474
+ assert_eq "查看全文/翻页后队列逐字节不变" "$qafter" "$qbefore"
475
+ [ "$before" != "$after" ] && ok "夹具自检:state 的指纹确实变了(面板写了 page/conf 这两处)" \
476
+ || bad "夹具自检:state 指纹没变(断言可能是空的)"
477
+ }
478
+
479
+ scn_workdetail() {
480
+ section "workdetail · P20/B5 工作页看板行:焦点 / 详情 / 原地返回 / 空与降级无死项"
481
+ server_up workdetail
482
+ wcap() { cap > "$tmp/$current/$1.txt"; }
483
+ wfile() { printf '%s/%s.txt' "$tmp/$current" "$1"; }
484
+ conf_set "lang=zh" "page=2" "activity=1" "mouse=1" "density=comfortable" "theme=dark"
485
+ printf '2\n' > "$(page_file)"
486
+ start_panel
487
+
488
+ # ① ↓ 聚焦第一绘制行(P14),enter 打开详情,仍在第 2 页
489
+ keys Down; sleep 0.6
490
+ wcap focus
491
+ assert_eq "B5 ↓ 后焦点在第一绘制行 P14" "$(focused_id "$(wfile focus)")" "P14"
492
+ assert_eq "B5 工作页焦点光标恰好一个" "$(grep -o '›' "$(wfile focus)" | wc -l | tr -d ' ')" "1"
493
+ keys Enter; sleep 1.4
494
+ wcap detail
495
+ assert_has "$(wfile detail)" "详情 P14" "B5 enter 打开第一行的详情"
496
+ assert_has "$(wfile detail)" "[brief]" "B5 详情第一个文件 tab 默认打开"
497
+ assert_not "$(wfile detail)" "任务看板" "B5 详情替换了工作页的块"
498
+ assert_eq "B5 打开详情后仍在第 2 页" "$(page_of)" "2"
499
+
500
+ # ② q 原地回工作页
501
+ keys q; sleep 0.8
502
+ wcap back-q
503
+ assert_has "$(wfile back-q)" "任务看板" "B5 q 回到工作页"
504
+ assert_not "$(wfile back-q)" "详情 P14" "B5 q 关掉了详情"
505
+ assert_eq "B5 返回后 panel-page 仍是 2" "$(page_of)" "2"
506
+
507
+ # ③ ↓ 再走一行:焦点到 V14(走的是绘制顺序)
508
+ keys Down; sleep 0.5
509
+ wcap focus-2
510
+ assert_eq "B5 ↓ 沿绘制顺序到 V14" "$(focused_id "$(wfile focus-2)")" "V14"
511
+
512
+ # ④ 看板页:enter 开详情、esc 回看板页(不是工作页)。焦点状态两页共用(按 entry id),
513
+ # 工作页刚把它走到 V14,所以看板页打开的也是 V14 —— 验证的是「返回原页」,不是 id。
514
+ keys 4; sleep 1
515
+ wcap board
516
+ assert_has "$(wfile board)" "已放弃" "B5 切到看板页"
517
+ assert_eq "B5 焦点状态两页共用(看板页也在 V14)" "$(focused_id "$(wfile board)")" "V14"
518
+ keys Enter; sleep 1.4
519
+ wcap board-detail
520
+ assert_has "$(wfile board-detail)" "详情 V14" "B5 看板页 enter 打开焦点卡详情"
521
+ keys Escape; sleep 0.8
522
+ wcap board-back
523
+ assert_has "$(wfile board-back)" "已放弃" "B5 esc 回到看板页"
524
+ assert_eq "B5 看板页返回后 panel-page=4" "$(page_of)" "4"
525
+ assert_eq "B5 看板页返回后焦点仍是 V14" "$(focused_id "$(wfile board-back)")" "V14"
526
+
527
+ # ⑤ 点击:第一下聚焦 V14,第二下打开(直驱 pty,字节证据)
528
+ local pstate="$tmp/$current/state-click"
529
+ mkdir -p "$pstate"
530
+ printf 'lang=zh\npage=2\nactivity=1\nmouse=1\ndensity=comfortable\ntheme=dark\n' > "$pstate/panel.conf"
531
+ printf '2\n' > "$pstate/panel-page"
532
+ python3 "$pty_direct" --js "$js" --panel "$panel" --root "$ROOT" --state-dir "$pstate" --team-cli "$stub" \
533
+ --out "$tmp/$current/click.bin" --out2 "$tmp/$current/click-after.bin" --expect-enable yes \
534
+ --click-col 20 --click-row 6 --click2-col 20 --click2-row 6 --cols 120 --rows 32 \
535
+ >"$tmp/$current/click.log" 2>&1
536
+ assert_eq "B5 直驱 pty:两次点击注入成功" "$?" "0"
537
+ python3 - "$tmp/$current/click.bin" > "$tmp/$current/click-clean.txt" <<'PYW'
538
+ import re, sys
539
+ raw = open(sys.argv[1], "rb").read().decode("utf-8", "replace")
540
+ print(re.sub(r"\x1b\[[0-9;?]*[A-Za-z]", "", raw))
541
+ PYW
542
+ if grep -qE '›\s*(·\s*)?V14' "$tmp/$current/click-clean.txt"; then
543
+ ok "B5 第一次点击把焦点移到 V14"
544
+ else
545
+ bad "B5 第一次点击没有聚焦 V14"
546
+ fi
547
+ if LC_ALL=C grep -aq '详情 V14' "$tmp/$current/click-after.bin"; then
548
+ ok "B5 第二次点击(同一行)打开 V14 的详情"
549
+ else
550
+ bad "B5 第二次点击没有打开详情"
551
+ fi
552
+
553
+ # ⑥ 空看板:没有光标、没有行键、没有 focus/open-focused 目标、enter 不开任何东西
554
+ python3 - "$tmp/$current/empty.json" <<'PYE'
555
+ import json, sys
556
+ json.dump({"rows": [], "counts": {}, "total": 0, "deliveries": []}, open(sys.argv[1], "w"))
557
+ PYE
558
+ printf '2\n' > "$(page_file)"
559
+ start_panel "B3_STUB_BOARD_FILE='$tmp/$current/empty.json'"
560
+ keys Down; sleep 0.5
561
+ keys Enter; sleep 0.8
562
+ wcap empty
563
+ assert_eq "B5 空看板:没有焦点光标" "$(grep -o '›' "$(wfile empty)" | wc -l | tr -d ' ')" "0"
564
+ assert_not "$(wfile empty)" "详情" "B5 空看板:enter 不开详情"
565
+ assert_eq "B5 空看板:panel-page 仍是 2" "$(page_of)" "2"
566
+ assert_has "$(wfile empty)" "看板为空" "B5 空看板:块显示空态而不是一行空行"
567
+ B3_STUB_BOARD_FILE="$tmp/$current/empty.json" "$js" "$panel" --snapshot --targets --root "$ROOT" --state-dir "$state" \
568
+ --team-cli "$stub" --lang zh --theme dark --width 120 --height 32 --page 2 >"$tmp/$current/empty-targets.json" 2>/dev/null
569
+ local kinds
570
+ kinds="$(kinds_of "$tmp/$current/empty-targets.json")"
571
+ case ",$kinds," in
572
+ *",focus,"*|*",open-focused,"*) bad "B5 空看板的目标表还有 focus/open-focused($kinds)" ;;
573
+ *) ok "B5 空看板的目标表没有 focus/open-focused($kinds)" ;;
574
+ esac
575
+
576
+ # ⑦ 60x10 降级:没有光标、没有行键、没有死项目标
577
+ start_panel
578
+ tmux -L "$sock" resize-window -t "$sess:panel" -x 60 -y 10 2>/dev/null || true
579
+ sleep 1.4
580
+ keys Down; sleep 0.5
581
+ keys Enter; sleep 0.8
582
+ wcap degraded
583
+ assert_eq "B5 60x10 降级:没有焦点光标" "$(grep -o '›' "$(wfile degraded)" | wc -l | tr -d ' ')" "0"
584
+ assert_not "$(wfile degraded)" "详情" "B5 60x10 降级:enter 不开详情"
585
+ assert_not "$(wfile degraded)" "↑/↓ 行" "B5 60x10 降级:键位带不发行键"
586
+ "$js" "$panel" --snapshot --targets --root "$ROOT" --state-dir "$state" --team-cli "$stub" \
587
+ --lang zh --theme dark --width 60 --height 10 --page 2 >"$tmp/$current/degraded-targets.json" 2>/dev/null
588
+ kinds="$(kinds_of "$tmp/$current/degraded-targets.json")"
589
+ case ",$kinds," in
590
+ *",focus,"*|*",open-focused,"*) bad "B5 60x10 降级的目标表还有 focus/open-focused($kinds)" ;;
591
+ *) ok "B5 60x10 降级的目标表没有 focus/open-focused($kinds)" ;;
592
+ esac
593
+ }
594
+
595
+ scn_mouse() {
596
+ section "mouse · SGR 直驱 + tmux 全链路(6.3)"
597
+ server_up mouse
598
+ conf_set "lang=zh" "page=1" "activity=1" "mouse=1" "density=comfortable" "theme=dark"
599
+ # (a) direct pty with the preference on: enable sequence + a click on the 工作 tab switches the page.
600
+ python3 "$pty_direct" --js "$js" --panel "$panel" --root "$ROOT" --state-dir "$state" --team-cli "$stub" \
601
+ --out "$tmp/$current/direct-on.bin" --expect-enable yes --expect-page 2 --click-col 12 --click-row 2 \
602
+ >"$tmp/$current/direct-on.log" 2>&1
603
+ assert_eq "直驱 pty:鼠标开 → 有 enable 序列且点页签切到 P2" "$?" "0"
604
+ # (b) preference off: no sequence at all, and the click does nothing.
605
+ conf_set "lang=zh" "page=1" "activity=1" "mouse=0" "density=comfortable" "theme=dark"
606
+ rm -f "$(page_file)"
607
+ python3 "$pty_direct" --js "$js" --panel "$panel" --root "$ROOT" --state-dir "$state" --team-cli "$stub" \
608
+ --out "$tmp/$current/direct-off.bin" --expect-enable no --expect-page "" --click-col 12 --click-row 2 \
609
+ >"$tmp/$current/direct-off.log" 2>&1
610
+ assert_eq "直驱 pty:鼠标关 → 0 个鼠标序列" "$?" "0"
611
+ if [ "$(page_of)" = "2" ]; then
612
+ bad "鼠标关时点击页签仍然切了页(click 不该生效)"
613
+ else
614
+ ok "鼠标关时点击页签没有切页"
615
+ fi
616
+ if grep -qF $'\033[?1000h' "$tmp/$current/direct-off.bin"; then
617
+ bad "鼠标关时仍写了 1000h"
618
+ else
619
+ ok "鼠标关的原始字节里没有 1000h/1006h"
620
+ fi
621
+ # (d) the overlay's mouse toggle takes effect on the next frame: after toggling it off the console
622
+ # emits the disable sequence (and no new enable), and the tab click no longer switches pages.
623
+ conf_set "lang=zh" "page=1" "activity=1" "mouse=1" "density=comfortable" "theme=dark"
624
+ rm -f "$(page_file)"
625
+ python3 "$pty_direct" --js "$js" --panel "$panel" --root "$ROOT" --state-dir "$state" --team-cli "$stub" \
626
+ --out "$tmp/$current/toggle.bin" --expect-enable yes --toggle-mouse-off --click-col 12 --click-row 2 \
627
+ >"$tmp/$current/toggle.log" 2>&1
628
+ assert_eq "直驱 pty:浮层里关掉鼠标 → 下一帧发出 disable 序列" "$?" "0"
629
+ if [ "$(page_of)" = "2" ]; then
630
+ bad "关掉鼠标后点击页签仍切页"
631
+ else
632
+ ok "关掉鼠标后点击页签无效(偏好已即时生效)"
633
+ fi
634
+ assert_has "$(conf)" "mouse=0" "浮层写回 panel.conf"
635
+
636
+ # (c) the full chain: a real terminal clicks the m hint and the compose line opens.
637
+ conf_set "lang=zh" "page=1" "activity=1" "mouse=1" "density=comfortable" "theme=dark"
638
+ start_panel
639
+ python3 "$pty_tmux" --sock "$sock" --session "$sess" --pane "$sess:panel" --hint "m 写信" \
640
+ --out "$tmp/$current/chain.bin" --rows 32 --cols 120 >"$tmp/$current/chain.log" 2>&1
641
+ assert_eq "tmux 全链路:点在 m 提示上" "$?" "0"
642
+ wait_cap_has chain-compose.txt "Enter 发送" "捕获里有 [Enter 发送]"
643
+ }
644
+
645
+ scn_wheel() {
646
+ section "mouse · 滚轮滚动(6.3)"
647
+ server_up wheel
648
+ conf_set "lang=zh" "page=3" "activity=1" "mouse=1" "density=comfortable" "theme=dark"
649
+ # The wheel shifts the patrol block's visible window (the stub has five lines). tmux keeps wheel
650
+ # events for itself even when the pane has requested reporting (measured), so the wheel is driven
651
+ # the same way the reference measurement was: directly on the pty (the click chain keeps tmux).
652
+ python3 "$pty_direct" --js "$js" --panel "$panel" --root "$ROOT" --state-dir "$state" --team-cli "$stub" \
653
+ --out "$tmp/$current/wheel.bin" --out2 "$tmp/$current/wheel-after.bin" --expect-enable yes \
654
+ --click-col 72 --click-row 6 --wheel down --wheel-clicks 3 >"$tmp/$current/wheel.log" 2>&1
655
+ assert_eq "直驱 pty:滚轮事件已注入且退出 0" "$?" "0"
656
+ if grep -qF '10:00:00Z' "$tmp/$current/wheel-after.bin"; then
657
+ bad "滚轮后滚出的帧里还有 10:00:00Z(窗口没有后移)"
658
+ elif grep -qF '10:45:00Z' "$tmp/$current/wheel-after.bin"; then
659
+ ok "滚轮下滚 3 格:可见窗口后移(10:00:00Z 移出、10:45:00Z 进入)"
660
+ else
661
+ bad "滚轮后滚出的帧里没有 10:45:00Z(滚动没生效)"; head -c 300 "$tmp/$current/wheel-after.bin" | cat -v
662
+ fi
663
+ }
664
+
665
+ scn_resize() {
666
+ section "layout · resize 实时重排(5.2)"
667
+ server_up resize
668
+ tmux -L "$sock" resize-window -t "$sess:panel" -x 99 -y 32 2>/dev/null || true
669
+ start_panel
670
+ tmux -L "$sock" resize-window -t "$sess:panel" -x 99 -y 32 2>/dev/null || true
671
+ sleep 0.6
672
+ cap_to narrow
673
+ assert_has "$tmp/$current/narrow.txt" "代理" "99 列:单列仍渲染 agent 表"
674
+ # Reflow to the wide tier: the agent table and the right block share a row.
675
+ tmux -L "$sock" resize-window -t "$sess:panel" -x 160 -y 32 2>/dev/null || true
676
+ sleep 1.2
677
+ cap_to wide
678
+ if grep -qE '代理.*活动(仅本 session' "$tmp/$current/wide.txt"; then
679
+ ok "160 列:重排成双列(表头与右栏同一行)"
680
+ else
681
+ bad "160 列:没有重排成双列"; sed -n '1,3p' "$tmp/$current/wide.txt"
682
+ fi
683
+ # Boundary captures at the four tiers (the real pane is resized for each).
684
+ for w in 160 100 99 60 59; do
685
+ tmux -L "$sock" resize-window -t "$sess:panel" -x "$w" -y 32 2>/dev/null || true
686
+ sleep 0.9
687
+ cap_to "w$w"
688
+ if ! grep -q 'teamsmith pulse' "$tmp/$current/w$w.txt"; then
689
+ bad "$w 列:帧是空的"
690
+ continue
691
+ fi
692
+ if [ "$w" = "160" ] || [ "$w" = "100" ]; then
693
+ if grep -qE '代理.*活动(仅本 session' "$tmp/$current/w$w.txt"; then
694
+ ok "$w 列:双列(表头与右栏同一行)"
695
+ else
696
+ bad "$w 列:应为双列"
697
+ fi
698
+ elif [ "$w" = "99" ] || [ "$w" = "60" ]; then
699
+ if grep -qE '代理.*活动(仅本 session' "$tmp/$current/w$w.txt"; then
700
+ bad "$w 列:不该是双列"
701
+ else
702
+ ok "$w 列:单列"
703
+ fi
704
+ else
705
+ if grep -q '●在' "$tmp/$current/w$w.txt" && grep -qF '41k/272k' "$tmp/$current/w$w.txt"; then
706
+ ok "$w 列:最小档(状态缩写、会话列完整)"
707
+ else
708
+ bad "$w 列:最小档没有生效"; sed -n '6,9p' "$tmp/$current/w$w.txt"
709
+ fi
710
+ fi
711
+ done
712
+ }
713
+
714
+ scn_collapse() {
715
+ section "collapse · q 收起后巡检仍在跑(7.1)"
716
+ server_up collapse
717
+ # P68:本场景的稳定帧等待捕 pulse 窗口(控制台在这里,不在 panel 窗口)。
718
+ local b3_cap_pane="pulse"
719
+ # The patrol interval is 2s so the tick's capacity line grows inside the fixture window. It must
720
+ # live in the project config, not the launcher's shell: `respawn-window` starts the headless loop
721
+ # from the tmux server's environment, not from the collapsing pane's.
722
+ printf 'TEAM_PULSE_INTERVAL=2\n' >> "$ROOT/.pi/team/config.sh"
723
+ tmux -L "$sock" new-window -d -t "$sess" -n cmd -c "$ROOT" \
724
+ "bash '$skill/scripts/team' pulse up > '$tmp/$current/up.log' 2>&1; sleep 1"
725
+ # P68:等日志自己点名窗口(原来是 sleep 5 + 单次采样)。
726
+ wait_file_has "$tmp/$current/up.log" "巡检已在" "pulse up 的日志点名窗口" \
727
+ || bad "pulse up 的日志没有在预算内点名窗口"
728
+ assert_has "$tmp/$current/up.log" "巡检已在" "pulse up 起了窗口"
729
+ # P68:等控制台自己的标题在稳定帧上(原来是 sleep 5 + 单次 capture-pane)。
730
+ if wait_console "$tmp/$current/console.txt" "pulse 窗口里的控制台首帧"; then
731
+ assert_has "$tmp/$current/console.txt" "teamsmith pulse" "pulse 窗口里是控制台"
732
+ else
733
+ b3_wait_verdict $? "pulse 窗口里是控制台" "pulse 窗口里没有在预算内出现控制台"
734
+ fi
735
+ # 计数放在控制台起来之后:`cmd` 辅助窗口的命令末尾有 `sleep 1`,它自己退掉后剩下的才是后端窗口。
736
+ local wins_before; wins_before="$(tmux -L "$sock" list-windows -t "$sess" | wc -l | tr -d ' ')"
737
+ # q collapses: same window, a headless tick loop, capacity.log keeps gaining lines.
738
+ tmux -L "$sock" send-keys -t "$sess:pulse" q
739
+ # P68:等窗口里的进程真的换成 --headless 巡检循环(原来是 sleep 3 后单次看 ps)。
740
+ wait_pane_args "pulse" "--headless" "q 收起后的无界面巡检" \
741
+ || bad "q 收起后窗口里的进程不是 --headless"
742
+ local wins_after; wins_after="$(tmux -L "$sock" list-windows -t "$sess" | wc -l | tr -d ' ')"
743
+ assert_eq "收前后窗口数不变(一个后端、一个窗口)" "$wins_after" "$wins_before"
744
+ local pane_pid args
745
+ pane_pid="$(tmux -L "$sock" list-panes -t "$sess:pulse" -F '#{pane_pid}' | head -1)"
746
+ args="$(ps -o args= -p "$pane_pid" 2>/dev/null || true)"
747
+ if printf '%s' "$args" | grep -q -- '--headless'; then
748
+ ok "窗口里跑的是无界面巡检($(printf '%s' "$args" | tr -s ' ' | cut -c1-80))"
749
+ else
750
+ bad "窗口里的进程不是 --headless:$args"
751
+ fi
752
+ local c1 c2
753
+ c1="$(grep -c . "$state/capacity.log" 2>/dev/null || echo 0)"
754
+ if c2="$(wait_capacity_growth "$state/capacity.log" "${c1:-0}" "收起后巡检仍在跑(capacity.log 行数增长)")"; then
755
+ ok "收起后巡检仍在跑(capacity.log $c1 → $c2 行)"
756
+ else
757
+ bad "收起后巡检停了(capacity.log $c1 → ${c2:-?} 行)"
758
+ fi
759
+ tmux -L "$sock" new-window -d -t "$sess" -n cmd2 -c "$ROOT" \
760
+ "bash '$skill/scripts/team' pulse status > '$tmp/$current/status-headless.log' 2>&1; sleep 0.3; \
761
+ bash '$skill/scripts/team' pulse up > '$tmp/$current/up2.log' 2>&1"
762
+ # P68:两份由命令自己写的日志分别等(原来是 sleep 6 + 两次单次采样)。
763
+ wait_file_has "$tmp/$current/status-headless.log" "无界面 tick" "pulse status 报无界面形态" \
764
+ || bad "pulse status 没有在预算内报无界面形态"
765
+ assert_has "$tmp/$current/status-headless.log" "无界面 tick" "pulse status 报无界面形态"
766
+ wait_file_has "$tmp/$current/up2.log" "恢复成控制台" "pulse up 原地恢复控制台" \
767
+ || bad "pulse up 没有在预算内恢复控制台"
768
+ assert_has "$tmp/$current/up2.log" "恢复成控制台" "pulse up 原地恢复控制台"
769
+ if wait_console "$tmp/$current/restored.txt" "恢复后的控制台首帧"; then
770
+ assert_has "$tmp/$current/restored.txt" "teamsmith pulse" "恢复后同一窗口里又是控制台"
771
+ else
772
+ b3_wait_verdict $? "恢复后同一窗口里又是控制台" "恢复后同一窗口里没有在预算内出现控制台"
773
+ fi
774
+ }
775
+
776
+ scn_board() {
777
+ section "board · 看板页:第四页记忆 / 焦点随重排 / 车道滚动 / 鼠标(4.2/5.3/5.4/6.1/6.2)"
778
+ server_up board
779
+ bcap() { cap > "$tmp/$current/$1.txt"; } # write a capture under the fixture dir
780
+ bfile() { printf '%s/%s.txt' "$tmp/$current" "$1"; } # read it back
781
+ conf_set "lang=zh" "page=1" "activity=1" "mouse=1" "density=comfortable" "theme=dark"
782
+ rm -f "$(page_file)"
783
+ start_panel
784
+ # 4.2: `4` switches, the file remembers it, a relaunch restores it.
785
+ keys 4
786
+ sleep 1
787
+ bcap p4
788
+ assert_has "$(bfile p4)" "已放弃" "按 4 切到看板页(六车道在场)"
789
+ assert_eq "按 4 后 panel-page=4" "$(page_of)" "4"
790
+ start_panel
791
+ bcap relaunch
792
+ assert_has "$(bfile relaunch)" "已放弃" "重启后仍在看板页(panel-page 记忆)"
793
+ assert_eq "重启后 panel-page 仍是 4" "$(page_of)" "4"
794
+ # 4.2: an out-of-range file falls back to the default page, never an error.
795
+ printf '9\n' > "$(page_file)"
796
+ start_panel
797
+ bcap oob
798
+ assert_has "$(bfile oob)" "项目进度" "panel-page=9 时回落到默认页(总览)"
799
+ assert_not "$(bfile oob)" "已放弃" "panel-page=9 时没有渲染看板页"
800
+ # 5.3: the focus is keyed by entry id — a reorder keeps it, a removal falls back inside the lane.
801
+ board_a="$tmp/$current/board-a.json"
802
+ board_b="$tmp/$current/board-b.json"
803
+ board_c="$tmp/$current/board-c.json"
804
+ python3 - "$board_a" "$board_b" "$board_c" <<'PYB'
805
+ import json, sys
806
+
807
+ def row(i, state, title):
808
+ return {"id": i, "title": title, "agent": "dev", "branch": "-", "deps": "-", "state": state, "phase": "apply"}
809
+
810
+ a = [row("M9", "todo", "聚焦的卡片"), row("M8", "todo", "第二条"), row("M7", "wip", "进行中的一条")]
811
+ b = [row("M8", "todo", "第二条"), row("M9", "todo", "聚焦的卡片"), row("M7", "wip", "进行中的一条")]
812
+ c = [row("M7", "wip", "进行中的一条"), row("M9", "todo", "聚焦的卡片")]
813
+ for path, rows in ((sys.argv[1], a), (sys.argv[2], b), (sys.argv[3], c)):
814
+ json.dump({"rows": rows, "counts": {}, "total": len(rows), "deliveries": []}, open(path, "w"))
815
+ PYB
816
+ printf '4\n' > "$(page_file)"
817
+ start_panel "B3_STUB_BOARD_FILE='$board_a'"
818
+ sleep 1
819
+ bcap focus-a
820
+ assert_eq "初始焦点在 M9(首条非空车道的第一张)" "$(focused_id "$(bfile focus-a)")" "M9"
821
+ keys Down
822
+ sleep 0.6
823
+ bcap focus-m8
824
+ assert_eq "↓ 把焦点移到 M8" "$(focused_id "$(bfile focus-m8)")" "M8"
825
+ cp "$board_b" "$board_a.tmp" && mv "$board_a.tmp" "$board_a"
826
+ keys r
827
+ sleep 1
828
+ bcap focus-reordered
829
+ assert_eq "重排后焦点仍在 M8(按 id 跟踪,不按行号)" "$(focused_id "$(bfile focus-reordered)")" "M8"
830
+ cp "$board_c" "$board_a.tmp" && mv "$board_a.tmp" "$board_a"
831
+ keys r
832
+ sleep 1
833
+ bcap focus-vanished
834
+ assert_eq "M8 离开看板后焦点落到该车道第一条(M9)" "$(focused_id "$(bfile focus-vanished)")" "M9"
835
+ # M48: two rows carry one id (the file's history does this). The cursor must walk both — each one
836
+ # step, no freeze — and the focus glyph must sit on exactly one row. The old id-keyed match lit
837
+ # both up and `↓` never left the first of them. The fixture gives the two rows distinct agents
838
+ # (visible in a lane card at 120 columns) and distinct titles (visible on the full-width work page).
839
+ board_dup="$tmp/$current/board-dup.json"
840
+ python3 - "$board_dup" <<'PYD'
841
+ import json, sys
842
+
843
+ def row(i, state, title, agent):
844
+ return {"id": i, "title": title, "agent": agent, "branch": "-", "deps": "-", "state": state, "phase": "apply"}
845
+
846
+ # P123: the card line no longer carries the agent, so the two same-id rows are told apart by their
847
+ # titles — short enough to survive the 120-column lane's title truncation (每条 3 个汉字).
848
+ rows = [row("M39", "todo", "第一条", "dev1"), row("M39", "todo", "第二条", "dev2"), row("M48", "todo", "第三条", "dev3")]
849
+ json.dump({"rows": rows, "counts": {}, "total": len(rows), "deliveries": []}, open(sys.argv[1], "w"))
850
+ PYD
851
+ printf '4\n' > "$(page_file)"
852
+ start_panel "B3_STUB_BOARD_FILE='$board_dup'"
853
+ sleep 1
854
+ bcap dup-1
855
+ assert_eq "M48 重复 ID:初始焦点在第一行 M39" "$(focused_id "$(bfile dup-1)")" "M39"
856
+ assert_eq "M48 重复 ID:焦点光标恰好一个(不是两行都亮)" "$(grep -o '›' "$(bfile dup-1)" | wc -l | tr -d ' ')" "1"
857
+ focused_row "$(bfile dup-1)" > "$tmp/$current/dup-1-row.txt"
858
+ assert_has "$tmp/$current/dup-1-row.txt" "M39 第一条" "M48 重复 ID:高亮落在第一条(按行身份,不是裸 ID)"
859
+ keys Down; sleep 0.5
860
+ bcap dup-2
861
+ assert_eq "M48 重复 ID:↓ 后仍只有一个光标" "$(grep -o '›' "$(bfile dup-2)" | wc -l | tr -d ' ')" "1"
862
+ focused_row "$(bfile dup-2)" > "$tmp/$current/dup-2-row.txt"
863
+ assert_has "$tmp/$current/dup-2-row.txt" "M39 第二条" "M48 重复 ID:↓ 走到同 ID 的第二行(不卡死)"
864
+ # Cross-frame persistence (the brief's requirement): a refresh and a detail round trip must keep the
865
+ # *second* row of the id, not snap back to the first one.
866
+ keys r; sleep 1
867
+ bcap dup-refresh
868
+ focused_row "$(bfile dup-refresh)" > "$tmp/$current/dup-refresh-row.txt"
869
+ assert_has "$tmp/$current/dup-refresh-row.txt" "M39 第二条" "M48 重复 ID:刷新(r)后焦点仍在第二条同 ID 行"
870
+ keys Enter; sleep 1.4
871
+ bcap dup-detail
872
+ assert_has "$(bfile dup-detail)" "详情 M39" "M48 重复 ID:Enter 打开的是焦点那一行的详情"
873
+ keys Escape; sleep 0.8
874
+ bcap dup-back
875
+ focused_row "$(bfile dup-back)" > "$tmp/$current/dup-back-row.txt"
876
+ assert_has "$tmp/$current/dup-back-row.txt" "M39 第二条" "M48 重复 ID:详情返回后焦点仍在第二条同 ID 行"
877
+ keys Down; sleep 0.5
878
+ bcap dup-3
879
+ assert_eq "M48 重复 ID:再 ↓ 走到 M48(同 ID 两行之后继续前进)" "$(focused_id "$(bfile dup-3)")" "M48"
880
+ keys Up; sleep 0.4; keys Up; sleep 0.4
881
+ bcap dup-4
882
+ assert_eq "M48 重复 ID:↑↑ 回到第一行 M39" "$(focused_id "$(bfile dup-4)")" "M39"
883
+ focused_row "$(bfile dup-4)" > "$tmp/$current/dup-4-row.txt"
884
+ assert_has "$tmp/$current/dup-4-row.txt" "M39 第一条" "M48 重复 ID:↑ 逐行经过第二条,回到第一条"
885
+ # The work page walks the same rows through its own drawn order (M48 changed both walks). Its
886
+ # first `↓` anchors on the first drawn row (P20/B5), so the second press is the first real step.
887
+ printf '2\n' > "$(page_file)"
888
+ start_panel "B3_STUB_BOARD_FILE='$board_dup'"
889
+ sleep 1
890
+ bcap dup-work-1
891
+ assert_eq "M48 重复 ID(工作页):初始焦点在第一绘制行 M39" "$(focused_id "$(bfile dup-work-1)")" "M39"
892
+ assert_eq "M48 重复 ID(工作页):焦点光标恰好一个" "$(grep -o '›' "$(bfile dup-work-1)" | wc -l | tr -d ' ')" "1"
893
+ focused_row "$(bfile dup-work-1)" > "$tmp/$current/dup-work-1-row.txt"
894
+ assert_has "$tmp/$current/dup-work-1-row.txt" "第一条" "M48 重复 ID(工作页):高亮落在第一条"
895
+ keys Down; sleep 0.5; keys Down; sleep 0.5
896
+ bcap dup-work-2
897
+ focused_row "$(bfile dup-work-2)" > "$tmp/$current/dup-work-2-row.txt"
898
+ assert_has "$tmp/$current/dup-work-2-row.txt" "第二条" "M48 重复 ID(工作页):↓ 走到第二条同 ID 行"
899
+ keys Down; sleep 0.5
900
+ bcap dup-work-3
901
+ assert_eq "M48 重复 ID(工作页):再 ↓ 走到 M48" "$(focused_id "$(bfile dup-work-3)")" "M48"
902
+ # The done-lane/wheel checks below need the kanban page back.
903
+ printf '4\n' > "$(page_file)"
904
+ # 5.4: a 20-card done lane anchors on the newest and counts what it hides; the wheel scrolls it.
905
+ start_panel "B3_STUB_DONE=20"
906
+ sleep 1
907
+ bcap lane-first
908
+ assert_has "$(bfile lane-first)" "↓" "20 张 done:第一帧在底边报出隐藏数量"
909
+ assert_has "$(bfile lane-first)" "D20" "20 张 done:第一帧锚定最新(D20 可见)"
910
+ assert_has "$(bfile lane-first)" "D01" "20 张 done:车道窗口里能看到更旧的卡片"
911
+ done_col="$(python3 - "$(bfile lane-first)" <<'PYC'
912
+ import re, sys
913
+
914
+ WIDE = [(0x1100,0x115f),(0x2e80,0x303e),(0x3041,0x33ff),(0x3400,0x4dbf),(0x4e00,0x9fff),(0xa000,0xa4cf),(0xac00,0xd7a3),(0xf900,0xfaff),(0xfe10,0xfe19),(0xfe30,0xfe6f),(0xff00,0xff60),(0xffe0,0xffe6)]
915
+
916
+ def disp(text):
917
+ return sum(2 if any(a <= ord(ch) <= b for a, b in WIDE) else 1 for ch in text)
918
+
919
+ rows = [re.sub(r"\x1b\[[0-9;]*m", "", l.rstrip("\n")) for l in open(sys.argv[1], encoding="utf-8")]
920
+ head = next((r for r in rows if "完成" in r), "")
921
+ print(disp(head.split("完成")[0]) + 3 if head else 63)
922
+ PYC
923
+ )"
924
+ # The wheel is injected into its own pty instance (tmux keeps wheel events for itself, measured in
925
+ # this suite's other wheel scenario), so the evidence is that instance's own byte stream: the rows
926
+ # Ink rewrites when the lane window moves hold ids that were hidden before.
927
+ B3_STUB_DONE=20 python3 "$pty_direct" --js "$js" --panel "$panel" --root "$ROOT" --state-dir "$state" \
928
+ --team-cli "$stub" --out "$tmp/$current/wheel-lane.bin" --out2 "$tmp/$current/wheel-lane-after.bin" \
929
+ --expect-enable yes --click-col "${done_col:-63}" --click-row 6 --wheel up --wheel-clicks 3 \
930
+ --cols 120 --rows 32 >"$tmp/$current/wheel-lane.log" 2>&1
931
+ assert_eq "直驱 pty:车道内滚轮事件注入成功(6.2)" "$?" "0"
932
+ if grep -qE 'D0[1-5]' "$tmp/$current/wheel-lane-after.bin" 2>/dev/null; then
933
+ ok "车道内滚轮上滚:done 窗口移到更旧的卡片(原先隐藏的 D01–D05 进入视图)"
934
+ else
935
+ bad "车道内滚轮上滚后没有看到原先隐藏的 done 卡片(车道没有滚动)"
936
+ fi
937
+
938
+ # 6.1: a click on a card focuses it — in the injected instance's own bytes, the focus cursor has
939
+ # to move onto the clicked card (the start of the frame puts it on the first card of `todo`).
940
+ B3_STUB_DONE=20 python3 "$pty_direct" --js "$js" --panel "$panel" --root "$ROOT" --state-dir "$state" \
941
+ --team-cli "$stub" --out "$tmp/$current/click-card.bin" --expect-enable yes \
942
+ --click-col 25 --click-row 4 --cols 120 --rows 32 >"$tmp/$current/click-card.log" 2>&1
943
+ assert_eq "直驱 pty:卡片点击注入成功(6.1)" "$?" "0"
944
+ click_moved="$(python3 - "$tmp/$current/click-card.bin" <<'PYM'
945
+ import re, sys
946
+
947
+ raw = open(sys.argv[1], "rb").read().decode("utf-8", "replace")
948
+ clean = re.sub(r"\x1b\[[0-9;?]*[A-Za-z]", "", raw)
949
+ # The cursor glyph followed by the clicked card's id on the same written row.
950
+ print("ok" if re.search(r"›\s*(?:[·▸◆✓✗—]\s*)?P14", clean) else "no")
951
+ PYM
952
+ )"
953
+ if [ "$click_moved" = "ok" ]; then
954
+ ok "点击 wip 车道第一张卡后焦点光标落在 P14 上(点击 = 聚焦)"
955
+ else
956
+ bad "点击卡片后焦点没有移到被点的卡($click_moved)"
957
+ fi
958
+ }
959
+
960
+ scn_detail() {
961
+ section "detail · 详情视图:打开/返回 / tab / 滚动 / 只读 / 首帧(9.1–9.4)"
962
+ server_up detail
963
+ dcap() { cap > "$tmp/$current/$1.txt"; }
964
+ dfile() { printf '%s/%s.txt' "$tmp/$current" "$1"; }
965
+ local docs_before other_before
966
+ # Real files under docs/ so the read-only proof has something to hash; the data itself is the stub.
967
+ mkdir -p "$ROOT/docs/team/tasks" "$ROOT/docs/team/reports" "$ROOT/docs/team/reviews"
968
+ printf '# fixture board\n' > "$ROOT/docs/team/BOARD.md"
969
+ printf '# V14 · real brief\n\nhand-written\n' > "$ROOT/docs/team/tasks/V14-a.md"
970
+ printf '# V14 · real report\n' > "$ROOT/docs/team/reports/V14-dev.md"
971
+ printf '# V14 · real review\n' > "$ROOT/docs/team/reviews/V14.md"
972
+ printf '# V14 · real review (done)\n' > "$ROOT/docs/team/reviews/V14-done.md"
973
+ conf_set "lang=zh" "page=4" "activity=1" "mouse=1" "density=comfortable" "theme=dark"
974
+ printf '4\n' > "$(page_file)"
975
+ # 9.3's baseline: everything under docs/ plus every state file except the console's own three
976
+ # (draft.md / panel.conf / panel-page — the console is allowed to write exactly those).
977
+ docs_before="$(cd "$ROOT" && find docs -type f | sort | xargs -r md5sum | md5sum)"
978
+ other_before="$(cd "$ROOT" && find .pi/team/state -type f ! -name draft.md ! -name panel.conf ! -name panel-page | sort | xargs -r md5sum | md5sum)"
979
+ start_panel
980
+ dcap board
981
+ assert_has "$(dfile board)" "已放弃" "夹具:控制台停在看板页(六车道在场)"
982
+
983
+ # 9.1 + 9.4: Enter opens the focused card's detail; the first detail frame is timed from the key,
984
+ # then the view is waited for (the first frame is the loading state — the block is one child away).
985
+ local t0 t1 opened=1 i
986
+ t0="$(date +%s.%N)"
987
+ keys Enter
988
+ for i in $(seq 1 40); do
989
+ if { cap || true; } | grep -qF '详情'; then opened=0; break; fi
990
+ sleep 0.03
991
+ done
992
+ t1="$(date +%s.%N)"
993
+ assert_eq "Enter 后 1.2s 内出现详情视图" "$opened" "0"
994
+ printf ' \033[36m·\033[0m 首帧耗时(Enter→详情标题上屏):%ss\n' "$(awk -v a="$t0" -v b="$t1" 'BEGIN { printf "%.3f", b - a }')"
995
+ for i in $(seq 1 40); do
996
+ if { cap || true; } | grep -qF '[brief]'; then break; fi
997
+ sleep 0.05
998
+ done
999
+ dcap open
1000
+ assert_has "$(dfile open)" "详情 V14" "详情视图打开(卡片聚焦的入口)"
1001
+ assert_has "$(dfile open)" "[brief]" "第一个文件 tab 默认打开"
1002
+ assert_has "$(dfile open)" "fixture brief" "详情视图渲染了 brief 的正文"
1003
+ assert_has "$(dfile open)" "verbatim fence body" "围栏代码块正文原样上屏"
1004
+ assert_not "$(dfile open)" "已放弃" "详情视图替换了看板块(替换块不留内容)"
1005
+
1006
+ # 9.2: ←/→ switch files, ↑/↓ scroll the document.
1007
+ keys Right
1008
+ sleep 0.8
1009
+ dcap report
1010
+ assert_has "$(dfile report)" "[report:dev]" "→ 切到第二个文件 tab"
1011
+ assert_has "$(dfile report)" "report line 01" "报告的正文从第一行开始"
1012
+ for i in 1 2 3 4 5 6 7 8; do keys Down; sleep 0.08; done
1013
+ sleep 0.6
1014
+ dcap scrolled
1015
+ assert_has "$(dfile scrolled)" "report line 09" "↓×8 把文档窗口后移(第 9 行进入视图)"
1016
+ assert_not "$(dfile scrolled)" "report line 01" "滚动后第 1 行移出窗口"
1017
+ keys Up
1018
+ sleep 0.5
1019
+ dcap scrolled-back
1020
+ assert_has "$(dfile scrolled-back)" "report line 08" "↑ 往回滚一行(第 8 行回到视图)"
1021
+
1022
+ # 9.1: q and Esc both return to the board page without collapsing the console.
1023
+ keys q
1024
+ sleep 0.8
1025
+ dcap back-q
1026
+ assert_has "$(dfile back-q)" "已放弃" "q 返回看板页"
1027
+ assert_not "$(dfile back-q)" "详情 V14" "q 之后详情视图关闭"
1028
+ local pane_pid args
1029
+ pane_pid="$(tmux -L "$sock" list-panes -t "$sess:panel" -F '#{pane_pid}' | head -1)"
1030
+ args="$(ps -o args= -p "$pane_pid" 2>/dev/null || true)"
1031
+ if printf '%s' "$args" | grep -q 'panel.js' && ! printf '%s' "$args" | grep -q -- '--headless'; then
1032
+ ok "q 没有收起控制台(窗口进程仍是渲染器:$(printf '%s' "$args" | tr -s ' ' | cut -c1-60))"
1033
+ else
1034
+ bad "q 之后窗口进程不是渲染器:$args"
1035
+ fi
1036
+ keys Enter
1037
+ sleep 0.8
1038
+ keys Escape
1039
+ sleep 0.8
1040
+ dcap back-esc
1041
+ assert_has "$(dfile back-esc)" "已放弃" "Esc 返回看板页"
1042
+ assert_not "$(dfile back-esc)" "详情 V14" "Esc 之后详情视图关闭"
1043
+
1044
+ # 9.3: read-only — only the console's own three state files may differ after the session.
1045
+ local docs_after other_after
1046
+ docs_after="$(cd "$ROOT" && find docs -type f | sort | xargs -r md5sum | md5sum)"
1047
+ other_after="$(cd "$ROOT" && find .pi/team/state -type f ! -name draft.md ! -name panel.conf ! -name panel-page | sort | xargs -r md5sum | md5sum)"
1048
+ assert_eq "详情会话没有写 docs/ 下任何文件" "$docs_before" "$docs_after"
1049
+ assert_eq "详情会话没有写 state/ 下除控制台自有三文件之外的任何文件" "$other_before" "$other_after"
1050
+
1051
+ # 9.2 [real] mouse: a click on a tab switches files; the wheel scrolls the document (the driver's
1052
+ # own byte stream is the evidence, because tmux keeps wheel events for itself — measured in the
1053
+ # board scenario).
1054
+ python3 "$pty_direct" --js "$js" --panel "$panel" --root "$ROOT" --state-dir "$state" --team-cli "$stub" \
1055
+ --out "$tmp/$current/detail-open.bin" --out2 "$tmp/$current/detail-click.bin" --expect-enable yes --no-click \
1056
+ --send enter --click2-col 27 --click2-row 4 --cols 120 --rows 32 >"$tmp/$current/detail-click.log" 2>&1
1057
+ assert_eq "直驱 pty:详情视图里点 review tab 注入成功" "$?" "0"
1058
+ detail_clean() { python3 - "$1" <<'PYD'
1059
+ import re, sys
1060
+ raw = open(sys.argv[1], "rb").read().decode("utf-8", "replace")
1061
+ print(re.sub(r"\x1b\[[0-9;?]*[A-Za-z]", "", raw))
1062
+ PYD
1063
+ }
1064
+ # A redirect, not a pipe: `grep -q` exits early and a piped python would die with SIGPIPE under
1065
+ # `set -o pipefail`, turning a match into a failure (measured while writing this fixture).
1066
+ detail_clean "$tmp/$current/detail-click.bin" > "$tmp/$current/detail-click.txt"
1067
+ assert_has "$tmp/$current/detail-click.txt" '[review]' "点击 tab 行切到 review([review] 高亮)"
1068
+ python3 "$pty_direct" --js "$js" --panel "$panel" --root "$ROOT" --state-dir "$state" --team-cli "$stub" \
1069
+ --out "$tmp/$current/detail-wheel.bin" --out2 "$tmp/$current/detail-wheel-after.bin" --expect-enable yes --no-click \
1070
+ --send enter,right --wheel down --wheel-clicks 6 --click-col 60 --click-row 8 --cols 120 --rows 32 \
1071
+ >"$tmp/$current/detail-wheel.log" 2>&1
1072
+ assert_eq "直驱 pty:详情视图里滚轮注入成功" "$?" "0"
1073
+ detail_clean "$tmp/$current/detail-wheel-after.bin" > "$tmp/$current/detail-wheel.txt"
1074
+ if grep -qE 'report line (09|1[0-9])' "$tmp/$current/detail-wheel.txt"; then
1075
+ ok "滚轮把详情文档窗口后移(更靠后的报告行上屏)"
1076
+ else
1077
+ bad "滚轮没有让详情文档滚动"
1078
+ fi
1079
+
1080
+ # 8.2 [real]: a hostile fixture text embedding ESC [2J cannot inject escape sequences into the
1081
+ # pane — the reader strips the raw control byte and the panel's sanitizer drops the CSI sequence,
1082
+ # so the frame survives and only the fence's visible text shows (the plain capture carries no
1083
+ # 0x1b byte, and the -e capture carries no injected clear).
1084
+ python3 - "$tmp/$current/hostile.json" <<'PYX'
1085
+ import json, sys
1086
+
1087
+ doc = "```\nBEFORE\u001b[2JAFTER\n```\n"
1088
+ json.dump({"id": "X3", "count": 1, "file": "docs/team/tasks/X3-a.md", "text": doc, "truncated": False,
1089
+ "files": [{"tab": "brief", "name": "X3-a.md", "path": "docs/team/tasks/X3-a.md", "size": 40, "truncated": False}]},
1090
+ open(sys.argv[1], "w", encoding="utf-8"), ensure_ascii=False)
1091
+ PYX
1092
+ start_panel "B3_STUB_DETAIL_FILE='$tmp/$current/hostile.json'"
1093
+ keys Enter
1094
+ sleep 1.0
1095
+ cap > "$tmp/$current/hostile-plain.txt"
1096
+ tmux -L "$sock" capture-pane -p -e -t "$sess:panel" > "$tmp/$current/hostile-esc.txt" 2>/dev/null
1097
+ assert_has "$tmp/$current/hostile-plain.txt" "BEFORE" "敌意字节:围栏前的可见文本仍在(帧没被清屏)"
1098
+ assert_has "$tmp/$current/hostile-plain.txt" "AFTER" "敌意字节:围栏后的可见文本仍在"
1099
+ if LC_ALL=C grep -q $'\x1b' "$tmp/$current/hostile-plain.txt"; then
1100
+ bad "敌意字节:纯文本捕获里出现了 0x1b"
1101
+ else
1102
+ ok "敌意字节:纯文本捕获里没有 0x1b 字节"
1103
+ fi
1104
+ if grep -qF '[2J' "$tmp/$current/hostile-esc.txt"; then
1105
+ bad "敌意字节:带转义的捕获里出现了注入的 [2J"
1106
+ else
1107
+ ok "敌意字节:带转义的捕获里没有注入的清屏序列"
1108
+ fi
1109
+ }
1110
+
1111
+ # ---------------------------------------------------------------- P123 fold (看板卡片与车道折叠)
1112
+ scn_fold() {
1113
+ section "fold · 看板折叠:c 键 / 车道头点击 / 滚轮 / 空车道默认 / 重启持久化(P123)"
1114
+ server_up fold
1115
+ fcap() { cap > "$tmp/$current/$1.txt"; }
1116
+ ffile() { printf '%s/%s.txt' "$tmp/$current" "$1"; }
1117
+ # The display column (1-based) where the <nth> occurrence of <needle> starts. The default is
1118
+ # the first occurrence; a folded lane's frame is found with its corner glyph `╭─╮` (the rows of
1119
+ # two frames look alike, so the caller picks the ordinal instead of a label the frame cannot
1120
+ # carry).
1121
+ lane_col() { # <capture file> <needle> [nth]
1122
+ python3 - "$1" "$2" "${3:-1}" <<'PYC'
1123
+ import re, sys
1124
+
1125
+ WIDE = [(0x1100, 0x115f), (0x2e80, 0x303e), (0x3041, 0x33ff), (0x3400, 0x4dbf), (0x4e00, 0x9fff),
1126
+ (0xa000, 0xa4cf), (0xac00, 0xd7a3), (0xf900, 0xfaff), (0xfe10, 0xfe19), (0xfe30, 0xfe6f),
1127
+ (0xff00, 0xff60), (0xffe0, 0xffe6), (0x1f300, 0x1f64f), (0x1f900, 0x1f9ff)]
1128
+
1129
+ def dw(text):
1130
+ total = 0
1131
+ for ch in text:
1132
+ cp = ord(ch)
1133
+ if cp in (0x200d, 0xfe0f) or 0x0300 <= cp <= 0x036f:
1134
+ continue
1135
+ total += 2 if any(a <= cp <= b for a, b in WIDE) else 1
1136
+ return total
1137
+
1138
+ rows = [re.sub(r"\x1b\[[0-9;]*m", "", l.rstrip("\n")) for l in open(sys.argv[1], encoding="utf-8")]
1139
+ needle, want = sys.argv[2], int(sys.argv[3])
1140
+ seen = 0
1141
+ for row in rows:
1142
+ i = -1
1143
+ while True:
1144
+ i = row.find(needle, i + 1)
1145
+ if i < 0:
1146
+ break
1147
+ seen += 1
1148
+ if seen == want:
1149
+ print(dw(row[:i]) + 1)
1150
+ sys.exit(0)
1151
+ PYC
1152
+ }
1153
+ conf_set "lang=zh" "page=4" "activity=1" "mouse=1" "density=comfortable" "theme=dark"
1154
+ printf '4\n' > "$(page_file)"
1155
+ start_panel
1156
+ # Default: the empty review/dropped lanes fold to their three-column frames; the focus sits on
1157
+ # the todo card.
1158
+ sleep 0.8
1159
+ fcap p123-default
1160
+ assert_not "$(ffile p123-default)" "▸ 待复验 0(已折叠)" "宽档:空车道不再是原地一行"
1161
+ assert_has "$(ffile p123-default)" "╭─╮" "空车道默认折叠(三列小框:圆角 + 省略号列)"
1162
+ assert_has "$(ffile p123-default)" "▾ 待办 1" "展开的车道头带镜像标记"
1163
+ focused_row "$(ffile p123-default)" > "$tmp/$current/p123-default-row.txt"
1164
+ assert_has "$tmp/$current/p123-default-row.txt" "V14" "初始焦点在 todo 的 V14"
1165
+ # `c` folds the focused lane and writes the explicit state at once.
1166
+ keys c
1167
+ sleep 1
1168
+ fcap p123-folded
1169
+ assert_has "$(ffile p123-folded)" "╭─╮" "c 把焦点车道折成三列小框"
1170
+ assert_not "$(ffile p123-folded)" "▸ 待办 1(已折叠)" "宽档折叠后不再画原地一行"
1171
+ assert_not "$(ffile p123-folded)" "V14" "折叠后该车道不再建卡片行"
1172
+ assert_has "$(ffile p123-folded)" "待办 1" "聚焦折叠车道的标签与计数显示在底栏(三列放不下标签)"
1173
+ focused_row "$(ffile p123-folded)" > "$tmp/$current/p123-folded-row.txt"
1174
+ assert_has "$tmp/$current/p123-folded-row.txt" "│›│" "聚焦车道折叠时焦点光标落在三列小框里(恰好一个)"
1175
+ conf_of > "$tmp/$current/p123-conf-folded.txt"
1176
+ assert_match "$tmp/$current/p123-conf-folded.txt" '^boardFold=todo$' "c 立即把 boardFold=todo 写进 panel.conf"
1177
+ # ↑/↓ no-op while the focused lane is folded; ←/→ still stop on it; Enter still opens the card.
1178
+ keys Down
1179
+ sleep 0.6
1180
+ fcap p123-down
1181
+ focused_row "$(ffile p123-down)" > "$tmp/$current/p123-down-row.txt"
1182
+ assert_has "$tmp/$current/p123-down-row.txt" "│›│" "聚焦车道折叠时 ↓ 不动焦点"
1183
+ keys Right
1184
+ sleep 0.8
1185
+ fcap p123-right
1186
+ focused_row "$(ffile p123-right)" > "$tmp/$current/p123-right-row.txt"
1187
+ assert_has "$tmp/$current/p123-right-row.txt" "P14" "→ 仍能走到(折叠车道之外的)下一车道卡片"
1188
+ keys Left
1189
+ sleep 0.8
1190
+ fcap p123-left
1191
+ focused_row "$(ffile p123-left)" > "$tmp/$current/p123-left-row.txt"
1192
+ assert_has "$tmp/$current/p123-left-row.txt" "│›│" "← 仍然停在持卡的折叠车道上"
1193
+ keys Enter
1194
+ sleep 1.4
1195
+ fcap p123-detail
1196
+ assert_has "$(ffile p123-detail)" "详情 V14" "Enter 仍打开折叠车道里焦点卡的详情"
1197
+ keys Escape
1198
+ sleep 0.8
1199
+ # Restart: the explicit fold survives.
1200
+ start_panel
1201
+ sleep 0.8
1202
+ fcap p123-restart
1203
+ assert_not "$(ffile p123-restart)" "▾ 待办 1" "重启后 todo 仍折叠(显式状态持久:展开头不出现)"
1204
+ assert_has "$(ffile p123-restart)" "│›│" "重启后 todo 的三列小框仍带焦点光标"
1205
+ assert_has "$(ffile p123-restart)" "待办 1" "重启后底栏仍点名被聚焦的折叠车道"
1206
+ # A second `c` is an explicit unfold, and it sticks across emptiness (review stays boxed).
1207
+ keys c
1208
+ sleep 1
1209
+ fcap p123-unfolded
1210
+ assert_has "$(ffile p123-unfolded)" "▾ 待办 1" "第二次 c 显式展开 todo"
1211
+ focused_row "$(ffile p123-unfolded)" > "$tmp/$current/p123-unfolded-row.txt"
1212
+ assert_has "$tmp/$current/p123-unfolded-row.txt" "V14" "第二次 c 展开后焦点仍落在同一张卡(V14)"
1213
+ conf_of > "$tmp/$current/p123-conf-shown.txt"
1214
+ assert_match "$tmp/$current/p123-conf-shown.txt" '^boardShow=todo$' "显式展开写 boardShow=todo"
1215
+ # The empty-lane default can be turned off: the empty lanes render boxed with the dim marker.
1216
+ keys c
1217
+ sleep 0.6 # (todo folded again; the next restart reads the file below)
1218
+ conf_set "lang=zh" "page=4" "activity=1" "mouse=1" "density=comfortable" "theme=dark" "boardEmptyFold=0"
1219
+ start_panel
1220
+ sleep 0.8
1221
+ fcap p123-emptyoff
1222
+ assert_has "$(ffile p123-emptyoff)" "▾ 待复验 0" "boardEmptyFold=0:空车道展开成盒子"
1223
+ assert_not "$(ffile p123-emptyoff)" "▸ 待复验 0(已折叠)" "boardEmptyFold=0:空车道不再默认折叠"
1224
+ # A click on a lane's header line toggles that lane: click the folded review line (row 3 = the
1225
+ # board's header row) and the conf records the explicit unfold.
1226
+ conf_set "lang=zh" "page=4" "activity=1" "mouse=1" "density=comfortable" "theme=dark"
1227
+ start_panel
1228
+ sleep 0.8
1229
+ fcap p123-clickbase
1230
+ review_col="$(lane_col "$(ffile p123-clickbase)" '╭─╮' 1)"
1231
+ python3 "$pty_direct" --js "$js" --panel "$panel" --root "$ROOT" --state-dir "$state" --team-cli "$stub" \
1232
+ --out "$tmp/$current/p123-click.bin" --expect-enable yes \
1233
+ --click-col "${review_col:-40}" --click-row 3 --cols 120 --rows 32 >"$tmp/$current/p123-click.log" 2>&1
1234
+ assert_eq "直驱 pty:折叠车道头上的点击注入成功" "$?" "0"
1235
+ conf_of > "$tmp/$current/p123-conf-click.txt"
1236
+ assert_match "$tmp/$current/p123-conf-click.txt" '^boardShow=review$' "点击折叠车道头 = 展开该车道(写 boardShow)"
1237
+ # The wheel over a folded line is that lane's region: the folded lane has nothing to scroll, and
1238
+ # the page behind is not the target either — the fold stays folded and no card appears.
1239
+ conf_set "lang=zh" "page=4" "activity=1" "mouse=1" "density=comfortable" "theme=dark" "boardFold=done"
1240
+ start_panel
1241
+ sleep 0.8
1242
+ fcap p123-wheelbase
1243
+ done_col="$(lane_col "$(ffile p123-wheelbase)" '╭─╮' 2)"
1244
+ python3 "$pty_direct" --js "$js" --panel "$panel" --root "$ROOT" --state-dir "$state" --team-cli "$stub" \
1245
+ --out "$tmp/$current/p123-wheel.bin" --out2 "$tmp/$current/p123-wheel-after.bin" --expect-enable yes --no-click \
1246
+ --wheel down --wheel-clicks 3 --click-col "${done_col:-60}" --click-row 3 --cols 120 --rows 32 \
1247
+ >"$tmp/$current/p123-wheel.log" 2>&1
1248
+ assert_eq "直驱 pty:折叠车道线上的滚轮注入成功" "$?" "0"
1249
+ if grep -aq 'P13' "$tmp/$current/p123-wheel-after.bin" 2>/dev/null || grep -aq '▾ 完成' "$tmp/$current/p123-wheel-after.bin" 2>/dev/null; then
1250
+ bad "滚轮在折叠车道线上把折叠翻开了(出现卡片或展开的车道头)"
1251
+ else
1252
+ ok "滚轮在折叠车道线上:折叠保持、没有卡片出现(页面没被滚动)"
1253
+ fi
1254
+ # The header of an *unfolded* lane keeps that lane's wheel region (the pre-P123 behaviour).
1255
+ conf_set "lang=zh" "page=4" "activity=1" "mouse=1" "density=comfortable" "theme=dark"
1256
+ printf '4\n' > "$(page_file)"
1257
+ start_panel "B3_STUB_DONE=20"
1258
+ sleep 0.8
1259
+ fcap p123-hwheelbase
1260
+ done_col="$(lane_col "$(ffile p123-hwheelbase)" '▾ 完成')"
1261
+ B3_STUB_DONE=20 python3 "$pty_direct" --js "$js" --panel "$panel" --root "$ROOT" --state-dir "$state" --team-cli "$stub" \
1262
+ --out "$tmp/$current/p123-hwheel.bin" --out2 "$tmp/$current/p123-hwheel-after.bin" --expect-enable yes --no-click \
1263
+ --wheel up --wheel-clicks 3 --click-col "${done_col:-60}" --click-row 3 --cols 120 --rows 32 \
1264
+ >"$tmp/$current/p123-hwheel.log" 2>&1
1265
+ assert_eq "直驱 pty:展开车道头上的滚轮注入成功" "$?" "0"
1266
+ if grep -aqE 'D0[1-5]' "$tmp/$current/p123-hwheel-after.bin" 2>/dev/null; then
1267
+ ok "展开车道头上的滚轮仍滚该车道(原先隐藏的 D01–D05 进入视图)"
1268
+ else
1269
+ bad "展开车道头上的滚轮没有滚动它的车道(车道区域丢了)"
1270
+ fi
1271
+ }
1272
+
1273
+ # ---------------------------------------------------------------- run
1274
+ want=("$@")
1275
+ run_scn() {
1276
+ local name="$1"
1277
+ if [ ${#want[@]} -gt 0 ]; then
1278
+ local w
1279
+ for w in "${want[@]}"; do [ "$w" = "$name" ] && { "$2"; return; }; done
1280
+ return
1281
+ fi
1282
+ "$2"
1283
+ }
1284
+
1285
+ run_scn pages scn_pages
1286
+ run_scn settings scn_settings
1287
+ run_scn conf scn_conf
1288
+ run_scn queue scn_queue
1289
+ run_scn board scn_board
1290
+ run_scn fold scn_fold
1291
+ run_scn detail scn_detail
1292
+ run_scn workdetail scn_workdetail
1293
+ run_scn mouse scn_mouse
1294
+ run_scn wheel scn_wheel
1295
+ run_scn resize scn_resize
1296
+ run_scn collapse scn_collapse
1297
+
1298
+ printf '\n\033[1m== 结果 ==\033[0m ✓ %d ✗ %d\n' "$PASS" "$FAIL"
1299
+ [ "$FAIL" -eq 0 ] && { printf '\033[32mpanel-b3 全绿\033[0m\n'; exit 0; }
1300
+ printf '\033[31mpanel-b3 有失败项(TEAM_B3_KEEP=1 保留现场)\033[0m\n'
1301
+ exit 1