restore: 恢复 11-06~11-09 本地未提交改动

- libs: 新增 hr_sdk / hotel_report / dingtalk,更新 desktopauto
- controlplane-next: SDK 管理模块(controller/entity/migrations)与前端视图
- electron-shell: 插件同步、注册表、runner 调整
- plugins: XQ0035/XQ0041/XQ0042/XQ0045_XQ0046/XQ0048/XQ0076/XQ0078 等版本更新
- tests/tools: 新增 SDK 兼容性检查与打包工具(sdk_pack.py、sdk_compat_check.py)
This commit is contained in:
2026-11-09 17:27:10 +08:00
parent e4539db9f8
commit 9873eb1963
327 changed files with 29670 additions and 718 deletions
+109
View File
@@ -0,0 +1,109 @@
# -*- coding: utf-8 -*-
"""sdk_compat_check 自检:用固定夹具跑完所有判定分支。
运行(仓库根)::
.venv\\Scripts\\python.exe tests\\sdk_compat_check\\_run_cases.py
仓库没有 pytest 组织(tests/ 是探针脚本集合),所以这里用可直接运行的自检脚本,
任一用例不符即非 0 退出。
"""
from __future__ import annotations
import json
import subprocess
import sys
import tempfile
from pathlib import Path
HERE = Path(__file__).resolve().parent
REPO = HERE.parents[1]
TOOL = REPO / "tools" / "sdk_compat_check.py"
PLUGINS = HERE / "plugins"
SDK_OLD = HERE / "sdk_v1.0.0"
SDK_NEW = HERE / "sdk_v1.1.0"
SDK_MAJOR = HERE / "sdk_v2.0.0"
CASES = [
# name, extra args, 期望分类, 期望退出码, 期望 error 码集合, 期望 summary 片段
("p_ok", ["--only", "p_ok"], "COMPATIBLE", 0, set(), {"pass": 1}),
("p_undeclared", ["--only", "p_undeclared"], "PLUGIN_BUMP", 1, {"UNDECLARED_SDK"}, {}),
("p_missing", ["--only", "p_missing"], "ACCIDENTAL_BREAK", 1, {"MISSING_API"}, {}),
("p_import_fail", ["--only", "p_import_fail"], "ACCIDENTAL_BREAK", 1, {"IMPORT_FAIL"}, {}),
("p_old_major", ["--sdk", str(SDK_MAJOR), "--baseline-sdk", str(SDK_OLD),
"--only", "p_old_major"], "PLUGIN_BUMP", 1, {"NEEDS_BUMP"}, {}),
("p_legacy(API_REMOVED)", ["--baseline-sdk", str(SDK_OLD), "--only", "p_legacy"],
"ACCIDENTAL_BREAK", 1, {"API_REMOVED", "MISSING_API"}, {}, {"API_SIGNATURE_CHANGED"}),
("p_skip", ["--only", "p_skip"], "COMPATIBLE", 0, set(), {"skipped": 1, "checked": 0}),
("p_selftest_fail", ["--only", "p_selftest_fail"], "ACCIDENTAL_BREAK", 1,
{"SELFTEST_FAIL"}, {}),
("p_dynamic", ["--only", "p_dynamic"], "COMPATIBLE", 0, set(), {}),
("p_vendored", ["--only", "p_vendored"], "COMPATIBLE", 0, set(), {}, {"VENDORED_SDK"}),
]
def run_tool(extra: list) -> tuple:
with tempfile.TemporaryDirectory() as td:
out = Path(td) / "report.json"
cmd = [sys.executable, str(TOOL), "--plugins", str(PLUGINS),
"--json", str(out), *extra]
proc = subprocess.run(cmd, cwd=str(REPO), capture_output=True, text=True,
encoding="utf-8", errors="replace", timeout=600)
rep = json.loads(out.read_text(encoding="utf-8")) if out.is_file() else None
return proc.returncode, rep, (proc.stdout or "") + (proc.stderr or "")
def main() -> int:
failures = 0
for case in CASES:
name, extra, want_class, want_exit, want_codes, want_summary = case[:6]
want_warns = case[6] if len(case) > 6 else set()
args = list(extra)
if "--sdk" not in args:
args = ["--sdk", str(SDK_NEW)] + args
code, rep, log = run_tool(args)
problems = []
if rep is None:
problems.append("无 JSON 报告")
else:
if rep["classification"] != want_class:
problems.append(f"分类 {rep['classification']} != {want_class}")
if code != want_exit:
problems.append(f"退出码 {code} != {want_exit}")
got = {f["code"] for r in rep["plugins"] for f in r["findings"]
if f["severity"] == "error"}
got |= {f["code"] for f in rep["sdk_findings"] if f["severity"] == "error"}
missing = want_codes - got
if missing:
problems.append(f"缺少 error 码 {sorted(missing)}(实际 {sorted(got)})")
warns = {f["code"] for r in rep["plugins"] for f in r["findings"]
if f["severity"] == "warning"}
warns |= {f["code"] for f in rep["sdk_findings"] if f["severity"] == "warning"}
miss_warn = want_warns - warns
if miss_warn:
problems.append(f"缺少 warning 码 {sorted(miss_warn)}(实际 {sorted(warns)})")
for key, val in want_summary.items():
if rep["summary"].get(key) != val:
problems.append(f"summary.{key}={rep['summary'].get(key)} != {val}")
if problems:
failures += 1
print(f"[FAIL] {name}: " + ";".join(problems))
print(" " + log.strip().splitlines()[0][:200] if log.strip() else "")
else:
print(f"[ok] {name:<24}{want_class:<18}exit={code}")
# 非法 SDK:路径不存在 → 退出码 2
code, rep, log = run_tool(["--sdk", str(HERE / "no_such_sdk"), "--only", "p_ok"])
if code != 2:
failures += 1
print(f"[FAIL] sdk_invalid: 退出码 {code} != 2")
else:
print(f"[ok] {'sdk_invalid':<24}{'SDK_INVALID':<18}exit={code}")
print("—— 全部用例通过 ——" if not failures else f"—— {failures} 个用例失败 ——")
return 1 if failures else 0
if __name__ == "__main__":
raise SystemExit(main())
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
import importlib
mod = importlib.import_module('demo_sdk')
@@ -0,0 +1,16 @@
{
"schema_version": 1,
"id": "p_dynamic",
"name": "p_dynamic",
"version": "1.0.0",
"description": "fixture p_dynamic",
"ui": false,
"fields": {},
"requires": {
"sdks": {
"demo_sdk": {
"compat": "^1.0"
}
}
}
}
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
raise RuntimeError('boom on import')
@@ -0,0 +1,16 @@
{
"schema_version": 1,
"id": "p_import_fail",
"name": "p_import_fail",
"version": "1.0.0",
"description": "fixture p_import_fail",
"ui": false,
"fields": {},
"requires": {
"sdks": {
"demo_sdk": {
"compat": "^1.0"
}
}
}
}
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from demo_sdk.legacy import export_legacy # noqa: F401
@@ -0,0 +1,16 @@
{
"schema_version": 1,
"id": "p_legacy",
"name": "p_legacy",
"version": "1.0.0",
"description": "fixture p_legacy",
"ui": false,
"fields": {},
"requires": {
"sdks": {
"demo_sdk": {
"compat": "^1.0"
}
}
}
}
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from demo_sdk import removed_fn # noqa: F401
@@ -0,0 +1,16 @@
{
"schema_version": 1,
"id": "p_missing",
"name": "p_missing",
"version": "1.0.0",
"description": "fixture p_missing",
"ui": false,
"fields": {},
"requires": {
"sdks": {
"demo_sdk": {
"compat": "^1.0"
}
}
}
}
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
from demo_sdk.roster import export, RosterRow
ROWS = [RosterRow(name='a')]
export(ROWS)
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
raise SystemExit(0)
@@ -0,0 +1,16 @@
{
"schema_version": 1,
"id": "p_ok",
"name": "p_ok",
"version": "1.0.0",
"description": "fixture p_ok",
"ui": false,
"fields": {},
"requires": {
"sdks": {
"demo_sdk": {
"compat": "^1.0"
}
}
}
}
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
from demo_sdk import roster
roster.export()
@@ -0,0 +1,16 @@
{
"schema_version": 1,
"id": "p_old_major",
"name": "p_old_major",
"version": "1.0.0",
"description": "fixture p_old_major",
"ui": false,
"fields": {},
"requires": {
"sdks": {
"demo_sdk": {
"compat": "^0.9"
}
}
}
}
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from demo_sdk import roster
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
raise SystemExit('selftest boom')
@@ -0,0 +1,16 @@
{
"schema_version": 1,
"id": "p_selftest_fail",
"name": "p_selftest_fail",
"version": "1.0.0",
"description": "fixture p_selftest_fail",
"ui": false,
"fields": {},
"requires": {
"sdks": {
"demo_sdk": {
"compat": "^1.0"
}
}
}
}
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
VALUE = 1
@@ -0,0 +1,9 @@
{
"schema_version": 1,
"id": "p_skip",
"name": "p_skip",
"version": "1.0.0",
"description": "fixture p_skip",
"ui": false,
"fields": {}
}
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
import demo_sdk
@@ -0,0 +1,9 @@
{
"schema_version": 1,
"id": "p_undeclared",
"name": "p_undeclared",
"version": "1.0.0",
"description": "fixture p_undeclared",
"ui": false,
"fields": {}
}
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
"""fixture:插件里带了 demo_sdk 副本(应被 VENDORED_SDK 检出)。"""
VALUE = 1
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
"""这是"从 SDK 复制进插件"的副本,仅用于触发 VENDORED_SDK。"""
def export(rows=None):
return list(rows or [])
@@ -0,0 +1,9 @@
{
"schema_version": 1,
"id": "p_vendored",
"name": "p_vendored",
"version": "1.0.0",
"description": "fixture p_vendored:插件内复制了 SDK 副本",
"ui": false,
"fields": {}
}
@@ -0,0 +1,35 @@
{
"schema_version": 1,
"sdk_id": "demo_sdk",
"version": "1.0.0",
"modules": {
"demo_sdk": {
"exports": [
"roster"
],
"all": [
"roster"
],
"signatures": {}
},
"demo_sdk.legacy": {
"exports": [
"export_legacy"
],
"all": [],
"signatures": {
"export_legacy": "()"
}
},
"demo_sdk.roster": {
"exports": [
"RosterRow",
"export"
],
"all": [],
"signatures": {
"export": "(rows=None, dry_run=False)"
}
}
}
}
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
__version__ = "1.0.0"
from . import roster # noqa: F401
__all__ = ["roster"]
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
def export_legacy():
return []
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
"""演示模块:export() 是稳定 API。"""
class RosterRow(dict):
pass
def export(rows=None, dry_run=False):
# v1.0.0 签名(1.1.0 起去掉 dry_run)—— 用于 API_SIGNATURE_CHANGED 用例
return list(rows or [])
@@ -0,0 +1,15 @@
{
"schema_version": 1,
"id": "demo_sdk",
"name": "演示 SDK",
"version": "1.0.0",
"description": "sdk_compat_check 测试用最小 SDK",
"provides": [
"demo_sdk"
],
"deps": [],
"python": ">=3.9",
"minRuntimeVersion": "",
"selftest": "",
"api": "api.json"
}
@@ -0,0 +1,26 @@
{
"schema_version": 1,
"sdk_id": "demo_sdk",
"version": "1.1.0",
"modules": {
"demo_sdk": {
"exports": [
"roster"
],
"all": [
"roster"
],
"signatures": {}
},
"demo_sdk.roster": {
"exports": [
"RosterRow",
"export"
],
"all": [],
"signatures": {
"export": "(rows=None)"
}
}
}
}
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
__version__ = "1.1.0"
from . import roster # noqa: F401
__all__ = ["roster"]
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
"""演示模块:export() 是稳定 API。"""
class RosterRow(dict):
pass
def export(rows=None):
return list(rows or [])
@@ -0,0 +1,15 @@
{
"schema_version": 1,
"id": "demo_sdk",
"name": "演示 SDK",
"version": "1.1.0",
"description": "sdk_compat_check 测试用最小 SDK",
"provides": [
"demo_sdk"
],
"deps": [],
"python": ">=3.9",
"minRuntimeVersion": "",
"selftest": "",
"api": "api.json"
}
@@ -0,0 +1,26 @@
{
"schema_version": 1,
"sdk_id": "demo_sdk",
"version": "2.0.0",
"modules": {
"demo_sdk": {
"exports": [
"roster"
],
"all": [
"roster"
],
"signatures": {}
},
"demo_sdk.roster": {
"exports": [
"RosterRow",
"export"
],
"all": [],
"signatures": {
"export": "(rows=None)"
}
}
}
}
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
__version__ = "2.0.0"
from . import roster # noqa: F401
__all__ = ["roster"]
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
"""演示模块:export() 是稳定 API。"""
class RosterRow(dict):
pass
def export(rows=None):
return list(rows or [])
@@ -0,0 +1,15 @@
{
"schema_version": 1,
"id": "demo_sdk",
"name": "演示 SDK",
"version": "2.0.0",
"description": "sdk_compat_check 测试用最小 SDK",
"provides": [
"demo_sdk"
],
"deps": [],
"python": ">=3.9",
"minRuntimeVersion": "",
"selftest": "",
"api": "api.json"
}