feat(lowcode): 低代码元数据引擎第一波 —— 解析 + 校验 + 3 个只读工具

- 新 crate sspf-lowcode(纯计算,AR7 钉住不依赖 DB/HTTP):widget 把 54 种 jnpfKey 归成 11 类
  (决定「怎么存、能不能接收入参」)/ form 解析控件树 / model 解析表结构 / validate 9 类诊断码
- DDL:base_visual_dev + base_visual_release 逐字对齐官方(21 → 23 张表)
- MCP 3 个只读工具:form.list / form.describe / form.validate,后两个支持 inline JSON
- 真实样例落盘为 fixture(官方初始化数据的「应收费用」:主表 6 字段 / 子表 8 字段)
- 新增 lowcode-smoke.sh 8 条(含两条反自证:改坏 __vModel__ 必被抓、未知控件只 warn)
- 影响:测试 306 → 344;十二闸全绿;三条真实方言已写进注释与测试
This commit is contained in:
admin committed 2026-10-31 11:47:40 +08:00
1 parent 16c0704c47
commit f0c77f731c
24 files changed
+4122 -22

No files matched your search

+209
View File
@@ -0,0 +1,209 @@
#!/usr/bin/env bash
# ============================================================================
# lowcode-smoke —— 低代码元数据引擎的契约尺子(P2-a)
#
# 验证什么:
# L1 真实样例(官方初始化数据里的「应收费用」表单)能解析:主表 6 字段 / 子表 8 字段
# L2 form.validate 对真实样例报 0 error(设计稿自洽)
# L3 同构:describe 的字段顺序与 JSON 原样一致
# L4 form.list 在空库上可用(0 条不算失败)
# L5 inline 模式缺 tablesData ⇒ MISSING_ARG(不许静默只校验一半)
# L6 🔴 反自证:故意改坏一个 __vModel__ ⇒ 必须报 COLUMN_NOT_IN_TABLE
# L7 🔴 反自证:故意塞一个未知控件 ⇒ 必须报 warn 且 ok 仍为 true
# L8 子表字段的 tableName 陷阱:子表 8 个字段自身的 tableName 全部不是子表名
#
# L6 / L7 是「尺子自己会不会骗人」的证明 —— 没有它们,
# 一把永远返回 ok=true 的尺子和「校验真的работает」看起来一模一样。
#
# 用法: bash scripts/lowcode-smoke.sh
# 退出码: 0 全过 / 1 有 ❌
# ============================================================================
set -u
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT" || exit 1
BIN="$ROOT/target/debug/ssw-platform"
[ -x "$BIN" ] || BIN="$ROOT/target/release/ssw-platform"
FIX="$ROOT/crates/sspf-lowcode/tests/fixtures"
if [ ! -x "$BIN" ]; then
echo "❌ 找不到 ssw-platform 二进制(先 cargo build)"
exit 1
fi
if [ ! -f "$FIX/sample_form.json" ] || [ ! -f "$FIX/sample_model.json" ]; then
echo "❌ 缺 fixture:$FIX/sample_form.json / sample_model.json"
exit 1
fi
TMP="$(mktemp -d /tmp/lowcode-smoke.XXXXXX)" || exit 1
trap 'rm -rf "$TMP"' EXIT
# ---- 生成请求(含两条「改坏」的变体)----
python3 - "$FIX" "$TMP/req.ndjson" <<'PY'
import json, sys, os, copy
fix, out = sys.argv[1], sys.argv[2]
form = json.load(open(os.path.join(fix, "sample_form.json"), encoding="utf-8"))
tables = json.load(open(os.path.join(fix, "sample_model.json"), encoding="utf-8"))
# 变体 A:把一个主表字段改成模型里不存在的名字 ⇒ 应报 COLUMN_NOT_IN_TABLE
bad_field = copy.deepcopy(form)
for f in bad_field["fields"]:
if f.get("__vModel__") == "F_Room":
f["__vModel__"] = "F_GhostColumn"
break
# 变体 B:塞一个未知控件 ⇒ 应报 warn,但 ok 仍为 true
bad_widget = copy.deepcopy(form)
bad_widget["fields"].append({
"__config__": {"jnpfKey": "futureWidgetXyz", "layout": "colFormItem",
"label": "未来控件", "tableName": "test_receivable"},
"__vModel__": "F_Room", # 复用已有列,确保只有「未知控件」这一条诊断
})
reqs = [
{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {}},
{"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "sspf_call", "arguments": {
"tool_id": "form.validate",
"args": {"formData": json.dumps(form, ensure_ascii=False),
"tablesData": json.dumps(tables, ensure_ascii=False)}}}},
{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "sspf_call", "arguments": {
"tool_id": "form.describe",
"args": {"formData": json.dumps(form, ensure_ascii=False)}}}},
{"jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": {"name": "sspf_call", "arguments": {
"tool_id": "form.list", "args": {}}}},
{"jsonrpc": "2.0", "id": 5, "method": "tools/call", "params": {"name": "sspf_call", "arguments": {
"tool_id": "form.validate",
"args": {"formData": json.dumps(form, ensure_ascii=False)}}}},
{"jsonrpc": "2.0", "id": 6, "method": "tools/call", "params": {"name": "sspf_call", "arguments": {
"tool_id": "form.validate",
"args": {"formData": json.dumps(bad_field, ensure_ascii=False),
"tablesData": json.dumps(tables, ensure_ascii=False)}}}},
{"jsonrpc": "2.0", "id": 7, "method": "tools/call", "params": {"name": "sspf_call", "arguments": {
"tool_id": "form.validate",
"args": {"formData": json.dumps(bad_widget, ensure_ascii=False),
"tablesData": json.dumps(tables, ensure_ascii=False)}}}},
]
with open(out, "w", encoding="utf-8") as f:
for r in reqs:
f.write(json.dumps(r, ensure_ascii=False) + "\n")
PY
# ---- 跑一次(临时库,不碰开发数据)----
PGLITE_DIR="$TMP/db" "$BIN" --mcp < "$TMP/req.ndjson" > "$TMP/out.ndjson" 2> "$TMP/err.log"
if [ ! -s "$TMP/out.ndjson" ]; then
echo "❌ 没有输出;stderr:"
grep -vE "stand-alone|^backend>|LOG:" "$TMP/err.log" | head -5
exit 1
fi
# ---- 断言 ----
python3 - "$TMP/out.ndjson" <<'PY'
import json, sys
rows = {}
for line in open(sys.argv[1], encoding="utf-8"):
if line.strip():
m = json.loads(line)
rows[m.get("id")] = m
PASS = [0]
FAIL = [0]
def ok(msg):
PASS[0] += 1
print(f"✅ {msg}")
def bad(msg):
FAIL[0] += 1
print(f"❌ {msg}")
def payload(i):
return (rows.get(i, {}).get("result") or {}).get("structuredContent", {})
def data(i):
return payload(i).get("data", {})
def codes(i):
return [d.get("code") for d in (data(i).get("diagnostics") or [])]
# L1 / L2 真实样例
d2 = data(2)
if d2.get("ok") is True and d2.get("errorCount") == 0:
ok(f"L1 真实样例校验通过(0 error / {d2.get('warnCount')} warn)")
else:
bad(f"L1 真实样例应 0 error,实际 {d2.get('errorCount')}:{codes(2)}")
d3 = data(3)
main = d3.get("mainFields") or []
subs = d3.get("subTables") or []
if len(main) == 6 and len(subs) == 1 and len(subs[0].get("fields") or []) == 8:
ok(f"L2 form.describe 结构正确(主表 {len(main)} 字段 / 子表 {len(subs[0]['fields'])} 字段)")
else:
bad(f"L2 结构不对:主表 {len(main)} / 子表 {[len(s.get('fields') or []) for s in subs]}")
# L3 同构:字段顺序与原文一致
expect = ["F_Building", "F_Room", "F_Company_name", "F_Userid", "F_Phone", "F_Ost"]
got = [f.get("vModel") for f in main]
if got == expect:
ok("L3 字段顺序与 JSON 原样一致(同构,没有重排)")
else:
bad(f"L3 字段顺序被改了:{got}")
# L4 空库 form.list
p4 = payload(4)
if p4.get("ok") is True and isinstance(p4.get("data", {}).get("forms"), list):
ok(f"L4 form.list 可用(空库 {p4['data'].get('count', 0)} 条,不算失败)")
else:
bad(f"L4 form.list 失败: {json.dumps(p4, ensure_ascii=False)[:150]}")
# L5 缺 tablesData
p5 = payload(5)
if p5.get("ok") is False and p5.get("error", {}).get("code") == "MISSING_ARG":
ok("L5 inline 模式缺 tablesData ⇒ MISSING_ARG(不静默只校验一半)")
else:
bad(f"L5 缺参未被拦: {json.dumps(p5, ensure_ascii=False)[:150]}")
# L6 🔴 反自证:改坏字段必须被抓到
d6 = data(6)
# 🔴 注意 `ok` 有两层:外层是 sspf_call 是否调用成功,data.ok 才是校验结论
if d6.get("ok") is False and "COLUMN_NOT_IN_TABLE" in codes(6):
diag = [d for d in d6["diagnostics"] if d["code"] == "COLUMN_NOT_IN_TABLE"][0]
if "f_title" in diag.get("message", "") or "f_building" in diag.get("message", ""):
ok("L6 反自证:改坏一个 __vModel__ ⇒ COLUMN_NOT_IN_TABLE,且列出了现有列")
else:
ok("L6 反自证:改坏一个 __vModel__ ⇒ COLUMN_NOT_IN_TABLE")
else:
bad(f"L6 🔴 校验没抓到坏字段 —— 这把尺子是假的: {codes(6)}")
# L7 🔴 反自证:未知控件是 warn 不是 error
d7 = data(7)
if "UNKNOWN_WIDGET" in codes(7) and d7.get("warnCount", 0) >= 1:
if d7.get("ok") is True:
ok("L7 反自证:未知控件 ⇒ warn 且 ok 仍为 true(降级不阻断)")
else:
bad("L7 未知控件不该让 ok=false(会逼得新控件表单完全不可用)")
else:
bad(f"L7 未知控件没被报出来: {codes(7)}")
# L8 子表 tableName 陷阱
script = json.dumps(d3, ensure_ascii=False)
if "test_details" in script:
ok("L8 子表归属取父节点 tableName(test_details),子表内字段自身的 tableName 不可信")
else:
bad("L8 子表 tableName 丢了")
print()
print(f"PASS={PASS[0]} FAIL={FAIL[0]}")
sys.exit(1 if FAIL[0] else 0)
PY
RC=$?
echo
if [ "$RC" -ne 0 ]; then
echo "❌ lowcode-smoke 有失败项(见上)"
exit 1
fi
echo "✅ lowcode-smoke 全过"