@topmindspace/tms-skills 0.1.0 → 0.1.2

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.
Files changed (102) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/README.md +9 -3
  3. package/bin/tms-skills.js +200 -160
  4. package/package.json +12 -9
  5. package/top-ppt-html/README.md +162 -254
  6. package/top-ppt-html/SKILL.md +126 -111
  7. package/top-ppt-html/assets/examples/2026-09-09-architecture-graphite-dark.html +3926 -3926
  8. package/top-ppt-html/assets/examples/2026-09-09-architecture-graphite-dark.model.json +167 -167
  9. package/top-ppt-html/assets/examples/2026-09-09-presentation-business-blue.html +4325 -4325
  10. package/top-ppt-html/assets/examples/2026-09-09-presentation-business-blue.model.json +320 -320
  11. package/top-ppt-html/assets/examples/2026-09-09-research-mckinsey.html +5527 -5527
  12. package/top-ppt-html/assets/examples/2026-09-09-research-mckinsey.model.json +913 -913
  13. package/top-ppt-html/assets/pptx-export.js +1944 -1944
  14. package/top-ppt-html/assets/style-gallery.html +589 -589
  15. package/top-ppt-html/assets/templates/architecture.html +3728 -3728
  16. package/top-ppt-html/assets/templates/engine.css +840 -840
  17. package/top-ppt-html/assets/templates/presentation.html +3738 -3738
  18. package/top-ppt-html/assets/templates/research.html +4017 -4017
  19. package/top-ppt-html/assets/templates/ui.js +520 -520
  20. package/top-ppt-html/assets/theme-overview-architecture.png +0 -0
  21. package/top-ppt-html/assets/theme-overview-research.png +0 -0
  22. package/top-ppt-html/assets/theme-overview.png +0 -0
  23. package/top-ppt-html/evals/prompts.csv +15 -15
  24. package/top-ppt-html/evals/rubric.schema.json +25 -25
  25. package/top-ppt-html/evals/run_evals.py +220 -220
  26. package/top-ppt-html/evals/trace.example.json +16 -16
  27. package/top-ppt-html/package-lock.json +186 -0
  28. package/top-ppt-html/package.json +11 -11
  29. package/top-ppt-html/references/charts-basic.md +624 -624
  30. package/top-ppt-html/references/charts-discipline.md +110 -108
  31. package/top-ppt-html/references/charts-extended.md +482 -482
  32. package/top-ppt-html/references/charts.md +37 -28
  33. package/top-ppt-html/references/components-atoms.md +624 -624
  34. package/top-ppt-html/references/components.md +30 -30
  35. package/top-ppt-html/references/content-rules.md +510 -490
  36. package/top-ppt-html/references/default-surface.md +61 -0
  37. package/top-ppt-html/references/design-system.md +478 -478
  38. package/top-ppt-html/references/failure-modes.md +227 -214
  39. package/top-ppt-html/references/high-fidelity.md +127 -127
  40. package/top-ppt-html/references/icons.md +176 -397
  41. package/top-ppt-html/references/infographics-stats.md +308 -308
  42. package/top-ppt-html/references/infographics-structure.md +226 -226
  43. package/top-ppt-html/references/infographics.md +43 -43
  44. package/top-ppt-html/references/layout-grammar.md +325 -315
  45. package/top-ppt-html/references/layouts-architecture.md +108 -108
  46. package/top-ppt-html/references/layouts-combo.md +600 -600
  47. package/top-ppt-html/references/layouts-research.md +160 -160
  48. package/top-ppt-html/references/modes.md +259 -254
  49. package/top-ppt-html/references/outline-design.md +275 -275
  50. package/top-ppt-html/references/playbook.md +284 -266
  51. package/top-ppt-html/references/pptx-export.md +227 -209
  52. package/top-ppt-html/references/presentation-craft.md +69 -0
  53. package/top-ppt-html/references/styles.md +370 -370
  54. package/top-ppt-html/references/tech-design.md +138 -138
  55. package/top-ppt-html/scripts/audit_css.py +109 -109
  56. package/top-ppt-html/scripts/audit_docs.py +176 -176
  57. package/top-ppt-html/scripts/audit_skill.py +231 -220
  58. package/top-ppt-html/scripts/audit_styles.py +351 -351
  59. package/top-ppt-html/scripts/build_examples.py +55 -2276
  60. package/top-ppt-html/scripts/build_pptx.js +2386 -2380
  61. package/top-ppt-html/scripts/capture_theme_overview.js +79 -78
  62. package/top-ppt-html/scripts/checks_html.py +166 -127
  63. package/top-ppt-html/scripts/cross_verify.py +298 -294
  64. package/top-ppt-html/scripts/env_probe.py +158 -158
  65. package/top-ppt-html/scripts/extract_model.py +210 -210
  66. package/top-ppt-html/scripts/extract_snippet.py +374 -374
  67. package/top-ppt-html/scripts/gen_channel_a.js +214 -214
  68. package/top-ppt-html/scripts/layout-constants.json +111 -18
  69. package/top-ppt-html/scripts/lib_layout_regions.js +410 -412
  70. package/top-ppt-html/scripts/measure_height.py +178 -178
  71. package/top-ppt-html/scripts/negative_tests.py +433 -307
  72. package/top-ppt-html/scripts/package_skill.py +294 -291
  73. package/top-ppt-html/scripts/prepare_images.py +341 -341
  74. package/top-ppt-html/scripts/probe_image_export.py +187 -188
  75. package/top-ppt-html/scripts/quality_gate.py +309 -301
  76. package/top-ppt-html/scripts/recommend_layout.py +384 -0
  77. package/top-ppt-html/scripts/regression.py +308 -308
  78. package/top-ppt-html/scripts/render_compare.py +275 -275
  79. package/top-ppt-html/scripts/render_from_model.py +698 -698
  80. package/top-ppt-html/scripts/scaffold_report.py +1054 -1054
  81. package/top-ppt-html/scripts/section-file-map.json +104 -104
  82. package/top-ppt-html/scripts/smoke_pptx.sh +30 -0
  83. package/top-ppt-html/scripts/sync_runtime.py +659 -662
  84. package/top-ppt-html/scripts/validate_pptx.py +1579 -1510
  85. package/top-ppt-html/scripts/validate_report.py +1755 -1456
  86. package/top-ppt-html/assets/examples/2026-09-09-architecture-spectrum.html +0 -3926
  87. package/top-ppt-html/assets/examples/2026-09-09-architecture-spectrum.model.json +0 -168
  88. package/top-ppt-html/assets/examples/2026-09-09-presentation-apple-mono.html +0 -4325
  89. package/top-ppt-html/assets/examples/2026-09-09-presentation-apple-mono.model.json +0 -321
  90. package/top-ppt-html/assets/examples/2026-09-09-presentation-brand-red.html +0 -4325
  91. package/top-ppt-html/assets/examples/2026-09-09-presentation-brand-red.model.json +0 -321
  92. package/top-ppt-html/assets/examples/2026-09-09-research-deep-teal.html +0 -5527
  93. package/top-ppt-html/assets/examples/2026-09-09-research-deep-teal.model.json +0 -914
  94. package/top-ppt-html/assets/examples/2026-09-09-research-indigo-violet.html +0 -5527
  95. package/top-ppt-html/assets/examples/2026-09-09-research-indigo-violet.model.json +0 -914
  96. package/top-ppt-html/assets/examples/2026-09-09-research-warm-sand.html +0 -5527
  97. package/top-ppt-html/assets/examples/2026-09-09-research-warm-sand.model.json +0 -914
  98. package/top-ppt-html/assets/theme-overview-presentation.png +0 -0
  99. package/top-ppt-html/references/design-system-engine.md +0 -235
  100. package/top-ppt-html/references/industry-benchmark.md +0 -105
  101. package/top-ppt-html/references/reform-plan.md +0 -252
  102. package/top-ppt-html/scripts/layout_slots.json +0 -830
