@sokeai/cli 1.0.116 → 1.0.118
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/README.md +2 -0
- package/docs/harmonyos.md +67 -0
- package/package.json +4 -1
- package/scripts/install.js +7 -21
- package/scripts/runtime-platform.js +32 -0
- 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,452 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""stock_probe.py — 工序 ① 之后、plan-parse 之前的「存量探测」闸门(**只读**)。
|
|
4
|
+
|
|
5
|
+
为什么必须单独一道闸门
|
|
6
|
+
--------------------
|
|
7
|
+
2026-10-22 老乡鸡 DEMO 的返工根因不是解析错,而是**在空租户假设下施工**:解析方案、
|
|
8
|
+
判 plan_only、生成 Banner、甚至新建门户,全部做完才发现租户里早就有 10 门课、6 张地图、
|
|
9
|
+
一个已发布的门户。整条 ②③④ 返工,还留下一个重复空壳。
|
|
10
|
+
|
|
11
|
+
一次探测 ≈ 10 次只读 CLI;不探测 ≈ 全链路返工。所以它必须是工序而不是"顺手看一眼"。
|
|
12
|
+
|
|
13
|
+
只做三件事
|
|
14
|
+
----------
|
|
15
|
+
1. 拉取七类对象的**总数**与**全量名单**(分页,口径按 platform-commands.md 的坑位表)
|
|
16
|
+
2. 与 BLUEPRINT 逐个名字对照,给出 已存在 / 缺失 / 同名重复
|
|
17
|
+
3. 落盘 `stock-snapshot.json` + 写一行 run.log
|
|
18
|
+
|
|
19
|
+
⛔ 本脚本不建、不改、不删任何平台对象;不带 --apply。
|
|
20
|
+
|
|
21
|
+
用法
|
|
22
|
+
----
|
|
23
|
+
<PY> stock_probe.py --demo-root <DEMO_ROOT>
|
|
24
|
+
<PY> stock_probe.py --demo-root <D> --blueprint <D>/DEMO-BLUEPRINT.json
|
|
25
|
+
<PY> stock_probe.py --demo-root <D> --json # 机器可读
|
|
26
|
+
<PY> stock_probe.py --self-test
|
|
27
|
+
|
|
28
|
+
退出码
|
|
29
|
+
------
|
|
30
|
+
0 = 探测完成(missing 不算失败——缺的本来就该新建)
|
|
31
|
+
2 = 至少一类探测失败(errors 非空),此时**不得**据此下"空租户"结论
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
from __future__ import annotations
|
|
35
|
+
|
|
36
|
+
import argparse
|
|
37
|
+
import json
|
|
38
|
+
import os
|
|
39
|
+
import re
|
|
40
|
+
import sys
|
|
41
|
+
import time
|
|
42
|
+
from datetime import datetime, timedelta
|
|
43
|
+
|
|
44
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
45
|
+
|
|
46
|
+
from cli_kit import Cli, pick_title, rows_of, short # noqa: E402
|
|
47
|
+
|
|
48
|
+
SNAPSHOT = "stock-snapshot.json"
|
|
49
|
+
PAGE_SIZE = 100 # course 上限 100(坑 #98/#117),其余同样取 100
|
|
50
|
+
MAX_PAGES = 25 # 2500 条护栏;超出记 truncated
|
|
51
|
+
|
|
52
|
+
# 探测表:kind → (中文名, 命令前缀, 是否分页, 蓝图字段 key)
|
|
53
|
+
# 命令口径来自 references/platform-commands.md 实测坑位表:
|
|
54
|
+
# · course 用 +list-courses(+list 的 --page/--page-size 已废弃)
|
|
55
|
+
# · learning-map 必须带毫秒时间窗(≤365 天),否则空返回且不报错
|
|
56
|
+
# · training-class 用 +list --status {1,0}(草稿班在 status=0,只查 1 会漏)
|
|
57
|
+
# · 分类:course/map/exam 用 +list-categories,培训班用 +category-list
|
|
58
|
+
PROBES = {
|
|
59
|
+
"portal": ("门户", ["portal", "+list", "--format", "json"], True),
|
|
60
|
+
"course": ("课程", ["course", "+list-courses"], True),
|
|
61
|
+
"map": ("学习地图", ["learning-map", "+list-maps"], True),
|
|
62
|
+
"exam": ("考试", ["exam", "+list-exams"], True),
|
|
63
|
+
"class": ("培训班", ["training-class", "+list", "--status", "1"], True),
|
|
64
|
+
"pool": ("题库", ["exam", "+list-pools", "--status", "1"], True),
|
|
65
|
+
"cat_course": ("课程分类", ["course", "+list-categories", "--format", "json"], True),
|
|
66
|
+
"cat_map": ("地图分类", ["learning-map", "+list-categories", "--format", "json"], True),
|
|
67
|
+
# 考试/培训班分类的 data.count 含子级统计(坑 #89:count=15 / rows=12),
|
|
68
|
+
# 按 count 翻页会永远差几条 → 保持单次拉取,不做 truncated 判定。
|
|
69
|
+
"cat_exam": ("考试分类", ["exam", "+list-categories", "--format", "json"], False),
|
|
70
|
+
"cat_class": ("培训班分类", ["training-class", "+category-list"], False),
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
# 蓝图段 → 探测 kind(顺序即摘要行的输出顺序)
|
|
74
|
+
BP_TO_KIND = [("portals", "portal"), ("courses", "course"), ("maps", "map"),
|
|
75
|
+
("exams", "exam"), ("projects", "class")]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# ------------------------------------------------------------------ 纯函数
|
|
79
|
+
|
|
80
|
+
def normalize(s) -> str:
|
|
81
|
+
"""名称归一:全角括号/空格/引号变体统一,去掉所有空白,英文小写。
|
|
82
|
+
|
|
83
|
+
平台里「(DEMO)」与「(DEMO)」、「新店开业「21 天」」与「新店开业"21天"」都真实存在过,
|
|
84
|
+
逐字比较会把已存在的对象判成缺失。
|
|
85
|
+
"""
|
|
86
|
+
s = "" if s is None else str(s)
|
|
87
|
+
table = {"(": "(", ")": ")", " ": " ", "「": '"', "」": '"',
|
|
88
|
+
""": '"', "”": '"', "“": '"', "‘": "'", "’": "'",
|
|
89
|
+
":": ":", ",": ","}
|
|
90
|
+
for a, b in table.items():
|
|
91
|
+
s = s.replace(a, b)
|
|
92
|
+
s = re.sub(r"\s+", "", s)
|
|
93
|
+
return s.lower()
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _count(obj):
|
|
97
|
+
"""信封里的总数:data.count / data.total(字符串数字也认)。"""
|
|
98
|
+
if not isinstance(obj, dict):
|
|
99
|
+
return None
|
|
100
|
+
holders = [obj.get("data"), obj]
|
|
101
|
+
for h in holders:
|
|
102
|
+
if isinstance(h, dict):
|
|
103
|
+
for k in ("count", "total"):
|
|
104
|
+
v = h.get(k)
|
|
105
|
+
if isinstance(v, bool):
|
|
106
|
+
continue
|
|
107
|
+
if isinstance(v, int):
|
|
108
|
+
return v
|
|
109
|
+
if isinstance(v, str) and v.isdigit():
|
|
110
|
+
return int(v)
|
|
111
|
+
return None
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _name_of(row):
|
|
115
|
+
return pick_title(row) or row.get("name") or row.get("title") or ""
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def match_rows(bp_names, rows):
|
|
119
|
+
"""把蓝图名字与平台行对照。返回 (compare, dups)。
|
|
120
|
+
|
|
121
|
+
compare: [{name, exists, hits:[{uuid,title,status}]}]
|
|
122
|
+
dups : [{name, hits:[...]}] —— 同名多条,需走 G-10 去重通道
|
|
123
|
+
"""
|
|
124
|
+
index = {}
|
|
125
|
+
for r in rows:
|
|
126
|
+
index.setdefault(normalize(_name_of(r)), []).append(r)
|
|
127
|
+
|
|
128
|
+
compare, dups = [], []
|
|
129
|
+
for raw in bp_names:
|
|
130
|
+
key = normalize(raw)
|
|
131
|
+
hits = index.get(key, [])
|
|
132
|
+
brief = [{"uuid": h.get("uuid") or h.get("id"),
|
|
133
|
+
"title": _name_of(h),
|
|
134
|
+
"status": h.get("status")} for h in hits]
|
|
135
|
+
compare.append({"name": raw, "exists": bool(hits), "hits": brief})
|
|
136
|
+
if len(hits) > 1:
|
|
137
|
+
dups.append({"name": raw, "hits": brief})
|
|
138
|
+
return compare, dups
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def blueprint_jobs(bp):
|
|
142
|
+
"""从蓝图取出「类别 → 待核对名字列表」。"""
|
|
143
|
+
jobs = {}
|
|
144
|
+
for sect, kind in BP_TO_KIND:
|
|
145
|
+
names = []
|
|
146
|
+
for it in bp.get(sect) or []:
|
|
147
|
+
nm = it.get("name") or it.get("title")
|
|
148
|
+
if nm:
|
|
149
|
+
names.append(nm)
|
|
150
|
+
jobs[kind] = names
|
|
151
|
+
|
|
152
|
+
tax = bp.get("taxonomies") or {}
|
|
153
|
+
# 课程分类:L1 与 L2 都要探(L2 才是课程真正挂载的节点)
|
|
154
|
+
cat = []
|
|
155
|
+
for node in tax.get("course") or []:
|
|
156
|
+
if isinstance(node, dict):
|
|
157
|
+
if node.get("l1"):
|
|
158
|
+
cat.append(node["l1"])
|
|
159
|
+
cat.extend([x for x in (node.get("l2") or []) if x])
|
|
160
|
+
jobs["cat_course"] = cat
|
|
161
|
+
|
|
162
|
+
jobs["pool"] = [p.get("name") for p in (tax.get("question_pool") or [])
|
|
163
|
+
if isinstance(p, dict) and p.get("name")]
|
|
164
|
+
jobs["cat_map"] = [p.get("name") for p in (tax.get("learning_map") or [])
|
|
165
|
+
if isinstance(p, dict) and p.get("name")]
|
|
166
|
+
jobs["cat_class"] = [x for x in (tax.get("training_class") or []) if x]
|
|
167
|
+
jobs["cat_exam"] = [x for x in (tax.get("exam") or []) if x]
|
|
168
|
+
return jobs
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
# ------------------------------------------------------------------ 探测
|
|
172
|
+
|
|
173
|
+
def probe_paged(cli, kind, argv, page_size=PAGE_SIZE, max_pages=MAX_PAGES):
|
|
174
|
+
"""分页拉全量。返回 (rows, total, pages, truncated, error)。
|
|
175
|
+
|
|
176
|
+
⚠️ 不能用 `len(got) < page_size` 判终止:实测 `exam +list-exams --page-size 100`
|
|
177
|
+
服务端每页只回 97 条(内部有过滤),按"不满页"判会停在第 2 页——990 场考试只拿到 197。
|
|
178
|
+
终止条件只认三种:空页 / 本页无新增(服务端忽略 --page)/ 已达 count。
|
|
179
|
+
"""
|
|
180
|
+
rows, total, pages, truncated = [], None, 0, False
|
|
181
|
+
seen = set()
|
|
182
|
+
for p in range(1, max_pages + 1):
|
|
183
|
+
call = list(argv) + ["--page", str(p), "--page-size", str(page_size),
|
|
184
|
+
"--format", "json"]
|
|
185
|
+
ok, obj = cli.read(call, timeout=120)
|
|
186
|
+
if not ok or not obj:
|
|
187
|
+
if p == 1:
|
|
188
|
+
return rows, total, pages, truncated, "read failed: %s" % short(str(argv), 80)
|
|
189
|
+
break
|
|
190
|
+
if total is None:
|
|
191
|
+
total = _count(obj)
|
|
192
|
+
got = rows_of(obj.get("data") if isinstance(obj, dict) else obj)
|
|
193
|
+
if not got:
|
|
194
|
+
break
|
|
195
|
+
fresh = []
|
|
196
|
+
for i, r in enumerate(got):
|
|
197
|
+
key = r.get("uuid") or r.get("id") or "p%d_%d" % (p, i)
|
|
198
|
+
key = str(key)
|
|
199
|
+
if key in seen:
|
|
200
|
+
continue
|
|
201
|
+
seen.add(key)
|
|
202
|
+
fresh.append(r)
|
|
203
|
+
if not fresh:
|
|
204
|
+
break
|
|
205
|
+
rows.extend(fresh)
|
|
206
|
+
pages += 1
|
|
207
|
+
if total is not None and len(rows) >= total:
|
|
208
|
+
break
|
|
209
|
+
else:
|
|
210
|
+
truncated = True
|
|
211
|
+
return rows, total, pages, truncated, None
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def probe_class(cli):
|
|
215
|
+
"""培训班要查 status=1(已发布)与 status=0(草稿)两遍。
|
|
216
|
+
|
|
217
|
+
只查 status=1 会把刚建好、学习内容还没挂的草稿班判成"不存在"——
|
|
218
|
+
2026-10-22 的「加盟商「开店认证」体系」就是这么被误判缺失的。
|
|
219
|
+
"""
|
|
220
|
+
all_rows, total, pages, trunc, err = [], 0, 0, False, None
|
|
221
|
+
for st in ("1", "0"):
|
|
222
|
+
rows, cnt, pg, tr, e = probe_paged(
|
|
223
|
+
cli, "class", ["training-class", "+list", "--status", st])
|
|
224
|
+
if e and err is None:
|
|
225
|
+
err = e
|
|
226
|
+
all_rows.extend(rows)
|
|
227
|
+
total += (cnt if cnt is not None else len(rows))
|
|
228
|
+
pages += pg
|
|
229
|
+
trunc = trunc or tr
|
|
230
|
+
return all_rows, total, pages, trunc, err
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def probe_flat(cli, argv):
|
|
234
|
+
ok, obj = cli.read(argv, timeout=120)
|
|
235
|
+
if not ok or not obj:
|
|
236
|
+
return [], None, "read failed"
|
|
237
|
+
rows = rows_of(obj.get("data") if isinstance(obj, dict) else obj)
|
|
238
|
+
return rows, _count(obj), None
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def run_probe(cli, demo_root, bp_path):
|
|
242
|
+
started = time.time()
|
|
243
|
+
bp = {}
|
|
244
|
+
if bp_path and os.path.isfile(bp_path):
|
|
245
|
+
with open(bp_path, encoding="utf-8") as fh:
|
|
246
|
+
bp = json.load(fh)
|
|
247
|
+
|
|
248
|
+
jobs = blueprint_jobs(bp) if bp else {}
|
|
249
|
+
snapshot = {"probed_at": datetime.now().astimezone().isoformat(timespec="seconds"),
|
|
250
|
+
"demo_root": demo_root, "blueprint": bp_path,
|
|
251
|
+
"counts": {}, "probed": {}, "compare": {}, "dups": [],
|
|
252
|
+
"missing": {}, "unverified": {}, "errors": [], "truncated": []}
|
|
253
|
+
|
|
254
|
+
for kind, (label, argv, paged) in PROBES.items():
|
|
255
|
+
if paged and kind == "map":
|
|
256
|
+
now = datetime.now()
|
|
257
|
+
argv = list(argv) + [
|
|
258
|
+
"--start-time", str(int((now - timedelta(days=300)).timestamp() * 1000)),
|
|
259
|
+
"--end-time", str(int((now + timedelta(days=1)).timestamp() * 1000)),
|
|
260
|
+
]
|
|
261
|
+
if kind == "class":
|
|
262
|
+
rows, total, pages, trunc, err = probe_class(cli)
|
|
263
|
+
elif paged:
|
|
264
|
+
rows, total, pages, trunc, err = probe_paged(cli, kind, argv)
|
|
265
|
+
else:
|
|
266
|
+
rows, total, err = probe_flat(cli, argv)
|
|
267
|
+
pages = 1
|
|
268
|
+
# 分类列表不分页:count 大于实际取到的行数 = 只拿到第一页
|
|
269
|
+
# (考试/培训班分类的 count 含子级统计,不可比,见坑 #89)
|
|
270
|
+
trunc = (bool(total and len(rows) < total)
|
|
271
|
+
and kind not in ("cat_exam", "cat_class"))
|
|
272
|
+
|
|
273
|
+
if err:
|
|
274
|
+
snapshot["errors"].append({"kind": kind, "label": label, "detail": err})
|
|
275
|
+
if trunc:
|
|
276
|
+
snapshot["truncated"].append(kind)
|
|
277
|
+
|
|
278
|
+
snapshot["counts"][kind] = total if total is not None else len(rows)
|
|
279
|
+
snapshot["probed"][kind] = {"label": label, "rows": len(rows), "count": total}
|
|
280
|
+
print(" [%s] %s 共 %s 条(实际取 %d)" % (label, kind,
|
|
281
|
+
snapshot["counts"][kind], len(rows)))
|
|
282
|
+
|
|
283
|
+
names = jobs.get(kind) or []
|
|
284
|
+
if names:
|
|
285
|
+
compare, dups = match_rows(names, rows)
|
|
286
|
+
snapshot["compare"][kind] = compare
|
|
287
|
+
snapshot["dups"].extend([dict(d, kind=kind) for d in dups])
|
|
288
|
+
miss = [c["name"] for c in compare if not c["exists"]]
|
|
289
|
+
if miss:
|
|
290
|
+
if trunc:
|
|
291
|
+
# 截断时"没找到"≠"不存在":⛔ 不得据此新建,先精确复查
|
|
292
|
+
snapshot["unverified"][kind] = miss
|
|
293
|
+
else:
|
|
294
|
+
snapshot["missing"][kind] = miss
|
|
295
|
+
|
|
296
|
+
snapshot["elapsed_s"] = round(time.time() - started, 1)
|
|
297
|
+
snapshot["ok"] = not snapshot["errors"]
|
|
298
|
+
return snapshot
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def summary_line(snap):
|
|
302
|
+
parts = []
|
|
303
|
+
for kind in PROBES:
|
|
304
|
+
total = snap["counts"].get(kind)
|
|
305
|
+
cmp_ = snap["compare"].get(kind) or []
|
|
306
|
+
if cmp_:
|
|
307
|
+
hit = sum(1 for c in cmp_ if c["exists"])
|
|
308
|
+
parts.append("%s=%s/%d" % (kind, total, hit))
|
|
309
|
+
else:
|
|
310
|
+
parts.append("%s=%s" % (kind, total))
|
|
311
|
+
ndup = len(snap["dups"])
|
|
312
|
+
nmiss = sum(len(v) for v in snap["missing"].values())
|
|
313
|
+
nunv = sum(len(v) for v in (snap.get("unverified") or {}).values())
|
|
314
|
+
nerr = len(snap["errors"])
|
|
315
|
+
return " ".join(parts) + " dup=%d missing=%d unverified=%d errors=%d" % (
|
|
316
|
+
ndup, nmiss, nunv, nerr)
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
def write_log(demo_root, line):
|
|
320
|
+
try:
|
|
321
|
+
import guard
|
|
322
|
+
guard.append_log(demo_root, "stock-probe", line, src="script")
|
|
323
|
+
except Exception:
|
|
324
|
+
path = os.path.join(demo_root, "run.log")
|
|
325
|
+
with open(path, "a", encoding="utf-8") as fh:
|
|
326
|
+
fh.write("[%s] [stock-probe] %s\n" % (
|
|
327
|
+
datetime.now().strftime("%Y-%m-%d %H:%M:%S"), line))
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
# ------------------------------------------------------------------ 自测
|
|
331
|
+
|
|
332
|
+
def self_test():
|
|
333
|
+
n = 0
|
|
334
|
+
bad = []
|
|
335
|
+
|
|
336
|
+
def ck(cond, label):
|
|
337
|
+
nonlocal n
|
|
338
|
+
n += 1
|
|
339
|
+
if not cond:
|
|
340
|
+
bad.append(label)
|
|
341
|
+
|
|
342
|
+
# 归一
|
|
343
|
+
ck(normalize("新店开业「21 天」训练营") == normalize('新店开业"21天"训练营'), "全角引号+空格归一")
|
|
344
|
+
ck(normalize("(DEMO)品牌文化") == normalize("(demo)品牌文化"), "全角括号+大小写归一")
|
|
345
|
+
ck(normalize(None) == "", "None 归一为空")
|
|
346
|
+
|
|
347
|
+
# 名称提取兼容 title/name
|
|
348
|
+
ck(_name_of({"title": "A"}) == "A", "取 title")
|
|
349
|
+
ck(_name_of({"name": "B"}) == "B", "取 name")
|
|
350
|
+
|
|
351
|
+
# 匹配:已存在 / 缺失 / 同名重复
|
|
352
|
+
rows = [{"uuid": "u1", "title": "员工手册精读", "status": 1},
|
|
353
|
+
{"uuid": "u2", "name": "新店员 21 天通关地图", "status": 1},
|
|
354
|
+
{"uuid": "u3", "name": "新店员21天通关地图", "status": 0}]
|
|
355
|
+
cmp_, dups = match_rows(["员工手册精读", "高峰排班法", "新店员 21 天通关地图"], rows)
|
|
356
|
+
ck(cmp_[0]["exists"] is True, "命中已存在")
|
|
357
|
+
ck(cmp_[1]["exists"] is False, "识别缺失")
|
|
358
|
+
ck(cmp_[2]["exists"] is True and len(cmp_[2]["hits"]) == 2, "同名两条都返回")
|
|
359
|
+
ck(len(dups) == 1 and dups[0]["name"] == "新店员 21 天通关地图", "重复进 dups")
|
|
360
|
+
|
|
361
|
+
# count 提取
|
|
362
|
+
ck(_count({"data": {"count": 985}}) == 985, "count int")
|
|
363
|
+
ck(_count({"data": {"count": "93"}}) == 93, "count str")
|
|
364
|
+
ck(_count({"data": {"list": []}}) is None, "无 count → None")
|
|
365
|
+
|
|
366
|
+
# 蓝图取名字
|
|
367
|
+
bp = {"portals": [{"name": "P"}], "courses": [{"title": "C1"}, {"title": "C2"}],
|
|
368
|
+
"maps": [{"name": "M"}], "exams": [{"name": "E"}], "projects": [{"name": "J"}],
|
|
369
|
+
"taxonomies": {"course": [{"l1": "L1", "l2": ["L2a", "L2b"]}],
|
|
370
|
+
"question_pool": [{"name": "Q"}],
|
|
371
|
+
"learning_map": [{"name": "LM"}],
|
|
372
|
+
"training_class": ["TC"], "exam": ["EC"]}}
|
|
373
|
+
jobs = blueprint_jobs(bp)
|
|
374
|
+
ck(jobs["portal"] == ["P"], "portals 名字")
|
|
375
|
+
ck(jobs["course"] == ["C1", "C2"], "courses 名字")
|
|
376
|
+
ck(jobs["cat_course"] == ["L1", "L2a", "L2b"], "课程分类 L1+L2")
|
|
377
|
+
ck(jobs["pool"] == ["Q"] and jobs["cat_exam"] == ["EC"], "题库/考试分类")
|
|
378
|
+
ck(jobs["cat_class"] == ["TC"], "培训班分类(纯字符串列表)")
|
|
379
|
+
|
|
380
|
+
# 摘要行形态
|
|
381
|
+
snap = {"counts": {"portal": 20}, "compare": {"portal": [{"exists": True}]},
|
|
382
|
+
"dups": [], "missing": {"course": ["X"]}, "errors": []}
|
|
383
|
+
s = summary_line(snap)
|
|
384
|
+
ck("portal=20/1" in s and "missing=1" in s and "errors=0" in s, "摘要行")
|
|
385
|
+
|
|
386
|
+
for label in bad:
|
|
387
|
+
print(" ✗ %s" % label)
|
|
388
|
+
print("stock_probe self-test: %d 项,%d 失败" % (n, len(bad)))
|
|
389
|
+
return 0 if not bad else 1
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
# ------------------------------------------------------------------ main
|
|
393
|
+
|
|
394
|
+
def main(argv=None):
|
|
395
|
+
ap = argparse.ArgumentParser(description="存量探测(只读)")
|
|
396
|
+
ap.add_argument("--demo-root", required=False)
|
|
397
|
+
ap.add_argument("--blueprint")
|
|
398
|
+
ap.add_argument("--out")
|
|
399
|
+
ap.add_argument("--cli", default=os.environ.get("SOKE_CLI")
|
|
400
|
+
or os.path.expanduser("~/.npm-global/bin/soke-cli"))
|
|
401
|
+
ap.add_argument("--json", action="store_true")
|
|
402
|
+
ap.add_argument("--self-test", action="store_true")
|
|
403
|
+
args = ap.parse_args(argv)
|
|
404
|
+
|
|
405
|
+
if args.self_test:
|
|
406
|
+
return self_test()
|
|
407
|
+
|
|
408
|
+
if not args.demo_root:
|
|
409
|
+
ap.error("--demo-root 必填(除 --self-test)")
|
|
410
|
+
demo_root = os.path.abspath(args.demo_root)
|
|
411
|
+
bp_path = args.blueprint or os.path.join(demo_root, "DEMO-BLUEPRINT.json")
|
|
412
|
+
if not os.path.isfile(bp_path):
|
|
413
|
+
bp_path = None
|
|
414
|
+
|
|
415
|
+
cli = Cli(args.cli, log_path=None, dry=False, echo=False)
|
|
416
|
+
if not args.json:
|
|
417
|
+
print("存量探测(只读)→ %s" % (bp_path or "(无蓝图,仅统计)"))
|
|
418
|
+
snap = run_probe(cli, demo_root, bp_path)
|
|
419
|
+
|
|
420
|
+
out = args.out or os.path.join(demo_root, SNAPSHOT)
|
|
421
|
+
with open(out, "w", encoding="utf-8") as fh:
|
|
422
|
+
json.dump(snap, fh, ensure_ascii=False, indent=2)
|
|
423
|
+
line = summary_line(snap)
|
|
424
|
+
write_log(demo_root, line)
|
|
425
|
+
|
|
426
|
+
if args.json:
|
|
427
|
+
print(json.dumps(snap, ensure_ascii=False, indent=2))
|
|
428
|
+
else:
|
|
429
|
+
print("\n摘要:%s" % line)
|
|
430
|
+
if snap["missing"]:
|
|
431
|
+
print("缺失(可新建):")
|
|
432
|
+
for k, names in snap["missing"].items():
|
|
433
|
+
print(" %s: %s" % (k, "、".join(names)))
|
|
434
|
+
if snap.get("unverified"):
|
|
435
|
+
print("未核实(列表被截断,⛔ 不得据此新建,先精确复查):")
|
|
436
|
+
for k, names in snap["unverified"].items():
|
|
437
|
+
print(" %s: %s" % (k, "、".join(names)))
|
|
438
|
+
if snap["dups"]:
|
|
439
|
+
print("同名重复(需 G-10):")
|
|
440
|
+
for d in snap["dups"]:
|
|
441
|
+
print(" %s: %d 条" % (d["name"], len(d["hits"])))
|
|
442
|
+
if snap["errors"]:
|
|
443
|
+
print("探测失败(⛔ 不得据此判空租户):")
|
|
444
|
+
for e in snap["errors"]:
|
|
445
|
+
print(" %s: %s" % (e["kind"], e["detail"]))
|
|
446
|
+
print("→ %s" % out)
|
|
447
|
+
|
|
448
|
+
return 0 if snap["ok"] else 2
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
if __name__ == "__main__":
|
|
452
|
+
sys.exit(main())
|