feat(onlineDev): 补齐 onlineDev 78 条 + 在线报表 23 条端点并同步契约三处

契约面(面 B):从 487 涨到 588 条,官方端点覆盖 474/580 -> 574/580。

实现
- platform/compat/online_dev.rs:表单设计 / 门户 / 短链 / 在线数据 / 个人化 /
  日志 / 分享 / OCR / 行政区划 / 仪表盘 共 78 条
- platform/compat/report.rs:在线报表 23 条(模板 / 版本 / 菜单)
- 报表元数据就地落库(report_template + report_version,官方 DDL 逐字导入):
  官方 /api/Report/* 属独立部署的第三方报表服务,主后端无对应 Controller

契约与尺子
- 新增 scripts/gen-contract-endpoints.py:从代码真实路由自动生成 [ENDPOINT] 与
  [OFFICIAL] 两段(守卫复用扫描器同一套推导,幂等、不覆盖已登记条目)
- check-contract-scan.py 修复守卫推导:三段路径解析、compat 文件纳入 plat_files、
  跨文件常量回落、「无守卫」判据(原先 compat 模块守卫全部推不出,CC6 静默失效)
- docs/contract.md 三处同步:+101 条端点、+101 条官方台账、面 B 计数 457 -> 558

修复的真 bug(集成测试抓到,静态闸门看不出来)
- 3 处 SQL 引用官方 DDL 里不存在的列:base_visual_release.f_platform_release、
  base_system.f_app_key/f_app_name、base_notice.f_full_name(官方是 f_title)
- 3 处官方契约形状偏差:getReleaseMenu 返裸对象(非 ListVO)、
  systemFilter 按官方 SystemListVO 投影(且官方忽略 category 入参)、
  Dashboard/Notice 返 ListVO 且入参 typeList 是数组
- visual_dev_list 计数 SQL 参数个数与 $N 不匹配;visual_dev_update 漏写
  f_last_modify_user_id;report_save_version 模板 id 兼容 id 且返 data:null

测试
- 新增 tests/batch17_it.rs:11 个集成测试(含 101 条端点逐条打一遍防 matchit
  参数名冲突)

数字:check-contract PASS=10 FAIL=0;cargo test --workspace 全绿 0 failed;
fe-gap 541/900(onlineDev 100/101、permission 137/137、system 196/196)
This commit is contained in:
admin committed 2026-11-02 16:01:24 +08:00
1 parent 1a41aed3b7
commit cf154d50ff
13 files changed
+6495 -52

No files matched your search

+109 -21
View File
@@ -43,7 +43,15 @@ import contract_expect # noqa: E402 (同目录)
# 再用**同一偏移**去原文取路径与方法。
ROUTE_CALL_RE = re.compile(r'\.route\(')
# 路由后面的 handler 表达式:`sys::user_list` / `demo_item_list` / `|State(..)| ..`(闭包)
HANDLER_RE = re.compile(r'\s*(?:([A-Za-z_][A-Za-z0-9_]*)::)?([A-Za-z_][A-Za-z0-9_]*)')
#
# 🔴 **三段路径**(批次 17 补):`compat::online_dev::visual_dev_list` ——
# 契约面的实现按官方模块名分文件(`platform/compat/<模块>.rs`),
# 路由注册时写成 `compat::<模块>::<handler>` ⇒ 只认**第一段**会拿到
# `compat`(一个目录,不是文件)⇒ 守卫推导**全部推不出**(静默失效)。
# ⇒ 这里记住**完整路径**,`mod` 取最后一段(真正的模块文件名),
# `mod_path` 保留全链(供 owner 判定用)。
HANDLER_RE = re.compile(
r'\s*(?:([A-Za-z_][A-Za-z0-9_]*)::)?(?:([A-Za-z_][A-Za-z0-9_]*)::)?([A-Za-z_][A-Za-z0-9_]*)')
# 契约表里 `{param}` ⇒ 代码里的通配
PARAM_RE = re.compile(r'\{[A-Za-z_][A-Za-z0-9_]*\}')
# 测试用的固定路径前缀(**不在契约端点表里** ⇒ 全部扫描都排除)
@@ -277,13 +285,24 @@ def scan_routes(path, owner):
rest = orig[name_start:name_start + 240]
hm = HANDLER_RE.match(rest)
mod, fn, closure = None, None, True
if hm and hm.group(2):
mod, fn = hm.group(1), hm.group(2)
mod_path = None
if hm and hm.group(3):
# 🔴 **三段路径**(批次 17 补):`compat::online_dev::visual_dev_list`
# ⇒ `mod_path` = `compat::online_dev`、`mod` = `online_dev`
# (真正的文件名);两段 `sys::user_list` ⇒ `mod` = `sys`。
if hm.group(2):
mod_path = "%s::%s" % (hm.group(1), hm.group(2))
mod = hm.group(2)
else:
mod_path = hm.group(1)
mod = hm.group(1)
fn = hm.group(3)
closure = False
out.append({
"path": route,
"method": method,
"mod": mod,
"mod_path": mod_path,
"fn": fn,
"closure": closure,
"owner": owner,
@@ -306,11 +325,16 @@ def scan_routes(path, owner):
return out, orig, masked
def resolve_const(orig, masked, name):
def resolve_const(orig, masked, name, global_consts=None):
"""`const NAME: &str = "value";` ⇒ value(取原文里的字面量)。
🔴 **带缓存**(同 [`find_fn_body`] 的理由):本函数在**整份文件**上跑正则,
362 条平台端点的守卫推导会反复查同一批常量名。
🔴 **跨文件回落**(批次 17 补):`global_consts` 是平台层**全局常量表**
(`{名: (来源文件, 值)}`)⇒ 当前文件里找不到的常量到表里找
(契约面的守卫常量集中在 `compat/helper.rs`,被各模块 `use` 导入)。
表里同名但**值不一致**的条目值为 `None` ⇒ 宁可推不出也不假推。
"""
key = id(orig)
entry = _CONST_CACHE.get(key)
@@ -322,6 +346,10 @@ def resolve_const(orig, masked, name):
return table[name]
m = re.search(r"\bconst\s+" + re.escape(name) + r"\b[^=]*=\s*\"([^\"]*)\"", orig)
value = m.group(1) if m else None
if value is None and global_consts:
hit = global_consts.get(name)
if hit is not None:
value = hit[1]
table[name] = value
return value
@@ -329,10 +357,17 @@ def resolve_const(orig, masked, name):
_CONST_CACHE = {}
def guard_of_platform(plat_files, mod, fn):
def guard_of_platform(plat_files, mod, fn, mod_path=None, plat_consts=None):
"""平台层 handler 的守卫 ⇒ 菜单 key / 点权限编码 / 登录 / 无;推不出 ⇒ None。
`plat_files` = {"sys": (orig, masked), "face_b": (orig, masked), ...}
🔴 **模块定位有两种形态**(批次 17 补):
- `mod_path` 是两段以上(`compat::online_dev`)⇒ 契约面实现文件在
`platform/compat/<模块>.rs` ⇒ key = `compat__<模块>`。
- `mod_path` 是一段(`sys`)⇒ 平台层根目录 `platform/<模块>.rs`。
⇒ 旧实现只拿 `mod` 查 ⇒ `online_dev` 找不到 `compat__online_dev`
⇒ 守卫**全部推不出**(CC6 静默退化成全是 WARN)。
"""
if mod == "auth" and fn == "login_handler":
return "无"
@@ -349,39 +384,62 @@ def guard_of_platform(plat_files, mod, fn):
if re.search(r"require_(login|module|login_jnpf)\s*\(", body) or re.search(r"\bguard\s*\(", body):
return None
return "无"
pair = plat_files.get(mod)
if not pair:
return None
orig, masked = pair
span = find_fn_body(masked, fn)
if not span:
return None
body = masked[span[0]:span[1]]
if mod == "sys":
# 🔴 **契约面实现文件**(批次 17 补):`platform/compat/<模块>.rs` ——
# key 形如 `compat__online_dev` ⇒ 与 `jnpf` / `face_b` **同一套**推导规则
# (`guard` / `guard_any` / `require_login_face_b`)。
# 🔴 `mod_path` 两段以上(`compat::online_dev`)⇒ 走 `compat__<模块>`;
# 一段(`sys`)⇒ 走根目录的 `<模块>`。
plat_key = mod
if mod_path and "::" in mod_path:
plat_key = "compat__" + mod
# 🔴 平台层根目录的单段模块(`sys::user_list`)⇒ `require_module` / `require_login`。
if plat_key == mod and mod not in ("jnpf", "face_b"):
pair = plat_files.get(mod)
if not pair:
return None
orig, masked = pair
span = find_fn_body(masked, fn)
if not span:
return None
body = masked[span[0]:span[1]]
m = re.search(r"require_module\(\s*&state\s*,\s*&headers\s*,\s*([A-Z_][A-Z0-9_]*)\s*\)", body)
if m:
return resolve_const(orig, masked, m.group(1))
return resolve_const(orig, masked, m.group(1), plat_consts)
if re.search(r"require_login(_any)?\s*\(", body):
return "登录"
return None
# 🔴 面 B 的实现文件 2026-10-26 从 `jnpf.rs` 改名为 `face_b.rs`
# ⇒ 这里**两个名字都认**(只认旧名会让整片面 B 的守卫检查静默失效)。
if mod in ("jnpf", "face_b"):
if mod in ("jnpf", "face_b") or plat_key.startswith("compat__"):
pair = plat_files.get(plat_key)
if not pair:
return None
orig, masked = pair
span = find_fn_body(masked, fn)
if not span:
return None
body = masked[span[0]:span[1]]
m = re.search(r"guard\(\s*&state\s*,\s*&headers\s*,\s*([A-Z_][A-Z0-9_]*)\s*\)", body)
if m:
return resolve_const(orig, masked, m.group(1))
return resolve_const(orig, masked, m.group(1), plat_consts)
# 🔴 官方的 `@SaCheckPermission(value={A,B}, mode=OR)` ⇒ 本仓 `guard_any(&[A,B])`:
# 契约里写成 `A|B`(同一个分隔符,**顺序即代码里的顺序**)。
m = re.search(r"guard_any\(\s*&state\s*,\s*&headers\s*,\s*&\[([^\]]*)\]", body)
if m:
codes = []
for name in re.findall(r"\b[A-Z_][A-Z0-9_]*\b", m.group(1)):
value = resolve_const(orig, masked, name)
value = resolve_const(orig, masked, name, plat_consts)
if value:
codes.append(value)
return "|".join(codes) if codes else None
if re.search(r"require_login_(jnpf|face_b)\s*\(", body):
return "登录"
# 🔴 **无守卫**(批次 17 补):handler 里**一次**鉴权调用都没有 ⇒ 「无」。
# 典型是登录页要用的公开端点(`compat/core.rs::get_login_config`
# —— 登录**前**就要拉 ⇒ 不能要 token)。
# 🔴 判据必须是「**没有任何**鉴权调用」而不是「没匹配到上面几种」:
# `require_login_face_b` 写成 `let _ = require_login_face_b(..)` 时
# 上面的正则仍能命中;只有**真的没有**才落到这里。
if not re.search(r"\bguard\b|\bguard_any\b|require_login|require_module", body):
return "无"
return None
return None
@@ -774,6 +832,33 @@ def scan_code(src_dir, packs_dir=None):
p = os.path.join(plat_dir, name)
o = read(p)
plat_files[name[:-3]] = (o, mask_rust(o))
# 🔴 **契约面实现文件**(批次 17 补):`platform/compat/<模块>.rs` ——
# 契约面按官方模块名分文件(`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))
# 🔴 **全局常量索引**(批次 17 补):契约面按官方模块分文件后,
# 守卫常量(`EN_ROLE` / `EN_ORGANIZE` / `EN_ACTION` …)**集中在
# `compat/helper.rs`** 里,被各模块 `use super::helper::{…}` 导入
# ⇒ 只在「当前文件」里找常量 ⇒ **只推得出本地定义的那一个**
# (`guard_any(&[EN_AUTH, EN_ORGANIZE, EN_ROLE])` 只认出 `EN_AUTH`)
# ⇒ 契约里的 `A|B|C` 与代码推出的 `A` **假漂移**。
# ⇒ 这里把平台层所有 `const NAME: &str = "…"` 收成一张表;
# 重名时**取值必须一致**(否则宁可不推,见 `resolve_const`)。
plat_consts = {}
for key, (o, _m) in plat_files.items():
for cm in re.finditer(r"\bconst\s+([A-Z_][A-Z0-9_]*)\s*:\s*&str\s*=\s*\"([^\"]*)\"", o):
name, value = cm.group(1), cm.group(2)
if name in plat_consts and plat_consts[name][1] != value:
plat_consts[name] = (key, None) # 同名不同值 ⇒ 不可信
elif name not in plat_consts:
plat_consts[name] = (key, value)
# ---- 业务模块(面 A)----
mod_dir = os.path.join(src_dir, "modules")
@@ -815,6 +900,7 @@ def scan_code(src_dir, packs_dir=None):
"plat_orig": plat_orig,
"plat_masked": plat_masked,
"plat_files": plat_files,
"plat_consts": plat_consts,
"mod_dir": mod_dir,
"modules_mod": os.path.join(mod_dir, "mod.rs"),
"mod_files": mod_files,
@@ -849,6 +935,7 @@ def analyze(contract_path, src_dir=None, packs_dir=None, code_snapshot=None):
plat_orig = code_snapshot["plat_orig"]
plat_masked = code_snapshot["plat_masked"]
plat_files = code_snapshot["plat_files"]
plat_consts = code_snapshot.get("plat_consts") or {}
mod_files = code_snapshot["mod_files"]
biz = code_snapshot["biz"]
mod_orig = code_snapshot["mod_orig"]
@@ -932,7 +1019,8 @@ def analyze(contract_path, src_dir=None, packs_dir=None, code_snapshot=None):
tail = plat_orig[plat_orig.find(hit["path"]):][:400]
derived = guard_of_closure(plat_orig, plat_masked, tail)
else:
derived = guard_of_platform(plat_files, hit["mod"], hit["fn"])
derived = guard_of_platform(plat_files, hit["mod"], hit["fn"],
hit.get("mod_path"), plat_consts)
else:
derived = guard_of_module_with_pack_fallback(
mod_orig[hit["owner"]], mod_masked[hit["owner"]],