teamsmith 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/README.md +4 -4
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +28 -0
  4. package/skills/teamsmith/SKILL.md +14 -7
  5. package/skills/teamsmith/extension/team-notify.ts +37 -6
  6. package/skills/teamsmith/extension/team.ts +438 -0
  7. package/skills/teamsmith/references/config.md +39 -6
  8. package/skills/teamsmith/references/migration.md +197 -47
  9. package/skills/teamsmith/references/protocol.md +176 -19
  10. package/skills/teamsmith/references/troubleshooting.md +124 -7
  11. package/skills/teamsmith/references/workflows.md +36 -2
  12. package/skills/teamsmith/scripts/lib/cmd-agents.sh +318 -23
  13. package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +2 -2
  14. package/skills/teamsmith/scripts/lib/cmd-config.sh +349 -67
  15. package/skills/teamsmith/scripts/lib/cmd-draft.sh +4 -4
  16. package/skills/teamsmith/scripts/lib/cmd-help.sh +677 -0
  17. package/skills/teamsmith/scripts/lib/cmd-init.sh +157 -5
  18. package/skills/teamsmith/scripts/lib/cmd-interrupt.sh +461 -0
  19. package/skills/teamsmith/scripts/lib/cmd-meeting.sh +2 -25
  20. package/skills/teamsmith/scripts/lib/cmd-project.sh +30 -103
  21. package/skills/teamsmith/scripts/lib/cmd-reap.sh +277 -0
  22. package/skills/teamsmith/scripts/lib/cmd-reply.sh +3 -3
  23. package/skills/teamsmith/scripts/lib/cmd-review.sh +175 -30
  24. package/skills/teamsmith/scripts/lib/cmd-status.sh +226 -17
  25. package/skills/teamsmith/scripts/lib/cmd-update.sh +36 -7
  26. package/skills/teamsmith/scripts/lib/cmd-watch.sh +564 -46
  27. package/skills/teamsmith/scripts/lib/common.sh +773 -48
  28. package/skills/teamsmith/scripts/lib/gate-lock.sh +544 -0
  29. package/skills/teamsmith/scripts/panel/draft-send.sh +11 -1
  30. package/skills/teamsmith/scripts/panel/panel.js +207 -207
  31. package/skills/teamsmith/scripts/panel/src/App.tsx +58 -21
  32. package/skills/teamsmith/scripts/panel/src/clipboard.ts +11 -5
  33. package/skills/teamsmith/scripts/panel/src/compose.ts +6 -3
  34. package/skills/teamsmith/scripts/panel/src/data.ts +11 -3
  35. package/skills/teamsmith/scripts/panel/src/layout.ts +209 -69
  36. package/skills/teamsmith/scripts/panel/src/main.tsx +33 -8
  37. package/skills/teamsmith/scripts/panel/src/strings/en.ts +39 -29
  38. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +41 -31
  39. package/skills/teamsmith/scripts/panel/src/types.ts +28 -3
  40. package/skills/teamsmith/scripts/replies.mjs +4 -1
  41. package/skills/teamsmith/scripts/shim/tmux +18 -0
  42. package/skills/teamsmith/scripts/strings/commands.tsv +86 -0
  43. package/skills/teamsmith/scripts/strings/help.en.tsv +503 -0
  44. package/skills/teamsmith/scripts/strings/help.zh.tsv +489 -0
  45. package/skills/teamsmith/scripts/team +19 -6
  46. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +8 -1
  47. package/skills/teamsmith/templates/config.sh.tmpl +20 -1
  48. package/skills/teamsmith/templates/pm-prompt.md.tmpl +21 -0
  49. package/skills/teamsmith/tests/bg-ledger-harness.mjs +464 -40
  50. package/skills/teamsmith/tests/bg-ledger.sh +168 -10
  51. package/skills/teamsmith/tests/checkout-shape-probe.sh +3 -1
  52. package/skills/teamsmith/tests/config-cli.sh +160 -14
  53. package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +7 -1
  54. package/skills/teamsmith/tests/fixtures/p287/lint-good.sh.in +3 -0
  55. package/skills/teamsmith/tests/fixtures/p287/lint-hardcoded.sh.in +3 -0
  56. package/skills/teamsmith/tests/fixtures/p287/lint-no-ns.sh.in +3 -0
  57. package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +18 -6
  58. package/skills/teamsmith/tests/flip-m33.sh +5 -3
  59. package/skills/teamsmith/tests/flip-m37.sh +4 -1
  60. package/skills/teamsmith/tests/flip-m4.3.sh +4 -1
  61. package/skills/teamsmith/tests/flip-m6.3.sh +4 -1
  62. package/skills/teamsmith/tests/flip-m6.5.sh +4 -1
  63. package/skills/teamsmith/tests/flip-m7.2.sh +4 -1
  64. package/skills/teamsmith/tests/flip-p158.sh +2 -1
  65. package/skills/teamsmith/tests/flip-p210.sh +4 -1
  66. package/skills/teamsmith/tests/flip-p217.sh +4 -1
  67. package/skills/teamsmith/tests/flip-p287-lock.sh +342 -0
  68. package/skills/teamsmith/tests/flip-p287-name.sh +279 -0
  69. package/skills/teamsmith/tests/flip-p304-read-side.sh +98 -0
  70. package/skills/teamsmith/tests/flip-p308-skip-not-pass.sh +151 -0
  71. package/skills/teamsmith/tests/flip-p309-p162-deep.sh +122 -0
  72. package/skills/teamsmith/tests/flip-p310-lock.sh +216 -0
  73. package/skills/teamsmith/tests/flip-p310-socket.sh +125 -0
  74. package/skills/teamsmith/tests/help-surface.sh +1664 -0
  75. package/skills/teamsmith/tests/install-shape.sh +279 -20
  76. package/skills/teamsmith/tests/key-replies-pty.sh +9 -10
  77. package/skills/teamsmith/tests/key-replies-ui.sh +0 -7
  78. package/skills/teamsmith/tests/key-replies.sh +240 -1
  79. package/skills/teamsmith/tests/ledger-ban.sh +5 -4
  80. package/skills/teamsmith/tests/ledger-claim.sh +2 -1
  81. package/skills/teamsmith/tests/lib/bounded-spin.sh +90 -0
  82. package/skills/teamsmith/tests/lib/model-policy.sh +4 -0
  83. package/skills/teamsmith/tests/lib/model-routing-flips.py +51 -0
  84. package/skills/teamsmith/tests/lib/reply-fixture.sh +4 -9
  85. package/skills/teamsmith/tests/lib/section-guard.sh +258 -13
  86. package/skills/teamsmith/tests/lib/tmp-root.sh +139 -27
  87. package/skills/teamsmith/tests/lib/tmux-cap.sh +10 -1
  88. package/skills/teamsmith/tests/lib/tmux-iso.sh +31 -13
  89. package/skills/teamsmith/tests/loop-inventory.tsv +59 -47
  90. package/skills/teamsmith/tests/panel-b2.sh +106 -3
  91. package/skills/teamsmith/tests/panel-b3-stub.sh +112 -4
  92. package/skills/teamsmith/tests/panel-b3.sh +175 -19
  93. package/skills/teamsmith/tests/panel-choices.sh +11 -6
  94. package/skills/teamsmith/tests/panel-cpu.sh +2 -1
  95. package/skills/teamsmith/tests/panel-knobs.sh +7 -1
  96. package/skills/teamsmith/tests/panel-p21.sh +156 -73
  97. package/skills/teamsmith/tests/panel-snapshots.sh +41 -225
  98. package/skills/teamsmith/tests/panel-strings.mjs +33 -18
  99. package/skills/teamsmith/tests/perf.sh +121 -30
  100. package/skills/teamsmith/tests/routes.sh +327 -93
  101. package/skills/teamsmith/tests/seat-interrupt.sh +1002 -0
  102. package/skills/teamsmith/tests/seat-visibility.sh +675 -0
  103. package/skills/teamsmith/tests/section-budgets.tsv +20 -10
  104. package/skills/teamsmith/tests/section-guard.sh +6 -1
  105. package/skills/teamsmith/tests/section-needs-audit.sh +24 -7
  106. package/skills/teamsmith/tests/section-paths.tsv +19 -13
  107. package/skills/teamsmith/tests/section-select.sh +8 -1
  108. package/skills/teamsmith/tests/slash-team-e2e.sh +323 -0
  109. package/skills/teamsmith/tests/slash-team.sh +617 -0
  110. package/skills/teamsmith/tests/smoke.sh +2972 -440
  111. package/skills/teamsmith/tests/task-model-routing.sh +507 -10
  112. package/skills/teamsmith/tests/tmp-hygiene.sh +782 -45
  113. package/skills/teamsmith/tests/tmux-identity-leak.sh +773 -0
  114. package/skills/teamsmith/tests/tmux-lint-legacy.txt +12 -18
  115. package/skills/teamsmith/tests/upgrade-recipe.sh +537 -0
  116. package/skills/teamsmith-init/SKILL.md +12 -12
  117. package/skills/teamsmith-init/references/bootstrap.md +3 -3