@@ -1,308 +1,308 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """TopPPT HTML · 全链路回归(维护工具,与机器环境无关)
4
-
5
- 链路:
6
- ① validate_report.py --strict 每份示例 HTML(三模式预算 + 模型一致性 + 版式断言)
7
- ② extract_model.py → build_pptx.js → validate_pptx.py --strict --model B 通道(交付通道)
8
- ③ gen_channel_a.js(页面预览同引擎产物)→ validate_pptx.py --strict --model --allow-shape-charts
9
- ④ probe_image_export.py(素材图片探针:示例矩阵零图片,真实素材路径/版式/门禁靠它覆盖)
10
- ⑤ 双区组合页探针(split 左区 = 图表):scaffold → extract → B 通道 + A 通道,两通道都过 strict
11
- ⑥ cross_verify.py(python-pptx 第三方裁判,可选:未安装则 SKIP)——覆盖示例矩阵与 ⑤ 探针
12
- ⑦ negative_tests.py(故障注入:往合格产物里埋已知缺陷,断言门禁必须报错)
13
- ⑦-b 任务路由全量遍历(extract_snippet TASK_ROUTES 每条路由可实际抽取,防修复链路静默断裂)
14
- ⑧ 深色主题探针(research / presentation × dark:示例矩阵只有 architecture 是 dark,
15
- stylesDark / styleDataColorsDark 路径靠它覆盖)
16
- ⑨ measure_height.py(浏览器真值:页高与容器裁切,可选:无 playwright 则 SKIP)
17
-
18
- 用法:
19
- python scripts/regression.py [--only <示例名关键字>]
20
-
21
- 环境解析(全部自动探测,不绑定任何机器的固定路径):
22
- Node 可执行文件:TOP_PPT_NODE_EXE > PATH 上的 node > 常见托管目录最新版
23
- pptxgenjs 所在 node_modules:TOP_PPT_NODE_PATH > 仓库内 node_modules > 逐级父目录 > 常见托管目录
24
- python-pptx:未安装时跳过交叉裁判(打印 SKIP,不计失败)
25
-
26
- 模板/常量/schema/运行时/示例任何改动后必跑。
27
- """
28
- from __future__ import annotations
29
-
30
- import argparse
31
- import json
32
- import subprocess
33
- import sys
34
- from pathlib import Path
35
-
36
- try:
37
- sys.stdout.reconfigure(encoding='utf-8', errors='replace')
38
- sys.stderr.reconfigure(encoding='utf-8', errors='replace')
39
- except Exception:
40
- pass
41
-
42
- sys.path.insert(0, str(Path(__file__).resolve().parent))
43
- from env_probe import (NODE_HINT, NODE_MODULES_HINT, find_node, # noqa: E402
44
- find_node_modules, has_python_pptx, node_env)
45
-
46
- ROOT = Path(__file__).resolve().parent.parent
47
- EX = ROOT / 'assets' / 'examples'
48
- B_OUT = ROOT / 'dist' / 'regression'
49
- A_OUT = ROOT / 'dist' / 'regression-a'
50
- PY = sys.executable
51
-
52
-
53
- # ── 执行 ─────────────────────────────────────────────────────────────────────
54
-
55
- def run(cmd: list[str], env: dict[str, str] | None = None) -> subprocess.CompletedProcess:
56
- return subprocess.run(cmd, capture_output=True, text=True, encoding='utf-8', env=env)
57
-
58
-
59
- def main() -> int:
60
- ap = argparse.ArgumentParser(description='TopPPT HTML 全链路回归')
61
- ap.add_argument('--only', help='只跑名字含该关键字的示例')
62
- args = ap.parse_args()
63
-
64
- node = find_node()
65
- node_path = find_node_modules()
66
- if not node:
67
- print('错误: ' + NODE_HINT)
68
- return 2
69
- if not node_path:
70
- print('错误: ' + NODE_MODULES_HINT)
71
- return 2
72
- env = node_env(node_path)
73
- print(f'Node: {node}')
74
- print(f'NODE_PATH: {node_path}')
75
- print(f'python-pptx 第三方裁判: {"可用" if has_python_pptx() else "未安装(交叉裁判将跳过)"}')
76
-
77
- B_OUT.mkdir(parents=True, exist_ok=True)
78
- fails: list[str] = []
79
- skipped: list[str] = []
80
-
81
- examples = sorted(EX.glob('*.html'))
82
- if args.only:
83
- examples = [h for h in examples if args.only in h.stem]
84
- if not examples:
85
- print('错误: assets/examples/ 下没有可回归的示例。')
86
- return 2
87
-
88
- for html in examples:
89
- stem = html.stem
90
- model = html.with_suffix('.model.json')
91
- print(f'=== {stem}')
92
- r0 = run([PY, str(ROOT / 'scripts' / 'validate_report.py'), str(html), '--strict'])
93
- print(' [validate_report --strict]', 'OK' if r0.returncode == 0 else 'FAIL')
94
- if r0.returncode != 0:
95
- fails.append(stem + ':report')
96
- print((r0.stdout or '')[-800:])
97
- continue
98
- r1 = run([PY, str(ROOT / 'scripts' / 'extract_model.py'), str(html)])
99
- if r1.returncode != 0:
100
- fails.append(stem + ':extract')
101
- print((r1.stdout or '')[-500:])
102
- continue
103
- bp = B_OUT / (stem + '.pptx')
104
- r2 = run([node, str(ROOT / 'scripts' / 'build_pptx.js'), str(bp), '--model=' + str(model)], env=env)
105
- if r2.returncode != 0 or not bp.exists():
106
- fails.append(stem + ':build')
107
- print((r2.stderr or r2.stdout or '')[-800:])
108
- continue
109
- r3 = run([PY, str(ROOT / 'scripts' / 'validate_pptx.py'), str(bp), '--strict', '--model=' + str(model)])
110
- print(' [B 通道 strict]', 'OK (0/0)' if r3.returncode == 0 else f'FAIL exit={r3.returncode}')
111
- if r3.returncode != 0:
112
- fails.append(stem + ':pptx-b')
113
- for line in (r3.stdout or '').splitlines()[-14:]:
114
- print(' ', line)
115
-
116
- print('\n=== A 通道(页面预览序列化引擎产物 · gen_channel_a 组装)')
117
- rA = run([node, str(ROOT / 'scripts' / 'gen_channel_a.js')], env=env)
118
- if rA.returncode != 0:
119
- fails.append('A:generate')
120
- print((rA.stderr or rA.stdout or '')[-800:])
121
- else:
122
- ppx_ok = has_python_pptx()
123
- for ap in sorted(A_OUT.glob('*.pptx')):
124
- model = EX / (ap.stem + '.model.json')
125
- if not model.exists():
126
- # 非示例产物(如 ⑤ 探针的 probe-split.pptx)由探针段单独校验,跳过避免误判
127
- continue
128
- # A 通道(预览引擎)图表为形状近似渲染,豁免 MODEL_CHART_COUNT(交付通道 B 不豁免)
129
- r = run([PY, str(ROOT / 'scripts' / 'validate_pptx.py'), str(ap), '--strict',
130
- '--model=' + str(model), '--allow-shape-charts'])
131
- ok = r.returncode == 0
132
- ppx = 'SKIP'
133
- if ppx_ok:
134
- p = run([PY, '-c',
135
- 'import sys;from pptx import Presentation;'
136
- 'print(len(list(Presentation(sys.argv[1]).slides)))', str(ap)])
137
- ppx = 'OK' if p.returncode == 0 else 'FAIL'
138
- print(f' {ap.name}: strict={"OK" if ok else "FAIL"} python-pptx={ppx}')
139
- if not ok:
140
- fails.append(ap.stem + ':pptx-a')
141
- for line in (r.stdout or '').splitlines()[-10:]:
142
- print(' ', line)
143
- if ppx == 'FAIL':
144
- fails.append(ap.stem + ':ppx-a')
145
- if ppx == 'SKIP':
146
- skipped.append(ap.stem + ':ppx-a')
147
-
148
- # ④ 素材图片导出探针:示例矩阵刻意零图片,真实素材路径/版式/门禁靠探针覆盖
149
- r5 = run([PY, str(ROOT / 'scripts' / 'probe_image_export.py')], env=env)
150
- print(' [probe_image_export]', 'OK' if r5.returncode == 0 else 'FAIL')
151
- if r5.returncode != 0:
152
- fails.append('probe-image')
153
- for line in (r5.stdout or '').splitlines()[-8:]:
154
- print(' ', line)
155
-
156
- # ⑤ 双区组合页探针(split 左区 = 图表):示例矩阵只覆盖"左文右图"缺省路径,
157
- # 左区图表/表格/图片三个变体靠脚手架生成一次走完整交付链路(v8 新增能力);
158
- # B 通道 + A 通道(同一模型)都跑,产物同名落两目录 → ⑥ 交叉裁判可逐页比对。
159
- print('\n=== 双区组合页探针(split 左区 = 图表)')
160
- probe_plan = B_OUT / 'probe-split.plan.json'
161
- probe_html = B_OUT / 'probe-split.html'
162
- probe_model = B_OUT / 'probe-split.model.json'
163
- probe_pptx = B_OUT / 'probe-split.pptx'
164
- probe_plan.write_text(json.dumps(
165
- [{'type': 'points', 'eyebrow': '01 · 前置', 'title': '前置要点页(探针占位)'},
166
- {'type': 'split', 'left_type': 'chart', 'eyebrow': '02 · 组合版式',
167
- 'title': '双区组合页探针:左图右文(左区图表路径)'}], ensure_ascii=False), encoding='utf-8')
168
- ok6, why6 = False, ''
169
- r6 = run([PY, str(ROOT / 'scripts' / 'scaffold_report.py'), '--mode', 'presentation',
170
- '--plan', str(probe_plan), '--out', str(probe_html)])
171
- if r6.returncode != 0:
172
- why6 = 'scaffold'
173
- else:
174
- r7 = run([PY, str(ROOT / 'scripts' / 'extract_model.py'), str(probe_html), str(probe_model)])
175
- if r7.returncode != 0:
176
- why6 = 'extract'
177
- else:
178
- r8 = run([node, str(ROOT / 'scripts' / 'build_pptx.js'), str(probe_pptx),
179
- '--model=' + str(probe_model)], env=env)
180
- if r8.returncode != 0 or not probe_pptx.exists():
181
- why6 = 'build'
182
- else:
183
- r9 = run([PY, str(ROOT / 'scripts' / 'validate_pptx.py'), str(probe_pptx),
184
- '--strict', '--model=' + str(probe_model)])
185
- ok6 = r9.returncode == 0
186
- if not ok6:
187
- why6 = 'validate_pptx_b'
188
- for line in (r9.stdout or '').splitlines()[-10:]:
189
- print(' ', line)
190
- else:
191
- # A 通道同模型(预览序列化引擎):产物同名落 dist/regression-a/
192
- probe_pptx_a = A_OUT / 'probe-split.pptx'
193
- if probe_pptx_a.exists():
194
- probe_pptx_a.unlink()
195
- r10 = run([node, str(ROOT / 'scripts' / 'gen_channel_a.js'),
196
- '--model=' + str(probe_model), '--out=' + str(A_OUT)], env=env)
197
- if r10.returncode != 0 or not probe_pptx_a.exists():
198
- ok6, why6 = False, 'channel_a'
199
- print((r10.stderr or r10.stdout or '')[-400:])
200
- else:
201
- # 预览引擎图表为形状近似 → 豁免 MODEL_CHART_COUNT(同示例矩阵口径)
202
- r11 = run([PY, str(ROOT / 'scripts' / 'validate_pptx.py'), str(probe_pptx_a),
203
- '--strict', '--model=' + str(probe_model),
204
- '--allow-shape-charts'])
205
- if r11.returncode != 0:
206
- ok6, why6 = False, 'validate_pptx_a'
207
- for line in (r11.stdout or '').splitlines()[-10:]:
208
- print(' ', line)
209
- print(' [split 左区图表 B/A 双通道]', 'OK' if ok6 else f'FAIL({why6})')
210
- if not ok6:
211
- fails.append('probe-split')
212
-
213
- # ⑥b 深色主题导出探针:示例矩阵只有 architecture/graphite-dark 是 dark,
214
- # research / presentation 的 stylesDark + styleDataColorsDark 路径此前零覆盖。
215
- print('\n=== 深色主题导出探针(research / presentation × dark)')
216
- dark_fail = []
217
- for stem in ('2026-09-09-research-mckinsey', '2026-09-09-presentation-business-blue'):
218
- src_model = EX / f'{stem}.model.json'
219
- if not src_model.exists():
220
- continue
221
- dm = B_OUT / f'{stem}-dark.model.json'
222
- dp = B_OUT / f'{stem}-dark.pptx'
223
- data = json.loads(src_model.read_text(encoding='utf-8'))
224
- data['theme'] = 'dark'
225
- dm.write_text(json.dumps(data, ensure_ascii=False), encoding='utf-8')
226
- rb = run([node, str(ROOT / 'scripts' / 'build_pptx.js'), str(dp),
227
- '--model=' + str(dm)], env=env)
228
- if rb.returncode != 0 or not dp.exists():
229
- dark_fail.append(stem + ':build')
230
- print((rb.stderr or rb.stdout or '')[-300:])
231
- continue
232
- rv = run([PY, str(ROOT / 'scripts' / 'validate_pptx.py'), str(dp),
233
- '--strict', '--model=' + str(dm)])
234
- print(f' {stem} dark:', 'OK' if rv.returncode == 0 else 'FAIL')
235
- if rv.returncode != 0:
236
- dark_fail.append(stem + ':validate')
237
- for line in (rv.stdout or '').splitlines()[-8:]:
238
- print(' ', line)
239
- if dark_fail:
240
- fails.append('dark-theme')
241
-
242
- # ⑥ 双通道交叉裁判(python-pptx):放在探针之后,A/B 产物齐全时才逐页比对
243
- r4 = run([PY, str(ROOT / 'scripts' / 'cross_verify.py')])
244
- if r4.returncode == 2:
245
- print(' [cross_verify] SKIP(python-pptx 未安装,可选第三方裁判)')
246
- skipped.append('cross-verify')
247
- else:
248
- print(' [cross_verify]', 'OK' if r4.returncode == 0 else 'FAIL')
249
- if r4.returncode != 0:
250
- fails.append('cross-verify')
251
- print((r4.stdout or '')[-600:])
252
-
253
- # ⑦ 门禁反向验证(故障注入):正向全绿只能证明“没误报”,这里证明“真能报”
254
- r12 = run([PY, str(ROOT / 'scripts' / 'negative_tests.py')])
255
- print(' [negative_tests]', 'OK' if r12.returncode == 0 else 'FAIL')
256
- if r12.returncode != 0:
257
- fails.append('negative-tests')
258
- print((r12.stdout or '')[-600:])
259
-
260
- # ⑦-b 任务路由全量遍历:--task 与 validate_report FIX_GUIDE 的修复链路不得静默断裂
261
- # (v8.3 前教训:中文节号不被解析,7/11 修复命令执行即报错且无任何审计覆盖;
262
- # 实现与 audit_docs ⑥ 共用 ES.verify_routes,防两处维护)
263
- try:
264
- import extract_snippet as ES # noqa: PLC0415
265
- route_bad = ES.verify_routes()
266
- print(' [task_routes]', 'OK' if not route_bad else f'FAIL {route_bad}')
267
- if route_bad:
268
- fails.append('task-routes')
269
- except ImportError:
270
- print(' [task_routes] FAIL(extract_snippet 不可导入)')
271
- fails.append('task-routes')
272
-
273
- # ⑧ 浏览器真值测量(可选):静态估算看不到「表格被半幅容器横向裁掉一列」这类真实布局缺陷。
274
- # 当前解释器可能未装 playwright(托管运行时常见);measure_height.py 会自动回落到
275
- # 本机已装 playwright 的解释器,因此这里只要能跑 measure_height 就不再跳过。
276
- mh_fail = []
277
- for html in examples:
278
- r13 = run([PY, str(ROOT / 'scripts' / 'measure_height.py'), str(html)])
279
- out = (r13.stdout or '') + (r13.stderr or '')
280
- if r13.returncode != 0:
281
- mh_fail.append(html.stem)
282
- print(out[-500:])
283
- elif '跳过:' in out and 'playwright' in out.lower():
284
- # 解释器与回落链都找不到 playwright → 整批跳过(可选依赖)
285
- print(' [measure_height] SKIP(playwright 未安装,可选真值裁判)')
286
- skipped.append('measure-height')
287
- mh_fail = []
288
- break
289
- if 'measure-height' not in skipped:
290
- print(' [measure_height 页高/容器裁切真值]', 'OK' if not mh_fail else f'FAIL {mh_fail}')
291
- if mh_fail:
292
- fails.append('measure-height')
293
-
294
- print('=' * 56)
295
- if skipped:
296
- print('跳过(可选依赖缺失):', sorted(set(skipped)))
297
- if fails:
298
- print('回归失败:', fails)
299
- return 1
300
- print('全链路回归通过:HTML strict + B 通道精导 strict 0/0 + A 通道(预览同引擎产物)strict 0/0'
301
- + ' + 双区组合页双通道探针 + 深色主题探针 + 门禁反向验证 + 任务路由全量遍历'
302
- + ('' if 'measure-height' in skipped else ' + 浏览器页高/裁切真值')
303
- + (' + python-pptx 双裁判 + 双通道交叉一致' if 'cross-verify' not in skipped else ''))
304
- return 0
305
-
306
-
307
- if __name__ == '__main__':
308
- sys.exit(main())
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """TopPPT HTML · 全链路回归(维护工具,与机器环境无关)
4
+
5
+ 链路:
6
+ ① validate_report.py --strict 每份示例 HTML(三模式预算 + 模型一致性 + 版式断言)
7
+ ② extract_model.py → build_pptx.js → validate_pptx.py --strict --model B 通道(交付通道)
8
+ ③ gen_channel_a.js(页面预览同引擎产物)→ validate_pptx.py --strict --model --allow-shape-charts
9
+ ④ probe_image_export.py(素材图片探针:示例矩阵零图片,真实素材路径/版式/门禁靠它覆盖)
10
+ ⑤ 双区组合页探针(split 左区 = 图表):scaffold → extract → B 通道 + A 通道,两通道都过 strict
11
+ ⑥ cross_verify.py(python-pptx 第三方裁判,可选:未安装则 SKIP)——覆盖示例矩阵与 ⑤ 探针
12
+ ⑦ negative_tests.py(故障注入:往合格产物里埋已知缺陷,断言门禁必须报错)
13
+ ⑦-b 任务路由全量遍历(extract_snippet TASK_ROUTES 每条路由可实际抽取,防修复链路静默断裂)
14
+ ⑧ 深色主题探针(research / presentation × dark:示例矩阵只有 architecture 是 dark,
15
+ stylesDark / styleDataColorsDark 路径靠它覆盖)
16
+ ⑨ measure_height.py(浏览器真值:页高与容器裁切,可选:无 playwright 则 SKIP)
17
+
18
+ 用法:
19
+ python scripts/regression.py [--only <示例名关键字>]
20
+
21
+ 环境解析(全部自动探测,不绑定任何机器的固定路径):
22
+ Node 可执行文件:TOP_PPT_NODE_EXE > PATH 上的 node > 常见托管目录最新版
23
+ pptxgenjs 所在 node_modules:TOP_PPT_NODE_PATH > 仓库内 node_modules > 逐级父目录 > 常见托管目录
24
+ python-pptx:未安装时跳过交叉裁判(打印 SKIP,不计失败)
25
+
26
+ 模板/常量/schema/运行时/示例任何改动后必跑。
27
+ """
28
+ from __future__ import annotations
29
+
30
+ import argparse
31
+ import json
32
+ import subprocess
33
+ import sys
34
+ from pathlib import Path
35
+
36
+ try:
37
+ sys.stdout.reconfigure(encoding='utf-8', errors='replace')
38
+ sys.stderr.reconfigure(encoding='utf-8', errors='replace')
39
+ except Exception:
40
+ pass
41
+
42
+ sys.path.insert(0, str(Path(__file__).resolve().parent))
43
+ from env_probe import (NODE_HINT, NODE_MODULES_HINT, find_node, # noqa: E402
44
+ find_node_modules, has_python_pptx, node_env)
45
+
46
+ ROOT = Path(__file__).resolve().parent.parent
47
+ EX = ROOT / 'assets' / 'examples'
48
+ B_OUT = ROOT / 'dist' / 'regression'
49
+ A_OUT = ROOT / 'dist' / 'regression-a'
50
+ PY = sys.executable
51
+
52
+
53
+ # ── 执行 ─────────────────────────────────────────────────────────────────────
54
+
55
+ def run(cmd: list[str], env: dict[str, str] | None = None) -> subprocess.CompletedProcess:
56
+ return subprocess.run(cmd, capture_output=True, text=True, encoding='utf-8', env=env)
57
+
58
+
59
+ def main() -> int:
60
+ ap = argparse.ArgumentParser(description='TopPPT HTML 全链路回归')
61
+ ap.add_argument('--only', help='只跑名字含该关键字的示例')
62
+ args = ap.parse_args()
63
+
64
+ node = find_node()
65
+ node_path = find_node_modules()
66
+ if not node:
67
+ print('错误: ' + NODE_HINT)
68
+ return 2
69
+ if not node_path:
70
+ print('错误: ' + NODE_MODULES_HINT)
71
+ return 2
72
+ env = node_env(node_path)
73
+ print(f'Node: {node}')
74
+ print(f'NODE_PATH: {node_path}')
75
+ print(f'python-pptx 第三方裁判: {"可用" if has_python_pptx() else "未安装(交叉裁判将跳过)"}')
76
+
77
+ B_OUT.mkdir(parents=True, exist_ok=True)
78
+ fails: list[str] = []
79
+ skipped: list[str] = []
80
+
81
+ examples = sorted(EX.glob('*.html'))
82
+ if args.only:
83
+ examples = [h for h in examples if args.only in h.stem]
84
+ if not examples:
85
+ print('错误: assets/examples/ 下没有可回归的示例。')
86
+ return 2
87
+
88
+ for html in examples:
89
+ stem = html.stem
90
+ model = html.with_suffix('.model.json')
91
+ print(f'=== {stem}')
92
+ r0 = run([PY, str(ROOT / 'scripts' / 'validate_report.py'), str(html), '--strict'])
93
+ print(' [validate_report --strict]', 'OK' if r0.returncode == 0 else 'FAIL')
94
+ if r0.returncode != 0:
95
+ fails.append(stem + ':report')
96
+ print((r0.stdout or '')[-800:])
97
+ continue
98
+ r1 = run([PY, str(ROOT / 'scripts' / 'extract_model.py'), str(html)])
99
+ if r1.returncode != 0:
100
+ fails.append(stem + ':extract')
101
+ print((r1.stdout or '')[-500:])
102
+ continue
103
+ bp = B_OUT / (stem + '.pptx')
104
+ r2 = run([node, str(ROOT / 'scripts' / 'build_pptx.js'), str(bp), '--model=' + str(model)], env=env)
105
+ if r2.returncode != 0 or not bp.exists():
106
+ fails.append(stem + ':build')
107
+ print((r2.stderr or r2.stdout or '')[-800:])
108
+ continue
109
+ r3 = run([PY, str(ROOT / 'scripts' / 'validate_pptx.py'), str(bp), '--strict', '--model=' + str(model)])
110
+ print(' [B 通道 strict]', 'OK (0/0)' if r3.returncode == 0 else f'FAIL exit={r3.returncode}')
111
+ if r3.returncode != 0:
112
+ fails.append(stem + ':pptx-b')
113
+ for line in (r3.stdout or '').splitlines()[-14:]:
114
+ print(' ', line)
115
+
116
+ print('\n=== A 通道(页面预览序列化引擎产物 · gen_channel_a 组装)')
117
+ rA = run([node, str(ROOT / 'scripts' / 'gen_channel_a.js')], env=env)
118
+ if rA.returncode != 0:
119
+ fails.append('A:generate')
120
+ print((rA.stderr or rA.stdout or '')[-800:])
121
+ else:
122
+ ppx_ok = has_python_pptx()
123
+ for ap in sorted(A_OUT.glob('*.pptx')):
124
+ model = EX / (ap.stem + '.model.json')
125
+ if not model.exists():
126
+ # 非示例产物(如 ⑤ 探针的 probe-split.pptx)由探针段单独校验,跳过避免误判
127
+ continue
128
+ # A 通道(预览引擎)图表为形状近似渲染,豁免 MODEL_CHART_COUNT(交付通道 B 不豁免)
129
+ r = run([PY, str(ROOT / 'scripts' / 'validate_pptx.py'), str(ap), '--strict',
130
+ '--model=' + str(model), '--allow-shape-charts'])
131
+ ok = r.returncode == 0
132
+ ppx = 'SKIP'
133
+ if ppx_ok:
134
+ p = run([PY, '-c',
135
+ 'import sys;from pptx import Presentation;'
136
+ 'print(len(list(Presentation(sys.argv[1]).slides)))', str(ap)])
137
+ ppx = 'OK' if p.returncode == 0 else 'FAIL'
138
+ print(f' {ap.name}: strict={"OK" if ok else "FAIL"} python-pptx={ppx}')
139
+ if not ok:
140
+ fails.append(ap.stem + ':pptx-a')
141
+ for line in (r.stdout or '').splitlines()[-10:]:
142
+ print(' ', line)
143
+ if ppx == 'FAIL':
144
+ fails.append(ap.stem + ':ppx-a')
145
+ if ppx == 'SKIP':
146
+ skipped.append(ap.stem + ':ppx-a')
147
+
148
+ # ④ 素材图片导出探针:示例矩阵刻意零图片,真实素材路径/版式/门禁靠探针覆盖
149
+ r5 = run([PY, str(ROOT / 'scripts' / 'probe_image_export.py')], env=env)
150
+ print(' [probe_image_export]', 'OK' if r5.returncode == 0 else 'FAIL')
151
+ if r5.returncode != 0:
152
+ fails.append('probe-image')
153
+ for line in (r5.stdout or '').splitlines()[-8:]:
154
+ print(' ', line)
155
+
156
+ # ⑤ 双区组合页探针(split 左区 = 图表):示例矩阵只覆盖"左文右图"缺省路径,
157
+ # 左区图表/表格/图片三个变体靠脚手架生成一次走完整交付链路(v8 新增能力);
158
+ # B 通道 + A 通道(同一模型)都跑,产物同名落两目录 → ⑥ 交叉裁判可逐页比对。
159
+ print('\n=== 双区组合页探针(split 左区 = 图表)')
160
+ probe_plan = B_OUT / 'probe-split.plan.json'
161
+ probe_html = B_OUT / 'probe-split.html'
162
+ probe_model = B_OUT / 'probe-split.model.json'
163
+ probe_pptx = B_OUT / 'probe-split.pptx'
164
+ probe_plan.write_text(json.dumps(
165
+ [{'type': 'points', 'eyebrow': '01 · 前置', 'title': '前置要点页(探针占位)'},
166
+ {'type': 'split', 'left_type': 'chart', 'eyebrow': '02 · 组合版式',
167
+ 'title': '双区组合页探针:左图右文(左区图表路径)'}], ensure_ascii=False), encoding='utf-8')
168
+ ok6, why6 = False, ''
169
+ r6 = run([PY, str(ROOT / 'scripts' / 'scaffold_report.py'), '--mode', 'presentation',
170
+ '--plan', str(probe_plan), '--out', str(probe_html)])
171
+ if r6.returncode != 0:
172
+ why6 = 'scaffold'
173
+ else:
174
+ r7 = run([PY, str(ROOT / 'scripts' / 'extract_model.py'), str(probe_html), str(probe_model)])
175
+ if r7.returncode != 0:
176
+ why6 = 'extract'
177
+ else:
178
+ r8 = run([node, str(ROOT / 'scripts' / 'build_pptx.js'), str(probe_pptx),
179
+ '--model=' + str(probe_model)], env=env)
180
+ if r8.returncode != 0 or not probe_pptx.exists():
181
+ why6 = 'build'
182
+ else:
183
+ r9 = run([PY, str(ROOT / 'scripts' / 'validate_pptx.py'), str(probe_pptx),
184
+ '--strict', '--model=' + str(probe_model)])
185
+ ok6 = r9.returncode == 0
186
+ if not ok6:
187
+ why6 = 'validate_pptx_b'
188
+ for line in (r9.stdout or '').splitlines()[-10:]:
189
+ print(' ', line)
190
+ else:
191
+ # A 通道同模型(预览序列化引擎):产物同名落 dist/regression-a/
192
+ probe_pptx_a = A_OUT / 'probe-split.pptx'
193
+ if probe_pptx_a.exists():
194
+ probe_pptx_a.unlink()
195
+ r10 = run([node, str(ROOT / 'scripts' / 'gen_channel_a.js'),
196
+ '--model=' + str(probe_model), '--out=' + str(A_OUT)], env=env)
197
+ if r10.returncode != 0 or not probe_pptx_a.exists():
198
+ ok6, why6 = False, 'channel_a'
199
+ print((r10.stderr or r10.stdout or '')[-400:])
200
+ else:
201
+ # 预览引擎图表为形状近似 → 豁免 MODEL_CHART_COUNT(同示例矩阵口径)
202
+ r11 = run([PY, str(ROOT / 'scripts' / 'validate_pptx.py'), str(probe_pptx_a),
203
+ '--strict', '--model=' + str(probe_model),
204
+ '--allow-shape-charts'])
205
+ if r11.returncode != 0:
206
+ ok6, why6 = False, 'validate_pptx_a'
207
+ for line in (r11.stdout or '').splitlines()[-10:]:
208
+ print(' ', line)
209
+ print(' [split 左区图表 B/A 双通道]', 'OK' if ok6 else f'FAIL({why6})')
210
+ if not ok6:
211
+ fails.append('probe-split')
212
+
213
+ # ⑥b 深色主题导出探针:示例矩阵只有 architecture/graphite-dark 是 dark,
214
+ # research / presentation 的 stylesDark + styleDataColorsDark 路径此前零覆盖。
215
+ print('\n=== 深色主题导出探针(research / presentation × dark)')
216
+ dark_fail = []
217
+ for stem in ('2026-09-09-research-mckinsey', '2026-09-09-presentation-business-blue'):
218
+ src_model = EX / f'{stem}.model.json'
219
+ if not src_model.exists():
220
+ continue
221
+ dm = B_OUT / f'{stem}-dark.model.json'
222
+ dp = B_OUT / f'{stem}-dark.pptx'
223
+ data = json.loads(src_model.read_text(encoding='utf-8'))
224
+ data['theme'] = 'dark'
225
+ dm.write_text(json.dumps(data, ensure_ascii=False), encoding='utf-8')
226
+ rb = run([node, str(ROOT / 'scripts' / 'build_pptx.js'), str(dp),
227
+ '--model=' + str(dm)], env=env)
228
+ if rb.returncode != 0 or not dp.exists():
229
+ dark_fail.append(stem + ':build')
230
+ print((rb.stderr or rb.stdout or '')[-300:])
231
+ continue
232
+ rv = run([PY, str(ROOT / 'scripts' / 'validate_pptx.py'), str(dp),
233
+ '--strict', '--model=' + str(dm)])
234
+ print(f' {stem} dark:', 'OK' if rv.returncode == 0 else 'FAIL')
235
+ if rv.returncode != 0:
236
+ dark_fail.append(stem + ':validate')
237
+ for line in (rv.stdout or '').splitlines()[-8:]:
238
+ print(' ', line)
239
+ if dark_fail:
240
+ fails.append('dark-theme')
241
+
242
+ # ⑥ 双通道交叉裁判(python-pptx):放在探针之后,A/B 产物齐全时才逐页比对
243
+ r4 = run([PY, str(ROOT / 'scripts' / 'cross_verify.py')] + (['--full-ab'] if '--full-ab' in sys.argv else []))
244
+ if r4.returncode == 2:
245
+ print(' [cross_verify] SKIP(python-pptx 未安装,可选第三方裁判)')
246
+ skipped.append('cross-verify')
247
+ else:
248
+ print(' [cross_verify]', 'OK' if r4.returncode == 0 else 'FAIL')
249
+ if r4.returncode != 0:
250
+ fails.append('cross-verify')
251
+ print((r4.stdout or '')[-600:])
252
+
253
+ # ⑦ 门禁反向验证(故障注入):正向全绿只能证明“没误报”,这里证明“真能报”
254
+ r12 = run([PY, str(ROOT / 'scripts' / 'negative_tests.py')])
255
+ print(' [negative_tests]', 'OK' if r12.returncode == 0 else 'FAIL')
256
+ if r12.returncode != 0:
257
+ fails.append('negative-tests')
258
+ print((r12.stdout or '')[-600:])
259
+
260
+ # ⑦-b 任务路由全量遍历:--task 与 validate_report FIX_GUIDE 的修复链路不得静默断裂
261
+ # (v8.3 前教训:中文节号不被解析,7/11 修复命令执行即报错且无任何审计覆盖;
262
+ # 实现与 audit_docs ⑥ 共用 ES.verify_routes,防两处维护)
263
+ try:
264
+ import extract_snippet as ES # noqa: PLC0415
265
+ route_bad = ES.verify_routes()
266
+ print(' [task_routes]', 'OK' if not route_bad else f'FAIL {route_bad}')
267
+ if route_bad:
268
+ fails.append('task-routes')
269
+ except ImportError:
270
+ print(' [task_routes] FAIL(extract_snippet 不可导入)')
271
+ fails.append('task-routes')
272
+
273
+ # ⑧ 浏览器真值测量(可选):静态估算看不到「表格被半幅容器横向裁掉一列」这类真实布局缺陷。
274
+ # 当前解释器可能未装 playwright(托管运行时常见);measure_height.py 会自动回落到
275
+ # 本机已装 playwright 的解释器,因此这里只要能跑 measure_height 就不再跳过。
276
+ mh_fail = []
277
+ for html in examples:
278
+ r13 = run([PY, str(ROOT / 'scripts' / 'measure_height.py'), str(html)])
279
+ out = (r13.stdout or '') + (r13.stderr or '')
280
+ if r13.returncode != 0:
281
+ mh_fail.append(html.stem)
282
+ print(out[-500:])
283
+ elif '跳过:' in out and 'playwright' in out.lower():
284
+ # 解释器与回落链都找不到 playwright → 整批跳过(可选依赖)
285
+ print(' [measure_height] SKIP(playwright 未安装,可选真值裁判)')
286
+ skipped.append('measure-height')
287
+ mh_fail = []
288
+ break
289
+ if 'measure-height' not in skipped:
290
+ print(' [measure_height 页高/容器裁切真值]', 'OK' if not mh_fail else f'FAIL {mh_fail}')
291
+ if mh_fail:
292
+ fails.append('measure-height')
293
+
294
+ print('=' * 56)
295
+ if skipped:
296
+ print('跳过(可选依赖缺失):', sorted(set(skipped)))
297
+ if fails:
298
+ print('回归失败:', fails)
299
+ return 1
300
+ print('全链路回归通过:HTML strict + B 通道精导 strict 0/0 + A 通道(预览同引擎产物)strict 0/0'
301
+ + ' + 双区组合页双通道探针 + 深色主题探针 + 门禁反向验证 + 任务路由全量遍历'
302
+ + ('' if 'measure-height' in skipped else ' + 浏览器页高/裁切真值')
303
+ + (' + python-pptx 双裁判 + 双通道交叉一致' if 'cross-verify' not in skipped else ''))
304
+ return 0
305
+
306
+
307
+ if __name__ == '__main__':
308
+ sys.exit(main())