@sokeai/cli 1.0.116 → 1.0.117
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/multi/demo-init/CHANGELOG.md +1241 -0
- package/skills/multi/demo-init/README.md +137 -0
- package/skills/multi/demo-init/SKILL.legacy.md +307 -0
- package/skills/multi/demo-init/assets/placeholder.pptx +0 -0
- package/skills/multi/demo-init/references/anti-patterns.md +83 -0
- package/skills/multi/demo-init/references/asset-design.md +230 -0
- package/skills/multi/demo-init/references/asset-spec.md +94 -0
- package/skills/multi/demo-init/references/blueprint-schema.md +174 -0
- package/skills/multi/demo-init/references/cli-onboarding.md +207 -0
- package/skills/multi/demo-init/references/cli-shared.md +183 -0
- package/skills/multi/demo-init/references/contracts.md +34 -0
- package/skills/multi/demo-init/references/course-setup.md +265 -0
- package/skills/multi/demo-init/references/demo-defaults.md +132 -0
- package/skills/multi/demo-init/references/demo-verify.md +355 -0
- package/skills/multi/demo-init/references/exam-setup.md +245 -0
- package/skills/multi/demo-init/references/gates-matrix.md +38 -0
- package/skills/multi/demo-init/references/map-setup.md +283 -0
- package/skills/multi/demo-init/references/plan-parse.md +185 -0
- package/skills/multi/demo-init/references/platform-access.md +55 -0
- package/skills/multi/demo-init/references/platform-commands.md +510 -0
- package/skills/multi/demo-init/references/point-setup.md +308 -0
- package/skills/multi/demo-init/references/portal-modules.md +130 -0
- package/skills/multi/demo-init/references/portal-setup.md +342 -0
- package/skills/multi/demo-init/references/project-setup.md +173 -0
- package/skills/multi/demo-init/references/run-protocol.md +208 -0
- package/skills/multi/demo-init/references/taxonomy-setup.md +101 -0
- package/skills/multi/demo-init/scripts/assign_backfill.py +281 -0
- package/skills/multi/demo-init/scripts/blueprint_lint.py +693 -0
- package/skills/multi/demo-init/scripts/blueprint_write.py +390 -0
- package/skills/multi/demo-init/scripts/category_bind.py +303 -0
- package/skills/multi/demo-init/scripts/category_create.py +748 -0
- package/skills/multi/demo-init/scripts/category_reassign.py +405 -0
- package/skills/multi/demo-init/scripts/category_verify.py +373 -0
- package/skills/multi/demo-init/scripts/cli_kit.py +597 -0
- package/skills/multi/demo-init/scripts/cli_probe.py +205 -0
- package/skills/multi/demo-init/scripts/course_build.py +857 -0
- package/skills/multi/demo-init/scripts/course_cover_repair.py +243 -0
- package/skills/multi/demo-init/scripts/doc_lint.py +619 -0
- package/skills/multi/demo-init/scripts/dup_cleanup.py +299 -0
- package/skills/multi/demo-init/scripts/dup_scan.py +368 -0
- package/skills/multi/demo-init/scripts/exam_build.py +551 -0
- package/skills/multi/demo-init/scripts/extract_docx.py +370 -0
- package/skills/multi/demo-init/scripts/gen_assets.py +1366 -0
- package/skills/multi/demo-init/scripts/guard.py +1272 -0
- package/skills/multi/demo-init/scripts/map_rebuild.py +391 -0
- package/skills/multi/demo-init/scripts/oss_image_upload.py +367 -0
- package/skills/multi/demo-init/scripts/portal_build.py +450 -0
- package/skills/multi/demo-init/scripts/portal_home_apply.py +255 -0
- package/skills/multi/demo-init/scripts/portal_home_layout.py +398 -0
- package/skills/multi/demo-init/scripts/project_build.py +309 -0
- package/skills/multi/demo-init/scripts/rebuild_taxonomy_map.py +100 -0
- package/skills/multi/demo-init/scripts/scope_plan.py +387 -0
- package/skills/multi/demo-init/scripts/selftest_all.py +211 -0
- package/skills/multi/demo-init/scripts/stock_probe.py +452 -0
- package/skills/multi/demo-init/scripts/taxonomy_build.py +512 -0
- package/skills/multi/demo-init-4.1.0.zip +0 -0
- package/skills/multi/demo-init-4.1.1.zip +0 -0
- package/skills/multi/demo-init-4.1.2.zip +0 -0
- package/skills/multi/demo-init-4.1.3.zip +0 -0
- package/skills/multi/ziQIJJpL +0 -0
- package/skills/multi/ziRsINis +0 -0
- package/skills/multi/ziUjKWRm +0 -0
- package/skills/multi/zipFWfuj +0 -0
|
@@ -0,0 +1,693 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""blueprint_lint.py — 文档驱动方案的引用、范围与技术规格校验。
|
|
3
|
+
|
|
4
|
+
用法:
|
|
5
|
+
<PY> blueprint_lint.py <DEMO-BLUEPRINT.json> # 自动在蓝图同目录找 scope-plan.json / run.log
|
|
6
|
+
<PY> blueprint_lint.py <bp.json> --out-dir <目录>
|
|
7
|
+
<PY> blueprint_lint.py <bp.json> --only portal # 只跑「建门户」相关闸门,其余 SKIP
|
|
8
|
+
<PY> blueprint_lint.py <bp.json> --only portal,course # 多对象
|
|
9
|
+
<PY> blueprint_lint.py --matrix # 打印「闸门 → 适用对象」映射表
|
|
10
|
+
<PY> blueprint_lint.py <bp.json> --json # 机器可读
|
|
11
|
+
<PY> blueprint_lint.py --self-test
|
|
12
|
+
|
|
13
|
+
退出码:0 = 全部通过(含 warn / skip);2 = 有阻塞项(block)。
|
|
14
|
+
|
|
15
|
+
设计边界(重要):
|
|
16
|
+
本脚本判定结构、显式引用与技术规格,并借 scope-plan 核验完整数量、名称与阶段引用。
|
|
17
|
+
不按硬配额裁剪,不因缺分类补造业务;缺项警告待明确。平台存量探测属于后续施工,
|
|
18
|
+
不是纯文档解析的依赖。原文忠实性仍须由 plan-entities.json 的来源证据保证。
|
|
19
|
+
|
|
20
|
+
批量技术校验(v4.5.0):
|
|
21
|
+
P 编号是函数检查索引,不是逐项调度或停轮闸门;一次调用完成全部适用检查。
|
|
22
|
+
执行层仅方案确认一次、施工结果按模块批量自动验收、交付最终汇总三个阶段检查点。
|
|
23
|
+
按对象裁剪,无对象输出 SKIP 而非 PASS;字段安全校验与必要结果回读不得省略。
|
|
24
|
+
地图/培训班/考试原文分类完整保留为资料,施工每模块复用一个已有默认分类,
|
|
25
|
+
不逼原文 taxonomy 闭包;真实 uuid 与平台结果在模块施工中校验,不在纯解析中猜测。
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
from __future__ import annotations
|
|
29
|
+
|
|
30
|
+
import argparse
|
|
31
|
+
import json
|
|
32
|
+
import os
|
|
33
|
+
import re
|
|
34
|
+
import sys
|
|
35
|
+
|
|
36
|
+
SKILL_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
37
|
+
ASSET_SIZES = {"banner_pc": "3840x1336", "banner_mobile": "750x360",
|
|
38
|
+
"cover_course": "960x540", "cover_map": "960x540", "logo": "240x56"}
|
|
39
|
+
|
|
40
|
+
# ---------------------------------------------------------------- 闸门适用性
|
|
41
|
+
# v4.3.0:闸门粒度从「文件」降到「对象」。此前 lint 校验整份蓝图,导致
|
|
42
|
+
# 只建 1 个门户也要背题库命名 / 引用闭包 / 培训班 items 等 9 道与门户无关的闸门。
|
|
43
|
+
# 取值:None = 任何蓝图都跑;集合 = 至少命中一个对象类型才跑,否则 SKIP(不计 PASS)。
|
|
44
|
+
|
|
45
|
+
OBJECT_TYPES = ("portal", "course", "exam", "map", "project", "taxonomy", "asset", "incentive")
|
|
46
|
+
|
|
47
|
+
GATE_REQUIRES = {
|
|
48
|
+
"P-1": {"asset", "portal", "course", "map"}, # 即使资产表缺失仍查悬空引用
|
|
49
|
+
"P-2": {"map", "project"}, # items 下标
|
|
50
|
+
"P-3": {"exam", "map"}, # 题库命名 / 地图分类重名
|
|
51
|
+
"P-4": {"incentive"}, # 积分形状
|
|
52
|
+
"P-6": {"asset"}, # prompt_hint 含主色
|
|
53
|
+
"P-7": {"map"}, # 地图引用闭包
|
|
54
|
+
"P-8": {"course"}, # 课程分类闭包
|
|
55
|
+
"P-9": {"map", "exam", "project"},
|
|
56
|
+
"P-10": {"map"}, # 降级可观测(degraded 只出现在地图 item 上)
|
|
57
|
+
"P-11": {"asset"}, # 已声明资产的技术规格
|
|
58
|
+
"P-12": None, # 确认表形态
|
|
59
|
+
"P-13": {"project"}, # 培训班 items 闭包
|
|
60
|
+
"P-15": None, # SCOPE 一致性
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
# 声明某对象时隐含需要的类型(门户/课程/地图都要图,故带上 asset)
|
|
64
|
+
IMPLIED = {
|
|
65
|
+
"portal": ("asset",),
|
|
66
|
+
"course": ("asset", "taxonomy"),
|
|
67
|
+
"map": ("asset", "taxonomy"),
|
|
68
|
+
"exam": ("taxonomy",),
|
|
69
|
+
"project": ("taxonomy",),
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def present_types(bp):
|
|
74
|
+
"""蓝图里实际存在哪些对象类型。"""
|
|
75
|
+
t = set()
|
|
76
|
+
if bp.get("portals"):
|
|
77
|
+
t.add("portal")
|
|
78
|
+
if bp.get("courses"):
|
|
79
|
+
t.add("course")
|
|
80
|
+
if bp.get("exams"):
|
|
81
|
+
t.add("exam")
|
|
82
|
+
if bp.get("maps"):
|
|
83
|
+
t.add("map")
|
|
84
|
+
if bp.get("projects"):
|
|
85
|
+
t.add("project")
|
|
86
|
+
if bp.get("taxonomies"):
|
|
87
|
+
t.add("taxonomy")
|
|
88
|
+
if bp.get("assets"):
|
|
89
|
+
t.add("asset")
|
|
90
|
+
if bp.get("incentives") is not None:
|
|
91
|
+
t.add("incentive")
|
|
92
|
+
return t
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def resolve_types(only, bp):
|
|
96
|
+
"""返回 (参与判定的类型集, 用户声明的类型集)。only 为空 = 按蓝图实际内容。"""
|
|
97
|
+
present = present_types(bp)
|
|
98
|
+
if not only:
|
|
99
|
+
return present, None
|
|
100
|
+
want = set()
|
|
101
|
+
for token in only:
|
|
102
|
+
if token not in OBJECT_TYPES:
|
|
103
|
+
raise ValueError("未知对象类型 %r(可选:%s)" % (token, " / ".join(OBJECT_TYPES)))
|
|
104
|
+
want.add(token)
|
|
105
|
+
want.update(IMPLIED.get(token, ()))
|
|
106
|
+
return present & want, want
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
# ---------------------------------------------------------------- helpers
|
|
110
|
+
|
|
111
|
+
def _load(path):
|
|
112
|
+
with open(path, encoding="utf-8") as fh:
|
|
113
|
+
return json.load(fh)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _fmt(ok, level, detail):
|
|
117
|
+
return {"ok": ok, "level": level, "detail": detail}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _pass(detail, level="info"):
|
|
121
|
+
return _fmt(True, level, detail)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _block(detail):
|
|
125
|
+
return _fmt(False, "block", detail)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _warn(detail):
|
|
129
|
+
return _fmt(True, "warn", detail)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _names(seq, field="name"):
|
|
133
|
+
"""兼容字符串、name/title 及原文多级分类节点。"""
|
|
134
|
+
out = []
|
|
135
|
+
for t in seq or []:
|
|
136
|
+
if isinstance(t, str):
|
|
137
|
+
out.append(t)
|
|
138
|
+
elif isinstance(t, dict):
|
|
139
|
+
out.append(t.get(field) or t.get("title"))
|
|
140
|
+
out.extend(_names(t.get("children"), field))
|
|
141
|
+
return {x for x in out if x}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
# ---------------------------------------------------------------- checks
|
|
145
|
+
|
|
146
|
+
def p1_asset_keys(bp, ctx):
|
|
147
|
+
"""P-1 asset_key 引用完整。"""
|
|
148
|
+
keys = {a.get("key") for a in bp.get("assets") or []}
|
|
149
|
+
refs = []
|
|
150
|
+
for c in bp.get("courses") or []:
|
|
151
|
+
if c.get("asset_key"):
|
|
152
|
+
refs.append(("courses." + str(c.get("title"))[:12], c["asset_key"]))
|
|
153
|
+
for m in (bp.get("maps") or []) + (bp.get("plan_only_maps") or []):
|
|
154
|
+
if m.get("asset_key"):
|
|
155
|
+
refs.append(("maps." + str(m.get("name"))[:12], m["asset_key"]))
|
|
156
|
+
for p in bp.get("portals") or []:
|
|
157
|
+
for k in p.get("banner_asset_keys") or []:
|
|
158
|
+
refs.append(("portals.banner", k))
|
|
159
|
+
cust = bp.get("customer") or {}
|
|
160
|
+
if cust.get("logo_asset_key"):
|
|
161
|
+
refs.append(("customer.logo", cust["logo_asset_key"]))
|
|
162
|
+
miss = [r for r in refs if r[1] not in keys]
|
|
163
|
+
if miss:
|
|
164
|
+
return _block("悬空 asset_key:%s" % ", ".join("%s->%s" % (a, b) for a, b in miss[:5]))
|
|
165
|
+
return _pass("%d 处引用 / %d 个资产" % (len(refs), len(keys)))
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def p2_ref_bounds(bp, ctx):
|
|
169
|
+
"""P-2 maps / projects 的 items 下标不越界。"""
|
|
170
|
+
nc, ne = len(bp.get("courses") or []), len(bp.get("exams") or [])
|
|
171
|
+
bad = []
|
|
172
|
+
for m in bp.get("maps") or []:
|
|
173
|
+
for st in m.get("stages") or []:
|
|
174
|
+
for it in st.get("items") or []:
|
|
175
|
+
if it.get("type") == "course":
|
|
176
|
+
r = it.get("course_ref")
|
|
177
|
+
if type(r) is not int or not (0 <= r < nc):
|
|
178
|
+
bad.append("%s/%s course_ref=%r" % (m.get("name"), st.get("name"), r))
|
|
179
|
+
elif it.get("type") == "exam":
|
|
180
|
+
r = it.get("exam_ref")
|
|
181
|
+
if type(r) is not int or not (0 <= r < ne):
|
|
182
|
+
bad.append("%s/%s exam_ref=%r" % (m.get("name"), st.get("name"), r))
|
|
183
|
+
for pj in bp.get("projects") or []:
|
|
184
|
+
for it in (pj.get("config") or {}).get("items") or []:
|
|
185
|
+
r = it.get("course_ref" if it.get("type") == "course" else "exam_ref")
|
|
186
|
+
limit = nc if it.get("type") == "course" else ne
|
|
187
|
+
if type(r) is not int or not (0 <= r < limit):
|
|
188
|
+
bad.append("%s items %s=%r" % (pj.get("name"), it.get("type"), r))
|
|
189
|
+
if bad:
|
|
190
|
+
return _block("越界 %d 处:%s" % (len(bad), "; ".join(bad[:4])))
|
|
191
|
+
return _pass("courses=%d / exams=%d 内全部下标合法" % (nc, ne))
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def p3_naming(bp, ctx):
|
|
195
|
+
"""P-3 题库与分类命名(v4.1.3 并入原 P-14):前缀 / 非双前缀 / 结尾 / 地图分类不重名。"""
|
|
196
|
+
tax = bp.get("taxonomies") or {}
|
|
197
|
+
pools = _names(tax.get("question_pool"))
|
|
198
|
+
bad = []
|
|
199
|
+
for nm in pools:
|
|
200
|
+
if "[DEMO]" not in nm:
|
|
201
|
+
bad.append("缺 [DEMO] 前缀:" + nm)
|
|
202
|
+
if "[DEMO][DEMO]" in nm:
|
|
203
|
+
bad.append("双前缀:" + nm)
|
|
204
|
+
if not nm.endswith("题库分类"):
|
|
205
|
+
bad.append("未以「题库分类」结尾:" + nm)
|
|
206
|
+
if bad:
|
|
207
|
+
return _block("; ".join(bad[:4]))
|
|
208
|
+
return _pass("%d 个题库 + %d 个地图分类命名合规" % (len(pools), len(_names(tax.get("learning_map")))))
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def p4_incentives(bp, ctx):
|
|
212
|
+
"""P-4 incentives 形状合法。"""
|
|
213
|
+
inc = bp.get("incentives")
|
|
214
|
+
if inc is None:
|
|
215
|
+
return _pass("null(未启用)")
|
|
216
|
+
if not isinstance(inc, dict):
|
|
217
|
+
return _block("incentives 类型应为 null 或 object,实为 %s" % type(inc).__name__)
|
|
218
|
+
if inc.get("enabled") is not True:
|
|
219
|
+
return _block("enabled 非 true 时不得给 rules")
|
|
220
|
+
if not inc.get("rules"):
|
|
221
|
+
return _block("enabled=true 但 rules 为空")
|
|
222
|
+
return _pass("enabled=true / %d 条规则" % len(inc["rules"]))
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def p6_theme_in_hint(bp, ctx):
|
|
226
|
+
"""P-6 每张图 prompt_hint 含主色值。"""
|
|
227
|
+
color = ((bp.get("customer") or {}).get("theme_color") or "").strip()
|
|
228
|
+
if not color:
|
|
229
|
+
return _warn("customer.theme_color 待明确,不虚构品牌主色")
|
|
230
|
+
miss = [a.get("key") for a in bp.get("assets") or []
|
|
231
|
+
if color.lower() not in (a.get("prompt_hint") or "").lower()]
|
|
232
|
+
if miss:
|
|
233
|
+
return _warn("%d 张图 prompt_hint 缺已知主色 %s:%s" % (len(miss), color, ", ".join(miss[:5])))
|
|
234
|
+
return _pass("%d 张图全部含 %s" % (len(bp.get("assets") or []), color))
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def p7_closure(bp, ctx):
|
|
238
|
+
"""P-7 引用闭包:map items 指向真实对象且 title 非空。"""
|
|
239
|
+
courses = bp.get("courses") or []
|
|
240
|
+
exams = bp.get("exams") or []
|
|
241
|
+
bad = []
|
|
242
|
+
for m in bp.get("maps") or []:
|
|
243
|
+
for st in m.get("stages") or []:
|
|
244
|
+
for it in st.get("items") or []:
|
|
245
|
+
if it.get("type") == "course":
|
|
246
|
+
r = it.get("course_ref")
|
|
247
|
+
if not (type(r) is int and 0 <= r < len(courses)):
|
|
248
|
+
bad.append("%s/%s 课引用悬空" % (m.get("name"), st.get("name")))
|
|
249
|
+
elif not (courses[r].get("title") or "").strip():
|
|
250
|
+
bad.append("%s/%s 指向课程无 title" % (m.get("name"), st.get("name")))
|
|
251
|
+
elif it.get("type") == "exam":
|
|
252
|
+
r = it.get("exam_ref")
|
|
253
|
+
if not (type(r) is int and 0 <= r < len(exams)):
|
|
254
|
+
bad.append("%s/%s 考引用悬空" % (m.get("name"), st.get("name")))
|
|
255
|
+
elif not (exams[r].get("name") or "").strip():
|
|
256
|
+
bad.append("%s/%s 指向考试无 name" % (m.get("name"), st.get("name")))
|
|
257
|
+
if bad:
|
|
258
|
+
return _block("闭包断裂 %d 处:%s" % (len(bad), "; ".join(bad[:4])))
|
|
259
|
+
n = sum(len(st.get("items") or []) for m in bp.get("maps") or [] for st in m.get("stages") or [])
|
|
260
|
+
return _pass("%d 个挂载项全部闭合" % n)
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def p8_course_category(bp, ctx):
|
|
264
|
+
"""P-8 只校验显式分类路径;缺分类待明确,不逼造二级分类。"""
|
|
265
|
+
tax = (bp.get("taxonomies") or {}).get("course") or []
|
|
266
|
+
paths = set()
|
|
267
|
+
for node in tax:
|
|
268
|
+
l1 = node if isinstance(node, str) else node.get("l1") or node.get("name")
|
|
269
|
+
paths.add((l1,))
|
|
270
|
+
for l2 in (node.get("l2") or []) if isinstance(node, dict) else []:
|
|
271
|
+
paths.add((l1, l2))
|
|
272
|
+
bad, pending = [], []
|
|
273
|
+
for c in bp.get("courses") or []:
|
|
274
|
+
path = c.get("category_path") or []
|
|
275
|
+
path = path.split("/") if isinstance(path, str) else path
|
|
276
|
+
if not path:
|
|
277
|
+
pending.append(str(c.get("title")))
|
|
278
|
+
elif tuple(path) not in paths:
|
|
279
|
+
bad.append("%s -> %s 不在 taxonomy" % (str(c.get("title"))[:10], "/".join(path)))
|
|
280
|
+
if bad:
|
|
281
|
+
return _block("分类不闭合 %d 门:%s" % (len(bad), "; ".join(bad[:4])))
|
|
282
|
+
if pending:
|
|
283
|
+
return _warn("%d 门课分类待明确;保留缺项,不自动建分类" % len(pending))
|
|
284
|
+
return _pass("显式课程分类全部在 taxonomy 内")
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def p9_object_category(bp, ctx):
|
|
288
|
+
"""P-9 校验原文分类字段形状,三模块施工统一复用已有默认分类。"""
|
|
289
|
+
bad = []
|
|
290
|
+
for key in ("maps", "exams", "projects"):
|
|
291
|
+
for entity in bp.get(key) or []:
|
|
292
|
+
category = entity.get("category")
|
|
293
|
+
if category is not None and not isinstance(category, str):
|
|
294
|
+
bad.append("%s/%s category 必须为字符串或 null" % (key, entity.get("name")))
|
|
295
|
+
if bad:
|
|
296
|
+
return _block("; ".join(bad[:4]))
|
|
297
|
+
return _pass("三模块原文分类保留为资料,不逼 taxonomy 闭包;施工每模块复用一个已有默认分类,无可用默认则 pending")
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def p10_degraded(bp, ctx):
|
|
301
|
+
"""P-10 降级可观测:每处 degraded 在 run.log 有记录。"""
|
|
302
|
+
txt = ctx.get("runlog")
|
|
303
|
+
items = []
|
|
304
|
+
courses = bp.get("courses") or []
|
|
305
|
+
for m in bp.get("maps") or []:
|
|
306
|
+
for st in m.get("stages") or []:
|
|
307
|
+
for it in st.get("items") or []:
|
|
308
|
+
if it.get("degraded"):
|
|
309
|
+
nm = ""
|
|
310
|
+
if it.get("type") == "course" and type(it.get("course_ref")) is int:
|
|
311
|
+
if 0 <= it["course_ref"] < len(courses):
|
|
312
|
+
nm = courses[it["course_ref"]].get("title") or ""
|
|
313
|
+
items.append((m.get("name") or "", st.get("name") or "", nm, it["degraded"]))
|
|
314
|
+
if not items:
|
|
315
|
+
return _pass("无降级项")
|
|
316
|
+
if txt is None:
|
|
317
|
+
return _block("%d 处 degraded 但 run.log 未找到" % len(items))
|
|
318
|
+
miss = []
|
|
319
|
+
for mname, sname, cname, kind in items:
|
|
320
|
+
hit = (cname and cname in txt) or (sname and sname in txt)
|
|
321
|
+
if not hit or ("degraded" not in txt and kind not in txt):
|
|
322
|
+
miss.append("%s/%s" % (mname, sname))
|
|
323
|
+
if miss:
|
|
324
|
+
return _block("%d 处降级无 run.log 记录:%s" % (len(miss), "; ".join(miss[:3])))
|
|
325
|
+
return _pass("%d 处降级均有记录" % len(items))
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
def p11_asset_specs(bp, ctx):
|
|
329
|
+
"""P-11 技术规格检查,不限定业务对象数量。"""
|
|
330
|
+
bad = []
|
|
331
|
+
for asset in bp.get("assets") or []:
|
|
332
|
+
kind, size = asset.get("type"), asset.get("size")
|
|
333
|
+
if kind and kind not in ASSET_SIZES:
|
|
334
|
+
bad.append("%s 未知资产类型 %s" % (asset.get("key"), kind))
|
|
335
|
+
elif kind and size and str(size).lower().replace("×", "x") != ASSET_SIZES[kind]:
|
|
336
|
+
bad.append("%s 尺寸 %s 应为 %s" % (asset.get("key"), size, ASSET_SIZES[kind]))
|
|
337
|
+
if bad:
|
|
338
|
+
return _block("; ".join(bad))
|
|
339
|
+
return _pass("已声明资产技术规格合法;业务数量按文档范围核验")
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
def p12_confirm_table(bp, ctx):
|
|
343
|
+
"""P-12 确认表形态(需 --confirm-table 提供文本;未提供则跳过不阻塞)。"""
|
|
344
|
+
txt = ctx.get("confirm_table")
|
|
345
|
+
if not txt:
|
|
346
|
+
return _warn("未提供确认表文本 → 跳过(输出前人眼过:单表 / 无字母分段 / 无成本字样)")
|
|
347
|
+
bad = []
|
|
348
|
+
if re.search(r"(?m)^\s*#{0,3}\s*[ABC][..、]", txt):
|
|
349
|
+
bad.append("出现字母分段标题")
|
|
350
|
+
for kw in ("成本", "授权", "兜底项"):
|
|
351
|
+
if kw in txt:
|
|
352
|
+
bad.append("出现「%s」字样" % kw)
|
|
353
|
+
if re.search(r"积分", "\n".join(l for l in txt.splitlines()
|
|
354
|
+
if not l.strip().startswith("| K009"))):
|
|
355
|
+
bad.append("非 K009 行出现「积分」")
|
|
356
|
+
if not re.search(r"K00\d", txt):
|
|
357
|
+
bad.append("缺 K 编码列")
|
|
358
|
+
if "请回复" not in txt:
|
|
359
|
+
bad.append("缺回复指引")
|
|
360
|
+
if bad:
|
|
361
|
+
return _block("确认表违规:%s" % "、".join(bad))
|
|
362
|
+
return _pass("单表 + K 编码 + 回复指引,无分段/成本字样")
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
def p13_project_closure(bp, ctx):
|
|
366
|
+
"""P-13 projects 引用闭包。"""
|
|
367
|
+
nc, ne = len(bp.get("courses") or []), len(bp.get("exams") or [])
|
|
368
|
+
bad, pending = [], []
|
|
369
|
+
for pj in bp.get("projects") or []:
|
|
370
|
+
items = (pj.get("config") or {}).get("items") or []
|
|
371
|
+
if not items:
|
|
372
|
+
pending.append(str(pj.get("name")))
|
|
373
|
+
continue
|
|
374
|
+
for it in items:
|
|
375
|
+
t = it.get("type")
|
|
376
|
+
if t not in ("course", "exam"):
|
|
377
|
+
bad.append("%s 非法 type=%r" % (pj.get("name"), t))
|
|
378
|
+
continue
|
|
379
|
+
ok = (type(it.get("course_ref")) is int and 0 <= it["course_ref"] < nc) if t == "course" \
|
|
380
|
+
else (type(it.get("exam_ref")) is int and 0 <= it["exam_ref"] < ne)
|
|
381
|
+
if not ok:
|
|
382
|
+
bad.append("%s %s 引用悬空" % (pj.get("name"), t))
|
|
383
|
+
if bad:
|
|
384
|
+
return _block("; ".join(bad[:4]))
|
|
385
|
+
if pending:
|
|
386
|
+
return _warn("培训班内容待明确:%s;保留空内容草案,不自动配课或发布" % "、".join(pending))
|
|
387
|
+
return _pass("%d 个培训班 items 全部闭合" % len(bp.get("projects") or []))
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
def p15_scope(bp, ctx):
|
|
391
|
+
"""P-15 SCOPE 一致性(复用 scope_plan.verify_blueprint)。"""
|
|
392
|
+
plan = ctx.get("scope_plan")
|
|
393
|
+
if plan is None:
|
|
394
|
+
return _block("scope-plan.json 缺失 → P-15 无法取值")
|
|
395
|
+
try:
|
|
396
|
+
sys.path.insert(0, os.path.join(SKILL_DIR, "scripts"))
|
|
397
|
+
from scope_plan import verify_blueprint
|
|
398
|
+
except Exception as exc: # pragma: no cover
|
|
399
|
+
return _block("无法导入 scope_plan.verify_blueprint:%s" % exc)
|
|
400
|
+
r = verify_blueprint(bp, plan)
|
|
401
|
+
if not r.get("ok"):
|
|
402
|
+
parts = list(r.get("diffs") or []) + ["shape:" + x for x in (r.get("shape") or [])]
|
|
403
|
+
return _block("; ".join(parts[:5]) or "不一致")
|
|
404
|
+
sc = plan.get("scope") or {}
|
|
405
|
+
detail = "courses=%s maps=%s(+%s) exams=%s projects=%s portals=%s" % (
|
|
406
|
+
sc.get("courses"), sc.get("maps"), sc.get("maps_plan_only"), sc.get("exams"),
|
|
407
|
+
sc.get("projects"), sc.get("portals"))
|
|
408
|
+
if plan.get("unresolved"):
|
|
409
|
+
return _warn(detail + ";%d 项待明确,不自动填充" % len(plan["unresolved"]))
|
|
410
|
+
return _pass(detail)
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
def _ctx(bp_path, out_dir, runlog_path, confirm_table=None):
|
|
414
|
+
d = out_dir or os.path.dirname(os.path.abspath(bp_path))
|
|
415
|
+
plan = os.path.join(d, "scope-plan.json")
|
|
416
|
+
log = runlog_path or os.path.join(d, "run.log")
|
|
417
|
+
ct = None
|
|
418
|
+
if confirm_table and os.path.isfile(confirm_table):
|
|
419
|
+
ct = open(confirm_table, encoding="utf-8").read()
|
|
420
|
+
return {"scope_plan": _load(plan) if os.path.isfile(plan) else None,
|
|
421
|
+
"runlog": open(log, encoding="utf-8").read() if os.path.isfile(log) else None,
|
|
422
|
+
"confirm_table": ct}
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
CHECKS = [
|
|
426
|
+
("P-1", "asset_key 引用完整", p1_asset_keys),
|
|
427
|
+
("P-2", "items 下标不越界", p2_ref_bounds),
|
|
428
|
+
("P-3", "题库与分类命名", p3_naming),
|
|
429
|
+
("P-4", "incentives 形状", p4_incentives),
|
|
430
|
+
("P-6", "prompt_hint 含主色", p6_theme_in_hint),
|
|
431
|
+
("P-7", "引用闭包", p7_closure),
|
|
432
|
+
("P-8", "课程分类闭包", p8_course_category),
|
|
433
|
+
("P-9", "三模块原文分类字段", p9_object_category),
|
|
434
|
+
("P-10", "降级可观测", p10_degraded),
|
|
435
|
+
("P-11", "资产技术规格", p11_asset_specs),
|
|
436
|
+
("P-12", "确认表形态", p12_confirm_table),
|
|
437
|
+
("P-13", "projects 引用闭包", p13_project_closure),
|
|
438
|
+
("P-15", "SCOPE 一致性", p15_scope),
|
|
439
|
+
]
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
# ---------------------------------------------------------------- runner
|
|
443
|
+
|
|
444
|
+
def lint(bp, ctx, only=None):
|
|
445
|
+
active, requested = resolve_types(only, bp)
|
|
446
|
+
rows = []
|
|
447
|
+
for gid, label, fn in CHECKS:
|
|
448
|
+
need = GATE_REQUIRES.get(gid)
|
|
449
|
+
if need is not None and not (need & active):
|
|
450
|
+
rows.append({"gate": gid, "label": label, "ok": True, "level": "skip",
|
|
451
|
+
"detail": "SKIP 无适用对象(需 %s;本蓝图 %s)"
|
|
452
|
+
% ("/".join(sorted(need)),
|
|
453
|
+
"/".join(sorted(active)) or "空")})
|
|
454
|
+
continue
|
|
455
|
+
try:
|
|
456
|
+
r = fn(bp, ctx)
|
|
457
|
+
except Exception as exc:
|
|
458
|
+
r = _block("检查自身异常:%s: %s" % (type(exc).__name__, exc))
|
|
459
|
+
rows.append({"gate": gid, "label": label, **r})
|
|
460
|
+
block = [r for r in rows if not r["ok"]]
|
|
461
|
+
warn = [r for r in rows if r["ok"] and r["level"] == "warn"]
|
|
462
|
+
skip = [r for r in rows if r["ok"] and r["level"] == "skip"]
|
|
463
|
+
return {"ok": not block, "rows": rows,
|
|
464
|
+
"block": len(block), "warn": len(warn), "skip": len(skip),
|
|
465
|
+
"ran": len(rows) - len(skip), "total": len(rows),
|
|
466
|
+
"only": list(requested) if requested else None,
|
|
467
|
+
"active": sorted(active)}
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
def main(argv=None):
|
|
471
|
+
ap = argparse.ArgumentParser(description="plan-parse 技术字段批量自动校验(编号非独立调度闸门)")
|
|
472
|
+
ap.add_argument("blueprint", nargs="?", help="DEMO-BLUEPRINT.json")
|
|
473
|
+
ap.add_argument("--out-dir", help="scope-plan.json / run.log 所在目录(缺省=蓝图同目录)")
|
|
474
|
+
ap.add_argument("--run-log", help="显式指定 run.log 路径")
|
|
475
|
+
ap.add_argument("--confirm-table", help="确认表 Markdown 落盘路径(可选,用于 P-12)")
|
|
476
|
+
ap.add_argument("--only", help="只跑指定对象相关闸门:%s(逗号分隔)" % ",".join(OBJECT_TYPES))
|
|
477
|
+
ap.add_argument("--matrix", action="store_true", help="打印闸门→适用对象映射表后退出")
|
|
478
|
+
ap.add_argument("--json", action="store_true")
|
|
479
|
+
ap.add_argument("--self-test", action="store_true")
|
|
480
|
+
args = ap.parse_args(argv)
|
|
481
|
+
|
|
482
|
+
if args.matrix:
|
|
483
|
+
print("闸门 适用对象(缺则该闸门 SKIP)")
|
|
484
|
+
for gid, label, _ in CHECKS:
|
|
485
|
+
need = GATE_REQUIRES.get(gid)
|
|
486
|
+
print(" %-5s %-22s %s" % (gid, label, "任何蓝图" if need is None else "/".join(sorted(need))))
|
|
487
|
+
print("\n--only 隐含类型:%s" % "; ".join("%s→%s" % (k, "+".join(v)) for k, v in IMPLIED.items()))
|
|
488
|
+
print("例:--only portal → 实际跑 %s"
|
|
489
|
+
% "/".join(g for g, _, _ in CHECKS if GATE_REQUIRES.get(g) is None
|
|
490
|
+
or GATE_REQUIRES[g] & {"portal", "asset"}))
|
|
491
|
+
return 0
|
|
492
|
+
if args.self_test:
|
|
493
|
+
return self_test()
|
|
494
|
+
if not args.blueprint:
|
|
495
|
+
ap.error("缺少 blueprint 参数(或用 --self-test / --matrix)")
|
|
496
|
+
only = [x.strip() for x in (args.only or "").split(",") if x.strip()] or None
|
|
497
|
+
bp = _load(args.blueprint)
|
|
498
|
+
try:
|
|
499
|
+
res = lint(bp, _ctx(args.blueprint, args.out_dir, args.run_log, args.confirm_table), only)
|
|
500
|
+
except ValueError as exc:
|
|
501
|
+
ap.error(str(exc))
|
|
502
|
+
if args.json:
|
|
503
|
+
print(json.dumps(res, ensure_ascii=False, indent=1))
|
|
504
|
+
else:
|
|
505
|
+
if res["only"]:
|
|
506
|
+
print("blueprint_lint: %d 项闸门(--only %s → 跑 %d / 跳 %d)"
|
|
507
|
+
% (res["total"], ",".join(res["only"]), res["ran"], res["skip"]))
|
|
508
|
+
else:
|
|
509
|
+
print("blueprint_lint: %d 项闸门(按蓝图实际对象 %s → 跑 %d / 跳 %d)"
|
|
510
|
+
% (res["total"], "/".join(res["active"]) or "空", res["ran"], res["skip"]))
|
|
511
|
+
for r in res["rows"]:
|
|
512
|
+
tag = "PASS" if r["ok"] and r["level"] == "info" else ("WARN" if r["ok"] and r["level"] == "warn"
|
|
513
|
+
else ("SKIP" if r["ok"] else "BLOCK"))
|
|
514
|
+
print(" %-5s %-4s %-16s %s" % (tag, r["gate"], r["label"], r["detail"]))
|
|
515
|
+
print(" %d PASS · %d WARN · %d SKIP · %d BLOCK → rc=%d"
|
|
516
|
+
% (res["ran"] - res["block"] - res["warn"], res["warn"], res["skip"],
|
|
517
|
+
res["block"], 0 if res["ok"] else 2))
|
|
518
|
+
return 0 if res["ok"] else 2
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
# ---------------------------------------------------------------- self-test
|
|
522
|
+
|
|
523
|
+
def self_test():
|
|
524
|
+
ok = []
|
|
525
|
+
|
|
526
|
+
def ck(cond, label):
|
|
527
|
+
ok.append((bool(cond), label))
|
|
528
|
+
|
|
529
|
+
good = {
|
|
530
|
+
"customer": {"theme_color": "#123456", "logo_asset_key": "logo.main"},
|
|
531
|
+
"taxonomies": {
|
|
532
|
+
"course": [{"l1": "L1", "l2": ["a", "b"]}],
|
|
533
|
+
"question_pool": [{"name": "[DEMO] X题库分类"}],
|
|
534
|
+
"learning_map": [{"name": "学习地图"}],
|
|
535
|
+
"exam": [{"name": "C1"}],
|
|
536
|
+
"training_class": [{"name": "T1"}],
|
|
537
|
+
},
|
|
538
|
+
"courses": [{"title": "课1", "asset_key": "cover.course.c1", "category_path": ["L1", "a"]},
|
|
539
|
+
{"title": "课2", "asset_key": "cover.course.c2", "category_path": ["L1", "b"]}],
|
|
540
|
+
"exams": [{"name": "考1", "category": "C1"}],
|
|
541
|
+
"maps": [{"name": "新员工地图", "category": "学习地图", "asset_key": "cover.map.m1",
|
|
542
|
+
"stages": [{"name": "S1", "items": [{"type": "course", "course_ref": 0},
|
|
543
|
+
{"type": "exam", "exam_ref": 0}]}]}],
|
|
544
|
+
"plan_only_maps": [],
|
|
545
|
+
"projects": [{"name": "班1", "category": "T1",
|
|
546
|
+
"config": {"items": [{"type": "course", "course_ref": 1}]}}],
|
|
547
|
+
"portals": [{"banner_asset_keys": ["banner.main.a"]}],
|
|
548
|
+
"incentives": None,
|
|
549
|
+
"assets": [{"key": "cover.course.c1", "prompt_hint": "#123456 封面"},
|
|
550
|
+
{"key": "cover.course.c2", "prompt_hint": "#123456 封面"},
|
|
551
|
+
{"key": "cover.map.m1", "prompt_hint": "#123456 地图"},
|
|
552
|
+
{"key": "banner.main.a", "prompt_hint": "#123456 横幅"},
|
|
553
|
+
{"key": "logo.main", "prompt_hint": "#123456 标识"}],
|
|
554
|
+
}
|
|
555
|
+
plan = {"scope": {"courses": 2, "maps": 1, "maps_plan_only": 0, "exams": 1, "projects": 1, "portals": 1}}
|
|
556
|
+
stock_ok = {"counts": {"portal": 1, "course": 2, "map": 1, "exam": 1, "class": 0},
|
|
557
|
+
"errors": [], "unverified": {}, "missing": {}, "dups": []}
|
|
558
|
+
ctx = {"scope_plan": plan, "runlog": "章节命中:x 共 5 类\n", "stock": stock_ok}
|
|
559
|
+
|
|
560
|
+
r = lint(good, ctx)
|
|
561
|
+
ck(r["ok"], "干净蓝图全过")
|
|
562
|
+
ck(r["block"] == 0, "干净蓝图 0 BLOCK")
|
|
563
|
+
|
|
564
|
+
import copy
|
|
565
|
+
# P-6:缺主色
|
|
566
|
+
b = copy.deepcopy(good); b["assets"][-1]["prompt_hint"] = "绿底白字"
|
|
567
|
+
ck(p6_theme_in_hint(b, ctx)["level"] == "warn", "P-6 缺主色提示只警告不补品牌事实")
|
|
568
|
+
ck(p6_theme_in_hint({"assets": [{}]}, ctx)["level"] == "warn", "P-6 文档没给品牌色待明确")
|
|
569
|
+
# P-7:course_ref 越界
|
|
570
|
+
b = copy.deepcopy(good); b["maps"][0]["stages"][0]["items"][0]["course_ref"] = 99
|
|
571
|
+
ck(not p7_closure(b, ctx)["ok"], "P-7 抓到悬空课引用")
|
|
572
|
+
# P-8:分类不在 taxonomy
|
|
573
|
+
b = copy.deepcopy(good); b["courses"][0]["category_path"] = ["L9", "z"]
|
|
574
|
+
ck(not p8_course_category(b, ctx)["ok"], "P-8 抓到分类不闭合")
|
|
575
|
+
# P-9:原文分类不驱动三模块施工闭包,字段类型仍严格校验。
|
|
576
|
+
b = copy.deepcopy(good); b["exams"][0]["category"] = "C9"
|
|
577
|
+
ck(p9_object_category(b, ctx)["ok"], "P-9 原文分类不闭包不阻塞技术默认施工")
|
|
578
|
+
b["exams"][0]["category"] = ["C9"]
|
|
579
|
+
ck(not p9_object_category(b, ctx)["ok"], "P-9 非法分类字段类型仍阻塞")
|
|
580
|
+
b["exams"][0]["category"] = {"uuid": "猜测"}
|
|
581
|
+
ck(not p9_object_category(b, ctx)["ok"], "P-9 拒绝字典伪装原文分类")
|
|
582
|
+
# P-9:空壳分类 → warn 不 block
|
|
583
|
+
b = copy.deepcopy(good); b["taxonomies"]["exam"].append({"name": "C2"})
|
|
584
|
+
rr = p9_object_category(b, ctx)
|
|
585
|
+
ck(rr["ok"] and rr["level"] == "info", "P-9 文档分类未被引用仍保留")
|
|
586
|
+
# P-10:degraded 无日志
|
|
587
|
+
b = copy.deepcopy(good); b["maps"][0]["stages"][0]["items"][0]["degraded"] = "rotation"
|
|
588
|
+
ck(not p10_degraded(b, {"scope_plan": plan, "runlog": "无"})["ok"], "P-10 抓到无日志降级")
|
|
589
|
+
ck(p10_degraded(b, {"scope_plan": plan, "runlog": "课1 degraded=rotation"})["ok"], "P-10 有日志放行")
|
|
590
|
+
# 不按旧配额裁剪;技术规格仍校验
|
|
591
|
+
b = copy.deepcopy(good); b["courses"] = [{"title": "c%d" % i} for i in range(21)]
|
|
592
|
+
ck(p11_asset_specs(b, ctx)["ok"], "P-11 不限制文档课程数量")
|
|
593
|
+
b["assets"][0].update({"type": "cover_course", "size": "1920x720"})
|
|
594
|
+
ck(not p11_asset_specs(b, ctx)["ok"], "P-11 仍拦截错误资产尺寸")
|
|
595
|
+
b["assets"][0]["size"] = "960×540"
|
|
596
|
+
ck(p11_asset_specs(b, ctx)["ok"], "P-11 正确技术尺寸通过")
|
|
597
|
+
# 缺项标待明确,不补造业务
|
|
598
|
+
b = copy.deepcopy(good); b["projects"][0]["config"]["items"] = []
|
|
599
|
+
ck(p13_project_closure(b, ctx)["level"] == "warn", "P-13 空 items 待明确不逼配课")
|
|
600
|
+
b = copy.deepcopy(good); b["courses"][0].pop("category_path")
|
|
601
|
+
ck(p8_course_category(b, ctx)["level"] == "warn", "P-8 缺分类待明确不逼造分类")
|
|
602
|
+
b = copy.deepcopy(good); b["courses"][0]["category_path"] = ["L1"]
|
|
603
|
+
ck(p8_course_category(b, ctx)["ok"], "P-8 文档一级分类不逼补二级")
|
|
604
|
+
b = copy.deepcopy(good); b["maps"][0].pop("category")
|
|
605
|
+
ck(p9_object_category(b, ctx)["level"] == "info", "P-9 三模块原文缺分类不阻塞解析")
|
|
606
|
+
# P-3:双前缀(原 P-14)
|
|
607
|
+
b = copy.deepcopy(good); b["taxonomies"]["question_pool"][0]["name"] = "[DEMO][DEMO] X题库分类"
|
|
608
|
+
ck(not p3_naming(b, ctx)["ok"], "P-3 抓到双前缀")
|
|
609
|
+
b = copy.deepcopy(good); b["taxonomies"]["question_pool"][0]["name"] = "[DEMO] X"
|
|
610
|
+
ck(not p3_naming(b, ctx)["ok"], "P-3 抓到未以「题库分类」结尾")
|
|
611
|
+
b = copy.deepcopy(good); b["maps"][0]["category"] = b["maps"][0]["name"]
|
|
612
|
+
b["taxonomies"]["learning_map"] = [{"title": b["maps"][0]["name"]}]
|
|
613
|
+
ck(p3_naming(b, ctx)["ok"] and p9_object_category(b, ctx)["ok"], "文档分类与对象同名不逼造改名,兼容 title")
|
|
614
|
+
b = copy.deepcopy(good); b["taxonomies"]["training_class"] = [{"name": "父分类", "children": [{"name": "T1"}]}]
|
|
615
|
+
ck(p9_object_category(b, ctx)["ok"], "原文多级培训班分类闭合")
|
|
616
|
+
b = copy.deepcopy(good); b["maps"][0]["stages"][0]["items"][0]["course_ref"] = True
|
|
617
|
+
ck(not p2_ref_bounds(b, ctx)["ok"], "布尔值不能伪装引用下标")
|
|
618
|
+
b = copy.deepcopy(good); b["assets"] = []
|
|
619
|
+
ck(any(r["gate"] == "P-1" and not r["ok"] for r in lint(b, ctx)["rows"]), "资产表缺失仍拦截悬空资产引用")
|
|
620
|
+
# P-9:taxonomy 纯字符串形态(真实蓝图就是这种)
|
|
621
|
+
b = copy.deepcopy(good); b["taxonomies"]["exam"] = ["C1"]
|
|
622
|
+
ck(p9_object_category(b, ctx)["ok"], "P-9 兼容字符串 taxonomy")
|
|
623
|
+
# P-12:确认表形态
|
|
624
|
+
good_ct = "| K001 | 门户 | 1 个 |\n| K003 | 课程 | 10 门 |\n\n请回复:K 编码 + 正确值;\"确认\" = 开跑\n"
|
|
625
|
+
ck(p12_confirm_table(good, {"confirm_table": good_ct})["ok"], "P-12 干净确认表通过")
|
|
626
|
+
ck(not p12_confirm_table(good, {"confirm_table": "A. 门户\n" + good_ct})["ok"], "P-12 抓到字母分段")
|
|
627
|
+
ck(not p12_confirm_table(good, {"confirm_table": good_ct + "| K008 | 图 | 15 张,成本 30 积分 |\n"})["ok"], "P-12 抓到成本字样")
|
|
628
|
+
ck(p12_confirm_table(good, {"confirm_table": None})["ok"], "P-12 未提供文本只 warn")
|
|
629
|
+
# P-15:数字不符
|
|
630
|
+
b = copy.deepcopy(good)
|
|
631
|
+
ck(not p15_scope(b, {"scope_plan": {"scope": {"courses": 3, "maps": 1,
|
|
632
|
+
"maps_plan_only": 0, "exams": 1,
|
|
633
|
+
"projects": 1}}})["ok"], "P-15 抓到课程数不符")
|
|
634
|
+
# P-15:缺 scope-plan
|
|
635
|
+
ck(not p15_scope(good, {"scope_plan": None, "runlog": ""})["ok"], "P-15 缺 scope-plan 即阻塞")
|
|
636
|
+
# P-2:type 非法(projects)
|
|
637
|
+
b = copy.deepcopy(good); b["projects"][0]["config"]["items"][0]["type"] = "map"
|
|
638
|
+
ck(not p13_project_closure(b, ctx)["ok"], "P-13 抓到非法 type")
|
|
639
|
+
# P-1:悬空 asset
|
|
640
|
+
b = copy.deepcopy(good); b["courses"][0]["asset_key"] = "cover.nope"
|
|
641
|
+
ck(not p1_asset_keys(b, ctx)["ok"], "P-1 抓到悬空 asset_key")
|
|
642
|
+
ck("P-16" not in {g for g, _, _ in CHECKS}, "P-16 平台探测不再是纯解析闸门")
|
|
643
|
+
ck(lint(good, {"scope_plan": plan})["ok"], "无存量快照纯文档解析也通过")
|
|
644
|
+
|
|
645
|
+
# ---- v4.3.0:闸门按对象裁剪(--only)
|
|
646
|
+
ck({g for g, _, _ in CHECKS} == set(GATE_REQUIRES), "GATE_REQUIRES 覆盖全部解析闸门")
|
|
647
|
+
r_all = lint(good, ctx)
|
|
648
|
+
skipped_all = [r["gate"] for r in r_all["rows"] if r["level"] == "skip"]
|
|
649
|
+
ck(skipped_all == ["P-4"], "incentives 未启用 → 只有 P-4 SKIP(不算通过)")
|
|
650
|
+
ck(r_all["ran"] == r_all["total"] - 1, "全对象蓝图只跳 1 道")
|
|
651
|
+
|
|
652
|
+
portal_only = {
|
|
653
|
+
"customer": {"theme_color": "#123456", "logo_asset_key": "logo.main"},
|
|
654
|
+
"portals": [{"name": "X 学堂", "banner_asset_keys": ["banner.main.a"]}],
|
|
655
|
+
"assets": [{"key": "banner.main.a", "prompt_hint": "#123456 横幅"},
|
|
656
|
+
{"key": "logo.main", "prompt_hint": "#123456 标识"}],
|
|
657
|
+
"incentives": None,
|
|
658
|
+
}
|
|
659
|
+
ctx0 = {"scope_plan": {"scope": {"courses": 0, "maps": 0, "maps_plan_only": 0,
|
|
660
|
+
"exams": 0, "projects": 0, "portals": 1}},
|
|
661
|
+
"runlog": "", "stock": stock_ok}
|
|
662
|
+
rp = lint(portal_only, ctx0, ["portal"])
|
|
663
|
+
ck(rp["ok"], "门户-only 蓝图通过")
|
|
664
|
+
ck(rp["ran"] == 5 and rp["skip"] == 8, "门户-only 跑 5 道 / SKIP 8 道")
|
|
665
|
+
ck({r["gate"] for r in rp["rows"] if r["level"] != "skip"} ==
|
|
666
|
+
{"P-1", "P-6", "P-11", "P-12", "P-15"}, "门户-only 命中 5 道门户相关闸门")
|
|
667
|
+
ck({"P-3", "P-7", "P-8", "P-13"} <= {r["gate"] for r in rp["rows"] if r["level"] == "skip"},
|
|
668
|
+
"门户-only 跳过题库/闭包/培训班闸门")
|
|
669
|
+
b = copy.deepcopy(portal_only)
|
|
670
|
+
b["courses"] = [{"title": "坏课", "category_path": ["X", "Y"]}]
|
|
671
|
+
b_ctx = {"scope_plan": {"scope": {"courses": 1, "maps": 0, "maps_plan_only": 0,
|
|
672
|
+
"exams": 0, "projects": 0, "portals": 1}},
|
|
673
|
+
"runlog": "", "stock": stock_ok}
|
|
674
|
+
ck(lint(b, b_ctx, ["portal"])["ok"], "课程分类坏了也不拦「只建门户」")
|
|
675
|
+
ck(not lint(b, b_ctx)["ok"], "全量模式仍会抓到同一个问题")
|
|
676
|
+
try:
|
|
677
|
+
resolve_types(["nope"], good)
|
|
678
|
+
ck(False, "未知对象类型应报错")
|
|
679
|
+
except ValueError:
|
|
680
|
+
ck(True, "未知对象类型报错")
|
|
681
|
+
ck(lint(portal_only, ctx0, ["portal"])["skip"] > 0 and
|
|
682
|
+
len([r for r in lint(portal_only, ctx0, ["portal"])["rows"] if r["level"] == "skip"]) == 8,
|
|
683
|
+
"SKIP 行保留在 rows 里可审计")
|
|
684
|
+
|
|
685
|
+
failed = [label for good_, label in ok if not good_]
|
|
686
|
+
for good_, label in ok:
|
|
687
|
+
print(("PASS " if good_ else "FAIL ") + label)
|
|
688
|
+
print("%d/%d 断言通过" % (len(ok) - len(failed), len(ok)))
|
|
689
|
+
return 0 if not failed else 1
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
if __name__ == "__main__":
|
|
693
|
+
sys.exit(main())
|