@@ -0,0 +1,617 @@
1
+ #!/usr/bin/env bash
2
+ # slash-team.sh — `/team` 扩展的**纯逻辑层**夹具(change: slash-team · 实现:P270)
3
+ #
4
+ # bash skills/teamsmith/tests/slash-team.sh [--select <g1,g2>] [--flip] [--keep]
5
+ # bash skills/teamsmith/tests/slash-team.sh # 全部组(含表↔CLI 探针)
6
+ #
7
+ # 组:command tokens whitelist menu refuse output env resolve probe
8
+ # command 只注册一条命令、零工具注册、零确认框
9
+ # tokens 用户打的 token 逐字交给子进程(引号/空格/反斜杠/未闭合)
10
+ # whitelist 读行严格形状、动行自由尾巴、表外拒绝
11
+ # menu 菜单与补全从同一张表渲染(夹具独立重算表 → 逐字比对)
12
+ # refuse 拒绝路径零副作用(零 exec)+ 文案点名
13
+ # output 短/长/失败/被杀/超量 五格落点与退出码
14
+ # env 剥离三个「替你说 yes」的变量、不注入 --yes
15
+ # resolve 项目根向上找、CLI 解析顺序(项目本地 → TEAM_CLI → 兄弟目录)
16
+ # probe 表里每行路径喂 `--teamsmith-slash-probe`,不得得到顶层「未知子命令:<命令>」
17
+ #
18
+ # `--flip`:把实现逐条改坏(scratch 副本),要求**具名组**变红、真实源保持绿 —— 证明这套夹具会咬人。
19
+ # 纯逻辑组零进程;只有 probe 组起真 CLI(read-only 的 `--teamsmith-slash-probe` 探针)。
20
+ #
21
+ # 退出码:0 全绿;1 有失败;2 用法错误;3 setup 失败(缺 bun / 源文件)。
22
+ set -uo pipefail
23
+
24
+ here="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
25
+ tree="$(cd -P "$here/../../.." && pwd)"
26
+ . "$here/lib/tmp-root.sh"
27
+
28
+ SEL_GROUPS=""
29
+ FLIP=0
30
+ KEEP=0
31
+ argc=$#
32
+ while [ $# -gt 0 ]; do
33
+ case "$1" in
34
+ --all) SEL_GROUPS=""; shift ;;
35
+ --select) SEL_GROUPS="${2:?--select 需要组名}"; shift 2 ;;
36
+ --select=*) SEL_GROUPS="${1#*=}"; shift ;;
37
+ --flip) FLIP=1; shift ;;
38
+ --keep) KEEP=1; export TEAM_TMP_KEEP=1; shift ;;
39
+ -h|--help) sed -n '2,20p' "$0"; exit 0 ;;
40
+ *) printf 'slash-team: 未知参数 %s(用法见 --help)\n' "$1" >&2; exit 2 ;;
41
+ esac
42
+ # 每个分支都必须 shift:`--keep` 曾经漏了 shift,脚本于是永不退出、零输出地空转
43
+ # (PM 2026-10-16 收掉过一个挂了 1h35m 的 --keep 进程)。这条守卫把同一类缺陷变成
44
+ # 立刻可见的 rc=2,而不是一个静默的死循环。
45
+ [ "$#" -lt "$argc" ] || { printf '%s: 参数循环没有前进(分支缺 shift?):%s\n' "slash-team" "$1" >&2; exit 2; }
46
+ argc=$#
47
+ done
48
+
49
+ ext="$tree/skills/teamsmith/extension/team.ts"
50
+ [ -f "$ext" ] || { printf 'slash-team: 没有扩展源 %s\n' "$ext" >&2; exit 3; }
51
+
52
+ BUN="${TEAM_SLASH_BUN:-$(command -v bun 2>/dev/null || true)}"
53
+ [ -n "$BUN" ] || [ -x "$HOME/.bun/bin/bun" ] && BUN="${BUN:-$HOME/.bun/bin/bun}"
54
+ if [ -z "${BUN:-}" ] || [ ! -x "$BUN" ]; then
55
+ printf 'slash-team: 本机没有 bun(设计要求的加载器)—— 装 bun 才能跑这一层\n' >&2
56
+ exit 3
57
+ fi
58
+
59
+ tmp="$(tmp_root_create slash-team)" || exit 3
60
+ cleanup() {
61
+ [ "${BASHPID:-$$}" = "$$" ] || return 0
62
+ if [ "$KEEP" = "1" ]; then printf '\n保留夹具目录:%s\n' "$tmp"
63
+ else tmp_root_reap_all; fi
64
+ }
65
+ trap cleanup EXIT
66
+
67
+ cat > "$tmp/drive.ts" <<'DRIVER'
68
+ // `/team` 纯逻辑夹具的驱动器:假 pi 驱动扩展的处理器,断言记录下来的每一次外部调用。
69
+ import { pathToFileURL } from 'node:url'
70
+ import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
71
+ import { dirname, join } from 'node:path'
72
+ import { spawnSync } from 'node:child_process'
73
+
74
+ const argv = process.argv.slice(2)
75
+ const opt = (name: string, dflt = ''): string => {
76
+ const i = argv.indexOf(name)
77
+ return i >= 0 && i + 1 < argv.length ? argv[i + 1] : dflt
78
+ }
79
+ const has = (name: string) => argv.includes(name)
80
+ const EXT = opt('--ext')
81
+ const TREE = opt('--tree')
82
+ const TMP = opt('--tmp')
83
+ const GROUPS = opt('--groups') ? opt('--groups').split(',').filter((s) => s !== '') : []
84
+ const FLIP = has('--flip')
85
+
86
+ const ALL_GROUPS = ['command', 'tokens', 'whitelist', 'menu', 'refuse', 'output', 'env', 'resolve', 'probe', 'args']
87
+ const want = (g: string) => GROUPS.length === 0 || GROUPS.includes(g)
88
+
89
+ let PASS = 0
90
+ let FAIL = 0
91
+ let CUR = ''
92
+ const failures: string[] = []
93
+ function check(name: string, cond: boolean, detail = ''): void {
94
+ if (!want(CUR)) return
95
+ if (cond) { PASS++; console.log(` \u2713 ${name}`) }
96
+ else { FAIL++; failures.push(`${CUR}: ${name}`); console.log(` \u2717 ${name}${detail ? `\uff08${detail}\uff09` : ''}`) }
97
+ }
98
+ function group(name: string): void { CUR = name; console.log(`\n== ${name} ==`) }
99
+
100
+ // ---------------------------------------------------------------- 假 pi
101
+ type ExecResult = { stdout: string; stderr: string; code: number; killed: boolean }
102
+ type Rec = {
103
+ commands: Array<{ name: string; opts: any }>
104
+ tools: number
105
+ confirms: number
106
+ execs: Array<{ command: string; args: string[]; options: any }>
107
+ messages: Array<{ customType: string; content: string; display?: boolean }>
108
+ notifies: Array<{ message: string; type?: string }>
109
+ }
110
+ let bust = 0
111
+ async function loadExt(path: string): Promise<any> {
112
+ return await import(pathToFileURL(path).href + `?bust=${bust++}`)
113
+ }
114
+ async function harness(extPath: string, opts: { cwd: string; results?: ExecResult[]; execFn?: (a: string[], o: any) => ExecResult }) {
115
+ const mod = await loadExt(extPath)
116
+ const rec: Rec = { commands: [], tools: 0, confirms: 0, execs: [], messages: [], notifies: [] }
117
+ const queue: ExecResult[] = opts.results ? opts.results.slice() : []
118
+ const exec = async (command: string, args: string[], options: any) => {
119
+ rec.execs.push({ command, args, options })
120
+ if (opts.execFn) return opts.execFn(args, options)
121
+ return queue.shift() ?? { stdout: 'ok\n', stderr: '', code: 0, killed: false }
122
+ }
123
+ const ctx = {
124
+ cwd: opts.cwd,
125
+ ui: {
126
+ notify: (message: string, type?: string) => { rec.notifies.push({ message, type }) },
127
+ confirm: () => { rec.confirms++; return Promise.resolve(true) },
128
+ },
129
+ }
130
+ const pi = {
131
+ registerCommand: (name: string, o: any) => { rec.commands.push({ name, opts: o }) },
132
+ registerTool: () => { rec.tools++ },
133
+ exec,
134
+ sendMessage: (m: any) => { rec.messages.push(m) },
135
+ }
136
+ mod.default(pi)
137
+ const cmd = rec.commands[0]
138
+ const run = async (args: string) => { await cmd.opts.handler(args, ctx) }
139
+ return { mod, rec, run, ctx, pi }
140
+ }
141
+
142
+ const okResult = (stdout: string): ExecResult => ({ stdout, stderr: '', code: 0, killed: false })
143
+
144
+ // ---------------------------------------------------------------- 夹具项目
145
+ const proj = join(TMP, 'proj')
146
+ const cliDir = join(proj, '.pi', 'skills', 'teamsmith', 'scripts')
147
+ mkdirSync(join(proj, '.pi', 'team'), { recursive: true })
148
+ writeFileSync(join(proj, '.pi', 'team', 'config.sh'), 'TEAM_SESSION=fixture\n')
149
+ mkdirSync(cliDir, { recursive: true })
150
+ const cliLocal = join(cliDir, 'team')
151
+ writeFileSync(cliLocal, '#!/usr/bin/env bash\nexit 0\n', { mode: 0o755 })
152
+
153
+ // 夹具自己的「菜单独立重算」:只依赖导出的表与文案,不调用 renderMenu —— 这样把菜单改成硬编码必红。
154
+ function expectedMenu(mod: any): string {
155
+ const name = (r: any) => r.paths.map((p: string[]) => p.join(' ')).join(' / ')
156
+ let width = 0
157
+ for (const r of mod.TEAM_ROWS) width = Math.max(width, name(r).length)
158
+ const lines: string[] = [mod.t('menu.title')]
159
+ for (const g of ['read', 'action']) {
160
+ lines.push('')
161
+ lines.push(mod.t(g === 'read' ? 'menu.group.read' : 'menu.group.action'))
162
+ for (const r of mod.TEAM_ROWS) {
163
+ if (r.group !== g) continue
164
+ const n = name(r)
165
+ lines.push(' ' + n + ' '.repeat(width - n.length + 2) + r.purpose)
166
+ }
167
+ }
168
+ lines.push('')
169
+ lines.push(mod.t('menu.footer'))
170
+ return lines.join('\n')
171
+ }
172
+
173
+ async function runGroups(): Promise<void> {
174
+ const savedCli = process.env.TEAM_CLI
175
+ delete process.env.TEAM_CLI
176
+
177
+ if (want('command')) {
178
+ group('command')
179
+ const h = await harness(EXT, { cwd: proj })
180
+ check('注册的命令恰好一条且名字是 team', h.rec.commands.length === 1 && h.rec.commands[0].name === 'team',
181
+ `commands=${h.rec.commands.map((c) => c.name).join(',')}`)
182
+ check('命令带 description(补全菜单里可读)', typeof h.rec.commands[0]?.opts?.description === 'string' && h.rec.commands[0].opts.description.length > 0)
183
+ check('零模型可调用的工具注册', h.rec.tools === 0, `registerTool=${h.rec.tools}`)
184
+ check('零自己的确认框', h.rec.confirms === 0, `confirm=${h.rec.confirms}`)
185
+ check('带参数补全函数', typeof h.rec.commands[0]?.opts?.getArgumentCompletions === 'function')
186
+ check('源文件里没有工具注册的调用点', !readFileSync(EXT, 'utf8').includes('registerTool'))
187
+ }
188
+
189
+ if (want('tokens')) {
190
+ group('tokens')
191
+ const h = await harness(EXT, { cwd: proj, results: [okResult('a\nb\n'), okResult('a\nb\n'), okResult('a\nb\n'), okResult('a\nb\n')] })
192
+ await h.run('ps')
193
+ check('子进程是 bash -c(剥离包装)', h.rec.execs[0]?.command === 'bash' && h.rec.execs[0]?.args[0] === '-c',
194
+ `command=${h.rec.execs[0]?.command} args0=${h.rec.execs[0]?.args[0]}`)
195
+ check('argv 逐字:/team ps → [ps]', JSON.stringify(h.rec.execs[0]?.args.slice(3)) === '["ps"]',
196
+ JSON.stringify(h.rec.execs[0]?.args.slice(3)))
197
+ check('CLI 是项目本地安装(路径解析先项目本地)', h.rec.execs[0]?.args[2] === cliLocal, `cli=${h.rec.execs[0]?.args[2]}`)
198
+ check('cwd = 项目根', h.rec.execs[0]?.options?.cwd === proj, `cwd=${h.rec.execs[0]?.options?.cwd}`)
199
+ check('有界等待 60000ms', h.rec.execs[0]?.options?.timeout === 60000, `timeout=${h.rec.execs[0]?.options?.timeout}`)
200
+ await h.run('meeting say alpha --intent proposal "two words"')
201
+ check('双引号里的空格是一个 token(argv 逐字)',
202
+ JSON.stringify(h.rec.execs[1]?.args.slice(3)) === '["meeting","say","alpha","--intent","proposal","two words"]',
203
+ JSON.stringify(h.rec.execs[1]?.args.slice(3)))
204
+ await h.run("meeting say 'a b' --intent proposal")
205
+ check('单引号原样(argv 逐字)',
206
+ JSON.stringify(h.rec.execs[2]?.args.slice(3)) === '["meeting","say","a b","--intent","proposal"]',
207
+ JSON.stringify(h.rec.execs[2]?.args.slice(3)))
208
+ await h.run('meeting say a\\ b --intent proposal')
209
+ check('引号外反斜杠转义(argv 逐字)',
210
+ JSON.stringify(h.rec.execs[3]?.args.slice(3)) === '["meeting","say","a b","--intent","proposal"]',
211
+ JSON.stringify(h.rec.execs[3]?.args.slice(3)))
212
+ const h2 = await harness(EXT, { cwd: proj })
213
+ await h2.run('meeting say "unclosed')
214
+ check('未闭合引号 ⇒ 拒绝且不起进程', h2.rec.execs.length === 0 && h2.rec.messages.length === 1,
215
+ `execs=${h2.rec.execs.length} messages=${h2.rec.messages.length}`)
216
+ check('未闭合引号的文案点名它', (h2.rec.messages[0]?.content ?? '').includes('没有闭合'), h2.rec.messages[0]?.content ?? '')
217
+ }
218
+
219
+ if (want('whitelist')) {
220
+ group('whitelist')
221
+ const mod = await loadExt(EXT)
222
+ const readRows = mod.TEAM_ROWS.filter((r: any) => r.forms)
223
+ const actionRows = mod.TEAM_ROWS.filter((r: any) => !r.forms)
224
+ check('表恰好 15 行(11 读 + 4 动)', mod.TEAM_ROWS.length === 15 && readRows.length === 11 && actionRows.length === 4,
225
+ `rows=${mod.TEAM_ROWS.length} read=${readRows.length} action=${actionRows.length}`)
226
+ for (const row of readRows) {
227
+ for (const form of row.forms) {
228
+ const tokens = form.map((x: string) => (x === mod.ARG ? 'X' : x))
229
+ const h = await harness(EXT, { cwd: proj, results: [okResult('a\nb\n')] })
230
+ await h.run(tokens.join(' '))
231
+ check(`读行接受自己的形状:team ${tokens.join(' ')}`, h.rec.execs.length === 1 && JSON.stringify(h.rec.execs[0].args.slice(3)) === JSON.stringify(tokens),
232
+ `execs=${h.rec.execs.length}`)
233
+ }
234
+ }
235
+ for (const row of actionRows) {
236
+ for (const path of row.paths) {
237
+ const tokens = [...path, '--flag', 'value']
238
+ const h = await harness(EXT, { cwd: proj, results: [okResult('a\nb\n')] })
239
+ await h.run(tokens.join(' '))
240
+ check(`动行原样透传尾巴:team ${tokens.join(' ')}`, h.rec.execs.length === 1 && JSON.stringify(h.rec.execs[0].args.slice(3)) === JSON.stringify(tokens),
241
+ `execs=${h.rec.execs.length}`)
242
+ }
243
+ }
244
+ const outside = [
245
+ ['dispatch', 'dev', 'P1', 'docs/team/tasks/P1.md'],
246
+ ['config', 'set', 'TEAM_AGENTS', 'x'],
247
+ ['say', 'dev', 'hello'], ['notify', 'dev', 'x'], ['close', 'P1'], ['teardown'],
248
+ ['smoke'], ['review', 'P1'], ['change', 'status', 'x'], ['archive', 'x'], ['bg', 'list'],
249
+ ['add-agent', 'bob'], ['init'], ['bootstrap'], ['draft', 'x'], ['outbox', 'flush'],
250
+ ['inbox', 'x'], ['thread', 'dev'], ['monitor'], ['pr', 'x'], ['gh', 'x'], ['frobnicate'],
251
+ ]
252
+ for (const tokens of outside) {
253
+ const h = await harness(EXT, { cwd: proj })
254
+ await h.run(tokens.join(' '))
255
+ const msg = h.rec.messages[0]?.content ?? ''
256
+ check(`表外拒绝且零进程:team ${tokens.join(' ')}`, h.rec.execs.length === 0 && msg.includes('不认') && msg.includes('PM') && msg.includes('终端'),
257
+ `execs=${h.rec.execs.length} msg=${msg.slice(0, 40)}`)
258
+ }
259
+ const named = await harness(EXT, { cwd: proj })
260
+ await named.run('config set TEAM_AGENTS x')
261
+ check('拒绝文案点名被拒的命令 config set', (named.rec.messages[0]?.content ?? '').includes('config set'), named.rec.messages[0]?.content ?? '')
262
+ for (const tokens of [['config', 'list', '--json'], ['version', '--check']]) {
263
+ const h = await harness(EXT, { cwd: proj })
264
+ await h.run(tokens.join(' '))
265
+ const msg = h.rec.messages[0]?.content ?? ''
266
+ check(`读行多余 token 拒绝且零进程:team ${tokens.join(' ')}`, h.rec.execs.length === 0 && msg.includes('不认') && msg.includes('PM') && msg.includes('终端'),
267
+ `execs=${h.rec.execs.length}`)
268
+ check(`读行多余 token 被点名:${tokens[tokens.length - 1]}`, msg.includes(tokens[tokens.length - 1]), msg.slice(0, 60))
269
+ }
270
+ }
271
+
272
+ if (want('menu')) {
273
+ group('menu')
274
+ const h = await harness(EXT, { cwd: proj })
275
+ await h.run('')
276
+ const menu = h.rec.messages[0]?.content ?? ''
277
+ const mod = h.mod
278
+ check('无参 /team 印菜单且进对话正文(display)', h.rec.messages.length === 1 && h.rec.messages[0].display === true && h.rec.execs.length === 0)
279
+ check('菜单与「从同一张表独立重算」逐字相同', menu === expectedMenu(mod),
280
+ menu === expectedMenu(mod) ? '' : '菜单不是从表渲染的')
281
+ for (const row of mod.TEAM_ROWS) {
282
+ for (const p of row.paths) {
283
+ const name = p.join(' ')
284
+ check(`菜单列出表里这一行:${name}`, menu.includes(name), `菜单里没有 ${name}`)
285
+ }
286
+ }
287
+ const rowNames = mod.TEAM_ROWS.map((r: any) => r.paths.map((p: string[]) => p.join(' '))).flat()
288
+ const cmdLines = menu.split('\n').filter((l: string) => l.startsWith(' ') && rowNames.some((n: string) => l.slice(2).startsWith(n)))
289
+ check('菜单的命令行列数 = 表里的行数(不多不少;pulse 一行三路径)', cmdLines.length === mod.TEAM_ROWS.length,
290
+ `lines=${cmdLines.length} rows=${mod.TEAM_ROWS.length}`)
291
+ const h2 = await harness(EXT, { cwd: proj })
292
+ await h2.run('help')
293
+ check('/team help 印同一张菜单', (h2.rec.messages[0]?.content ?? '') === menu)
294
+ const paths = mod.TEAM_ROWS.flatMap((r: any) => r.paths.map((p: string[]) => p.join(' ')))
295
+ const comp = h.rec.commands[0].opts.getArgumentCompletions('')
296
+ check('补全的首词集合来自同一张表', JSON.stringify(comp.map((c: any) => c.value).sort()) === JSON.stringify([...paths].sort()),
297
+ `comp=${comp.map((c: any) => c.value).join(',')}`)
298
+ const compC = h.rec.commands[0].opts.getArgumentCompletions('conf')
299
+ check('补全按前缀过滤(conf → config list / config upgrade-models)',
300
+ JSON.stringify(compC.map((c: any) => c.value).sort()) === JSON.stringify(['config list', 'config upgrade-models']),
301
+ JSON.stringify(compC.map((c: any) => c.value)))
302
+ }
303
+
304
+ if (want('refuse')) {
305
+ group('refuse')
306
+ for (const tokens of [['up'], ['up', '--fresh-pm'], ['status', '--fresh-pm']]) {
307
+ const h = await harness(EXT, { cwd: proj })
308
+ await h.run(tokens.join(' '))
309
+ const msg = h.rec.messages[0]?.content ?? ''
310
+ check(`up / --fresh-pm 拒绝且零进程:team ${tokens.join(' ')}`, h.rec.execs.length === 0 && h.rec.messages.length === 1,
311
+ `execs=${h.rec.execs.length}`)
312
+ check(`PM 会话原因 + 终端出路:team ${tokens.join(' ')}`, msg.includes('PM 会话') && msg.includes('终端'), msg.slice(0, 60))
313
+ }
314
+ const h = await harness(EXT, { cwd: proj })
315
+ await h.run('dispatch dev P1 docs/team/tasks/P1.md')
316
+ check('拒绝路径零副作用(无 exec、无窗口、无文件)', h.rec.execs.length === 0 && h.rec.messages.length === 1 && h.rec.notifies.length === 0)
317
+ }
318
+
319
+ if (want('output')) {
320
+ group('output')
321
+ {
322
+ const h = await harness(EXT, { cwd: proj, results: [okResult('teamsmith 0.1.0\n')] })
323
+ await h.run('version')
324
+ check('短成功 ⇒ 通知(info)且不进正文', h.rec.notifies.length === 1 && h.rec.notifies[0].type === 'info' && h.rec.messages.length === 0,
325
+ `notify=${h.rec.notifies.length} msg=${h.rec.messages.length}`)
326
+ check('通知内容就是那一行', h.rec.notifies[0]?.message === 'teamsmith 0.1.0', h.rec.notifies[0]?.message ?? '')
327
+ }
328
+ {
329
+ const h = await harness(EXT, { cwd: proj, results: [okResult('a\nb\n')] })
330
+ await h.run('ps')
331
+ const c = h.rec.messages[0]?.content ?? ''
332
+ check('多行成功 ⇒ 进正文且 display', h.rec.messages.length === 1 && h.rec.messages[0].display === true && h.rec.notifies.length === 0)
333
+ check('正文头是命令行与退出码', c.includes('$ team ps') && c.includes('exit 0') && c.includes('--- stdout ---') && c.includes('a') && c.includes('b'), c.slice(0, 40))
334
+ check('多行成功不发失败通知', h.rec.notifies.length === 0)
335
+ }
336
+ {
337
+ const h = await harness(EXT, { cwd: proj, results: [{ stdout: 'out\n', stderr: 'boom\n', code: 3, killed: false }] })
338
+ await h.run('doctor')
339
+ const c = h.rec.messages[0]?.content ?? ''
340
+ check('非 0 ⇒ 失败通知点名退出码 3', h.rec.notifies.length === 1 && h.rec.notifies[0].type === 'error' && h.rec.notifies[0].message.includes('3'),
341
+ JSON.stringify(h.rec.notifies))
342
+ check('非 0 ⇒ 正文带两路流与同一个码', c.includes('exit 3') && c.includes('--- stdout ---') && c.includes('out') && c.includes('--- stderr ---') && c.includes('boom'), c.slice(0, 60))
343
+ }
344
+ {
345
+ const h = await harness(EXT, { cwd: proj, results: [{ stdout: '', stderr: '', code: -1, killed: true }] })
346
+ await h.run('ps')
347
+ const c = h.rec.messages[0]?.content ?? ''
348
+ check('被杀 ⇒ 失败通知点名等待上限', h.rec.notifies.length === 1 && h.rec.notifies[0].type === 'error' && h.rec.notifies[0].message.includes('60'),
349
+ JSON.stringify(h.rec.notifies))
350
+ check('被杀 ⇒ 正文写明被杀原因', c.includes('killed') && c.includes('60'), c.slice(0, 60))
351
+ }
352
+ {
353
+ const big = Array.from({ length: 600 }, (_, i) => `line-${i + 1}`).join('\n')
354
+ const h = await harness(EXT, { cwd: proj, results: [okResult(big)] })
355
+ await h.run('status')
356
+ const c = h.rec.messages[0]?.content ?? ''
357
+ check('超量 ⇒ 保留首行', c.includes('line-1\n'), '')
358
+ check('超量 ⇒ 保留末行', c.includes('line-600'), '')
359
+ check('超量 ⇒ 显式说明省略与去哪看全文', c.includes('省略') && c.includes('team status'), c.slice(c.indexOf('省略') - 10, c.indexOf('省略') + 60))
360
+ check('超量 ⇒ 中间行确实被删(line-300 不在)', !c.includes('line-300\n'), '')
361
+ }
362
+ }
363
+
364
+ if (want('env')) {
365
+ group('env')
366
+ const mod = await loadExt(EXT)
367
+ const h = await harness(EXT, { cwd: proj, results: [okResult('a\nb\n')] })
368
+ await h.run('config upgrade-models --task-models routine=vendor/light --pm-model vendor/strong')
369
+ const script: string = h.rec.execs[0]?.args[1] ?? ''
370
+ check('剥离包装点名三个「替你说 yes」的变量',
371
+ script.includes('unset TEAM_ASSUME_YES TEAM_UPGRADE_CONFIRMED TEAM_ALLOW_FOREIGN_SESSION;') && script.endsWith('exec "$0" "$@"'),
372
+ script)
373
+ check('用户没打 --yes 就不注入 --yes', JSON.stringify(h.rec.execs[0]?.args.slice(3)) === JSON.stringify(['config', 'upgrade-models', '--task-models', 'routine=vendor/light', '--pm-model', 'vendor/strong']),
374
+ JSON.stringify(h.rec.execs[0]?.args.slice(3)))
375
+ const h2 = await harness(EXT, { cwd: proj, results: [okResult('a\nb\n')] })
376
+ await h2.run('config upgrade-models --task-models routine=vendor/light --pm-model vendor/strong --yes')
377
+ check('用户自己打的 --yes 原样到达', h2.rec.execs[0]?.args.slice(3).includes('--yes'), JSON.stringify(h2.rec.execs[0]?.args.slice(3)))
378
+ check('UNSET_VARS 就是那三个(单一来源)',
379
+ JSON.stringify(mod.UNSET_VARS) === JSON.stringify(['TEAM_ASSUME_YES', 'TEAM_UPGRADE_CONFIRMED', 'TEAM_ALLOW_FOREIGN_SESSION']),
380
+ JSON.stringify(mod.UNSET_VARS))
381
+ }
382
+
383
+ if (want('resolve')) {
384
+ group('resolve')
385
+ const mod = await loadExt(EXT)
386
+ check('项目根:从 cwd 向上找到含 .pi/team/config.sh 的目录', mod.findProjectRoot(join(proj, 'a', 'b')) === proj,
387
+ String(mod.findProjectRoot(join(proj, 'a', 'b'))))
388
+ const noProj = join(TMP, 'noproj')
389
+ mkdirSync(noProj, { recursive: true })
390
+ check('不是 teamsmith 项目 ⇒ null', mod.findProjectRoot(noProj) === null)
391
+ const h = await harness(EXT, { cwd: join(proj, 'a', 'b'), results: [okResult('a\nb\n')] })
392
+ await h.run('ps')
393
+ check('子进程 cwd = 解析出的项目根(不是当前子目录)', h.rec.execs[0]?.options?.cwd === proj, String(h.rec.execs[0]?.options?.cwd))
394
+ check('CLI 解析:项目本地安装永远赢过 TEAM_CLI', mod.resolveCli(proj, { TEAM_CLI: '/nonexistent/cli' }) === cliLocal,
395
+ String(mod.resolveCli(proj, { TEAM_CLI: '/nonexistent/cli' })))
396
+ const bare = join(TMP, 'bareproj')
397
+ mkdirSync(join(bare, '.pi', 'team'), { recursive: true })
398
+ writeFileSync(join(bare, '.pi', 'team', 'config.sh'), 'TEAM_SESSION=bare\n')
399
+ check('CLI 解析:没有项目本地时用 TEAM_CLI', mod.resolveCli(bare, { TEAM_CLI: '/tmp/fake-cli' }) === '/tmp/fake-cli',
400
+ String(mod.resolveCli(bare, { TEAM_CLI: '/tmp/fake-cli' })))
401
+ const extSib = join(TMP, 'sib', 'extension')
402
+ mkdirSync(join(TMP, 'sib', 'scripts'), { recursive: true })
403
+ writeFileSync(join(TMP, 'sib', 'scripts', 'team'), '#!/usr/bin/env bash\nexit 0\n', { mode: 0o755 })
404
+ check('CLI 解析:都没有时用扩展的兄弟目录', mod.resolveCli(bare, {}, extSib) === join(TMP, 'sib', 'scripts', 'team'),
405
+ String(mod.resolveCli(bare, {}, extSib)))
406
+ check('CLI 解析:都找不到 ⇒ null', mod.resolveCli(bare, {}, join(TMP, 'nowhere')) === null)
407
+ const h3 = await harness(EXT, { cwd: noProj })
408
+ await h3.run('ps')
409
+ check('不是项目 ⇒ 拒绝并指名 config.sh,零进程', h3.rec.execs.length === 0 && (h3.rec.messages[0]?.content ?? '').includes('config.sh'),
410
+ h3.rec.messages[0]?.content ?? '')
411
+ const bare2 = join(TMP, 'bare2')
412
+ mkdirSync(join(bare2, '.pi', 'team'), { recursive: true })
413
+ writeFileSync(join(bare2, '.pi', 'team', 'config.sh'), 'TEAM_SESSION=b2\n')
414
+ // 隔离副本:它自己的兄弟目录没有 scripts/team,所以三条解析路线全空 ⇒ 必须拒绝并指名 team init。
415
+ const isoDir = join(TMP, 'isolated', 'extension')
416
+ mkdirSync(isoDir, { recursive: true })
417
+ const isoExt = join(isoDir, 'team.ts')
418
+ writeFileSync(isoExt, readFileSync(EXT, 'utf8'))
419
+ const h4 = await harness(isoExt, { cwd: bare2 })
420
+ await h4.run('ps')
421
+ check('找不到 CLI ⇒ 拒绝并指名 team init,零进程', h4.rec.execs.length === 0 && (h4.rec.messages[0]?.content ?? '').includes('team init'),
422
+ h4.rec.messages[0]?.content ?? '')
423
+ }
424
+
425
+ if (want('probe')) {
426
+ group('probe')
427
+ const mod = await loadExt(EXT)
428
+ const cli = join(TREE, 'skills', 'teamsmith', 'scripts', 'team')
429
+ check('探针前提:CLI 在', existsSync(cli), cli)
430
+ // 探针在**最小夹具项目**(git 仓库 + docs/team/)里跑:只问 dispatcher 是否分发这条路径,
431
+ // 不读真仓库的账本、也不受它规模影响(真仓库里 digest 要 12s,这里 60ms)。
432
+ const pp = join(TMP, 'probe-proj')
433
+ rmSync(pp, { recursive: true, force: true })
434
+ mkdirSync(join(pp, '.pi', 'team'), { recursive: true })
435
+ mkdirSync(join(pp, 'docs', 'team'), { recursive: true })
436
+ writeFileSync(join(pp, '.pi', 'team', 'config.sh'), 'TEAM_SESSION=probe\n')
437
+ spawnSync('git', ['init', '-q', '-b', 'main'], { cwd: pp, encoding: 'utf8' })
438
+ spawnSync('git', ['-c', 'user.email=c@teamsmith', '-c', 'user.name=c', 'commit', '-q', '--allow-empty', '-m', 'init'], { cwd: pp, encoding: 'utf8' })
439
+ const cleanEnv: Record<string, string> = {}
440
+ for (const [k, v] of Object.entries(process.env)) {
441
+ if (/^TEAM_/.test(k) || /^TMUX/.test(k)) continue
442
+ cleanEnv[k] = v as string
443
+ }
444
+ const runCli = (tokens: string[]) => {
445
+ const r = spawnSync('bash', [cli, ...tokens, '--teamsmith-slash-probe'], { cwd: pp, encoding: 'utf8', timeout: 60000, env: cleanEnv })
446
+ return `${r.stdout ?? ''}${r.stderr ?? ''}`
447
+ }
448
+ let ownRefusals = 0
449
+ for (const row of mod.TEAM_ROWS) {
450
+ for (const p of row.paths) {
451
+ const out = runCli(p)
452
+ const top = `未知子命令:${p[0]}`
453
+ if (out.includes('未知参数') || out.includes('未知子命令')) ownRefusals++
454
+ check(`表里这一行 CLI 真的分发:team ${p.join(' ')}`, !out.includes(top), out.split('\n')[0].slice(0, 60))
455
+ }
456
+ }
457
+ check('探针非空洞:至少 5 行得到 CLI 自己的参数/子命令拒绝(真的分发了)', ownRefusals >= 5, `ownRefusals=${ownRefusals}`)
458
+ const bad = runCli(['frobnicate'])
459
+ check('红侧样本:表外命令得到顶层「未知子命令:frobnicate」', bad.includes('未知子命令:frobnicate'), bad.split('\n')[0].slice(0, 60))
460
+ }
461
+
462
+ if (savedCli === undefined) delete process.env.TEAM_CLI
463
+ else process.env.TEAM_CLI = savedCli
464
+ }
465
+
466
+ // ---------------------------------------------------------------- 翻转变异(scratch 副本)
467
+ type Mutation = { name: string; groups: string[]; apply: (src: string) => string | null }
468
+ const MUTATIONS: Mutation[] = [
469
+ {
470
+ name: 'menu-decoupled', groups: ['menu'],
471
+ apply: (s) => {
472
+ const from = 'export function renderMenu(): string {'
473
+ if (!s.includes(from)) return null
474
+ return s.replace(from, `${from} return '硬编码菜单:team status';`)
475
+ },
476
+ },
477
+ {
478
+ name: 'unset-empty', groups: ['env'],
479
+ apply: (s) => {
480
+ const from = "export const UNSET_VARS = ['TEAM_ASSUME_YES', 'TEAM_UPGRADE_CONFIRMED', 'TEAM_ALLOW_FOREIGN_SESSION']"
481
+ if (!s.includes(from)) return null
482
+ return s.replace(from, 'export const UNSET_VARS: string[] = []')
483
+ },
484
+ },
485
+ {
486
+ name: 'refuse-short-circuit', groups: ['refuse', 'whitelist'],
487
+ apply: (s) => {
488
+ const from = 'export function matchInvocation(tokens: string[]): Match {\n if (tokens.length === 0) return { kind: \'menu\' }'
489
+ if (!s.includes(from)) return null
490
+ return s.replace(from, "export function matchInvocation(tokens: string[]): Match {\n if (true) return { kind: 'run', row: TEAM_ROWS[0], tokens }\n if (tokens.length === 0) return { kind: 'menu' }")
491
+ },
492
+ },
493
+ {
494
+ name: 'no-failure-notify', groups: ['output'],
495
+ apply: (s) => {
496
+ const from = " if (res.killed || res.code !== 0) deps.notify(failureNotice(m.tokens, res), 'error')\n"
497
+ if (!s.includes(from)) return null
498
+ return s.replace(from, '')
499
+ },
500
+ },
501
+ {
502
+ name: 'entry-to-notify', groups: ['output'],
503
+ apply: (s) => {
504
+ const from = ' const content = formatEntry(m.tokens, res)\n deps.sendMessage({ customType: CUSTOM_TYPE, content, display: true })'
505
+ if (!s.includes(from)) return null
506
+ return s.replace(from, " const content = formatEntry(m.tokens, res)\n deps.notify(content, 'info')")
507
+ },
508
+ },
509
+ {
510
+ name: 'no-fuse', groups: ['output'],
511
+ apply: (s) => {
512
+ const from = ' if (lines.length <= FUSE_LINES && bytes <= FUSE_BYTES) return text'
513
+ if (!s.includes(from)) return null
514
+ return s.replace(from, ' if (true) return text')
515
+ },
516
+ },
517
+ {
518
+ name: 'table-frobnicate', groups: ['probe'],
519
+ apply: (s) => {
520
+ const from = 'export const TEAM_ROWS: Row[] = ['
521
+ if (!s.includes(from)) return null
522
+ return s.replace(from, `${from}\n { group: 'read', paths: [['frobnicate']], forms: [['frobnicate']], purpose: '红侧样本' },`)
523
+ },
524
+ },
525
+ ]
526
+
527
+ function runChild(extPath: string, groups: string[]): { pass: number; fail: number; out: string } {
528
+ const r = spawnSync(process.execPath, [process.argv[1], '--ext', extPath, '--tree', TREE, '--tmp', TMP, '--groups', groups.join(',')],
529
+ { encoding: 'utf8', timeout: 600000, env: { ...process.env, SLASH_TEAM_CHILD: '1' } })
530
+ const out = `${r.stdout ?? ''}${r.stderr ?? ''}`
531
+ const pass = Number((out.match(/RESULT pass=(\d+)/) ?? [])[1] ?? -1)
532
+ const fail = Number((out.match(/RESULT pass=\d+ fail=(\d+)/) ?? [])[1] ?? -1)
533
+ return { pass, fail, out }
534
+ }
535
+
536
+ async function runFlips(): Promise<void> {
537
+ console.log('\n== flip ==')
538
+ for (const m of MUTATIONS) {
539
+ const src = readFileSync(EXT, 'utf8')
540
+ const mutated = m.apply(src)
541
+ if (mutated === null || mutated === src) {
542
+ FAIL++
543
+ console.log(` \u2717 flip ${m.name}:变异没落地(夹具没生效)`)
544
+ continue
545
+ }
546
+ const dir = join(TMP, `flip-${m.name}`)
547
+ mkdirSync(dir, { recursive: true })
548
+ const file = join(dir, 'team.ts')
549
+ writeFileSync(file, mutated)
550
+ const control = runChild(EXT, m.groups)
551
+ const red = runChild(file, m.groups)
552
+ const controlGreen = control.fail === 0 && control.pass > 0
553
+ const redHit = red.fail > 0
554
+ if (controlGreen && redHit) {
555
+ PASS++
556
+ console.log(` \u2713 flip ${m.name}:对照绿(pass=${control.pass} fail=0)→ 变异红(pass=${red.pass} fail=${red.fail})`)
557
+ const named = red.out.split('\n').filter((l) => l.includes('\u2717')).slice(0, 2)
558
+ for (const l of named) console.log(` ${l.trim()}`)
559
+ } else {
560
+ FAIL++
561
+ console.log(` \u2717 flip ${m.name}:${controlGreen ? '' : '对照没有全绿 '}${redHit ? '' : '变异后判据还绿(没钉住)'}`)
562
+ console.log(` control pass=${control.pass} fail=${control.fail} / red pass=${red.pass} fail=${red.fail}`)
563
+ }
564
+ if (existsSync(file)) rmSync(dir, { recursive: true, force: true })
565
+ }
566
+ }
567
+
568
+ if (want('args')) {
569
+ group('args')
570
+ // 缺陷类:参数分支漏 shift ⇒ 脚本永不退出、零输出地空转(PM 2026-10-16 收掉过一个挂了 1h35m 的
571
+ // `--keep` 进程)。这里把红侧钉在 e2e 的**前进守卫**上:拿掉 shift 的变异副本必须在秒级 rc=2、
572
+ // 并点名缺 shift —— 同类缺陷从此不许再静默转下去。
573
+ const e2ePath = join(TREE, 'skills', 'teamsmith', 'tests', 'slash-team-e2e.sh')
574
+ const dir = join(TMP, 'arg-guard')
575
+ mkdirSync(join(dir, 'lib'), { recursive: true })
576
+ const src = readFileSync(e2ePath, 'utf8')
577
+ const mutated = src.replace('--keep) KEEP=1; export TEAM_TMP_KEEP=1; shift ;;',
578
+ '--keep) KEEP=1; export TEAM_TMP_KEEP=1 ;;')
579
+ check('变异落地:e2e 的 --keep 分支被拿掉 shift', mutated !== src)
580
+ writeFileSync(join(dir, 'slash-team-e2e.sh'), mutated)
581
+ copyFileSync(join(TREE, 'skills', 'teamsmith', 'tests', 'lib', 'tmp-root.sh'), join(dir, 'lib', 'tmp-root.sh'))
582
+ const t0 = Date.now()
583
+ const r = spawnSync('timeout', ['10', 'bash', join(dir, 'slash-team-e2e.sh'), '--keep'], { encoding: 'utf8', timeout: 20000 })
584
+ const dt = Date.now() - t0
585
+ const out = `${r.stdout ?? ''}${r.stderr ?? ''}`
586
+ check('漏 shift 的副本:前进守卫立刻 rc=2(不是空转)', r.status === 2, `status=${String(r.status)} ${dt}ms`)
587
+ check('守卫点名「参数循环没有前进」', out.includes('参数循环没有前进'), out.split('\n').slice(-2).join(' | ').slice(0, 120))
588
+ check('守卫秒级返回(原始缺陷会转 1h35m)', dt < 8000, `${dt}ms`)
589
+ // 正面:真脚本的 --keep 与 --flip 都必须被解析到位(argv 存档是 re-exec 的前提)
590
+ const realE2e = readFileSync(e2ePath, 'utf8')
591
+ check('e2e 存了原始 argv 再交守卫(re-exec 不丢 --flip)',
592
+ realE2e.includes('ORIG_ARGS=("$@")') && realE2e.includes('e2e_guard "${ORIG_ARGS[@]}"'))
593
+ rmSync(dir, { recursive: true, force: true })
594
+ }
595
+
596
+ if (process.env.SLASH_TEAM_CHILD === '1') {
597
+ await runGroups()
598
+ console.log(`\nRESULT pass=${PASS} fail=${FAIL}`)
599
+ process.exitCode = FAIL === 0 ? 0 : 1
600
+ } else {
601
+ await runGroups()
602
+ if (FLIP) await runFlips()
603
+ console.log(`\nRESULT pass=${PASS} fail=${FAIL}`)
604
+ if (FAIL > 0) {
605
+ console.log(`FAILED:\n${failures.slice(0, 20).map((f) => ` - ${f}`).join('\n')}`)
606
+ }
607
+ process.exitCode = FAIL === 0 ? 0 : 1
608
+ }
609
+ DRIVER
610
+
611
+ args=(--ext "$ext" --tree "$tree" --tmp "$tmp")
612
+ [ -n "$SEL_GROUPS" ] && args+=(--groups "$SEL_GROUPS")
613
+ [ "$FLIP" = "1" ] && args+=(--flip)
614
+
615
+ "$BUN" "$tmp/drive.ts" "${args[@]}"
616
+ rc=$?
617
+ exit "$rc"