refactor(arch): M3 契约面公共底座下沉 —— helper/res 进 crates/sspf-compat-core

平台能力全迁 crates/ 迁移计划第 3 批(docs/CRATES-MIGRATION.md)。
本批次 = M3:被 14 个契约面模块共用的底座先下沉,M4 的 6 个包才能都依赖它。

搬迁:
- compat/helper.rs(994) + compat/res.rs(460) git mv 进 crates/sspf-compat-core/src/
- src/backend/src/platform/compat/{helper,res}.rs 改成 pub use sspf_compat_core::<mod>::*
  ⇒ 14 个契约面模块的 use super::helper::{…} 零感知
- 路径改写 crate::platform::X → sspf_core::X(独立 crate 不能用 crate::X)
- pub(super) → pub(54 处):转发壳的 pub use …::* 只转发 pub 项(含 struct 字段)
- helper 的 8 个单测自足 ⇒ 随迁,总测试数不变 695

闸门改造(同 M2 纪律 = 两处都扫:真源 + 转发壳):
- check-arch.sh AR11 扫 crates/sspf-compat-core/src/helper.rs + 壳,
  并新增 Cargo.toml 级判据(sspf-compat-core 不许依赖 sspf-compat-* ⇒ M4 的 6 个包)
- check-arch.sh 反自证 6/6 两处注入探针、按路径分别验
- check-contract-scan.py 的 plat_files 对 compat__<mod> 收真源 + 壳同键拼接
  (守卫常量 EN_ROLE 等在 helper 真源里,漏收 ⇒ CC6 假漂移)
- 修 1 条引文:compat/helper.rs:89-92 → crates/sspf-compat-core/src/helper.rs:87-91

反向验证:只往真源 helper 塞 use crate::res::Res; ⇒ AR11 报红;清理后恢复绿。

顺带落档四个决策(§11):壳最后删 / compat 拆 6 包 / mcp_compat 放 crates / tests 跟着拆。

影响:功能零变化(响应形状、路由、语义均未动),纯结构下沉。
验证:cargo build 零警告;cargo test --workspace 695 passed / 0 failed(与基线一致);
check-arch 14/14;--self-test 6/6;check-boundary 11/11;check-contract 10/10(CC6 零漂移);
check-module 123/123;check-citations 4/4;verify --smoke 14 步全绿(561.3s)。
This commit is contained in:
admin committed 2026-11-03 17:48:41 +08:00
1 parent 94d05f4649
commit eea3d0329f
13 files changed
+1688 -1517

No files matched your search

