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.
- package/LICENSE +21 -0
- package/README.md +158 -2
- package/bin/team.mjs +59 -0
- package/install.sh +94 -0
- package/package.json +37 -4
- package/skills/teamsmith/CHANGELOG.md +763 -0
- package/skills/teamsmith/SKILL.md +312 -0
- package/skills/teamsmith/extension/team-bg.ts +435 -0
- package/skills/teamsmith/extension/team-inbox-watch.ts +1412 -0
- package/skills/teamsmith/extension/team-notify.ts +663 -0
- package/skills/teamsmith/references/agent-adapters.md +643 -0
- package/skills/teamsmith/references/config.md +477 -0
- package/skills/teamsmith/references/meeting.md +124 -0
- package/skills/teamsmith/references/memory.md +133 -0
- package/skills/teamsmith/references/migration.md +227 -0
- package/skills/teamsmith/references/openspec.md +222 -0
- package/skills/teamsmith/references/philosophy.md +95 -0
- package/skills/teamsmith/references/protocol.md +712 -0
- package/skills/teamsmith/references/troubleshooting.md +1384 -0
- package/skills/teamsmith/references/workflows.md +448 -0
- package/skills/teamsmith/scripts/lib/cmd-agents.sh +1709 -0
- package/skills/teamsmith/scripts/lib/cmd-bg.sh +284 -0
- package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +311 -0
- package/skills/teamsmith/scripts/lib/cmd-config.sh +1156 -0
- package/skills/teamsmith/scripts/lib/cmd-death.sh +562 -0
- package/skills/teamsmith/scripts/lib/cmd-docs.sh +149 -0
- package/skills/teamsmith/scripts/lib/cmd-draft.sh +124 -0
- package/skills/teamsmith/scripts/lib/cmd-init.sh +212 -0
- package/skills/teamsmith/scripts/lib/cmd-meeting.sh +904 -0
- package/skills/teamsmith/scripts/lib/cmd-outbox.sh +196 -0
- package/skills/teamsmith/scripts/lib/cmd-project.sh +642 -0
- package/skills/teamsmith/scripts/lib/cmd-review.sh +1393 -0
- package/skills/teamsmith/scripts/lib/cmd-status.sh +1399 -0
- package/skills/teamsmith/scripts/lib/cmd-update.sh +191 -0
- package/skills/teamsmith/scripts/lib/cmd-watch.sh +1681 -0
- package/skills/teamsmith/scripts/lib/common.sh +4964 -0
- package/skills/teamsmith/scripts/lib/draft-entry.sh +51 -0
- package/skills/teamsmith/scripts/lib/outbox.sh +2042 -0
- package/skills/teamsmith/scripts/lib/tmux-argv.sh +165 -0
- package/skills/teamsmith/scripts/monitor.mjs +616 -0
- package/skills/teamsmith/scripts/panel/README.md +192 -0
- package/skills/teamsmith/scripts/panel/build.sh +47 -0
- package/skills/teamsmith/scripts/panel/bun.lock +109 -0
- package/skills/teamsmith/scripts/panel/draft-send.sh +68 -0
- package/skills/teamsmith/scripts/panel/package.json +24 -0
- package/skills/teamsmith/scripts/panel/panel.js +388 -0
- package/skills/teamsmith/scripts/panel/src/App.tsx +2150 -0
- package/skills/teamsmith/scripts/panel/src/clipboard.ts +154 -0
- package/skills/teamsmith/scripts/panel/src/compose.ts +691 -0
- package/skills/teamsmith/scripts/panel/src/data.ts +555 -0
- package/skills/teamsmith/scripts/panel/src/format.ts +50 -0
- package/skills/teamsmith/scripts/panel/src/layout.ts +2562 -0
- package/skills/teamsmith/scripts/panel/src/main.tsx +894 -0
- package/skills/teamsmith/scripts/panel/src/markdown.ts +340 -0
- package/skills/teamsmith/scripts/panel/src/sanitize.ts +42 -0
- package/skills/teamsmith/scripts/panel/src/settings.ts +154 -0
- package/skills/teamsmith/scripts/panel/src/strings/en.ts +416 -0
- package/skills/teamsmith/scripts/panel/src/strings/index.ts +65 -0
- package/skills/teamsmith/scripts/panel/src/strings/types.ts +9 -0
- package/skills/teamsmith/scripts/panel/src/strings/zh.ts +414 -0
- package/skills/teamsmith/scripts/panel/src/theme.ts +116 -0
- package/skills/teamsmith/scripts/panel/src/types.ts +652 -0
- package/skills/teamsmith/scripts/panel/src/width.ts +105 -0
- package/skills/teamsmith/scripts/panel/tsconfig.json +16 -0
- package/skills/teamsmith/scripts/shim/signal-gate +156 -0
- package/skills/teamsmith/scripts/shim/tmux +403 -0
- package/skills/teamsmith/scripts/team +143 -0
- package/skills/teamsmith/templates/AGENTS.section.md.tmpl +147 -0
- package/skills/teamsmith/templates/BOARD.md.tmpl +18 -0
- package/skills/teamsmith/templates/DECISIONS.md.tmpl +22 -0
- package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +25 -0
- package/skills/teamsmith/templates/PROTOCOL.md.tmpl +84 -0
- package/skills/teamsmith/templates/ROADMAP.md.tmpl +29 -0
- package/skills/teamsmith/templates/config.sh.tmpl +106 -0
- package/skills/teamsmith/templates/memory-seed.md.tmpl +46 -0
- package/skills/teamsmith/templates/pm-prompt.md.tmpl +110 -0
- package/skills/teamsmith/templates/report.md.tmpl +36 -0
- package/skills/teamsmith/templates/task.md.tmpl +65 -0
- package/skills/teamsmith/templates/threads-README.md +17 -0
- package/skills/teamsmith/tests/bg-ledger-harness.mjs +682 -0
- package/skills/teamsmith/tests/bg-ledger.sh +307 -0
- package/skills/teamsmith/tests/checkout-shape-probe.sh +800 -0
- package/skills/teamsmith/tests/config-cli.sh +1562 -0
- package/skills/teamsmith/tests/container-tmux.sh +493 -0
- package/skills/teamsmith/tests/coverage-inventory.sh +173 -0
- package/skills/teamsmith/tests/death-cause.sh +564 -0
- package/skills/teamsmith/tests/delivery-truth.sh +1231 -0
- package/skills/teamsmith/tests/fake-tui.py +450 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/README.md +60 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/judge-second.py +139 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/mock-server.py +29 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/observe.ts +20 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/run-case.sh +79 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +175 -0
- package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +229 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/README.md +22 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/dev2.seen +8 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/dev2.wake +9 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/pm-nudges.wake +3 -0
- package/skills/teamsmith/tests/fixtures/signal-lint-cases.txt +40 -0
- package/skills/teamsmith/tests/flip-glue.sh +162 -0
- package/skills/teamsmith/tests/flip-m12-26c.sh +129 -0
- package/skills/teamsmith/tests/flip-m12.sh +185 -0
- package/skills/teamsmith/tests/flip-m16.sh +166 -0
- package/skills/teamsmith/tests/flip-m17.sh +204 -0
- package/skills/teamsmith/tests/flip-m33.sh +284 -0
- package/skills/teamsmith/tests/flip-m34.sh +96 -0
- package/skills/teamsmith/tests/flip-m37.sh +185 -0
- package/skills/teamsmith/tests/flip-m4.3.sh +375 -0
- package/skills/teamsmith/tests/flip-m43.sh +128 -0
- package/skills/teamsmith/tests/flip-m44.sh +262 -0
- package/skills/teamsmith/tests/flip-m45.sh +244 -0
- package/skills/teamsmith/tests/flip-m46.sh +238 -0
- package/skills/teamsmith/tests/flip-m48.sh +304 -0
- package/skills/teamsmith/tests/flip-m6.2.sh +205 -0
- package/skills/teamsmith/tests/flip-m6.3.sh +283 -0
- package/skills/teamsmith/tests/flip-m6.4.sh +267 -0
- package/skills/teamsmith/tests/flip-m6.5.sh +113 -0
- package/skills/teamsmith/tests/flip-m7.1.sh +135 -0
- package/skills/teamsmith/tests/flip-m7.2.sh +321 -0
- package/skills/teamsmith/tests/flip-p144.sh +112 -0
- package/skills/teamsmith/tests/flip-p156.sh +133 -0
- package/skills/teamsmith/tests/flip-p158.sh +301 -0
- package/skills/teamsmith/tests/flip-p160.sh +182 -0
- package/skills/teamsmith/tests/flip-p171.sh +249 -0
- package/skills/teamsmith/tests/flip-p18.1.sh +95 -0
- package/skills/teamsmith/tests/flip-p20.sh +286 -0
- package/skills/teamsmith/tests/flip-p201.sh +249 -0
- package/skills/teamsmith/tests/flip-p210.sh +239 -0
- package/skills/teamsmith/tests/flip-p211.sh +152 -0
- package/skills/teamsmith/tests/flip-p217.sh +288 -0
- package/skills/teamsmith/tests/flip-p22.sh +123 -0
- package/skills/teamsmith/tests/flip-p23.sh +239 -0
- package/skills/teamsmith/tests/flip-p25.sh +165 -0
- package/skills/teamsmith/tests/flip-p71.sh +184 -0
- package/skills/teamsmith/tests/flip-p72.sh +202 -0
- package/skills/teamsmith/tests/frames/README.md +176 -0
- package/skills/teamsmith/tests/frames/p78-conversation-rule-below-box.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-cursor-mid-draft.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-below-cursor-line.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-below-cursor.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-blank-region.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-only.txt +5 -0
- package/skills/teamsmith/tests/frames/p78-spinner-row-below-cursor.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-wider-rule-below-cursor.txt +6 -0
- package/skills/teamsmith/tests/frames/p86-f1-mixed-width-disjoint-box.txt +8 -0
- package/skills/teamsmith/tests/frames/p86-f1-narrower-width-disjoint-box.txt +8 -0
- package/skills/teamsmith/tests/frames/p86-f1-spinner-top-disjoint-box.txt +8 -0
- package/skills/teamsmith/tests/frames/pi-0.85.1-update-banner.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-draft-half-sentence.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-empty-box.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-one-line-draft.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-project-trust-prompt.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.99.2-empty-editor.txt +32 -0
- package/skills/teamsmith/tests/frames/pi-0.99.2-human-draft.txt +32 -0
- package/skills/teamsmith/tests/frames/pi-1.0.0-git-error-in-box.txt +32 -0
- package/skills/teamsmith/tests/gate-guard.sh +112 -0
- package/skills/teamsmith/tests/guard-matrix.sh +233 -0
- package/skills/teamsmith/tests/install-shape.sh +731 -0
- package/skills/teamsmith/tests/ledger-ban.sh +612 -0
- package/skills/teamsmith/tests/lib/box-judge.sh +68 -0
- package/skills/teamsmith/tests/lib/checkout-shape.sh +129 -0
- package/skills/teamsmith/tests/lib/loop-scan.awk +114 -0
- package/skills/teamsmith/tests/lib/pty-wait.sh +676 -0
- package/skills/teamsmith/tests/lib/section-guard.sh +855 -0
- package/skills/teamsmith/tests/lib/shell-lex.pl +261 -0
- package/skills/teamsmith/tests/lib/tmp-root.sh +528 -0
- package/skills/teamsmith/tests/lib/tmux-cap.sh +35 -0
- package/skills/teamsmith/tests/lib/tmux-iso-call-probe.sh +81 -0
- package/skills/teamsmith/tests/lib/tmux-iso-probe.sh +46 -0
- package/skills/teamsmith/tests/lib/tmux-iso.sh +381 -0
- package/skills/teamsmith/tests/load-experiment.sh +290 -0
- package/skills/teamsmith/tests/loop-inventory.tsv +84 -0
- package/skills/teamsmith/tests/panel-b2-slow-stub.sh +19 -0
- package/skills/teamsmith/tests/panel-b2.sh +1183 -0
- package/skills/teamsmith/tests/panel-b3-pty-mouse.py +240 -0
- package/skills/teamsmith/tests/panel-b3-pty-tmux-mouse.py +138 -0
- package/skills/teamsmith/tests/panel-b3-stub.sh +279 -0
- package/skills/teamsmith/tests/panel-b3.sh +1301 -0
- package/skills/teamsmith/tests/panel-choices.sh +572 -0
- package/skills/teamsmith/tests/panel-clipboard-model.ts +187 -0
- package/skills/teamsmith/tests/panel-compose-model.ts +290 -0
- package/skills/teamsmith/tests/panel-contrast.mjs +81 -0
- package/skills/teamsmith/tests/panel-cpu-premise.sh +173 -0
- package/skills/teamsmith/tests/panel-cpu.sh +391 -0
- package/skills/teamsmith/tests/panel-flip-m54.sh +207 -0
- package/skills/teamsmith/tests/panel-flip-p123.sh +278 -0
- package/skills/teamsmith/tests/panel-flip-p125.sh +318 -0
- package/skills/teamsmith/tests/panel-flip-p128.sh +259 -0
- package/skills/teamsmith/tests/panel-keyprobe-pty.py +99 -0
- package/skills/teamsmith/tests/panel-keyprobe-stub.sh +41 -0
- package/skills/teamsmith/tests/panel-keyprobe.sh +82 -0
- package/skills/teamsmith/tests/panel-keyprobe.tsx +116 -0
- package/skills/teamsmith/tests/panel-knobs.sh +83 -0
- package/skills/teamsmith/tests/panel-p21.sh +2181 -0
- package/skills/teamsmith/tests/panel-snapshots.sh +802 -0
- package/skills/teamsmith/tests/panel-strings.mjs +195 -0
- package/skills/teamsmith/tests/perf.sh +740 -0
- package/skills/teamsmith/tests/pm-box-real.sh +350 -0
- package/skills/teamsmith/tests/pulse-nudge-key.sh +563 -0
- package/skills/teamsmith/tests/routes.sh +1652 -0
- package/skills/teamsmith/tests/section-budgets.tsv +150 -0
- package/skills/teamsmith/tests/section-guard.sh +231 -0
- package/skills/teamsmith/tests/section-needs-audit.sh +94 -0
- package/skills/teamsmith/tests/section-paths.tsv +142 -0
- package/skills/teamsmith/tests/section-select.sh +655 -0
- package/skills/teamsmith/tests/signal-gate.sh +366 -0
- package/skills/teamsmith/tests/signal-lint-legacy.txt +14 -0
- package/skills/teamsmith/tests/signal-lint.pl +416 -0
- package/skills/teamsmith/tests/skill-load.mjs +65 -0
- package/skills/teamsmith/tests/smoke.sh +19711 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-120-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-120-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-120.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-160-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-160.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-59-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-59-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-59.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-99-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-99.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-120-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-120-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-120.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-160-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-160.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-59-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-59-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-59.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-99-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-99.txt +32 -0
- package/skills/teamsmith/tests/spec-ledger-refs.tsv +78 -0
- package/skills/teamsmith/tests/spec-refs.sh +826 -0
- package/skills/teamsmith/tests/task-header-model.sh +267 -0
- package/skills/teamsmith/tests/team-bg-flip.sh +239 -0
- package/skills/teamsmith/tests/team-bg-harness.mjs +392 -0
- package/skills/teamsmith/tests/team-bg-stop.sh +434 -0
- package/skills/teamsmith/tests/team-inbox-watch-flip.sh +191 -0
- package/skills/teamsmith/tests/team-inbox-watch-harness.mjs +1559 -0
- package/skills/teamsmith/tests/tmp-hygiene.sh +1190 -0
- package/skills/teamsmith/tests/tmux-lint-legacy.txt +31 -0
- package/skills/teamsmith/tests/tmux-lint.pl +604 -0
- package/skills/teamsmith-init/SKILL.md +100 -0
- package/skills/teamsmith-init/references/bootstrap.md +74 -0
- package/skills/teamsmith-init/templates/bootstrap-prompt.md.tmpl +46 -0
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* teamsmith · team-bg 扩展的确定性夹具(M27)
|
|
4
|
+
*
|
|
5
|
+
* <node|bun> team-bg-harness.mjs <skill>/extension/team-bg.ts [--keep]
|
|
6
|
+
*
|
|
7
|
+
* 为什么用「假 Pi 宿主」而不是真模型:本夹具要证的是**扩展自己的契约**——job 表、收割/未收割、
|
|
8
|
+
* 合并成一条、账本行格式、日志有界、结果文本点名命令(P33:单行化 + 100 码点缩略)。这些都被接口
|
|
9
|
+
* (registerTool / agent_settled / sendMessage)完全
|
|
10
|
+
* 决定,用真模型只会把判据换成「模型有没有照着做」。真实的「唤醒一个空闲 pi 会话」由 E8 的 RPC 探针
|
|
11
|
+
* 实证过(docs/team/reports/E8-verify/probes/),本夹具不重复付那份成本(模型调用 + 波动)。
|
|
12
|
+
*
|
|
13
|
+
* 隔离纪律(M7.2 的教训):继承来的团队身份先清掉,TEAM_ROOT 显式指向临时仓库;每条断言都要求
|
|
14
|
+
* 产物落在临时仓库里;跑完再对比**真实仓库** state/ 的前后快照(反向守卫)。
|
|
15
|
+
*
|
|
16
|
+
* 每个用例打印一行 `TEAM-BG-CASE PASS|FAIL <name> [:: detail]`,任一 FAIL → 退出码 1。
|
|
17
|
+
*/
|
|
18
|
+
import { execFileSync } from 'node:child_process'
|
|
19
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
20
|
+
import { tmpdir } from 'node:os'
|
|
21
|
+
import { join, resolve, basename } from 'node:path'
|
|
22
|
+
|
|
23
|
+
const args = process.argv.slice(2)
|
|
24
|
+
const keep = args.includes('--keep') || process.env.TEAM_BG_KEEP === '1'
|
|
25
|
+
// P159:--record-only 只跑「作业身份记录」用例,并**故意留着作业**(sleep 300)把 id/root 交给
|
|
26
|
+
// 调用方(门禁段接着跑 `team bg stop <id>`)——那是「记录 → 按记录停」的端到端衔接点。
|
|
27
|
+
const recordOnly = args.includes('--record-only')
|
|
28
|
+
const ext = args.find(a => !a.startsWith('--'))
|
|
29
|
+
if (!ext) {
|
|
30
|
+
console.error('usage: team-bg-harness.mjs <path/to/team-bg.ts> [--keep]')
|
|
31
|
+
process.exit(2)
|
|
32
|
+
}
|
|
33
|
+
const EXT = resolve(ext)
|
|
34
|
+
|
|
35
|
+
// ── 身份隔离:绝不继承调用者的团队身份与 tmux 身份 ──────────────────────────────
|
|
36
|
+
for (const key of Object.keys(process.env)) {
|
|
37
|
+
if (/^(TEAM_|SMOKE_)/.test(key) || key === 'TMUX' || key === 'TMUX_PANE') delete process.env[key]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const sleep = (ms) => new Promise(r => setTimeout(r, ms))
|
|
41
|
+
const waitFor = async (fn, ms = 3000) => { const t = Date.now(); for (;;) { if (fn()) return true; if (Date.now() - t > ms) return false; await sleep(25) } }
|
|
42
|
+
let failures = 0
|
|
43
|
+
const check = (name, ok, detail = '') => {
|
|
44
|
+
console.log(`TEAM-BG-CASE ${ok ? 'PASS' : 'FAIL'} ${name}${detail ? ` :: ${detail}` : ''}`)
|
|
45
|
+
if (!ok) failures++
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// ── 夹具仓库(有 .pi/team/config.sh 的 git 仓库;findRoot 走 git 主工作树那一支)────────
|
|
49
|
+
const TMP = mkdtempSync(join(tmpdir(), 'teamsmith-bg-'))
|
|
50
|
+
const ROOT = join(TMP, 'repo')
|
|
51
|
+
mkdirSync(ROOT, { recursive: true })
|
|
52
|
+
process.env.TEAM_ROOT = ROOT
|
|
53
|
+
if (!keep && !recordOnly) process.on('exit', () => { try { rmSync(TMP, { recursive: true, force: true }) } catch {} })
|
|
54
|
+
try { execFileSync('git', ['init', '-q', '-b', 'main', ROOT], { stdio: 'ignore' }) } catch {}
|
|
55
|
+
mkdirSync(join(ROOT, '.pi/team'), { recursive: true })
|
|
56
|
+
writeFileSync(join(ROOT, '.pi/team/config.sh'), 'TEAM_PROJECT="bg-harness"\n')
|
|
57
|
+
const STATE = join(ROOT, '.pi/team/state')
|
|
58
|
+
|
|
59
|
+
// ── 反向守卫:真实仓库 state/ 前后快照 ────────────────────────────────────────
|
|
60
|
+
const REAL_REPO = resolve(EXT, '../../..') // <repo>/skills/teamsmith/extension/team-bg.ts
|
|
61
|
+
const snapshot = (dir) => {
|
|
62
|
+
if (!existsSync(dir)) return 'absent'
|
|
63
|
+
const walk = (d) => readdirSync(d, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name)).flatMap(e =>
|
|
64
|
+
e.isDirectory() ? walk(join(d, e.name)) : [`${join(d, e.name)}:${statSync(join(d, e.name)).size}:${statSync(join(d, e.name)).mtimeMs}`])
|
|
65
|
+
return walk(dir).join('\n')
|
|
66
|
+
}
|
|
67
|
+
const REAL_STATE = join(REAL_REPO, '.pi/team/state')
|
|
68
|
+
const REAL_BEFORE = snapshot(REAL_STATE)
|
|
69
|
+
|
|
70
|
+
// ── 假 Pi 宿主 ────────────────────────────────────────────────────────────────
|
|
71
|
+
const sent = []
|
|
72
|
+
const tools = {}
|
|
73
|
+
const handlers = {}
|
|
74
|
+
const api = {
|
|
75
|
+
on: (name, fn) => { (handlers[name] ||= []).push(fn) },
|
|
76
|
+
registerTool: (def) => { tools[def.name] = def },
|
|
77
|
+
registerCommand: () => {},
|
|
78
|
+
sendMessage: (msg, opts) => { sent.push({ msg, opts }) },
|
|
79
|
+
getAllTools: () => Object.keys(tools),
|
|
80
|
+
}
|
|
81
|
+
const emit = async (name, ...rest) => { for (const fn of handlers[name] ?? []) await fn(...rest) }
|
|
82
|
+
const ctx = { cwd: ROOT }
|
|
83
|
+
const turnStart = () => emit('agent_start', {}, ctx)
|
|
84
|
+
const turnEnd = () => emit('agent_settled', {}, ctx)
|
|
85
|
+
|
|
86
|
+
if (!existsSync(EXT)) {
|
|
87
|
+
check('import', false, `extension missing: ${EXT}`)
|
|
88
|
+
console.log('TEAM-BG-HARNESS FAIL (extension missing — this is the pre-M27 shape)')
|
|
89
|
+
process.exit(1)
|
|
90
|
+
}
|
|
91
|
+
let factory
|
|
92
|
+
try {
|
|
93
|
+
factory = (await import(EXT)).default
|
|
94
|
+
} catch (error) {
|
|
95
|
+
check('import', false, String(error?.stack ?? error))
|
|
96
|
+
console.log('TEAM-BG-HARNESS FAIL (import)')
|
|
97
|
+
process.exit(1)
|
|
98
|
+
}
|
|
99
|
+
factory(api)
|
|
100
|
+
check('factory registers team_bg_run', typeof tools.team_bg_run?.execute === 'function')
|
|
101
|
+
check('factory registers team_bg_wait', typeof tools.team_bg_wait?.execute === 'function')
|
|
102
|
+
check('factory starts no session resource (no ledger before any job)', !existsSync(join(STATE, 'bg.log')))
|
|
103
|
+
check('session_start / session_shutdown hooks registered',
|
|
104
|
+
(handlers.session_start ?? []).length > 0 && (handlers.session_shutdown ?? []).length > 0)
|
|
105
|
+
await emit('session_start', { reason: 'startup' }, ctx)
|
|
106
|
+
|
|
107
|
+
const run = async (command, name) => {
|
|
108
|
+
const res = await tools.team_bg_run.execute('call-run', { command, name }, null, null, ctx)
|
|
109
|
+
const text = String(res?.content?.[0]?.text ?? '')
|
|
110
|
+
const id = /job ([^ ]+) started/.exec(text)?.[1]
|
|
111
|
+
check(`run ${name} returns id+pid inside the fixture root`,
|
|
112
|
+
!!id && /pid \d+/.test(text) && String(res?.details?.log ?? '').startsWith(ROOT), `id=${id}`)
|
|
113
|
+
return { id, log: String(res?.details?.log ?? ''), pid: Number(res?.details?.pid ?? 0), text }
|
|
114
|
+
}
|
|
115
|
+
const wait = async (id, timeout_ms) => String((await tools.team_bg_wait.execute('call-wait', { id, timeout_ms }, null)).content[0].text)
|
|
116
|
+
const ledger = () => existsSync(join(STATE, 'bg.log')) ? readFileSync(join(STATE, 'bg.log'), 'utf8').trim().split('\n') : []
|
|
117
|
+
const settledCounts = () => ledger().map(l => Number(/ settled-with-unharvested=(\d+)/.exec(l)?.[1] ?? -1))
|
|
118
|
+
|
|
119
|
+
// ── P159 · 作业身份记录(state/bg/<id>.job)的读取与断言 ───────────────────────────
|
|
120
|
+
// 契约:扩展在**返回 job id 之前**落盘 id/pid/pgid/start/cwd/log/cmd;`team bg stop` 只按这份
|
|
121
|
+
// 记录里的 (pid, 启动时间指纹) 停作业。判据全部从**真文件**与 **/proc** 读回,不看扩展内部变量。
|
|
122
|
+
const recordOf = (id) => join(STATE, 'bg', `${id}.job`)
|
|
123
|
+
const readRecord = (id) => {
|
|
124
|
+
const f = recordOf(id)
|
|
125
|
+
if (!existsSync(f)) return {}
|
|
126
|
+
return Object.fromEntries(readFileSync(f, 'utf8').trim().split('\n').filter(Boolean).map(l => {
|
|
127
|
+
const i = l.indexOf('=')
|
|
128
|
+
return [l.slice(0, i), l.slice(i + 1)]
|
|
129
|
+
}))
|
|
130
|
+
}
|
|
131
|
+
const procStatFields = (pid) => {
|
|
132
|
+
let stat = ''
|
|
133
|
+
try { stat = readFileSync(`/proc/${pid}/stat`, 'utf8') } catch { return {} }
|
|
134
|
+
const rest = stat.slice(stat.lastIndexOf(')') + 1).trim().split(/\s+/)
|
|
135
|
+
return { pgid: rest[2] ?? '', start: rest[19] ?? '' }
|
|
136
|
+
}
|
|
137
|
+
const checkJobRecord = (id, pid, expectedCmd, tag) => {
|
|
138
|
+
const rec = recordOf(id)
|
|
139
|
+
check(`${tag} the job record exists`, existsSync(rec), rec)
|
|
140
|
+
const f = readRecord(id)
|
|
141
|
+
const st = procStatFields(pid)
|
|
142
|
+
const live = existsSync(`/proc/${pid}`)
|
|
143
|
+
check(`${tag} record id/pid match the live process`, f.id === id && Number(f.pid) === pid && live,
|
|
144
|
+
JSON.stringify({ id: f.id, pid: f.pid, live }))
|
|
145
|
+
check(`${tag} record pgid is the live pid's process group (detached spawn ⇒ pgid == pid)`,
|
|
146
|
+
f.pgid !== '' && f.pgid === st.pgid, `record=${f.pgid} proc=${st.pgid} pid=${pid}`)
|
|
147
|
+
check(`${tag} record start is the /proc/<pid>/stat start-time fingerprint`,
|
|
148
|
+
f.start !== '' && f.start === st.start, `record=${f.start} proc=${st.start}`)
|
|
149
|
+
check(`${tag} record carries cwd/log/cmd`, f.cwd === ROOT && String(f.log).startsWith(`${STATE}/bg/`) && f.cmd === expectedCmd,
|
|
150
|
+
JSON.stringify({ cwd: f.cwd, log: f.log, cmd: f.cmd }))
|
|
151
|
+
return f
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// --record-only:起一个**真作业**(sleep 300,真扩展真 spawn),断言记录,然后把 id/根交给调用方,
|
|
155
|
+
// 自己**不退临时根、不杀作业**。调用方按 `team bg stop` 停它 —— 记录与停止两头都用真东西。
|
|
156
|
+
if (recordOnly) {
|
|
157
|
+
const { id, pid } = await run('sleep 300', 'p159-record')
|
|
158
|
+
checkJobRecord(id, pid, 'sleep 300', 'S13')
|
|
159
|
+
console.log(`TEAM-BG-RECORD id=${id} pid=${pid} root=${ROOT} record=${recordOf(id)} state=${STATE}`)
|
|
160
|
+
console.log(failures === 0 ? 'TEAM-BG-HARNESS OK' : `TEAM-BG-HARNESS FAIL (${failures})`)
|
|
161
|
+
console.log(`fixture: ${TMP}`)
|
|
162
|
+
process.exit(failures === 0 ? 0 : 1)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// ── S1:未收割 → 空闲时被唤醒(合并窗口后一条消息) ─────────────────────────────
|
|
166
|
+
{
|
|
167
|
+
const { id } = await run('sleep 0.4; echo S1-DONE', 's1')
|
|
168
|
+
await turnStart(); await turnEnd() // 回合在作业还在跑时结束
|
|
169
|
+
check('S1 no wake before the job exits', sent.length === 0, `sent=${sent.length}`)
|
|
170
|
+
await sleep(1500)
|
|
171
|
+
const wake = sent[0]
|
|
172
|
+
check('S1 unharvested job wakes the idle agent exactly once', sent.length === 1, `sent=${sent.length}`)
|
|
173
|
+
check('S1 wake is a followUp with triggerTurn', wake?.opts?.triggerTurn === true && wake?.opts?.deliverAs === 'followUp',
|
|
174
|
+
JSON.stringify(wake?.opts ?? {}))
|
|
175
|
+
check('S1 wake names the job and its exit code',
|
|
176
|
+
String(wake?.msg?.content ?? '').includes(id) && String(wake?.msg?.content ?? '').includes('exit=0'))
|
|
177
|
+
const waited = await wait(id)
|
|
178
|
+
check('S1 harvest returns the result inline', waited.includes('exit=0') && waited.includes('S1-DONE'))
|
|
179
|
+
await sleep(500)
|
|
180
|
+
check('S1 harvested job stays silent afterwards', sent.length === 1, `sent=${sent.length}`)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// ── S2:已收割 → 静默(#689 第 1 条) ─────────────────────────────────────────
|
|
184
|
+
{
|
|
185
|
+
const { id } = await run('sleep 0.2; echo S2-DONE', 's2')
|
|
186
|
+
const waited = await wait(id) // 阻塞等到结束并收割
|
|
187
|
+
check('S2 wait harvests a running job', waited.includes('exit=0') && waited.includes('S2-DONE'))
|
|
188
|
+
const before = sent.length
|
|
189
|
+
await turnStart(); await turnEnd()
|
|
190
|
+
await sleep(800)
|
|
191
|
+
check('S2 harvested job never wakes the agent',
|
|
192
|
+
sent.length === before && !sent.slice(before).some(m => String(m?.msg?.content ?? '').includes(id)),
|
|
193
|
+
`sent ${before} -> ${sent.length}`)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// ── S3:空闲时多条同时完成 → 合并成一条 ───────────────────────────────────────
|
|
197
|
+
{
|
|
198
|
+
const before = sent.length
|
|
199
|
+
const { id: a } = await run('sleep 0.15; echo M1', 'm1')
|
|
200
|
+
const { id: b } = await run('sleep 0.2; echo M2', 'm2')
|
|
201
|
+
await sleep(1500)
|
|
202
|
+
const merged = sent.slice(before)
|
|
203
|
+
check('S3 two jobs finishing together produce exactly one message', merged.length === 1, `messages=${merged.length}`)
|
|
204
|
+
const body = String(merged[0]?.msg?.content ?? '')
|
|
205
|
+
check('S3 the merged message names both jobs', body.includes(a) && body.includes(b) && /2 background job/.test(body))
|
|
206
|
+
check('S3 merged wake is followUp+triggerTurn',
|
|
207
|
+
merged[0]?.opts?.triggerTurn === true && merged[0]?.opts?.deliverAs === 'followUp')
|
|
208
|
+
// 礼貌的 agent 被唤醒后会把结果收割掉(也证明「先通知后收割」这条路通)
|
|
209
|
+
check('S3 both notified jobs can still be harvested inline',
|
|
210
|
+
(await wait(a)).includes('M1') && (await wait(b)).includes('M2'))
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// ── S4:agent 跑着时完成 → 等 settled 再合并投递(不插队) ─────────────────────
|
|
214
|
+
{
|
|
215
|
+
const before = sent.length
|
|
216
|
+
await turnStart()
|
|
217
|
+
const { id: a } = await run('sleep 0.15; echo N1', 'n1')
|
|
218
|
+
const { id: b } = await run('sleep 0.2; echo N2', 'n2')
|
|
219
|
+
await sleep(800) // 两条都在回合内结束
|
|
220
|
+
check('S4 nothing is delivered while the agent is running', sent.length === before, `sent=${sent.length}`)
|
|
221
|
+
await turnEnd()
|
|
222
|
+
const merged = sent.slice(before)
|
|
223
|
+
check('S4 settle delivers one merged message', merged.length === 1, `messages=${merged.length}`)
|
|
224
|
+
const body = String(merged[0]?.msg?.content ?? '')
|
|
225
|
+
check('S4 merged message names both jobs', body.includes(a) && body.includes(b))
|
|
226
|
+
await wait(a); await wait(b) // 收尾:清掉未收割状态
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// ── S5:账本格式(state/bg.log:每回合一行 settled-with-unharvested=<n>) ───────
|
|
230
|
+
{
|
|
231
|
+
const lines = ledger()
|
|
232
|
+
const iso = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z /
|
|
233
|
+
check('S5 every ledger line starts with an ISO timestamp', lines.length > 0 && lines.every(l => iso.test(l)),
|
|
234
|
+
`${lines.length} lines`)
|
|
235
|
+
const settled = lines.filter(l => / settled-with-unharvested=\d+( |$)/.test(l))
|
|
236
|
+
const counts = settledCounts().filter(n => n >= 0)
|
|
237
|
+
check('S5 settled lines report the unharvested count', counts.includes(1), `counts=${counts.join(',')}`)
|
|
238
|
+
check('S5 settled line 0 after the harvested job', counts.includes(0), `counts=${counts.join(',')}`)
|
|
239
|
+
check('S5 settled-with-unharvested=2 while two jobs wait', counts.includes(2), `counts=${counts.join(',')}`)
|
|
240
|
+
check('S5 job detail is appended for unharvested jobs',
|
|
241
|
+
settled.some(l => /jobs=[^ ]+:(running|exit-?\d+)/.test(l)), settled.find(l => l.includes('jobs=')) ?? '(none)')
|
|
242
|
+
check('S5 wake lines carry count+ids', lines.some(l => / wake count=2 ids=[^ ]+,[^ ]+/.test(l)))
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// ── S6:日志有界(截断留尾段)+ 收割结果内联 ──────────────────────────────────
|
|
246
|
+
{
|
|
247
|
+
process.env.TEAM_BG_LOG_MAX_BYTES = '4096'
|
|
248
|
+
const { id, log } = await run("head -c 60000 /dev/zero | tr '\\0' x; echo TAIL-MARKER-S6", 'big')
|
|
249
|
+
const waited = await wait(id)
|
|
250
|
+
const size = existsSync(log) ? statSync(log).size : -1
|
|
251
|
+
check('S6 log stays under the cap', size > 0 && size <= 4096, `bytes=${size}`)
|
|
252
|
+
const body = existsSync(log) ? readFileSync(log, 'utf8') : ''
|
|
253
|
+
check('S6 truncation keeps the tail', body.includes('TAIL-MARKER-S6') && body.includes('[team-bg] truncated'))
|
|
254
|
+
check('S6 harvest reports the truncation and the tail', waited.includes('exit=0') && waited.includes('TAIL-MARKER-S6') && waited.includes('[team-bg] truncated'))
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// ── S12:结果里点名命令(P33:单行化 + 100 码点缩略;details.cmd 原样) ────────
|
|
258
|
+
// 用户反馈(P33):结果里只有 job id/pid/log,看不出「我到底跑的是什么命令」。契约(P33 任务书):
|
|
259
|
+
// ① 文本里有 `cmd: <命令>`;② **单行化**(换行/连串空白 → 一格),多行命令也要一眼能读;
|
|
260
|
+
// ③ 超过 100 个**码点**缩略加 `…`,按码点切(不许把 CJK/代理对劈成半个 —— P28 的字节切会造非法
|
|
261
|
+
// UTF-8);④ `details.cmd` 原样、不缩略;⑤ 收割回执(running / finished 两种形状)同样点名。
|
|
262
|
+
{
|
|
263
|
+
const cmdLine = (text) => text.split('\n').find(l => l.startsWith(' cmd:')) ?? '(no cmd line)'
|
|
264
|
+
const utf8RoundTrip = (s) => new TextDecoder().decode(new TextEncoder().encode(s))
|
|
265
|
+
|
|
266
|
+
// ① 短命令:文本点名 + details 原样(且作业照常跑)
|
|
267
|
+
const shortCmd = 'echo P33-SHORT'
|
|
268
|
+
const r1 = await tools.team_bg_run.execute('call-p33-short', { command: shortCmd, name: 'p33-short' }, null, null, ctx)
|
|
269
|
+
const t1 = String(r1?.content?.[0]?.text ?? '')
|
|
270
|
+
check('S12 short command is named in the result text', t1.includes(`cmd: ${shortCmd}`), cmdLine(t1))
|
|
271
|
+
check('S12 details.cmd is the short command verbatim', r1?.details?.cmd === shortCmd, JSON.stringify(r1?.details?.cmd ?? null))
|
|
272
|
+
check('S12 the named short command still runs', (await wait(String(r1?.details?.id ?? ''))).includes('P33-SHORT'))
|
|
273
|
+
|
|
274
|
+
// ② 长命令(>100 码点、含 CJK 与代理对):前 100 码点 + …,末字完整,尾部被丢弃,details 原样
|
|
275
|
+
const longCmd = `${'命令'.repeat(45)}🚀${'令'.repeat(20)} DROP-ME-TAIL` // 124 码点(125 UTF-16 单元)
|
|
276
|
+
const expected100 = `${'命令'.repeat(45)}🚀${'令'.repeat(9)}` // 恰好 100 码点
|
|
277
|
+
const r2 = await tools.team_bg_run.execute('call-p33-long', { command: longCmd, name: 'p33-long' }, null, null, ctx)
|
|
278
|
+
const t2 = String(r2?.content?.[0]?.text ?? '')
|
|
279
|
+
const shown = cmdLine(t2).slice(' cmd: '.length)
|
|
280
|
+
check('S12 long command is truncated at the 100th code point + ellipsis',
|
|
281
|
+
shown === `${expected100}…`,
|
|
282
|
+
`codepoints=${Array.from(shown).length} tail=${JSON.stringify(Array.from(shown).slice(-3).join(''))}`)
|
|
283
|
+
check('S12 truncation drops the tail and never splits a code point (valid UTF-8)',
|
|
284
|
+
!shown.includes('DROP-ME-TAIL') && Array.from(shown).length === 101 && utf8RoundTrip(t2) === t2,
|
|
285
|
+
`tail-leak=${shown.includes('DROP-ME-TAIL')} roundtrip=${utf8RoundTrip(t2) === t2}`)
|
|
286
|
+
check('S12 details.cmd stays verbatim (untruncated) for the long command',
|
|
287
|
+
r2?.details?.cmd === longCmd, `codepoints=${Array.from(String(r2?.details?.cmd ?? '')).length}`)
|
|
288
|
+
await wait(String(r2?.details?.id ?? ''))
|
|
289
|
+
|
|
290
|
+
// ③ 带换行的命令:文本里是单行(无换行),details 仍原样,作业仍按原文跑
|
|
291
|
+
const multiCmd = 'echo P33-MULTI-A\necho P33-MULTI-B\t \n echo P33-MULTI-C'
|
|
292
|
+
const r3 = await tools.team_bg_run.execute('call-p33-multi', { command: multiCmd, name: 'p33-multi' }, null, null, ctx)
|
|
293
|
+
const t3 = String(r3?.content?.[0]?.text ?? '')
|
|
294
|
+
check('S12 multiline command is single-lined in the result text',
|
|
295
|
+
multiCmd.includes('\n') && cmdLine(t3) === ' cmd: echo P33-MULTI-A echo P33-MULTI-B echo P33-MULTI-C',
|
|
296
|
+
JSON.stringify(cmdLine(t3)))
|
|
297
|
+
check('S12 details.cmd keeps the multiline command verbatim', r3?.details?.cmd === multiCmd)
|
|
298
|
+
check('S12 the multiline job still runs as written (all three echoes)', (await wait(String(r3?.details?.id ?? ''))).includes('P33-MULTI-C'))
|
|
299
|
+
|
|
300
|
+
// ④ 收割回执的两种形状(finished / still running)也同样点名命令
|
|
301
|
+
const r4 = await tools.team_bg_run.execute('call-p33-receipt', { command: 'echo P33-RECEIPT', name: 'p33-receipt' }, null, null, ctx)
|
|
302
|
+
const finished = await wait(String(r4?.details?.id ?? ''))
|
|
303
|
+
check('S12 the harvest receipt (finished) names the command too',
|
|
304
|
+
finished.includes(` cmd: echo P33-RECEIPT`), cmdLine(finished))
|
|
305
|
+
const r5 = await tools.team_bg_run.execute('call-p33-running', { command: 'sleep 2; echo P33-RUNNING-DONE', name: 'p33-running' }, null, null, ctx)
|
|
306
|
+
const running = await wait(String(r5?.details?.id ?? ''), 0) // timeout_ms=0 → 立刻回 running 形状
|
|
307
|
+
check('S12 the harvest receipt (still running) names the command too',
|
|
308
|
+
running.includes('still running') && running.includes(' cmd: sleep 2; echo P33-RUNNING-DONE'), cmdLine(running))
|
|
309
|
+
await wait(String(r5?.details?.id ?? '')) // 收尾:收割,别再叫
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// ── S11:worktree 会话的产物落在**自己的 worktree**(M30 修正:不得用 git-common-dir)──
|
|
313
|
+
// 现场(M30):worker 在 worktree 里把门禁放后台跑,日志却写进了主工作树的 .pi/team/state/bg/ ——
|
|
314
|
+
// 门禁自己的 stdout 里带着各段夹具的名字,于是下一次 M16 隔离断言把它当成「夹具泄漏进真实账本」。
|
|
315
|
+
// 判据:工具返回的 log 路径 + 真实文件 + 账本行 + 唤醒消息里的路径,全部落在 worktree 侧;
|
|
316
|
+
// 共享根(主工作树)不得收到这个作业的任何痕迹。
|
|
317
|
+
{
|
|
318
|
+
try { execFileSync('git', ['-C', ROOT, 'add', '-A'], { stdio: 'ignore' }) } catch {}
|
|
319
|
+
// M47: a runner/container has no global git identity — pass one explicitly, or the commit
|
|
320
|
+
// (and with it the linked worktree below) silently never happens and S11 goes red.
|
|
321
|
+
try {
|
|
322
|
+
execFileSync('git', ['-C', ROOT, '-c', 'user.email=harness@teamsmith', '-c', 'user.name=harness', 'commit', '-qm', 'fixture'], { stdio: 'ignore' })
|
|
323
|
+
} catch {}
|
|
324
|
+
const WT = join(TMP, 'wt')
|
|
325
|
+
let wtOk = true
|
|
326
|
+
try { execFileSync('git', ['-C', ROOT, 'worktree', 'add', '-b', 'wt-branch', WT], { stdio: 'ignore' }) } catch { wtOk = false }
|
|
327
|
+
const ctxWt = { cwd: WT }
|
|
328
|
+
check('S11 fixture: linked worktree with its own .pi/team/config.sh',
|
|
329
|
+
wtOk && existsSync(join(WT, '.pi/team/config.sh')), `wt=${WT}`)
|
|
330
|
+
|
|
331
|
+
// ① 立刻能看出日志落在哪:工具返回的路径必须是 worktree 侧
|
|
332
|
+
const res = await tools.team_bg_run.execute('call-wt', { command: 'echo WT-JOB-DONE', name: 'wt' }, null, null, ctxWt)
|
|
333
|
+
const log = String(res?.details?.log ?? '')
|
|
334
|
+
const id = String(res?.details?.id ?? '')
|
|
335
|
+
check('S11 a worktree session writes its job log inside the worktree', log.startsWith(`${WT}/.pi/team/state/bg/`), `log=${log}`)
|
|
336
|
+
check('S11 the shared root does not receive that job log', !!log && !existsSync(join(ROOT, '.pi/team/state/bg', basename(log))))
|
|
337
|
+
check('S11 worktree job can still be harvested inline', (await wait(id)).includes('WT-JOB-DONE'))
|
|
338
|
+
|
|
339
|
+
// ② 账本 + 唤醒消息里的路径同样在 worktree 侧(回合在 worktree 里结束)
|
|
340
|
+
const before = sent.length
|
|
341
|
+
const un = await tools.team_bg_run.execute('call-wt2', { command: 'sleep 0.3; echo WT-UNHARVESTED', name: 'wt2' }, null, null, ctxWt)
|
|
342
|
+
const id2 = String(un?.details?.id ?? '')
|
|
343
|
+
const log2 = String(un?.details?.log ?? '')
|
|
344
|
+
await emit('agent_settled', {}, ctxWt)
|
|
345
|
+
const woke = await waitFor(() => sent.length > before, 4000)
|
|
346
|
+
check('S11 unharvested worktree job still wakes the session', woke, `messages=${sent.length - before}`)
|
|
347
|
+
const wakeBody = String(sent.at(-1)?.msg?.content ?? '')
|
|
348
|
+
check('S11 the wake names the worktree-side log', wakeBody.includes(log2) && log2.startsWith(WT),
|
|
349
|
+
wakeBody.split('\n').filter(l => l.includes('log=')).join(' | '))
|
|
350
|
+
const ledgerWt = existsSync(join(WT, '.pi/team/state/bg.log')) ? readFileSync(join(WT, '.pi/team/state/bg.log'), 'utf8') : ''
|
|
351
|
+
const ledgerShared = existsSync(join(ROOT, '.pi/team/state/bg.log')) ? readFileSync(join(ROOT, '.pi/team/state/bg.log'), 'utf8') : ''
|
|
352
|
+
check('S11 the session ledger line lands in the worktree', ledgerWt.includes(`jobs=${id2}:`), `ledger lines=${ledgerWt.split('\n').filter(Boolean).length}`)
|
|
353
|
+
check('S11 the shared root ledger has no line for that job', !ledgerShared.includes(id2), `shared lines=${ledgerShared.split('\n').filter(Boolean).length}`)
|
|
354
|
+
await wait(id2) // 收尾:收割,别再叫
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// ── S7:session 级 job 表(shutdown 清空;detached 作业不被杀) ────────────────
|
|
358
|
+
{
|
|
359
|
+
const t0 = Date.now()
|
|
360
|
+
const { id, pid } = await run('sleep 5; echo NEVER-HARVESTED', 's7')
|
|
361
|
+
const elapsed = Date.now() - t0
|
|
362
|
+
check('S7 team_bg_run returns immediately while the job runs', elapsed < 1500, `${elapsed}ms`)
|
|
363
|
+
const status = await wait(id, 0)
|
|
364
|
+
check('S7 timeout_ms=0 just reports that it is still running', /still running/.test(status))
|
|
365
|
+
await emit('session_shutdown', { reason: 'quit' }, ctx)
|
|
366
|
+
let threw = false
|
|
367
|
+
try { await wait(id) } catch { threw = true }
|
|
368
|
+
check('S7 session_shutdown clears the job table (old ids are unknown)', threw)
|
|
369
|
+
let alive = false
|
|
370
|
+
try { process.kill(pid, 0); alive = true } catch { alive = false }
|
|
371
|
+
check('S7 the detached job survives session_shutdown', alive, `pid=${pid}`)
|
|
372
|
+
try { process.kill(pid, 'SIGKILL') } catch {}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// ── S13:作业身份记录在返回 id 之前落盘(P159:pid + 启动时间指纹 + 组)────────────────
|
|
376
|
+
// 为什么:`team bg stop` 的全部依据就是这份记录(pid 会被复用,所以还要启动时间指纹)。
|
|
377
|
+
{
|
|
378
|
+
const { id, pid } = await run('sleep 2; echo S13-DONE', 's13')
|
|
379
|
+
checkJobRecord(id, pid, 'sleep 2; echo S13-DONE', 'S13')
|
|
380
|
+
check('S13 the recorded job can still be harvested inline', (await wait(id)).includes('S13-DONE'))
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// ── 反向守卫:真实仓库 state/ 未被触碰 ───────────────────────────────────────
|
|
384
|
+
{
|
|
385
|
+
const after = snapshot(REAL_STATE)
|
|
386
|
+
check('reverse guard: the real repo state/ is untouched', after === REAL_BEFORE,
|
|
387
|
+
after === REAL_BEFORE ? '' : 'real state/ changed during the harness')
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
console.log(failures === 0 ? 'TEAM-BG-HARNESS OK' : `TEAM-BG-HARNESS FAIL (${failures})`)
|
|
391
|
+
console.log(`fixture: ${keep || process.env.TEAM_BG_KEEP === '1' ? TMP : '(removed)'}`)
|
|
392
|
+
process.exit(failures === 0 ? 0 : 1)
|