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.
- package/README.md +4 -4
- package/package.json +1 -1
- package/skills/teamsmith/CHANGELOG.md +28 -0
- package/skills/teamsmith/SKILL.md +14 -7
- package/skills/teamsmith/extension/team-notify.ts +37 -6
- package/skills/teamsmith/extension/team.ts +438 -0
- package/skills/teamsmith/references/config.md +39 -6
- package/skills/teamsmith/references/migration.md +197 -47
- package/skills/teamsmith/references/protocol.md +176 -19
- package/skills/teamsmith/references/troubleshooting.md +124 -7
- package/skills/teamsmith/references/workflows.md +36 -2
- package/skills/teamsmith/scripts/lib/cmd-agents.sh +318 -23
- package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +2 -2
- package/skills/teamsmith/scripts/lib/cmd-config.sh +349 -67
- package/skills/teamsmith/scripts/lib/cmd-draft.sh +4 -4
- package/skills/teamsmith/scripts/lib/cmd-help.sh +677 -0
- package/skills/teamsmith/scripts/lib/cmd-init.sh +157 -5
- package/skills/teamsmith/scripts/lib/cmd-interrupt.sh +461 -0
- package/skills/teamsmith/scripts/lib/cmd-meeting.sh +2 -25
- package/skills/teamsmith/scripts/lib/cmd-project.sh +30 -103
- package/skills/teamsmith/scripts/lib/cmd-reap.sh +277 -0
- package/skills/teamsmith/scripts/lib/cmd-reply.sh +3 -3
- package/skills/teamsmith/scripts/lib/cmd-review.sh +175 -30
- package/skills/teamsmith/scripts/lib/cmd-status.sh +226 -17
- package/skills/teamsmith/scripts/lib/cmd-update.sh +36 -7
- package/skills/teamsmith/scripts/lib/cmd-watch.sh +564 -46
- package/skills/teamsmith/scripts/lib/common.sh +773 -48
- package/skills/teamsmith/scripts/lib/gate-lock.sh +544 -0
- package/skills/teamsmith/scripts/panel/draft-send.sh +11 -1
- package/skills/teamsmith/scripts/panel/panel.js +207 -207
- package/skills/teamsmith/scripts/panel/src/App.tsx +58 -21
- package/skills/teamsmith/scripts/panel/src/clipboard.ts +11 -5
- package/skills/teamsmith/scripts/panel/src/compose.ts +6 -3
- package/skills/teamsmith/scripts/panel/src/data.ts +11 -3
- package/skills/teamsmith/scripts/panel/src/layout.ts +209 -69
- package/skills/teamsmith/scripts/panel/src/main.tsx +33 -8
- package/skills/teamsmith/scripts/panel/src/strings/en.ts +39 -29
- package/skills/teamsmith/scripts/panel/src/strings/zh.ts +41 -31
- package/skills/teamsmith/scripts/panel/src/types.ts +28 -3
- package/skills/teamsmith/scripts/replies.mjs +4 -1
- package/skills/teamsmith/scripts/shim/tmux +18 -0
- package/skills/teamsmith/scripts/strings/commands.tsv +86 -0
- package/skills/teamsmith/scripts/strings/help.en.tsv +503 -0
- package/skills/teamsmith/scripts/strings/help.zh.tsv +489 -0
- package/skills/teamsmith/scripts/team +19 -6
- package/skills/teamsmith/templates/AGENTS.section.md.tmpl +8 -1
- package/skills/teamsmith/templates/config.sh.tmpl +20 -1
- package/skills/teamsmith/templates/pm-prompt.md.tmpl +21 -0
- package/skills/teamsmith/tests/bg-ledger-harness.mjs +464 -40
- package/skills/teamsmith/tests/bg-ledger.sh +168 -10
- package/skills/teamsmith/tests/checkout-shape-probe.sh +3 -1
- package/skills/teamsmith/tests/config-cli.sh +160 -14
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +7 -1
- package/skills/teamsmith/tests/fixtures/p287/lint-good.sh.in +3 -0
- package/skills/teamsmith/tests/fixtures/p287/lint-hardcoded.sh.in +3 -0
- package/skills/teamsmith/tests/fixtures/p287/lint-no-ns.sh.in +3 -0
- package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +18 -6
- package/skills/teamsmith/tests/flip-m33.sh +5 -3
- package/skills/teamsmith/tests/flip-m37.sh +4 -1
- package/skills/teamsmith/tests/flip-m4.3.sh +4 -1
- package/skills/teamsmith/tests/flip-m6.3.sh +4 -1
- package/skills/teamsmith/tests/flip-m6.5.sh +4 -1
- package/skills/teamsmith/tests/flip-m7.2.sh +4 -1
- package/skills/teamsmith/tests/flip-p158.sh +2 -1
- package/skills/teamsmith/tests/flip-p210.sh +4 -1
- package/skills/teamsmith/tests/flip-p217.sh +4 -1
- package/skills/teamsmith/tests/flip-p287-lock.sh +342 -0
- package/skills/teamsmith/tests/flip-p287-name.sh +279 -0
- package/skills/teamsmith/tests/flip-p304-read-side.sh +98 -0
- package/skills/teamsmith/tests/flip-p308-skip-not-pass.sh +151 -0
- package/skills/teamsmith/tests/flip-p309-p162-deep.sh +122 -0
- package/skills/teamsmith/tests/flip-p310-lock.sh +216 -0
- package/skills/teamsmith/tests/flip-p310-socket.sh +125 -0
- package/skills/teamsmith/tests/help-surface.sh +1664 -0
- package/skills/teamsmith/tests/install-shape.sh +279 -20
- package/skills/teamsmith/tests/key-replies-pty.sh +9 -10
- package/skills/teamsmith/tests/key-replies-ui.sh +0 -7
- package/skills/teamsmith/tests/key-replies.sh +240 -1
- package/skills/teamsmith/tests/ledger-ban.sh +5 -4
- package/skills/teamsmith/tests/ledger-claim.sh +2 -1
- package/skills/teamsmith/tests/lib/bounded-spin.sh +90 -0
- package/skills/teamsmith/tests/lib/model-policy.sh +4 -0
- package/skills/teamsmith/tests/lib/model-routing-flips.py +51 -0
- package/skills/teamsmith/tests/lib/reply-fixture.sh +4 -9
- package/skills/teamsmith/tests/lib/section-guard.sh +258 -13
- package/skills/teamsmith/tests/lib/tmp-root.sh +139 -27
- package/skills/teamsmith/tests/lib/tmux-cap.sh +10 -1
- package/skills/teamsmith/tests/lib/tmux-iso.sh +31 -13
- package/skills/teamsmith/tests/loop-inventory.tsv +59 -47
- package/skills/teamsmith/tests/panel-b2.sh +106 -3
- package/skills/teamsmith/tests/panel-b3-stub.sh +112 -4
- package/skills/teamsmith/tests/panel-b3.sh +175 -19
- package/skills/teamsmith/tests/panel-choices.sh +11 -6
- package/skills/teamsmith/tests/panel-cpu.sh +2 -1
- package/skills/teamsmith/tests/panel-knobs.sh +7 -1
- package/skills/teamsmith/tests/panel-p21.sh +156 -73
- package/skills/teamsmith/tests/panel-snapshots.sh +41 -225
- package/skills/teamsmith/tests/panel-strings.mjs +33 -18
- package/skills/teamsmith/tests/perf.sh +121 -30
- package/skills/teamsmith/tests/routes.sh +327 -93
- package/skills/teamsmith/tests/seat-interrupt.sh +1002 -0
- package/skills/teamsmith/tests/seat-visibility.sh +675 -0
- package/skills/teamsmith/tests/section-budgets.tsv +20 -10
- package/skills/teamsmith/tests/section-guard.sh +6 -1
- package/skills/teamsmith/tests/section-needs-audit.sh +24 -7
- package/skills/teamsmith/tests/section-paths.tsv +19 -13
- package/skills/teamsmith/tests/section-select.sh +8 -1
- package/skills/teamsmith/tests/slash-team-e2e.sh +323 -0
- package/skills/teamsmith/tests/slash-team.sh +617 -0
- package/skills/teamsmith/tests/smoke.sh +2972 -440
- package/skills/teamsmith/tests/task-model-routing.sh +507 -10
- package/skills/teamsmith/tests/tmp-hygiene.sh +782 -45
- package/skills/teamsmith/tests/tmux-identity-leak.sh +773 -0
- package/skills/teamsmith/tests/tmux-lint-legacy.txt +12 -18
- package/skills/teamsmith/tests/upgrade-recipe.sh +537 -0
- package/skills/teamsmith-init/SKILL.md +12 -12
- package/skills/teamsmith-init/references/bootstrap.md +3 -3
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# flip-p287-name.sh — P287「命名面」的翻转夹具(change: gate-lock-external-deletion)
|
|
3
|
+
#
|
|
4
|
+
# bash skills/teamsmith/tests/flip-p287-name.sh [--keep]
|
|
5
|
+
# bash skills/teamsmith/tests/flip-p287-name.sh --break=<stage> # 只为红侧证据把判定换回旧形状(见下)
|
|
6
|
+
#
|
|
7
|
+
# 四条腿:
|
|
8
|
+
# leg0 green :私有临时根下跑一套夹具运行(真入口),把它**为自己**直接创建的条目逐条点名:
|
|
9
|
+
# 每个都点开头或带**运行自己写下的 ns**(发布锁路径是唯一的例外 —— 「兼容声明」那条
|
|
10
|
+
# 要求管它,断言里显式排除并点名);契约点名的那条平铺形状(`teamsmith-smoke.*`,
|
|
11
|
+
# 事故命令的射程)对这些条目零命中。
|
|
12
|
+
# leg1 shadow :同一条腿换成被测树自己的翻转开关 `TMP_ROOT_BREAK=flat-name`(根回到平铺名)
|
|
13
|
+
# → 契约那条形状必须被命中,且那条目不满足命名规则 → leg0 那两条断言必红
|
|
14
|
+
# (证明它判的是命名规则,不是某一条具体命令)。
|
|
15
|
+
# leg2 lint :`--lint` 的两份副本 —— ①写死 `/tmp`;②家族前缀在、但丢了本项目的 ns —— 各必须
|
|
16
|
+
# 红且点名 file:line;还原成合式后必须绿。
|
|
17
|
+
# leg3 shape :命名判据的三条定名臂(正/反/反):①契约那条平铺旧名必须判平铺;②③带 ns 的合法名
|
|
18
|
+
# 必须判合法 —— 两条臂只差项目名里的 `_`,②(项目名不含 `_`)正是 V53-F1 的现场。
|
|
19
|
+
#
|
|
20
|
+
# 判据来自命名规则本身(V53-F1):**平铺 ⇔ 不是点开头、也不带运行自己的 ns**;不猜「家族正则」——
|
|
21
|
+
# ns 是 `<slug>-<hash8>`,slug 允许 `-`/`_`/字母数字,一条「中间段随便吃」的正则必然把 `<kind>-<ns>`
|
|
22
|
+
# 也吃进去:改动前那条 `^(teamsmith|review)-[a-z0-9-]*\.[A-Za-z0-9]{6}$` 在项目名不含 `_` 时把**合法根**
|
|
23
|
+
# `teamsmith-smoke-cand-<hash8>.<rand>` 判成平铺名(同一个交付物里 34c 段用的却是契约那条
|
|
24
|
+
# `teamsmith-smoke.*`;`--break=flat-regex` 把那条旧正则装回来,红侧就是它)。
|
|
25
|
+
# 「运行自己的 ns」取自**运行自己写的台账头**(`… ns=<ns>`),并与本夹具算的 ns 对照:两者必须同源 ——
|
|
26
|
+
# smoke.sh 自己 unset TEAM_PROJECT(第 58 行),运行的 ns 一律由检出路径推出,所以本夹具算 ns 时也不认
|
|
27
|
+
# 调用者环境里的 TEAM_PROJECT(否则父进程一个 ns、子运行另一个 ns,判定就没有参照了)。
|
|
28
|
+
#
|
|
29
|
+
# 红侧(`--break=`,只作用于本夹具的判定:不改被测树,也不改任何产品行为):
|
|
30
|
+
# never-flat —— 平铺判定永不成立:leg1 与 leg3① 必须因此变红(那两条臂有牙)。
|
|
31
|
+
# flat-regex —— 平铺判定换回改动前那条过宽的家族正则:leg3② 必须因此变红(F1 的现场)。
|
|
32
|
+
#
|
|
33
|
+
# 判绿规则:leg0 全绿、leg1/leg2/leg3 各按预期。全绿 exit 0;任何一条没按预期 → exit 1。
|
|
34
|
+
# 只写自己的临时根(`${TMPDIR:-/tmp}` 下,点开头或带 ns),只碰自己的私有锁与私有临时根;
|
|
35
|
+
# 绝不碰机器锁(`TEAM_SMOKE_LOCK` 一律显式指向私有路径)。
|
|
36
|
+
set -uo pipefail
|
|
37
|
+
|
|
38
|
+
FLIP_SKILL="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
39
|
+
KEEP=0; FLIP_BREAK=""
|
|
40
|
+
# 参数:`--self-test`(= 跑全部腿;任务书的验收行)/ `--keep`(留现场)/ `--break=<stage>` /
|
|
41
|
+
# `<树>`(指定被测树)
|
|
42
|
+
while [ $# -gt 0 ]; do
|
|
43
|
+
case "$1" in
|
|
44
|
+
--self-test) shift ;;
|
|
45
|
+
--keep) KEEP=1; shift ;;
|
|
46
|
+
--break=*) FLIP_BREAK="${1#--break=}"; shift ;;
|
|
47
|
+
"") shift ;;
|
|
48
|
+
*) FLIP_SKILL="$(cd "$1" 2>/dev/null && pwd)" \
|
|
49
|
+
|| { printf 'flip-p287-name: 树不存在:%s\n' "$1" >&2; exit 2; }
|
|
50
|
+
shift ;;
|
|
51
|
+
esac
|
|
52
|
+
done
|
|
53
|
+
case "$FLIP_BREAK" in
|
|
54
|
+
""|never-flat|flat-regex) ;;
|
|
55
|
+
*) printf 'flip-p287-name: 未知的 --break=%s(只认 never-flat / flat-regex)\n' "$FLIP_BREAK" >&2; exit 2 ;;
|
|
56
|
+
esac
|
|
57
|
+
|
|
58
|
+
# ns 的唯一实现在被测树的 scripts/lib/common.sh(本文件也要给自己起带 ns 的名字)
|
|
59
|
+
if ! declare -F team_project_ns >/dev/null 2>&1; then
|
|
60
|
+
# shellcheck source=../scripts/lib/common.sh
|
|
61
|
+
. "$FLIP_SKILL/scripts/lib/common.sh" 2>/dev/null \
|
|
62
|
+
|| { printf 'flip-p287-name: 找不到 %s/scripts/lib/common.sh(skill 树不全)\n' "$FLIP_SKILL" >&2; exit 2; }
|
|
63
|
+
fi
|
|
64
|
+
# 本夹具算的 ns 必须与**嵌套运行实际用的那个**同源:`TEAM_PROJECT=`(空)让 team_project_ns 走
|
|
65
|
+
# 「检出路径」那条路 —— smoke.sh 自己 unset TEAM_PROJECT,运行的 ns 也一律由检出路径推出。
|
|
66
|
+
p287n_ns_path() { TEAM_PROJECT= team_project_ns 2>/dev/null || printf 'nosig-00000000'; }
|
|
67
|
+
# 同一个实现、指定项目名(leg3 的 ②③ 两臂用:只换 slug,不复制 ns 的形状假设)
|
|
68
|
+
p287n_ns_slug() { TEAM_PROJECT="$1" team_project_ns 2>/dev/null || printf 'nosig-00000000'; }
|
|
69
|
+
NS="$(p287n_ns_path)"
|
|
70
|
+
BASE="$(team_tmp_root)"
|
|
71
|
+
OUT="$(mktemp -d "$BASE/.teamsmith-p287flip-name-$NS.XXXXXX")" || exit 2
|
|
72
|
+
FLIP_RC=0
|
|
73
|
+
note() { printf '%s\n' "$*"; }
|
|
74
|
+
line_ok() { note " ✓ $*"; }
|
|
75
|
+
line_bad() { note " ✗ $*"; FLIP_RC=1; }
|
|
76
|
+
|
|
77
|
+
# 唯一被排除的条目:发布锁路径(它的丢失只印不停,由 P287 的另一条要求管)
|
|
78
|
+
PUB_LOCK="teamsmith-smoke.lock"
|
|
79
|
+
# 契约点名的那条平铺形状(事故命令的射程):前缀 + 点 —— 带 ns 的名字里点前面还有 `-<ns>`,够不着。
|
|
80
|
+
# 这条 glob 是承重的:它与 34c 段「平铺家族模式(teamsmith-smoke.*)零命中」同口径;但它**不**承担
|
|
81
|
+
# 「判平铺」的全部语义(那由命名规则负责,见 p287n_is_flat),只负责钉住事故那条射程。
|
|
82
|
+
p287n_contract_hit() { # <条目名> → 0 = 落在事故那条射程里
|
|
83
|
+
case "$1" in teamsmith-smoke.*) return 0 ;; *) return 1 ;; esac
|
|
84
|
+
}
|
|
85
|
+
# 平铺判定 = 命名规则本身:不是点开头、也不带参照 ns。`--break=` 只把这条换回旧形状(红侧证据)。
|
|
86
|
+
p287n_is_flat() { # <条目名> <参照 ns> → 0 = 平铺旧形状
|
|
87
|
+
local name="$1" ns="${2:-$NS}"
|
|
88
|
+
case "$FLIP_BREAK" in
|
|
89
|
+
never-flat) return 1 ;; # 红侧:判定永不判平铺(腿得有牙才看得出)
|
|
90
|
+
flat-regex) # 红侧:改动前那条过宽的家族正则 —— 项目名不含 `_` 时吃掉整个 ns 段
|
|
91
|
+
case "$name" in .*) return 1 ;; esac
|
|
92
|
+
[[ "$name" =~ ^(teamsmith|review)-[a-z0-9-]*\.[A-Za-z0-9]{6}$ ]] && return 0
|
|
93
|
+
return 1 ;;
|
|
94
|
+
esac
|
|
95
|
+
case "$name" in .*) return 1 ;; esac
|
|
96
|
+
[ -n "$ns" ] || return 0 # 没有参照 ns:fail-closed(判平铺),绝不当成「合规」
|
|
97
|
+
case "$name" in *"$ns"*) return 1 ;; esac
|
|
98
|
+
return 0
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
# 一套夹具运行:私有 TMPDIR + 私有锁;边跑边把临时根里的条目收进 watch 文件
|
|
102
|
+
p287n_run() { # <tmpdir> <日志> [<break 值>]
|
|
103
|
+
local td="$1" log="$2" brk="${3:-}" b=() watch ledger leg
|
|
104
|
+
# 注意:同一个 local 语句里后面的变量不能引用前面刚赋的(left-to-right 求值时还没赋值)
|
|
105
|
+
leg="$(basename "${log%.log}")"
|
|
106
|
+
watch="$OUT/watch-$leg.txt"; ledger="$OUT/ledger-$leg.txt"
|
|
107
|
+
[ -n "$brk" ] && b=(TMP_ROOT_BREAK="$brk")
|
|
108
|
+
: > "$watch"
|
|
109
|
+
( cd "$td" && env -u TEAM_ROOT -u TEAM_MAIN_ROOT -u TEAM_PROJECT -u TEAM_SESSION -u TEAM_SMOKE_LOCK \
|
|
110
|
+
-u TEAM_SMOKE_LOCK_WAIT -u TEAM_SMOKE_BREAK -u TEAM_SMOKE_FAST -u TEAM_SMOKE_NO_LOCK \
|
|
111
|
+
-u SMOKE_LOCK_WRAPPED -u SMOKE_LOCK_QUEUED -u SMOKE_LOCK_MARKER -u SMOKE_LOCK \
|
|
112
|
+
-u TMP_ROOT_BREAK -u TMP_ROOT_NS \
|
|
113
|
+
TMPDIR="$td" TEAM_SMOKE_LOCK="$td/$PUB_LOCK" TEAM_SMOKE_FIXTURE=1 ${b[@]+"${b[@]}"} \
|
|
114
|
+
bash "$FLIP_SKILL/tests/smoke.sh" --select 0b,0c ) >"$log" 2>&1 &
|
|
115
|
+
local pid=$! i
|
|
116
|
+
for i in $(seq 1 600); do
|
|
117
|
+
kill -0 "$pid" 2>/dev/null || break
|
|
118
|
+
for e in "$td"/* "$td"/.[!.]*; do
|
|
119
|
+
[ -e "$e" ] || continue
|
|
120
|
+
printf '%s\n' "${e##*/}" >>"$watch"
|
|
121
|
+
# 运行自己写的台账头(带 ns=)在**主人活着时**抓一次:干净收尾会把它们一起收走
|
|
122
|
+
case "${e##*/}" in
|
|
123
|
+
.teamsmith-tmp-ledger.*) [ -s "$ledger" ] || head -1 "$e" >"$ledger" 2>/dev/null || true ;;
|
|
124
|
+
esac
|
|
125
|
+
done
|
|
126
|
+
sleep 0.05
|
|
127
|
+
done
|
|
128
|
+
wait "$pid"
|
|
129
|
+
}
|
|
130
|
+
p287n_entries() { sort -u "$1" | grep -v '^$' || true; }
|
|
131
|
+
# 该腿运行**自己写下**的 ns(台账头 `# teamsmith temp ledger run=… repo=… ns=<ns>`);读不到 → 非 0
|
|
132
|
+
p287n_leg_ns() { # <腿名>
|
|
133
|
+
local f="$OUT/ledger-$1.txt"
|
|
134
|
+
[ -s "$f" ] || return 1
|
|
135
|
+
sed -n 's/.* ns=//p' "$f" | head -1
|
|
136
|
+
}
|
|
137
|
+
# 条目判定(leg0/leg1 的唯一实现):点开头或带参照 ns = 合规;否则就是平铺旧形状。打印 BAD 条数。
|
|
138
|
+
p287n_classify() { # <watch 文件> <参照 ns> <审计文件>
|
|
139
|
+
local w="$1" ns="$2" out="$3" name bad=0
|
|
140
|
+
: > "$out"
|
|
141
|
+
# 去重后再判:watch 文件是**轮询**攒的,同一个条目会出现很多次(display 用的 p287n_entries 也一样)
|
|
142
|
+
while IFS= read -r name; do
|
|
143
|
+
[ -n "$name" ] || continue
|
|
144
|
+
if [ "$name" = "$PUB_LOCK" ]; then
|
|
145
|
+
printf 'EXCLUDE %s(发布锁路径:兼容声明,由另一条要求管)\n' "$name" >>"$out"
|
|
146
|
+
continue
|
|
147
|
+
fi
|
|
148
|
+
if p287n_is_flat "$name" "$ns"; then
|
|
149
|
+
printf 'BAD %s ← 既不点开头、也不带 ns %s(平铺旧形状)\n' "$name" "$ns" >>"$out"
|
|
150
|
+
bad=$((bad + 1))
|
|
151
|
+
else
|
|
152
|
+
printf 'OK %s\n' "$name" >>"$out"
|
|
153
|
+
fi
|
|
154
|
+
done < <(p287n_entries "$w")
|
|
155
|
+
printf '%s\n' "$bad"
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
note "== leg0 green:私有临时根里,每个条目点开头或带 ns =="
|
|
159
|
+
TD0="$BASE/.teamsmith-p287n0-$$"; rm -rf "$TD0"; mkdir -p "$TD0"
|
|
160
|
+
p287n_run "$TD0" "$OUT/leg0.log"
|
|
161
|
+
ENTRIES="$(p287n_entries "$OUT/watch-leg0.txt")"
|
|
162
|
+
[ -n "$ENTRIES" ] && line_ok "收到临时根里的条目:$(printf '%s' "$ENTRIES" | tr '\n' ' ')" \
|
|
163
|
+
|| line_bad "临时根里一个条目都没收到(夹具没跑起来?)"
|
|
164
|
+
# 参照 ns = 运行自己写的那个;读不到或不一致都算红(判绿不许建立在假设的 ns 上)
|
|
165
|
+
NS0="$(p287n_leg_ns leg0)" || NS0=""
|
|
166
|
+
if [ -z "$NS0" ]; then
|
|
167
|
+
line_bad "leg0:读不到运行自己写的 ns(台账头 $OUT/ledger-leg0.txt)—— 判定没有参照"
|
|
168
|
+
elif [ "$NS0" != "$NS" ]; then
|
|
169
|
+
line_bad "leg0:运行自己写的 ns($NS0)与本夹具算的($NS)不同源 —— 参照必须是运行自己写的那个"
|
|
170
|
+
else
|
|
171
|
+
line_ok "leg0:运行自己写的 ns 与本夹具算的一致($NS0)"
|
|
172
|
+
fi
|
|
173
|
+
BAD0="$(p287n_classify "$OUT/watch-leg0.txt" "$NS0" "$OUT/leg0.txt")"
|
|
174
|
+
if [ "${BAD0:-x}" != "0" ]; then
|
|
175
|
+
line_bad "leg0:有条目不合规(${BAD0:-?} 条)—— 见 $OUT/leg0.txt"
|
|
176
|
+
sed 's/^/ /' "$OUT/leg0.txt" | grep '^ BAD' | head -5
|
|
177
|
+
else
|
|
178
|
+
line_ok "leg0:全部条目点开头或带 ns($(grep -c '^OK ' "$OUT/leg0.txt") 条)"
|
|
179
|
+
fi
|
|
180
|
+
# 契约那条形状(事故命令的射程)零命中 —— 与 34c 段同一条断言口径(发布锁路径是显式例外)
|
|
181
|
+
FLAT0="$(printf '%s\n' "$ENTRIES" | grep -vxF -- "$PUB_LOCK" | grep -E '^teamsmith-smoke\.' || true)"
|
|
182
|
+
[ -z "$FLAT0" ] && line_ok "leg0:契约那条平铺形状(teamsmith-smoke.*)零命中" \
|
|
183
|
+
|| line_bad "leg0:契约平铺形状命中:$(printf '%s' "$FLAT0" | tr '\n' ' ')"
|
|
184
|
+
if [ -n "$NS0" ] && grep -q "^OK .*teamsmith-.*$NS0\..*" "$OUT/leg0.txt"; then
|
|
185
|
+
line_ok "leg0:至少一个条目是带 ns 的 owned 根(名字里有 -$NS0.)"
|
|
186
|
+
else
|
|
187
|
+
line_bad "leg0:没有收到带 ns 的根(名字里找不到 -$NS0.)"
|
|
188
|
+
fi
|
|
189
|
+
|
|
190
|
+
note "== leg1 shadow:TMP_ROOT_BREAK=flat-name(根回到平铺名)→ 契约那条形状必须命中 =="
|
|
191
|
+
TD1="$BASE/.teamsmith-p287n1-$$"; rm -rf "$TD1"; mkdir -p "$TD1"
|
|
192
|
+
p287n_run "$TD1" "$OUT/leg1.log" flat-name
|
|
193
|
+
ENTRIES1="$(p287n_entries "$OUT/watch-leg1.txt")"
|
|
194
|
+
NS1="$(p287n_leg_ns leg1)" || NS1=""
|
|
195
|
+
[ -n "$NS1" ] && [ "$NS1" = "$NS" ] \
|
|
196
|
+
|| line_bad "leg1:运行自己写的 ns 读不到或不一致([$NS1] vs [$NS])"
|
|
197
|
+
BAD1="$(p287n_classify "$OUT/watch-leg1.txt" "$NS1" "$OUT/leg1.txt")"
|
|
198
|
+
# 契约那条形状里的条目(发布锁路径是显式例外,与 leg0 同口径)
|
|
199
|
+
CONTRACT1="$(printf '%s\n' "$ENTRIES1" | grep -vxF -- "$PUB_LOCK" | grep -E '^teamsmith-smoke\.' || true)"
|
|
200
|
+
if [ -n "$CONTRACT1" ] && [ "${BAD1:-0}" != "0" ]; then
|
|
201
|
+
line_ok "leg1:shadow 下 $(printf '%s' "$CONTRACT1" | tr '\n' ' ') 命中契约形状,且它不满足命名规则(判的是命名规则)"
|
|
202
|
+
else
|
|
203
|
+
line_bad "leg1:shadow 下契约形状零命中 / 没有不合规条目(contract=[$CONTRACT1] bad=${BAD1:-?})—— 那条断言判不出「根回到平铺名」"
|
|
204
|
+
fi
|
|
205
|
+
|
|
206
|
+
note "== leg2 lint:写死 /tmp 与「家族前缀在、ns 丢了」两份副本各必须红,合式必须绿 =="
|
|
207
|
+
# 红侧素材放在 fixtures/p287/*.sh.in(不是 .sh,所以它们不在扫描面里):本夹具把它们**拷进副本树**再扫
|
|
208
|
+
# —— 这样「坏模板」只存在于临时副本里,不会让 `--lint` 对被测树自己报警,也不削弱那条规则。
|
|
209
|
+
for shape in hardcoded no-ns good; do
|
|
210
|
+
C="$OUT/lint-$shape"; mkdir -p "$C/lib"
|
|
211
|
+
IN="$FLIP_SKILL/tests/fixtures/p287/lint-$shape.sh.in"
|
|
212
|
+
if [ ! -f "$IN" ]; then printf 'flip-p287-name: 缺红侧素材 %s\n' "$IN" >&2; FLIP_RC=1; continue; fi
|
|
213
|
+
case "$shape" in
|
|
214
|
+
good) sed "s/@NS@/$NS/" "$IN" > "$C/lib/a.sh" ;;
|
|
215
|
+
*) cp "$IN" "$C/lib/a.sh" ;;
|
|
216
|
+
esac
|
|
217
|
+
rc=0
|
|
218
|
+
# `env -u TEAM_PROJECT`:`--lint` 的参照 ns 与运行的 ns 同源(检出路径),调用者环境不许漂移它
|
|
219
|
+
env -u TEAM_PROJECT bash "$FLIP_SKILL/tests/tmp-hygiene.sh" --lint --dir "$C" >"$OUT/lint-$shape.log" 2>&1 || rc=$?
|
|
220
|
+
printf '%s\n' "$rc" >"$OUT/lint-$shape.rc"
|
|
221
|
+
done
|
|
222
|
+
if [ "$(cat "$OUT/lint-hardcoded.rc")" != "0" ] && grep -qE 'a\.sh:[0-9]+' "$OUT/lint-hardcoded.log"; then
|
|
223
|
+
line_ok "leg2①:写死 /tmp 的副本红且点名 file:line($(grep -E -m1 'a\.sh:[0-9]+' "$OUT/lint-hardcoded.log" | sed 's/^ *//'))"
|
|
224
|
+
else
|
|
225
|
+
line_bad "leg2①:写死 /tmp 的副本没有红 / 没点名(rc=$(cat "$OUT/lint-hardcoded.rc"))"
|
|
226
|
+
fi
|
|
227
|
+
if [ "$(cat "$OUT/lint-no-ns.rc")" != "0" ] && grep -q '命名空间' "$OUT/lint-no-ns.log"; then
|
|
228
|
+
line_ok "leg2②:家族前缀在、丢了 ns 的副本红并点名命名空间($(grep -E -m1 'a\.sh:[0-9]+' "$OUT/lint-no-ns.log" | sed 's/^ *//'))"
|
|
229
|
+
else
|
|
230
|
+
line_bad "leg2②:丢了 ns 的副本没有红 / 没点名命名空间(rc=$(cat "$OUT/lint-no-ns.rc"))"
|
|
231
|
+
fi
|
|
232
|
+
if [ "$(cat "$OUT/lint-good.rc")" = "0" ]; then
|
|
233
|
+
line_ok "leg2③:合式(点开头/带 ns)绿"
|
|
234
|
+
else
|
|
235
|
+
line_bad "leg2③:合式副本被误判红(见 $OUT/lint-good.log)"
|
|
236
|
+
fi
|
|
237
|
+
|
|
238
|
+
note "== leg3 shape:①契约平铺旧名必须判平铺;②③带 ns 的合法名(项目名不含/含 \`_\`)必须判合法 =="
|
|
239
|
+
# 两条臂的 ns 都由**同一个** team_project_ns 生成,只换项目名(slug)—— 不复制它的形状假设。
|
|
240
|
+
NS_A="$(p287n_ns_slug cand)" # 项目名不含 `_`:②是 V53-F1 的现场
|
|
241
|
+
NS_B="$(p287n_ns_slug can_d)" # 项目名含 `_`:③是改动前恰好绿的那个方向
|
|
242
|
+
case "$NS_A" in
|
|
243
|
+
*_*) line_bad "leg3:臂②的项目名没有兑现「不含 \`_\`」(ns=$NS_A)—— 那条臂就不算 F1 的现场了" ;;
|
|
244
|
+
*) line_ok "leg3:臂②的 ns 里没有 \`_\`(ns=$NS_A,项目名不含 \`_\`)" ;;
|
|
245
|
+
esac
|
|
246
|
+
case "$NS_B" in
|
|
247
|
+
*_*) line_ok "leg3:臂③的 ns 里有 \`_\`(ns=$NS_B,项目名含 \`_\`)" ;;
|
|
248
|
+
*) line_bad "leg3:臂③的项目名没有兑现「含 \`_\`」(ns=$NS_B)—— 那个方向没被覆盖" ;;
|
|
249
|
+
esac
|
|
250
|
+
p287n_arm() { # <臂说明> <条目名> <期望 flat|named> <参照 ns>
|
|
251
|
+
local what="$1" name="$2" want="$3" ns="$4" got
|
|
252
|
+
if p287n_is_flat "$name" "$ns"; then got=flat; else got=named; fi
|
|
253
|
+
if [ "$got" = "$want" ]; then
|
|
254
|
+
line_ok "$what:$name → 判「$( [ "$want" = flat ] && printf '平铺' || printf '合法' )」(期望)"
|
|
255
|
+
else
|
|
256
|
+
line_bad "$what:$name → 期望 $want、实得 $got(判据与命名规则不一致)"
|
|
257
|
+
fi
|
|
258
|
+
}
|
|
259
|
+
p287n_arm "leg3①:契约那条平铺旧名" "teamsmith-smoke.Ab3xY9" flat "$NS"
|
|
260
|
+
p287n_arm "leg3②:带 ns 的合法名(项目名不含 \`_\`)" "teamsmith-smoke-$NS_A.Ab3xY9" named "$NS_A"
|
|
261
|
+
p287n_arm "leg3③:带 ns 的合法名(项目名含 \`_\`)" "teamsmith-smoke-$NS_B.Ab3xY9" named "$NS_B"
|
|
262
|
+
# 契约那条 glob 与命名判定必须一致:命中事故射程的只有①(②③是带 ns 的合法名,够不着那条 glob)
|
|
263
|
+
p287n_contract_hit "teamsmith-smoke.Ab3xY9" \
|
|
264
|
+
&& line_ok "leg3:①落在契约那条形状的射程里(teamsmith-smoke.*)" \
|
|
265
|
+
|| line_bad "leg3:①不在契约那条形状的射程里 —— 臂本身选错了"
|
|
266
|
+
if p287n_contract_hit "teamsmith-smoke-$NS_A.Ab3xY9" || p287n_contract_hit "teamsmith-smoke-$NS_B.Ab3xY9"; then
|
|
267
|
+
line_bad "leg3:②/③这种带 ns 的合法名命中了契约那条形状的射程 —— 两套判据互相矛盾"
|
|
268
|
+
else
|
|
269
|
+
line_ok "leg3:②/③都够不着契约那条形状的射程"
|
|
270
|
+
fi
|
|
271
|
+
|
|
272
|
+
note ""
|
|
273
|
+
if [ "$FLIP_RC" = "0" ]; then
|
|
274
|
+
note "FLIP 全绿:leg0 全绿 + shadow/lint/shape 三条腿各按预期(证据:$OUT)"
|
|
275
|
+
else
|
|
276
|
+
note "FLIP 有未达预期的腿(证据:$OUT)"
|
|
277
|
+
fi
|
|
278
|
+
[ "$KEEP" = "1" ] || { rm -rf "$TD0" "$TD1" 2>/dev/null || true; }
|
|
279
|
+
exit "$FLIP_RC"
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# flip-p304-read-side.sh — P304「读侧」的翻转夹具(change: tmux-identity-scope,apply-2)
|
|
3
|
+
#
|
|
4
|
+
# bash skills/teamsmith/tests/flip-p304-read-side.sh [--self-test|--keep]
|
|
5
|
+
#
|
|
6
|
+
# 三条红侧,每条只让**一条**规则失效,改的是产品源码的**副本**(`tests/tmux-identity-leak.sh --break=`,
|
|
7
|
+
# 本树从不改动),每条后面紧跟一条还原腿(不带 --break 再跑一次);红侧还必须**点名**具体那条断言:
|
|
8
|
+
#
|
|
9
|
+
# refuse 可归因路径退回「直接拒绝」 → ⑤(读侧自愈)必须红:rc=1 + ⑤c/⑤d/⑤e 被点名
|
|
10
|
+
# attrib-any 归因不看来源(有冲突就放行) → ⑥(守卫保留)必须红:⑥a/⑥b 放行了不可归因的现场
|
|
11
|
+
# doctor-write doctor 那行不再是只读 → ⑦(doctor 只读)必须红:全局环境被改 + state 被写
|
|
12
|
+
#
|
|
13
|
+
# 判绿规则:三条红各出 rc=1 且 ✗>0、三条还原各出 rc=0 且 ✗=0;全绿 exit 0,否则 exit 1。
|
|
14
|
+
# 只写自己的临时根(点开头 + 项目 ns,tmp-hygiene 的 owned 家族),--keep 才留现场。
|
|
15
|
+
set -uo pipefail
|
|
16
|
+
|
|
17
|
+
FLIP_SKILL="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
18
|
+
KEEP=0
|
|
19
|
+
case "${1:-}" in
|
|
20
|
+
--self-test|"") ;;
|
|
21
|
+
--keep) KEEP=1 ;;
|
|
22
|
+
*) printf 'flip-p304-read-side: 不认识的参数 %s(只认 --self-test / --keep)\n' "$1" >&2; exit 2 ;;
|
|
23
|
+
esac
|
|
24
|
+
|
|
25
|
+
FIX="$FLIP_SKILL/tests/tmux-identity-leak.sh"
|
|
26
|
+
[ -f "$FIX" ] || { printf 'flip-p304-read-side: 找不到 %s\n' "$FIX" >&2; exit 2; }
|
|
27
|
+
# shellcheck source=../scripts/lib/common.sh
|
|
28
|
+
. "$FLIP_SKILL/scripts/lib/common.sh" 2>/dev/null \
|
|
29
|
+
|| { printf 'flip-p304-read-side: 找不到 %s/scripts/lib/common.sh(skill 树不全)\n' "$FLIP_SKILL" >&2; exit 2; }
|
|
30
|
+
NS="$(team_project_ns 2>/dev/null || printf 'nosig-00000000')"
|
|
31
|
+
BASE="$(team_tmp_root)"
|
|
32
|
+
ROOT="$(mktemp -d "$BASE/.teamsmith-p304flip-$NS.XXXXXX")" || exit 2
|
|
33
|
+
|
|
34
|
+
FLIP_RC=0
|
|
35
|
+
note() { printf '%s\n' "$*"; }
|
|
36
|
+
line_ok() { note " ✓ $*"; }
|
|
37
|
+
line_bad() { note " ✗ $*"; FLIP_RC=1; }
|
|
38
|
+
|
|
39
|
+
# 一条腿:跑夹具,抓 rc 与末行 ✓/✗ 计数。期望 rc:红侧 1、还原 0。
|
|
40
|
+
leg() { # <名字> <期望 rc> <选择> <break 值|-> <必须点名的 ✗ 文本|-> …
|
|
41
|
+
local name="$1" want="$2" sel="$3" brk="$4"; shift 4
|
|
42
|
+
local log="$ROOT/$name.log" rc=0 want_flip=0 x=""
|
|
43
|
+
[ "$want" = "1" ] && want_flip=1
|
|
44
|
+
if [ "$brk" = "-" ]; then
|
|
45
|
+
( cd "$FLIP_SKILL" && bash "$FIX" --select "$sel" ) >"$log" 2>&1 || rc=$?
|
|
46
|
+
else
|
|
47
|
+
( cd "$FLIP_SKILL" && bash "$FIX" --select "$sel" --break="$brk" ) >"$log" 2>&1 || rc=$?
|
|
48
|
+
fi
|
|
49
|
+
# 夹具的结果行带 ANSI 颜色(`✓ 15 ✗ 0`)——先剥色再取 ✗ 计数;剥色后的副本也用作点名判据(grep -a 在二进制风险上更稳)
|
|
50
|
+
sed -e 's/\x1b\[[0-9;]*m//g' "$log" > "$log.clean" 2>/dev/null || : > "$log.clean"
|
|
51
|
+
x="$(sed -n 's/.*结果 ==.*✗[[:space:]]*\([0-9][0-9]*\).*/\1/p' "$log.clean" | tail -1)"
|
|
52
|
+
note "leg $name:rc=$rc ✗=${x:-?}($sel${brk:+/--break=$brk})"
|
|
53
|
+
[ "$rc" = "$want" ] || line_bad "$name:退出码应当 $want,实际 $rc"
|
|
54
|
+
if [ -z "$x" ]; then
|
|
55
|
+
line_bad "$name:日志里没有结果行(夹具没跑到收口)"
|
|
56
|
+
elif [ "$want_flip" = "1" ] && [ "$x" = "0" ]; then
|
|
57
|
+
line_bad "$name:红侧一条 ✗ 都没有(守卫没被证到)"
|
|
58
|
+
elif [ "$want_flip" = "0" ] && [ "$x" != "0" ]; then
|
|
59
|
+
line_bad "$name:还原后仍有 $x 条 ✗"
|
|
60
|
+
fi
|
|
61
|
+
local pat
|
|
62
|
+
for pat in ${1+"$@"}; do
|
|
63
|
+
[ -n "$pat" ] || continue
|
|
64
|
+
if grep -aqF -- "✗ $pat" "$log.clean"; then line_ok "$name:点名了「$pat」"
|
|
65
|
+
else line_bad "$name:没有点名「$pat」(红侧不够具体)"; fi
|
|
66
|
+
done
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
note "== flip-p304-read-side(P304 读侧三条红 + 三条还原)=="
|
|
70
|
+
note "临时根:$ROOT"
|
|
71
|
+
note "夹具:$FIX"
|
|
72
|
+
|
|
73
|
+
# ⑤ 读侧自愈:可归因路径退回「直接拒绝」→ 自愈不成立
|
|
74
|
+
leg red-refuse 1 residue refuse \
|
|
75
|
+
'⑤c 残留形状下 team up 退出码 0(自愈:不再拒绝)' \
|
|
76
|
+
'⑤e stderr 一行点名来源:运行中的 tmux server 的全局环境'
|
|
77
|
+
leg green-residue 0 residue -
|
|
78
|
+
|
|
79
|
+
# ⑥ 守卫保留:归因不看来源 → 不可归因的现场被放行
|
|
80
|
+
leg red-attrib-any 1 guard-kept attrib-any \
|
|
81
|
+
'⑥a 显式外来环境仍被拒(rc=1)' \
|
|
82
|
+
'⑥b 半可归因仍被拒(rc=1)'
|
|
83
|
+
leg green-guard-kept 0 guard-kept -
|
|
84
|
+
|
|
85
|
+
# ⑦ doctor 只读:那一行开始写盘 / 写共享 server 全局环境
|
|
86
|
+
leg red-doctor-write 1 doctor doctor-write \
|
|
87
|
+
'⑦c 跑完全局环境逐字节未变(只读,不代改)' \
|
|
88
|
+
'⑦c 项目 state 里一个文件都没多/没变(产品自己不写盘)'
|
|
89
|
+
leg green-doctor 0 doctor -
|
|
90
|
+
|
|
91
|
+
note ""
|
|
92
|
+
if [ "$FLIP_RC" = "0" ]; then
|
|
93
|
+
note "FLIP 全绿:三条红各自点名、三条还原各自回绿(证据:$ROOT)"
|
|
94
|
+
else
|
|
95
|
+
note "FLIP 有未达预期的腿(证据:$ROOT)"
|
|
96
|
+
fi
|
|
97
|
+
[ "$KEEP" = "1" ] || rm -rf "$ROOT"
|
|
98
|
+
exit "$FLIP_RC"
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# flip-p308-skip-not-pass.sh — P308「跳过不是通过」的翻转夹具(change: tmux-identity-scope · F1′)
|
|
3
|
+
#
|
|
4
|
+
# bash skills/teamsmith/tests/flip-p308-skip-not-pass.sh [--keep]
|
|
5
|
+
#
|
|
6
|
+
# 修的是一条**判据**:`tests/tmux-identity-leak.sh` 的收口原来判 `PASS==0 && FAIL==0`,而两条隔离断言
|
|
7
|
+
# 在任何现场都给 ✓ —— 于是「tmux 坏了、七段全跳过」的现场拿到 rc=0(V48 的 F1′)。现在按**段数**判。
|
|
8
|
+
# 三条腿把「修的是判据」这件事钉住(改的都是现场或临时副本,本树的夹具只在腿 2 里被**复制**再改):
|
|
9
|
+
#
|
|
10
|
+
# red-now 假 tmux(解析得到、`-V` 失败)+ `--all` → rc=77,并点名「跳过不是通过」
|
|
11
|
+
# legacy-predicate 同一现场 + 收口换回 `PASS==0 && FAIL==0` → **rc=0**(旧判据把同一个现场判成通过)
|
|
12
|
+
# audit-single 同一现场 + `--select audit` → rc=0(④ 不需要 tmux,合法单跑不许被误判成跳过)
|
|
13
|
+
# green-normal 正常环境 + `--all` → rc=0 且没有段被跳过(不许把正常情形判成跳过)
|
|
14
|
+
#
|
|
15
|
+
# 判绿:四条腿都符合预期 → exit 0;有腿不符 → exit 1;正常环境没有可用的 tmux(green-normal 没法测)
|
|
16
|
+
# → 别的腿照判,全对时 exit 77(跳过不是通过 —— 这个脚本自己也守同一条纪律)。
|
|
17
|
+
# 只写自己的临时根(点开头 + 项目 ns,tmp-hygiene 的 owned 家族),--keep 才留现场。
|
|
18
|
+
set -uo pipefail
|
|
19
|
+
|
|
20
|
+
FLIP_SKILL="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
21
|
+
KEEP=0
|
|
22
|
+
case "${1:-}" in
|
|
23
|
+
--self-test|"") ;;
|
|
24
|
+
--keep) KEEP=1 ;;
|
|
25
|
+
*) printf 'flip-p308-skip-not-pass: 不认识的参数 %s(只认 --self-test / --keep)\n' "$1" >&2; exit 2 ;;
|
|
26
|
+
esac
|
|
27
|
+
|
|
28
|
+
FIX="$FLIP_SKILL/tests/tmux-identity-leak.sh"
|
|
29
|
+
[ -f "$FIX" ] || { printf 'flip-p308-skip-not-pass: 找不到 %s\n' "$FIX" >&2; exit 2; }
|
|
30
|
+
grep -qF '# >>> P308 close-out predicate' "$FIX" \
|
|
31
|
+
|| { printf 'flip-p308-skip-not-pass: %s 里没有变异标记(夹具被改过?)\n' "$FIX" >&2; exit 2; }
|
|
32
|
+
# shellcheck source=../scripts/lib/common.sh
|
|
33
|
+
. "$FLIP_SKILL/scripts/lib/common.sh" 2>/dev/null \
|
|
34
|
+
|| { printf 'flip-p308-skip-not-pass: 找不到 %s/scripts/lib/common.sh(skill 树不全)\n' "$FLIP_SKILL" >&2; exit 2; }
|
|
35
|
+
NS="$(team_project_ns 2>/dev/null || printf 'nosig-00000000')"
|
|
36
|
+
BASE="$(team_tmp_root)"
|
|
37
|
+
ROOT="$(mktemp -d "$BASE/.teamsmith-p308flip-$NS.XXXXXX")" || exit 2
|
|
38
|
+
|
|
39
|
+
FLIP_RC=0; SKIPPED=0
|
|
40
|
+
note() { printf '%s\n' "$*"; }
|
|
41
|
+
line_ok() { note " ✓ $*"; }
|
|
42
|
+
line_bad() { note " ✗ $*"; FLIP_RC=1; }
|
|
43
|
+
strip() { sed -e 's/\x1b\[[0-9;]*m//g' "$1" > "$1.clean" 2>/dev/null || : > "$1.clean"; }
|
|
44
|
+
|
|
45
|
+
# 假 tmux:**解析得到**(`command -v tmux` 命中)、但 `-V` 失败 —— V48 那个现场的精确形状。
|
|
46
|
+
# 它不执行任何 tmux 动词,只是让夹具的可用性探针失败(`exit 1`)。
|
|
47
|
+
FAKEBIN="$ROOT/fakebin"
|
|
48
|
+
mkdir -p "$FAKEBIN"
|
|
49
|
+
printf '#!/usr/bin/env bash\nexit 1\n' > "$FAKEBIN/tmux"
|
|
50
|
+
chmod +x "$FAKEBIN/tmux"
|
|
51
|
+
FAKE_PATH="$FAKEBIN:/usr/bin:/bin"
|
|
52
|
+
|
|
53
|
+
# 腿:跑一份夹具,抓 rc / 结果行
|
|
54
|
+
leg() { # <名字> <PATH> <夹具路径> <args…> → 打印 "rc=<n>",日志在 $ROOT/<名字>.log[.clean]
|
|
55
|
+
local name="$1" path="$2" fix="$3"; shift 3
|
|
56
|
+
local rc=0
|
|
57
|
+
( cd "$FLIP_SKILL" && PATH="$path" bash "$fix" "$@" ) > "$ROOT/$name.log" 2>&1 || rc=$?
|
|
58
|
+
strip "$ROOT/$name.log"
|
|
59
|
+
printf '%s' "$rc"
|
|
60
|
+
}
|
|
61
|
+
res_line() { grep -a '== tmux-identity-leak 结果 ==' "$ROOT/$1.log.clean" | tail -1; }
|
|
62
|
+
leg_has() { grep -aqF -- "$3" "$ROOT/$2.log.clean" && line_ok "$1:出现「$3」" || line_bad "$1:没有出现「$3」"; }
|
|
63
|
+
leg_not() { grep -aqF -- "$3" "$ROOT/$2.log.clean" && line_bad "$1:不该出现「$3」" || line_ok "$1:没有「$3」"; }
|
|
64
|
+
leg_rc() { if [ "$3" = "$2" ]; then line_ok "$1:rc=$2"; else line_bad "$1:退出码应当 $2,实际 $3"; fi }
|
|
65
|
+
|
|
66
|
+
note "== flip-p308-skip-not-pass(P308 · 收口按段数判,不按 PASS 判)=="
|
|
67
|
+
note "临时根:$ROOT"
|
|
68
|
+
note "夹具:$FIX"
|
|
69
|
+
|
|
70
|
+
# ── 腿 1:现在的现场(假 tmux、全跳过)必须 rc=77 ───────────────────────────────────────────────
|
|
71
|
+
rc="$(leg red-now "$FAKE_PATH" "$FIX" --all)"
|
|
72
|
+
note "leg red-now:rc=$rc($([ "$rc" = 77 ] && echo 77 || echo "期望 77"))"
|
|
73
|
+
leg_rc red-now 77 "$rc"
|
|
74
|
+
leg_has red-now red-now '跳过不是通过'
|
|
75
|
+
leg_has red-now red-now '需要 tmux 的 6 段一段都没跑起来'
|
|
76
|
+
leg_has red-now red-now '跳过 7 段'
|
|
77
|
+
|
|
78
|
+
# ── 腿 2:把收口换回旧判据(PASS==0 && FAIL==0)→ 同一个现场必须**再次 rc=0** ──────────────────
|
|
79
|
+
# 变异只发生在临时镜像里:夹具复制到 <tmp>/mirror/skills/teamsmith/tests/,lib 与 scripts 用软链指回本树
|
|
80
|
+
# (这样 REPO_ROOT/SKILL_DIR 的推导与真身一致,产品代码仍是本树那一份,本树逐字节不动)。
|
|
81
|
+
MIRROR="$ROOT/mirror/skills/teamsmith"
|
|
82
|
+
mkdir -p "$MIRROR/tests"
|
|
83
|
+
ln -s "$FLIP_SKILL/tests/lib" "$MIRROR/tests/lib"
|
|
84
|
+
ln -s "$FLIP_SKILL/scripts" "$MIRROR/scripts"
|
|
85
|
+
LEGACY_BLOCK="$ROOT/legacy-closeout.sh"
|
|
86
|
+
cat > "$LEGACY_BLOCK" <<'LEGACYEOF'
|
|
87
|
+
if [ "$PASS" -eq 0 ] && [ "$FAIL" -eq 0 ]; then
|
|
88
|
+
printf '\033[33m跳过不是通过\033[0m:tmux 解析到了但不可用(%s -V 失败),本机没有可测的现场(rc=77)\n' "$REAL_TMUX"
|
|
89
|
+
exit 77
|
|
90
|
+
fi
|
|
91
|
+
LEGACYEOF
|
|
92
|
+
awk -v legacy="$LEGACY_BLOCK" '
|
|
93
|
+
/^# >>> P308 close-out predicate/ { inblock = 1; next }
|
|
94
|
+
/^# <<< P308 close-out predicate/ { inblock = 0; while ((getline l < legacy) > 0) print l; close(legacy); next }
|
|
95
|
+
inblock { next }
|
|
96
|
+
{ print }
|
|
97
|
+
' "$FIX" > "$MIRROR/tests/tmux-identity-leak.sh"
|
|
98
|
+
# 变异必须真的应用了(不然这条腿证不到任何东西)
|
|
99
|
+
if grep -qF 'if [ "$PASS" -eq 0 ] && [ "$FAIL" -eq 0 ]; then' "$MIRROR/tests/tmux-identity-leak.sh" \
|
|
100
|
+
&& ! grep -qF '# >>> P308 close-out predicate' "$MIRROR/tests/tmux-identity-leak.sh"; then
|
|
101
|
+
line_ok 'legacy-predicate:临时镜像里的收口已换回旧判据(PASS==0 && FAIL==0)'
|
|
102
|
+
else
|
|
103
|
+
line_bad 'legacy-predicate:变异没应用(镜像里还是新判据 / 旧判据没写进去)'
|
|
104
|
+
fi
|
|
105
|
+
rc="$(leg legacy-predicate "$FAKE_PATH" "$MIRROR/tests/tmux-identity-leak.sh" --all)"
|
|
106
|
+
note "leg legacy-predicate:rc=$rc(旧判据下同一现场应当 rc=0 —— 这就是 F1′ 的假绿)"
|
|
107
|
+
leg_rc legacy-predicate 0 "$rc"
|
|
108
|
+
leg_not legacy-predicate legacy-predicate '跳过不是通过'
|
|
109
|
+
leg_has legacy-predicate legacy-predicate '跳过 7 段'
|
|
110
|
+
|
|
111
|
+
# ── 腿 3:④(审计)不需要 tmux —— 合法单跑不许被新判据误判成「全跳过」 ─────────────────────────
|
|
112
|
+
rc="$(leg audit-single "$FAKE_PATH" "$FIX" --select audit)"
|
|
113
|
+
note "leg audit-single:rc=$rc(④ 只靠 stub,合法单跑应当 rc=0)"
|
|
114
|
+
leg_rc audit-single 0 "$rc"
|
|
115
|
+
leg_not audit-single audit-single '跳过不是通过'
|
|
116
|
+
|
|
117
|
+
# ── 腿 4:正常环境:rc=0 且**没有段被跳过**(不许把正常情形判成跳过)────────────────────────────
|
|
118
|
+
REAL_TMUX="$(command -v tmux 2>/dev/null || true)"
|
|
119
|
+
if [ -z "$REAL_TMUX" ] || ! timeout 5 "$REAL_TMUX" -V >/dev/null 2>&1; then
|
|
120
|
+
note "leg green-normal:· 跳过 —— 本机没有可用的 tmux(${REAL_TMUX:-解析不到}),这一段测不了"
|
|
121
|
+
SKIPPED=1
|
|
122
|
+
else
|
|
123
|
+
rc="$(leg green-normal "$PATH" "$FIX" --all)"
|
|
124
|
+
note "leg green-normal:rc=$rc($(res_line green-normal))"
|
|
125
|
+
leg_rc green-normal 0 "$rc"
|
|
126
|
+
mg="$(res_line green-normal)"
|
|
127
|
+
case "$mg" in
|
|
128
|
+
*跳过*) line_bad "green-normal:正常环境里仍有段被跳过($mg)" ;;
|
|
129
|
+
'') line_bad 'green-normal:没有结果行(夹具没跑到收口)' ;;
|
|
130
|
+
*) line_ok "green-normal:没有段被跳过($mg)" ;;
|
|
131
|
+
esac
|
|
132
|
+
grep -aqF '✓ ①c server 全局环境里本项目 TEAM_* 条数' "$ROOT/green-normal.log.clean" \
|
|
133
|
+
&& line_ok 'green-normal:①(写侧)真的跑了(不是只剩隔离断言)' \
|
|
134
|
+
|| line_bad 'green-normal:① 没跑(正常环境里身份契约没被测)'
|
|
135
|
+
fi
|
|
136
|
+
|
|
137
|
+
# ── 收口 ────────────────────────────────────────────────────────────────────────────────────────
|
|
138
|
+
note ""
|
|
139
|
+
if [ "$FLIP_RC" != "0" ]; then
|
|
140
|
+
note "FLIP 有未达预期的腿(证据:$ROOT)"
|
|
141
|
+
[ "$KEEP" = "1" ] || rm -rf "$ROOT"
|
|
142
|
+
exit 1
|
|
143
|
+
fi
|
|
144
|
+
if [ "$SKIPPED" = "1" ]; then
|
|
145
|
+
note "FLIP 的三条腿全中,但正常环境的绿侧测不了(没有可用的 tmux)—— 跳过不是通过(rc=77)"
|
|
146
|
+
[ "$KEEP" = "1" ] || rm -rf "$ROOT"
|
|
147
|
+
exit 77
|
|
148
|
+
fi
|
|
149
|
+
note "FLIP 全绿:同一现场旧判据 rc=0 / 新判据 rc=77,审计单跑不被误判,正常环境无跳过(证据:$ROOT)"
|
|
150
|
+
[ "$KEEP" = "1" ] || rm -rf "$ROOT"
|
|
151
|
+
exit 0
|