+49 -29
View File
@@ -299,17 +299,36 @@ PY
# M1 已把 `menu_node` / `official_view_path` / `USER_DETAIL_COLUMNS` /
# `organize_name_of` 搬进 helper,切断了这两条边。
#
# 判据:`compat/helper.rs` 里不许 `use super::` 指向**非 helper 的模块**。
# 🔴 **M3 起底座真源在 `crates/sspf-compat-core/src/helper.rs`**(壳只剩 `pub use`)
# ⇒ 两处都扫(扫真源管实现 + 扫壳防塞私货)。跨 crate 形态的同一纪律 =
# `sspf-compat-core` 的 Cargo.toml 不许依赖 `sspf-compat-*`(M4 的 6 个包)。
#
# 判据(两处):
# ① `helper.rs`(真源或壳)里不许 `use super::` 指向**非 helper 的模块**,
# 也不许 `use crate::res`(同 crate 内的反向依赖);
# ② `crates/sspf-compat-core/Cargo.toml` 不许依赖 `sspf-compat-*`。
check_ar11() {
local f="$KERNEL/src/platform/compat/helper.rs"
[ -f "$f" ] || { skip "AR11 compat/helper.rs 不存在"; return; }
local hits
hits="$(grep -nE '^[[:space:]]*(pub )?use[[:space:]]+super::[a-z_]+' "$f" 2>/dev/null \
| grep -v 'super::helper' || true)"
local files=()
[ -f "$CRATES/sspf-compat-core/src/helper.rs" ] && files+=("$CRATES/sspf-compat-core/src/helper.rs")
[ -f "$KERNEL/src/platform/compat/helper.rs" ] && files+=("$KERNEL/src/platform/compat/helper.rs")
local hits=""
if [ "${#files[@]}" -gt 0 ]; then
hits="$(grep -nE '^[[:space:]]*(pub )?use[[:space:]]+(super::[a-z_]+|crate::res)' "${files[@]}" 2>/dev/null \
| grep -vE 'super::helper|crate::helper' || true)"
fi
# 跨 crate 形态:底座的 Cargo.toml 不许依赖 6 个契约面包
local toml="$CRATES/sspf-compat-core/Cargo.toml"
if [ -f "$toml" ]; then
local dep_hits
dep_hits="$(grep -nE '^\s*sspf-compat-[a-z-]+\s*=' "$toml" 2>/dev/null || true)"
if [ -n "$dep_hits" ]; then
hits="${hits:+$hits$'\n'}${dep_hits}"
fi
fi
if [ -z "$hits" ]; then
ok "AR11 契约面底座(helper)不依赖其它契约面模块(14 个模块依赖它 ⇒ 反向依赖即成环)"
ok "AR11 契约面底座(helper/sspf-compat-core)不依赖其它契约面模块(14 个模块依赖它 ⇒ 反向依赖即成环)"
else
bad "AR11 契约面底座(helper)反向依赖契约面业务模块(拆 crate 时即成环):"
bad "AR11 契约面底座反向依赖契约面业务模块(拆 crate 时即成环):"
printf '%s\n' "$hits" | sed 's/^/ /'
fi
}
@@ -593,28 +612,29 @@ RS
echo "── 反自证 6/6:往契约面底座塞 use super::system,AR11 必须报 ❌ ──"
#
# 🔴 造在**临时副本**上:不动真文件(helper.rs 是 900+ 行的活文件)。
local a11dir="$KERNEL/src/platform/compat"
local a11probe="$a11dir/__ar11_selftest.rs"
if [ -d "$a11dir" ] && [ -f "$a11dir/helper.rs" ]; then
# 🔴 AR11 只扫 `helper.rs` ⇒ 探针必须是 helper.rs 本身。
# 做法:备份真文件 → 追加违规行 → 跑判据 → 还原。
cp "$a11dir/helper.rs" "$a11dir/helper.rs.bak"
printf '\nuse super::system::menu_node;\n' >> "$a11dir/helper.rs"
before=$FAIL
check_ar11 >/dev/null 2>&1
caught=0
[ "$FAIL" -gt "$before" ] && caught=1
mv "$a11dir/helper.rs.bak" "$a11dir/helper.rs"
FAIL=$before
if [ "$caught" -eq 1 ]; then
echo "✅ 反自证通过:AR11 抓到了契约面底座里的 use super::system"
else
echo "❌ 反自证失败:AR11 没抓到底座的反向依赖 ⇒ 尺子是假的"
rc=1
fi
# 🔴 **M3 起底座有两处**:真源 `crates/sspf-compat-core/src/helper.rs`(实现)
# + 转发壳 `src/backend/src/platform/compat/helper.rs`。**两处都注入、
# 两处都被抓到**才算尺子有效(只注入一处会漏判「闸门只扫壳/只扫真源」)。
# 做法:备份真文件 → 追加违规行 → 跑判据 → 还原(helper.rs 是活文件)。
local a11ok=0
local a11core="$CRATES/sspf-compat-core/src/helper.rs"
local a11shell="$KERNEL/src/platform/compat/helper.rs"
local a11need=0 a11c=0 a11out
if [ -f "$a11core" ] || [ -f "$a11shell" ]; then
[ -f "$a11core" ] && cp "$a11core" "$a11core.bak" && printf '\nuse super::system::menu_node;\n' >> "$a11core" && a11need=$((a11need+1))
[ -f "$a11shell" ] && cp "$a11shell" "$a11shell.bak" && printf '\nuse super::system::menu_node;\n' >> "$a11shell" && a11need=$((a11need+1))
a11out="$(check_ar11 2>&1 || true)"
[ -f "$a11core.bak" ] && mv "$a11core.bak" "$a11core"
[ -f "$a11shell.bak" ] && mv "$a11shell.bak" "$a11shell"
[ -f "$a11core" ] && { echo "$a11out" | grep -q "sspf-compat-core/src/helper.rs" && a11c=$((a11c+1)); }
[ -f "$a11shell" ] && { echo "$a11out" | grep -q "platform/compat/helper.rs" && a11c=$((a11c+1)); }
[ "$a11need" -gt 0 ] && [ "$a11c" -ge "$a11need" ] && a11ok=1
fi
if [ "$a11ok" -eq 1 ]; then
echo "✅ 反自证通过:AR11 抓到了真源与转发壳里的 use super::system"
else
echo "⏭ 跳过 AR11 反自证(契约面目录或 helper.rs 不存在)"
echo "❌ 反自证失败:AR11 没抓到底座的反向依赖(或漏扫了真源/转发壳)⇒ 尺子是假的"
rc=1
fi
return $rc
+12 -7
View File
@@ -856,13 +856,18 @@ def scan_code(src_dir, packs_dir=None):
# 契约面按官方模块名分文件(`online_dev.rs` / `report.rs` / `system.rs` …),
# 路由注册写 `compat::<模块>::<handler>` ⇒ 这些文件**必须**进 `plat_files`,
# 否则守卫推导**全部推不出**(CC6 退化成「全是 WARN」⇒ 静默失效)。
compat_dir = os.path.join(plat_dir, "compat")
if os.path.isdir(compat_dir):
for name in sorted(os.listdir(compat_dir)):
if name.endswith(".rs"):
p = os.path.join(compat_dir, name)
o = read(p)
plat_files["compat__" + name[:-3]] = (o, mask_rust(o))
# 🔴 **M3 起契约面底座真源在 `crates/sspf-compat-core/src/`**(`helper.rs` 装守卫常量
# `EN_ROLE` 等)⇒ 必须一并收(与壳同键拼接),否则守卫常量找不到 ⇒ CC6 假漂移。
compat_dirs = [
os.path.join(ROOT, "crates", "sspf-compat-core", "src"), # M3 真源(helper/res)
os.path.join(plat_dir, "compat"), # 壳 + 尚未搬走的模块
]
for d in compat_dirs:
if os.path.isdir(d):
for name in sorted(os.listdir(d)):
if name.endswith(".rs"):
p = os.path.join(d, name)
_absorb("compat__" + name[:-3], read(p))
# 🔴 **全局常量索引**(批次 17 补):契约面按官方模块分文件后,
# 守卫常量(`EN_ROLE` / `EN_ORGANIZE` / `EN_ACTION` …)**集中在
# `compat/helper.rs`** 里,被各模块 `use super::helper::{…}` 导入