Files
ssw-platform/scripts/check-naming.sh
T
admin ecb77b230f 平台包零业务:示例移到技能仓、解绑 example-packs、闸门全部改防回流
- 物理移出 packs/{asset,books,demo,shop}、modules/ 四个面 A 适配器、纯技能副本、
  纯业务测试 crud_it.rs 与 new-pack 脚手架(v0.3.0 tag 完整保留旧形态)。
- 删 example-packs feature / example_packs() / sspf-pack-* 依赖 / packs/* member;
  packs_gen.rs 与 modules/mod.rs 生成段降级为恒空的注入点,装配链一条不删;
  pack-sync.py 把「零包」钉成合法目标态。
- 尺子不再「跳过」:CP1 防回流清单、check-module 三条、AR2/PACK1 正向断言、
  AR17 升级为零业务依赖判据(含注入式反自证)、契约反自证换平台锚点、FACE 零包重算。
- 面 A 冒烟 43→21 条(17 条平台权限闭环 + 4 条业务端点 404);pack_smoke_it 改
  运行时防回流探针;auth/db/batch7/permission/seed/routes 单测换平台内置夹具。
- 契约 [MENU_TREE] 收成 5 条系统菜单、[RULER] 改 21/3;README/CLAUDE/HANDOFF/
  CHANGELOG/contract §5.1/schema.sql/db.rs 注释同步。

验收:cargo test --workspace --no-fail-fast 649 passed / 0 failed / 6 ignored;
verify.sh --smoke 14/14;check-arch 24/24 + 反自证 14/14;
cargo tree -p sspf 无 sspf-pack-*。前端 src/frontend 按要求保留。
2026-11-04 21:54:22 +08:00

209 lines
7.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# sspf 命名闸门 —— 原厂标识符剥离(PLAN.md §7.1)
#
# 判据只有一条:**前端 / 移动端 / 存量库是否依赖它**。
# - 结构性字符串(路径 / 键名 / 头名 / 码值 / 枚举 / 表单 JSON 的 jnpfKey)⇒ **一字不改**
# - 内部标识(crate / 模块 / 类型 / 函数 / 变量 / 文件名)⇒ **必须改**
# - 展示性文案(msg)⇒ 可改,语义不变
#
# 🔴 本尺子只查**内部标识**,绝不碰字符串字面量 ——
# 字符串里可能是契约(`/api/permission/Users`、表名、`jnpfKey`),改了前端就挂。
#
# 用法:
# bash scripts/check-naming.sh # 全查(RED 阻断 + YELLOW 报数)
# bash scripts/check-naming.sh --strict # 注释里的提及也算红(技术债清零时用)
# bash scripts/check-naming.sh --self-test # 反自证:造违规必须被抓到
#
# 退出码:0 全过 / 1 有 ❌ / 2 用法错
#
# ── 判据 ──
# NM1 源文件/目录名含原厂名 ⇒ 🔴 阻断
# NM2 Rust 标识符含原厂名 ⇒ 🔴 阻断
# (fn / struct / enum / trait / mod / const / static / type 之后的名字)
# NM3 Cargo.toml 的 package name 含原厂名 ⇒ 🔴 阻断
# NM4 代码注释里的提及 ⇒ 🟡 报数(技术债,逐步清零)
# `--strict` 时升级为 🔴
#
# 🔴 为什么注释不一刀切:`技能仓 JNPF_SOURCE_AUDIT.md` 这类文档整篇都是基线平台源码分析,
# 注释里写「官方 `VisualAiServiceImpl.form()`」是**出处**,不是品牌露出。
# 一刀切会逼人删掉溯源信息,反而降低可维护性。⇒ 量化 + 逐步替换成「基线平台」。
set -u
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
STRICT=0
SELF_TEST=0
for a in "$@"; do
case "$a" in
--strict) STRICT=1 ;;
--self-test) SELF_TEST=1 ;;
--help) sed -n '2,30p' "$0"; exit 0 ;;
*) echo "未知参数: $a"; exit 2 ;;
esac
done
PASS=0
FAIL=0
WARN=0
ok() { PASS=$((PASS + 1)); printf '✅ %s\n' "$1"; }
bad() { FAIL=$((FAIL + 1)); printf '❌ %s\n' "$1"; }
warn() { WARN=$((WARN + 1)); printf '🟡 %s\n' "$1"; }
# 只扫这些根(不要扫 target / node_modules / .workbuddy)
SCAN_ROOTS=("$ROOT/src" "$ROOT/crates" "$ROOT/packs")
# 原厂名模式(大小写全部覆盖;中文「引迈」单独一份)
PAT_EN='([Jj][Nn][Pp][Ff])'
PAT_ZH='引迈'
list_rs() {
local d
for d in "${SCAN_ROOTS[@]}"; do
[ -d "$d" ] || continue
find "$d" -name '*.rs' -not -path '*/target/*' 2>/dev/null
done
}
# ---------------------------------------------------------------- NM1 文件名
check_nm1() {
local hits
hits="$(for d in "${SCAN_ROOTS[@]}"; do
[ -d "$d" ] || continue
find "$d" \( -iname "*jnpf*" -o -name "*引迈*" \) -not -path '*/target/*' 2>/dev/null
done)"
if [ -z "$hits" ]; then
ok "NM1 源文件名无原厂名"
else
bad "NM1 源文件名含原厂名(改文件名 + 同步 mod 声明与引用):"
printf '%s\n' "$hits" | sed 's/^/ /'
fi
}
# ---------------------------------------------------------------- NM2 标识符
# 只匹配**声明位置**的名字,不碰字符串字面量与注释。
check_nm2() {
local hits
hits="$(python3 - "$ROOT" <<'PY'
import os, re, sys
root = sys.argv[1]
# 声明关键字后面的标识符
decl = re.compile(r'\b(fn|struct|enum|trait|mod|const|static|type)\s+([A-Za-z_][A-Za-z0-9_]*)')
bad_name = re.compile(r'(jnpf|引迈)', re.I)
out = []
for base in ('src', 'crates', 'packs'):
for dirpath, dirnames, files in os.walk(os.path.join(root, base)):
dirnames[:] = [d for d in dirnames if d not in ('target', 'node_modules', 'data')]
for fn in files:
if not fn.endswith('.rs'):
continue
p = os.path.join(dirpath, fn)
try:
lines = open(p, encoding='utf-8').read().splitlines()
except OSError:
continue
for i, line in enumerate(lines, 1):
code = line.split('//', 1)[0]
for m in decl.finditer(code):
name = m.group(2)
if bad_name.search(name):
out.append(f'{os.path.relpath(p, root)}:{i}: {m.group(1)} {name}')
for x in out:
print(x)
PY
)"
if [ -z "$hits" ]; then
ok "NM2 代码标识符无原厂名"
else
bad "NM2 标识符含原厂名(前端读不到 ⇒ 必须改):"
printf '%s\n' "$hits" | sed 's/^/ /'
fi
}
# ---------------------------------------------------------------- NM3 crate 名
check_nm3() {
local hits
hits="$(grep -rlEi '^name[[:space:]]*=[[:space:]]*".*(jnpf|引迈)' \
"$ROOT"/Cargo.toml "$ROOT"/src/*/Cargo.toml "$ROOT"/crates/*/Cargo.toml "$ROOT"/packs/*/Cargo.toml 2>/dev/null)"
if [ -z "$hits" ]; then
ok "NM3 crate / package 名无原厂名"
else
bad "NM3 crate 名含原厂名:"
printf '%s\n' "$hits" | sed 's/^/ /'
fi
}
# ---------------------------------------------------------------- NM4 注释提及
check_nm4() {
local n
n="$(python3 - "$ROOT" <<'PY'
import os, re, sys
root = sys.argv[1]
bad = re.compile(r'(jnpf|引迈)', re.I)
count = 0
for base in ('src', 'crates', 'packs'):
for dirpath, dirnames, files in os.walk(os.path.join(root, base)):
dirnames[:] = [d for d in dirnames if d not in ('target', 'node_modules', 'data')]
for fn in files:
if not fn.endswith('.rs'):
continue
p = os.path.join(dirpath, fn)
try:
text = open(p, encoding='utf-8').read()
except OSError:
continue
for line in text.splitlines():
idx = line.find('//')
if idx >= 0 and bad.search(line[idx:]):
count += 1
print(count)
PY
)"
if [ "$n" -eq 0 ]; then
ok "NM4 注释里无原厂名"
elif [ "$STRICT" -eq 1 ]; then
bad "NM4 注释里有 ${n} 处原厂名(--strict 模式):逐步替换为「基线平台 / baseline」"
else
warn "NM4 注释里有 ${n} 处提及(技术债,不阻断;--strict 可升级为红)"
fi
}
# ---------------------------------------------------------------- 反自证
self_test() {
echo "── 反自证:造一个含原厂标识符的文件,NM2 必须报 ❌ ──"
local tmp="$ROOT/crates/__naming_selftest__"
mkdir -p "$tmp/src"
printf 'pub fn jnpf_probe() {}\n' > "$tmp/src/lib.rs"
local before=$FAIL
check_nm2 >/dev/null 2>&1
local caught=0
[ "$FAIL" -gt "$before" ] && caught=1
rm -rf "$tmp"
FAIL=$before
if [ "$caught" -eq 1 ]; then
echo "✅ 反自证通过:NM2 抓到了 jnpf_probe"
return 0
fi
echo "❌ 反自证失败:NM2 没抓到明显违规 ⇒ 尺子是假的"
return 1
}
# ---------------------------------------------------------------- main
echo "── 命名闸门(内部标识剥离;结构性字符串不在检查范围)──"
check_nm1
check_nm2
check_nm3
check_nm4
echo
printf '结果: %d 通过 / %d 失败 / %d 提示\n' "$PASS" "$FAIL" "$WARN"
if [ "$SELF_TEST" -eq 1 ]; then
echo
self_test || exit 1
fi
[ "$FAIL" -eq 0 ] || exit 1
exit 0