@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,307 +1,433 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """TopPPT HTML · 门禁反向验证(故障注入)
4
-
5
- 校验器最容易退化成「只会说 OK 的摆设」。本脚本往合格产物里**注入已知缺陷**,
6
- 断言对应门禁必须报错——门禁抓不到即视为失败。
7
-
8
- 覆盖:
9
- N1 Exhibit 框漏编号(旧实现只校验已编号者的连续性 → 静默通过)
10
- N2 参考资料两位数编号错配(旧正则 `ref-\\d` 两侧同时落空 → 静默通过)
11
- N3 参考资料编号跳号
12
- N4 PPTX 演讲者备注被剔离(dataTable=notes 声称数据入备注,不核对就只是一句承诺)
13
- N5 模型图表数值篡改(cross_verify 数值核对)
14
- N6 行动标题判断词鉴别力(正则本身)
15
- N7 PPTX 字号越出比例尺
16
- N8 data-chart 未登记类型(登记表白名单)
17
- N9 图表多样性塌陷(全篇压成同型 → 不同类型数 < 模式下限)
18
- N10 图片外链(零外链铁律)
19
- N11 待核实有标色无图例(.tbd 必须配 .tbd-legend/.flagbar)
20
- N12 模型 theme 与 data-theme 矛盾
21
- N13 模型 mode 与 data-mode 矛盾
22
- N14 内部锚点断裂(链接目标 id 不存在)
23
-
24
- 用法: python scripts/negative_tests.py
25
- """
26
- from __future__ import annotations
27
-
28
- import json
29
- import re
30
- import subprocess
31
- import sys
32
- import zipfile
33
- from pathlib import Path
34
-
35
- try:
36
- sys.stdout.reconfigure(encoding='utf-8', errors='replace')
37
- except Exception:
38
- pass
39
-
40
- ROOT = Path(__file__).resolve().parent.parent
41
- OUT = ROOT / 'dist' / 'negtest'
42
- PY = sys.executable
43
-
44
-
45
- def run_validate(path: Path) -> tuple[int, str]:
46
- r = subprocess.run([PY, str(ROOT / 'scripts' / 'validate_report.py'), str(path), '--strict'],
47
- capture_output=True, text=True, encoding='utf-8', errors='replace')
48
- return r.returncode, (r.stdout or '') + (r.stderr or '')
49
-
50
-
51
- def expect_fail(name: str, path: Path, keyword: str) -> bool:
52
- code, out = run_validate(path)
53
- # --strict 下 WARN 同样计失败(退出码 1),故 [WARN] 行也算「门禁抓到」
54
- hit = [ln for ln in out.splitlines()
55
- if keyword in ln and ('[FAIL]' in ln or '[WARN]' in ln)]
56
- ok = code != 0 and bool(hit)
57
- print(f' [{"OK" if ok else "FAIL"}] {name}')
58
- if hit:
59
- print(f' 抓到: {hit[0].strip()[:120]}')
60
- elif not ok:
61
- print(f' 门禁未触发(期望 FAIL 含「{keyword}」)')
62
- return ok
63
-
64
-
65
- def main() -> int:
66
- base = ROOT / 'assets' / 'examples' / '2026-09-09-research-mckinsey.html'
67
- if not base.exists():
68
- print(f'SKIP:基准示例缺失 {base}')
69
- return 0
70
- txt = base.read_text(encoding='utf-8')
71
- OUT.mkdir(parents=True, exist_ok=True)
72
-
73
- code, out = run_validate(base)
74
- if code != 0:
75
- print('[FAIL] 基准示例本身未通过 strict,反向验证失去意义')
76
- return 1
77
- print('基准示例 strict 通过,开始故障注入:')
78
-
79
- cases: list[tuple[str, str, str]] = []
80
-
81
- # N1 抹掉一个 Exhibit 编号(框仍在)
82
- cases.append(('N1 Exhibit 框漏编号',
83
- txt.replace('class="exhibit__no"', 'class="exhibit__no--x"', 1),
84
- 'Exhibit 框均已编号'))
85
-
86
- # N2 参考资料改成两位数编号,与正文引用错配
87
- cases.append(('N2 引用编号两位数错配',
88
- re.sub(r'id="ref-1"', 'id="ref-10"', txt, count=1),
89
- '双向对齐'))
90
-
91
- # N3 编号跳号(两侧同时改,集合仍对齐,但 1..N 不连续)
92
- t3 = txt.replace('ref-2"', 'ref-9"')
93
- cases.append(('N3 参考资料编号跳号', t3, '编号连续'))
94
-
95
- # N8 data-chart 用了登记表外的类型
96
- cases.append(('N8 图表类型未登记',
97
- txt.replace('data-chart="hbar"', 'data-chart="hbarx"', 1),
98
- '登记表内'))
99
-
100
- # N9 图表多样性塌陷(全部压成 bar → 不同类型数 1 < research 下限 6)
101
- t9 = txt
102
- for ct in ('hbar', 'donut', 'waterfall', 'sankey', 'treemap', 'boxplot',
103
- 'network', 'marimekko', 'streamgraph', 'gantt', 'rose', 'candlestick'):
104
- t9 = t9.replace(f'data-chart="{ct}"', 'data-chart="bar"')
105
- cases.append(('N9 图表多样性塌陷', t9, '图表多样性'))
106
-
107
- # N10 外链图片(零外链铁律)
108
- cases.append(('N10 图片外链',
109
- txt.replace('</body>',
110
- '<img src="https://example.com/x.png" alt="外链注入"></body>', 1),
111
- '图片源无外链'))
112
-
113
- # N11 待核实有标色无图例(改名不得包含原串——校验是子串判断)
114
- t11 = txt.replace('tbd-legend', 'tbd-leg').replace('flagbar', 'flag-bar')
115
- cases.append(('N11 待核实无图例', t11, '待核实标注'))
116
-
117
- # N12 模型 theme 与页面 data-theme 矛盾
118
- cases.append(('N12 模型主题不一致',
119
- txt.replace('"theme": "light"', '"theme": "dark"', 1),
120
- 'data-theme 一致'))
121
-
122
- # N13 模型 mode 与页面 data-mode 矛盾
123
- cases.append(('N13 模型模式不一致',
124
- txt.replace('"mode": "research"', '"mode": "presentation"', 1),
125
- 'data-mode 一致'))
126
-
127
- # N14 内部锚点断裂(链接目标 id 不存在)
128
- cases.append(('N14 锚点断裂',
129
- txt.replace('href="#s1"', 'href="#s404"'),
130
- '锚点闭环'))
131
-
132
- # N15 HTML 标签泄漏进可见文本(截图级:转义标签当字面量显示)
133
- cases.append(('N15 标签泄漏',
134
- txt.replace('</p>',
135
- ' &lt;a class="cite" href="#ref-1"&gt;[1]&lt;/a&gt;。</p>', 1),
136
- 'HTML_TAG_IN_TEXT'))
137
-
138
- # N16 极偏 donut(0.5% vs 99.5% 应改 KPI,禁环图)
139
- t16 = txt
140
- if '"type": "donut"' in t16 or '"type":"donut"' in t16:
141
- t16 = re.sub(
142
- r'("type"\s*:\s*"donut"[\s\S]{0,200}?"values"\s*:\s*\[)[^\]]*(\])',
143
- r'\g<1>0.5, 99.5\g<2>', t16, count=1)
144
- cases.append(('N16 极偏 donut', t16, 'CHART_SKEW'))
145
-
146
- # N17 模型字段夹带 HTML 标签(extract 净化 + validate 扫描 REPORT_MODEL)
147
- t17 = re.sub(
148
- r'("soWhat"\s*:\s*")',
149
- r'\g<1><a class=\\"cite\\" href=\\"#ref-1\\">[1]</a> ',
150
- txt, count=1)
151
- if t17 == txt:
152
- t17 = txt.replace(
153
- '"footnote":',
154
- '"footnote": "<strong>x</strong> ', 1)
155
- cases.append(('N17 模型夹带标签', t17, 'HTML_TAG_IN_TEXT'))
156
-
157
- ok = True
158
- for name, content, keyword in cases:
159
- if content == txt:
160
- print(f' [SKIP] {name}(基准示例无对应结构)')
161
- continue
162
- p = OUT / (name.split()[0] + '.html')
163
- p.write_text(content, encoding='utf-8')
164
- ok = expect_fail(name, p, keyword) and ok
165
-
166
- ok = _pptx_notes_case() and ok
167
- ok = _chart_data_case() and ok
168
- ok = _title_pattern_case() and ok
169
- ok = _font_scale_case() and ok
170
-
171
- print('反向验证通过:注入的缺陷都被门禁抓住。' if ok
172
- else '反向验证失败:存在抓不到的缺陷,门禁有假阴性。')
173
- return 0 if ok else 1
174
-
175
-
176
- def _font_scale_case() -> bool:
177
- """N7:往 PPTX 里塞一个比例尺外的字号 → FONT_SIZE_OFF_SCALE 必须报。"""
178
- name = '2026-09-09-research-mckinsey'
179
- src = ROOT / 'dist' / 'regression' / f'{name}.pptx'
180
- model = ROOT / 'assets' / 'examples' / f'{name}.model.json'
181
- if not src.exists() or not model.exists():
182
- print(' [SKIP] N7 字号越出比例尺(需先跑 regression)')
183
- return True
184
- out = OUT / 'N7-off-scale.pptx'
185
- patched = False
186
- with zipfile.ZipFile(src) as zin, zipfile.ZipFile(out, 'w', zipfile.ZIP_DEFLATED) as zout:
187
- for item in zin.infolist():
188
- data = zin.read(item.filename)
189
- if not patched and item.filename == 'ppt/slides/slide4.xml':
190
- text = data.decode('utf-8')
191
- new = re.sub(r'sz="\d+"', 'sz="1234"', text, count=1) # 12.34pt:任何档位都没有
192
- if new != text:
193
- data = new.encode('utf-8')
194
- patched = True
195
- zout.writestr(item, data)
196
- if not patched:
197
- print(' [SKIP] N7 字号越出比例尺(未找到可改写的 sz 属性)')
198
- return True
199
- report = OUT / 'N7.json'
200
- subprocess.run([PY, str(ROOT / 'scripts' / 'validate_pptx.py'), str(out),
201
- '--strict', '--model=' + str(model), '--json-out', str(report)],
202
- capture_output=True, text=True, encoding='utf-8', errors='replace')
203
- try:
204
- data = json.loads(report.read_text(encoding='utf-8'))
205
- except (OSError, json.JSONDecodeError):
206
- print(' [FAIL] N7 字号越出比例尺:校验报告不可解析')
207
- return False
208
- codes = {i.get('code') for i in (data.get('errors') or []) + (data.get('warnings') or [])}
209
- ok = 'FONT_SIZE_OFF_SCALE' in codes
210
- print(f' [{"OK" if ok else "FAIL"}] N7 字号越出比例尺')
211
- if not ok:
212
- print(f' 门禁未触发(期望 FONT_SIZE_OFF_SCALE,实际 {sorted(codes)[:6]})')
213
- return ok
214
-
215
-
216
- def _title_pattern_case() -> bool:
217
- """N6:主题词式长标题必须被判为「无判断信号」,结论句标题必须放行。"""
218
- lc = json.loads((ROOT / 'scripts' / 'layout-constants.json').read_text(encoding='utf-8'))
219
- pat = ((lc.get('contentQuality') or {}).get('researchTitle') or {}).get('judgmentPattern')
220
- if not pat:
221
- print(' [SKIP] N6 行动标题判断词(未配置 judgmentPattern)')
222
- return True
223
- topic = ['智能体平台的应用架构与技术选型说明', '关于数据治理需求的整体情况介绍',
224
- '企业知识库建设的相关背景与范围', '平台能力地图与模块组成一览表',
225
- '项目实施过程中的应急预案汇总', '面向未来的技术路线图规划说明']
226
- claim = ['投入产出比在第 3 季度首次转正', '三成团队已把智能体纳入日常流程',
227
- '数据质量是当前最大的落地瓶颈', '推理成本一年内下降 62%',
228
- '从试点到规模化:关键卡在治理', '自建方案的总成本高于采购方案']
229
- leaked = [t for t in topic if re.search(pat, t)]
230
- hurt = [t for t in claim if not re.search(pat, t)]
231
- ok = not leaked and not hurt
232
- print(f' [{"OK" if ok else "FAIL"}] N6 行动标题判断词鉴别力'
233
- f'(漏放主题词 {len(leaked)}/{len(topic)} · 误伤结论句 {len(hurt)}/{len(claim)})')
234
- for t in (leaked + hurt)[:3]:
235
- print(f' {t}')
236
- return ok
237
-
238
-
239
- def _chart_data_case() -> bool:
240
- """N5:篡改模型里的图表数值 → cross_verify 的数值核对必须报不符。"""
241
- name = '2026-09-09-research-mckinsey'
242
- pptx = ROOT / 'dist' / 'regression' / f'{name}.pptx'
243
- mp = ROOT / 'assets' / 'examples' / f'{name}.model.json'
244
- if not pptx.exists() or not mp.exists():
245
- print(' [SKIP] N5 图表数值篡改(需先跑 regression)')
246
- return True
247
- sys.path.insert(0, str(ROOT / 'scripts'))
248
- try:
249
- from pptx import Presentation # noqa: PLC0415
250
- import cross_verify as CV # noqa: PLC0415
251
- except ImportError:
252
- print(' [SKIP] N5 图表数值篡改(python-pptx 未安装)')
253
- return True
254
- model = json.loads(mp.read_text(encoding='utf-8'))
255
- touched = False
256
- for sec in (model.get('sections') or []):
257
- c = CV._model_chart(sec) if isinstance(sec, dict) else None
258
- if c and isinstance(c.get('values'), list) and c['values']:
259
- c['values'] = [(v + 777) if isinstance(v, (int, float)) else v for v in c['values']]
260
- touched = True
261
- break
262
- if not touched:
263
- print(' [SKIP] N5 图表数值篡改(基准模型无可改图表)')
264
- return True
265
- issues = CV.chart_data_verify(Presentation(str(pptx)), model, name)
266
- ok = bool(issues)
267
- print(f' [{"OK" if ok else "FAIL"}] N5 模型图表数值被篡改')
268
- if ok:
269
- print(f' 抓到: {issues[0][:120]}')
270
- else:
271
- print(' 门禁未触发(数值核对形同虚设)')
272
- return ok
273
-
274
-
275
- def _pptx_notes_case() -> bool:
276
- """N4:剥离演讲者备注 → dataTable=notes 的图表数据不可追溯,必须被 strict 抓住。"""
277
- name = '2026-09-09-research-mckinsey'
278
- src = ROOT / 'dist' / 'regression' / f'{name}.pptx'
279
- model = ROOT / 'assets' / 'examples' / f'{name}.model.json'
280
- if not src.exists() or not model.exists():
281
- print(' [SKIP] N4 备注剥离(需先跑 regression 生成 PPTX)')
282
- return True
283
- stripped = OUT / 'N4-no-notes.pptx'
284
- with zipfile.ZipFile(src) as zin, zipfile.ZipFile(stripped, 'w', zipfile.ZIP_DEFLATED) as zout:
285
- for item in zin.infolist():
286
- if item.filename.startswith('ppt/notesSlides/'):
287
- continue
288
- zout.writestr(item, zin.read(item.filename))
289
- report = OUT / 'N4.json'
290
- subprocess.run([PY, str(ROOT / 'scripts' / 'validate_pptx.py'), str(stripped),
291
- '--strict', '--model=' + str(model), '--json-out', str(report)],
292
- capture_output=True, text=True, encoding='utf-8', errors='replace')
293
- try:
294
- data = json.loads(report.read_text(encoding='utf-8'))
295
- except (OSError, json.JSONDecodeError):
296
- print(' [FAIL] N4 备注剥离:校验报告不可解析')
297
- return False
298
- codes = {i.get('code') for i in (data.get('errors') or []) + (data.get('warnings') or [])}
299
- ok = 'MODEL_CHART_NOTES_MISSING' in codes
300
- print(f' [{"OK" if ok else "FAIL"}] N4 演讲者备注被剥离')
301
- if not ok:
302
- print(f' 门禁未触发(期望 MODEL_CHART_NOTES_MISSING,实际 {sorted(codes)[:6]})')
303
- return ok
304
-
305
-
306
- if __name__ == '__main__':
307
- sys.exit(main())
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """TopPPT HTML · 门禁反向验证(故障注入)
4
+
5
+ 校验器最容易退化成「只会说 OK 的摆设」。本脚本往合格产物里**注入已知缺陷**,
6
+ 断言对应门禁必须报错——门禁抓不到即视为失败。
7
+
8
+ 覆盖:
9
+ N1 Exhibit 框漏编号(旧实现只校验已编号者的连续性 → 静默通过)
10
+ N2 参考资料两位数编号错配(旧正则 `ref-\\d` 两侧同时落空 → 静默通过)
11
+ N3 参考资料编号跳号
12
+ N4 PPTX 演讲者备注被剔离(dataTable=notes 声称数据入备注,不核对就只是一句承诺)
13
+ N5 模型图表数值篡改(cross_verify 数值核对)
14
+ N6 行动标题判断词鉴别力(正则本身)
15
+ N7 PPTX 字号越出比例尺
16
+ N8 data-chart 未登记类型(登记表白名单)
17
+ N9 图表多样性塌陷(全篇压成同型 → 不同类型数 < 模式下限)
18
+ N10 图片外链(零外链铁律)
19
+ N11 待核实有标色无图例(.tbd 必须配 .tbd-legend/.flagbar)
20
+ N12 模型 theme 与 data-theme 矛盾
21
+ N13 模型 mode 与 data-mode 矛盾
22
+ N14 内部锚点断裂(链接目标 id 不存在)
23
+ L4 截断迹象(列表项省略号砍义)
24
+ L5 溢出未拆页
25
+ L6 混排缺对齐(ALIGN_RHYTHM)
26
+
27
+ 用法: python scripts/negative_tests.py
28
+ """
29
+ from __future__ import annotations
30
+
31
+ import json
32
+ import re
33
+ import subprocess
34
+ import sys
35
+ import zipfile
36
+ from pathlib import Path
37
+
38
+ try:
39
+ sys.stdout.reconfigure(encoding='utf-8', errors='replace')
40
+ except Exception:
41
+ pass
42
+
43
+ ROOT = Path(__file__).resolve().parent.parent
44
+ OUT = ROOT / 'dist' / 'negtest'
45
+ PY = sys.executable
46
+
47
+
48
+ def run_validate(path: Path) -> tuple[int, str]:
49
+ r = subprocess.run([PY, str(ROOT / 'scripts' / 'validate_report.py'), str(path), '--strict'],
50
+ capture_output=True, text=True, encoding='utf-8', errors='replace')
51
+ return r.returncode, (r.stdout or '') + (r.stderr or '')
52
+
53
+
54
+ def expect_fail(name: str, path: Path, keyword: str) -> bool:
55
+ code, out = run_validate(path)
56
+ # --strict 下 WARN 同样计失败(退出码 1),故 [WARN] 行也算「门禁抓到」
57
+ hit = [ln for ln in out.splitlines()
58
+ if keyword in ln and ('[FAIL]' in ln or '[WARN]' in ln)]
59
+ ok = code != 0 and bool(hit)
60
+ print(f' [{"OK" if ok else "FAIL"}] {name}')
61
+ if hit:
62
+ print(f' 抓到: {hit[0].strip()[:120]}')
63
+ elif not ok:
64
+ print(f' 门禁未触发(期望 FAIL 含「{keyword}」)')
65
+ return ok
66
+
67
+
68
+
69
+ def expect_layout_qa_fail(name: str, path: Path, keyword: str) -> bool:
70
+ """Run validate_report --strict --layout-qa and require FAIL containing keyword."""
71
+ r = subprocess.run(
72
+ [PY, str(ROOT / 'scripts' / 'validate_report.py'), str(path),
73
+ '--strict', '--layout-qa'],
74
+ capture_output=True, text=True, encoding='utf-8', errors='replace')
75
+ out = (r.stdout or '') + (r.stderr or '')
76
+ hit = [ln for ln in out.splitlines()
77
+ if keyword in ln and ('[FAIL]' in ln or 'FAIL' in ln)]
78
+ ok = r.returncode != 0 and bool(hit)
79
+ print(f' [{"OK" if ok else "FAIL"}] {name}')
80
+ if hit:
81
+ print(f' 抓到: {hit[0].strip()[:120]}')
82
+ elif not ok:
83
+ print(f' layout-qa 未触发(期望含「{keyword}」)')
84
+ return ok
85
+
86
+
87
+ def main() -> int:
88
+ base = ROOT / 'assets' / 'examples' / '2026-09-09-research-mckinsey.html'
89
+ if not base.exists():
90
+ print(f'SKIP:基准示例缺失 {base}')
91
+ return 0
92
+ txt = base.read_text(encoding='utf-8')
93
+ OUT.mkdir(parents=True, exist_ok=True)
94
+
95
+ code, out = run_validate(base)
96
+ if code != 0:
97
+ print('[FAIL] 基准示例本身未通过 strict,反向验证失去意义')
98
+ return 1
99
+ print('基准示例 strict 通过,开始故障注入:')
100
+
101
+ cases: list[tuple[str, str, str]] = []
102
+
103
+ # N1 抹掉一个 Exhibit 编号(框仍在)
104
+ cases.append(('N1 Exhibit 框漏编号',
105
+ txt.replace('class="exhibit__no"', 'class="exhibit__no--x"', 1),
106
+ 'Exhibit 框均已编号'))
107
+
108
+ # N2 参考资料改成两位数编号,与正文引用错配
109
+ cases.append(('N2 引用编号两位数错配',
110
+ re.sub(r'id="ref-1"', 'id="ref-10"', txt, count=1),
111
+ '双向对齐'))
112
+
113
+ # N3 编号跳号(两侧同时改,集合仍对齐,但 1..N 不连续)
114
+ t3 = txt.replace('ref-2"', 'ref-9"')
115
+ cases.append(('N3 参考资料编号跳号', t3, '编号连续'))
116
+
117
+ # N8 data-chart 用了登记表外的类型
118
+ cases.append(('N8 图表类型未登记',
119
+ txt.replace('data-chart="hbar"', 'data-chart="hbarx"', 1),
120
+ '登记表内'))
121
+
122
+ # N9 图表多样性塌陷(全部压成 bar → 不同类型数 1 < research 下限 6)
123
+ t9 = txt
124
+ for ct in ('hbar', 'donut', 'waterfall', 'sankey', 'treemap', 'boxplot',
125
+ 'network', 'marimekko', 'streamgraph', 'gantt', 'rose', 'candlestick'):
126
+ t9 = t9.replace(f'data-chart="{ct}"', 'data-chart="bar"')
127
+ cases.append(('N9 图表多样性塌陷', t9, '图表多样性'))
128
+
129
+ # N10 外链图片(零外链铁律)
130
+ cases.append(('N10 图片外链',
131
+ txt.replace('</body>',
132
+ '<img src="https://example.com/x.png" alt="外链注入"></body>', 1),
133
+ '图片源无外链'))
134
+
135
+ # N11 待核实有标色无图例(改名不得包含原串——校验是子串判断)
136
+ t11 = txt.replace('tbd-legend', 'tbd-leg').replace('flagbar', 'flag-bar')
137
+ cases.append(('N11 待核实无图例', t11, '待核实标注'))
138
+
139
+ # N12 模型 theme 与页面 data-theme 矛盾
140
+ cases.append(('N12 模型主题不一致',
141
+ txt.replace('"theme": "light"', '"theme": "dark"', 1),
142
+ 'data-theme 一致'))
143
+
144
+ # N13 模型 mode 与页面 data-mode 矛盾
145
+ cases.append(('N13 模型模式不一致',
146
+ txt.replace('"mode": "research"', '"mode": "presentation"', 1),
147
+ 'data-mode 一致'))
148
+
149
+ # N14 内部锚点断裂(链接目标 id 不存在)
150
+ cases.append(('N14 锚点断裂',
151
+ txt.replace('href="#s1"', 'href="#s404"'),
152
+ '锚点闭环'))
153
+
154
+ # N15 HTML 标签泄漏进可见文本(截图级:转义标签当字面量显示)
155
+ cases.append(('N15 标签泄漏',
156
+ txt.replace('</p>',
157
+ ' &lt;a class="cite" href="#ref-1"&gt;[1]&lt;/a&gt;。</p>', 1),
158
+ 'HTML_TAG_IN_TEXT'))
159
+
160
+ # N16 极偏 donut(0.5% vs 99.5% 应改 KPI,禁环图)
161
+ t16 = txt
162
+ if '"type": "donut"' in t16 or '"type":"donut"' in t16:
163
+ t16 = re.sub(
164
+ r'("type"\s*:\s*"donut"[\s\S]{0,200}?"values"\s*:\s*\[)[^\]]*(\])',
165
+ r'\g<1>0.5, 99.5\g<2>', t16, count=1)
166
+ cases.append(('N16 极偏 donut', t16, 'CHART_SKEW'))
167
+
168
+ # N17 模型字段夹带 HTML 标签(extract 净化 + validate 扫描 REPORT_MODEL)
169
+ t17 = re.sub(
170
+ r'("soWhat"\s*:\s*")',
171
+ r'\g<1><a class=\\"cite\\" href=\\"#ref-1\\">[1]</a> ',
172
+ txt, count=1)
173
+ if t17 == txt:
174
+ t17 = txt.replace(
175
+ '"footnote":',
176
+ '"footnote": "<strong>x</strong> ', 1)
177
+ cases.append(('N17 模型夹带标签', t17, 'HTML_TAG_IN_TEXT'))
178
+
179
+ ok = True
180
+ for name, content, keyword in cases:
181
+ if content == txt:
182
+ print(f' [SKIP] {name}(基准示例无对应结构)')
183
+ continue
184
+ p = OUT / (name.split()[0] + '.html')
185
+ p.write_text(content, encoding='utf-8')
186
+ ok = expect_fail(name, p, keyword) and ok
187
+
188
+
189
+ # ── Batch 2 · layout-qa 专用负例 ─────────────────────────────────────
190
+ # L1 管线产物缺 data-skel:先造带 skel 的页,再撕掉其中一页的标记
191
+ import tempfile
192
+ scaf = OUT / 'L1-scaffold.html'
193
+ subprocess.run(
194
+ [PY, str(ROOT / 'scripts' / 'scaffold_report.py'),
195
+ '--mode', 'presentation', '--style', 'business-blue', '--theme', 'light',
196
+ '--title', 'LayoutQA Neg', '--sections', '5', '--out', str(scaf)],
197
+ capture_output=True, text=True)
198
+ if scaf.exists() and 'data-skel="' in scaf.read_text(encoding='utf-8'):
199
+ t_l1 = scaf.read_text(encoding='utf-8')
200
+ # 撕掉第一个内容页的 data-skel
201
+ t_l1b = re.sub(r'(id="s1") data-skel="P\d+"', r'\1', t_l1, count=1)
202
+ p_l1 = OUT / 'L1-missing-skel.html'
203
+ p_l1.write_text(t_l1b, encoding='utf-8')
204
+ ok = expect_layout_qa_fail('L1 缺 data-skel', p_l1, 'LAYOUT_QA_MISSING_SKEL') and ok
205
+ # L2 连续 3 页同一 skel
206
+ t_l2 = t_l1
207
+ # force s1,s2,s3 all P4
208
+ t_l2 = re.sub(r'(id="s1"[^>]*data-skel=")P\d+"', r'\1P4"', t_l2, count=1)
209
+ t_l2 = re.sub(r'(id="s2"[^>]*data-skel=")P\d+"', r'\1P4"', t_l2, count=1)
210
+ t_l2 = re.sub(r'(id="s3"[^>]*data-skel=")P\d+"', r'\1P4"', t_l2, count=1)
211
+ # also rewrite if attribute order is data-skel before id
212
+ t_l2 = re.sub(r'(data-skel=")P\d+(" data-page-type="[^"]+" id="s1")', r'\1P4\2', t_l2)
213
+ t_l2 = re.sub(r'(data-skel=")P\d+("([^>]*) id="s1")', r'\1P4\2', t_l2)
214
+ # simpler: replace first three data-skel values
215
+ def _force_p4(src, n=3):
216
+ out, c = [], 0
217
+ for part in re.split(r'(data-skel="P\d+")', src):
218
+ if part.startswith('data-skel="') and c < n:
219
+ out.append('data-skel="P4"'); c += 1
220
+ else:
221
+ out.append(part)
222
+ return ''.join(out)
223
+ t_l2 = _force_p4(t_l1, 3)
224
+ p_l2 = OUT / 'L2-skel-streak.html'
225
+ p_l2.write_text(t_l2, encoding='utf-8')
226
+ ok = expect_layout_qa_fail('L2 连续同 skel', p_l2, 'LAYOUT_QA_SKEL_STREAK') and ok
227
+ # L3 极偏 donut in REPORT_MODEL
228
+ t_l3 = t_l1
229
+ if 'window.REPORT_MODEL' in t_l3:
230
+ # inject a skewed donut section into model JSON
231
+ inj = (
232
+ '{"type":"donut","title":"极偏环",'
233
+ '"chart":{"type":"donut","labels":["A","B"],"values":[0.5,99.5]}},'
234
+ )
235
+ t_l3 = re.sub(r'("sections"\s*:\s*\[)', r'\1' + inj, t_l3, count=1)
236
+ p_l3 = OUT / 'L3-skew-donut.html'
237
+ p_l3.write_text(t_l3, encoding='utf-8')
238
+ ok = expect_layout_qa_fail('L3 极偏 donut', p_l3, 'LAYOUT_QA_SKEW_DONUT') and ok
239
+
240
+ # L4 截断迹象:列表项以省略号砍义
241
+ t_l4 = t_l1
242
+ inj4 = '<div class="card"><ul><li class="card__li">这项证据其实很长但被故意截断了…</li></ul></div>'
243
+ t_l4 = re.sub(r'(id="s1"[^>]*>)', lambda m: m.group(1) + inj4, t_l4, count=1)
244
+ p_l4 = OUT / 'L4-truncation.html'
245
+ p_l4.write_text(t_l4, encoding='utf-8')
246
+ ok = expect_layout_qa_fail('L4 截断迹象', p_l4, 'LAYOUT_QA_TRUNCATION') and ok
247
+
248
+ # L5 溢出未拆页:塞入超长正文使页高估算爆掉且无续页信号
249
+ t_l5 = t_l1
250
+ wall = '论证要点' + ('详细证据与口径说明,必须完整保留不得删减。' * 40)
251
+ t_l5 = re.sub(
252
+ r'(id="s1"[^>]*>)',
253
+ lambda m: m.group(1) + '<div class="card"><p>' + wall + '</p></div>'
254
+ + '<div class="card"><p>' + wall + '</p></div>'
255
+ + '<div class="card"><p>' + wall + '</p></div>',
256
+ t_l5, count=1)
257
+ p_l5 = OUT / 'L5-overflow-nosplit.html'
258
+ p_l5.write_text(t_l5, encoding='utf-8')
259
+ ok = expect_layout_qa_fail('L5 溢出未拆页', p_l5, 'LAYOUT_QA_OVERFLOW_NO_SPLIT') and ok
260
+
261
+ # L6 混排缺对齐:图+卡同页但无对齐类
262
+ t_l6 = t_l1
263
+ inj6 = (
264
+ '<div class="grid g-2">'
265
+ '<div class="fig"><svg class="chart" data-chart="bar" style="height:200px"></svg></div>'
266
+ '<div class="card"><ul><li>证据甲</li><li>证据乙</li></ul></div>'
267
+ '</div>'
268
+ )
269
+ t_l6 = re.sub(r'(id="s1"[^>]*>)', lambda m: m.group(1) + inj6, t_l6, count=1)
270
+ # 撕掉 s1 段内对齐类,确保 ALIGN_RHYTHM 能抓住
271
+ def _strip_align_s1(src: str) -> str:
272
+ m = re.search(r'(<section[^>]*id="s1"[^>]*>)([\s\S]*?)(</section>)', src)
273
+ if not m:
274
+ # attribute order may be data-skel before id
275
+ m = re.search(r'(<section[^>]*id="s1"[^>]*>)([\s\S]*?)(</section>)', src)
276
+ if not m:
277
+ return src
278
+ body = m.group(2)
279
+ body = re.sub(r'\ba-start\b', '', body)
280
+ body = re.sub(r'\ba-c\b', '', body)
281
+ body = re.sub(r'\ba-end\b', '', body)
282
+ body = body.replace('align-items:start', '').replace('align-items: center', '')
283
+ return src[:m.start()] + m.group(1) + body + m.group(3) + src[m.end():]
284
+ t_l6 = _strip_align_s1(t_l6)
285
+ p_l6 = OUT / 'L6-align-rhythm.html'
286
+ p_l6.write_text(t_l6, encoding='utf-8')
287
+ ok = expect_layout_qa_fail('L6 混排缺对齐', p_l6, 'LAYOUT_QA_ALIGN_RHYTHM') and ok
288
+
289
+ else:
290
+ print(' [SKIP] layout-qa 负例(scaffold 未产出 data-skel)')
291
+
292
+ ok = _pptx_notes_case() and ok
293
+ ok = _chart_data_case() and ok
294
+ ok = _title_pattern_case() and ok
295
+ ok = _font_scale_case() and ok
296
+
297
+ print('反向验证通过:注入的缺陷都被门禁抓住。' if ok
298
+ else '反向验证失败:存在抓不到的缺陷,门禁有假阴性。')
299
+ return 0 if ok else 1
300
+
301
+
302
+ def _font_scale_case() -> bool:
303
+ """N7:往 PPTX 里塞一个比例尺外的字号 → FONT_SIZE_OFF_SCALE 必须报。"""
304
+ name = '2026-09-09-research-mckinsey'
305
+ src = ROOT / 'dist' / 'regression' / f'{name}.pptx'
306
+ model = ROOT / 'assets' / 'examples' / f'{name}.model.json'
307
+ if not src.exists() or not model.exists():
308
+ print(' [SKIP] N7 字号越出比例尺(需先跑 regression)')
309
+ return True
310
+ out = OUT / 'N7-off-scale.pptx'
311
+ patched = False
312
+ with zipfile.ZipFile(src) as zin, zipfile.ZipFile(out, 'w', zipfile.ZIP_DEFLATED) as zout:
313
+ for item in zin.infolist():
314
+ data = zin.read(item.filename)
315
+ if not patched and item.filename == 'ppt/slides/slide4.xml':
316
+ text = data.decode('utf-8')
317
+ new = re.sub(r'sz="\d+"', 'sz="1234"', text, count=1) # 12.34pt:任何档位都没有
318
+ if new != text:
319
+ data = new.encode('utf-8')
320
+ patched = True
321
+ zout.writestr(item, data)
322
+ if not patched:
323
+ print(' [SKIP] N7 字号越出比例尺(未找到可改写的 sz 属性)')
324
+ return True
325
+ report = OUT / 'N7.json'
326
+ subprocess.run([PY, str(ROOT / 'scripts' / 'validate_pptx.py'), str(out),
327
+ '--strict', '--model=' + str(model), '--json-out', str(report)],
328
+ capture_output=True, text=True, encoding='utf-8', errors='replace')
329
+ try:
330
+ data = json.loads(report.read_text(encoding='utf-8'))
331
+ except (OSError, json.JSONDecodeError):
332
+ print(' [FAIL] N7 字号越出比例尺:校验报告不可解析')
333
+ return False
334
+ codes = {i.get('code') for i in (data.get('errors') or []) + (data.get('warnings') or [])}
335
+ ok = 'FONT_SIZE_OFF_SCALE' in codes
336
+ print(f' [{"OK" if ok else "FAIL"}] N7 字号越出比例尺')
337
+ if not ok:
338
+ print(f' 门禁未触发(期望 FONT_SIZE_OFF_SCALE,实际 {sorted(codes)[:6]})')
339
+ return ok
340
+
341
+
342
+ def _title_pattern_case() -> bool:
343
+ """N6:主题词式长标题必须被判为「无判断信号」,结论句标题必须放行。"""
344
+ lc = json.loads((ROOT / 'scripts' / 'layout-constants.json').read_text(encoding='utf-8'))
345
+ pat = ((lc.get('contentQuality') or {}).get('researchTitle') or {}).get('judgmentPattern')
346
+ if not pat:
347
+ print(' [SKIP] N6 行动标题判断词(未配置 judgmentPattern)')
348
+ return True
349
+ topic = ['智能体平台的应用架构与技术选型说明', '关于数据治理需求的整体情况介绍',
350
+ '企业知识库建设的相关背景与范围', '平台能力地图与模块组成一览表',
351
+ '项目实施过程中的应急预案汇总', '面向未来的技术路线图规划说明']
352
+ claim = ['投入产出比在第 3 季度首次转正', '三成团队已把智能体纳入日常流程',
353
+ '数据质量是当前最大的落地瓶颈', '推理成本一年内下降 62%',
354
+ '从试点到规模化:关键卡在治理', '自建方案的总成本高于采购方案']
355
+ leaked = [t for t in topic if re.search(pat, t)]
356
+ hurt = [t for t in claim if not re.search(pat, t)]
357
+ ok = not leaked and not hurt
358
+ print(f' [{"OK" if ok else "FAIL"}] N6 行动标题判断词鉴别力'
359
+ f'(漏放主题词 {len(leaked)}/{len(topic)} · 误伤结论句 {len(hurt)}/{len(claim)})')
360
+ for t in (leaked + hurt)[:3]:
361
+ print(f' {t}')
362
+ return ok
363
+
364
+
365
+ def _chart_data_case() -> bool:
366
+ """N5:篡改模型里的图表数值 → cross_verify 的数值核对必须报不符。"""
367
+ name = '2026-09-09-research-mckinsey'
368
+ pptx = ROOT / 'dist' / 'regression' / f'{name}.pptx'
369
+ mp = ROOT / 'assets' / 'examples' / f'{name}.model.json'
370
+ if not pptx.exists() or not mp.exists():
371
+ print(' [SKIP] N5 图表数值篡改(需先跑 regression)')
372
+ return True
373
+ sys.path.insert(0, str(ROOT / 'scripts'))
374
+ try:
375
+ from pptx import Presentation # noqa: PLC0415
376
+ import cross_verify as CV # noqa: PLC0415
377
+ except ImportError:
378
+ print(' [SKIP] N5 图表数值篡改(python-pptx 未安装)')
379
+ return True
380
+ model = json.loads(mp.read_text(encoding='utf-8'))
381
+ touched = False
382
+ for sec in (model.get('sections') or []):
383
+ c = CV._model_chart(sec) if isinstance(sec, dict) else None
384
+ if c and isinstance(c.get('values'), list) and c['values']:
385
+ c['values'] = [(v + 777) if isinstance(v, (int, float)) else v for v in c['values']]
386
+ touched = True
387
+ break
388
+ if not touched:
389
+ print(' [SKIP] N5 图表数值篡改(基准模型无可改图表)')
390
+ return True
391
+ issues = CV.chart_data_verify(Presentation(str(pptx)), model, name)
392
+ ok = bool(issues)
393
+ print(f' [{"OK" if ok else "FAIL"}] N5 模型图表数值被篡改')
394
+ if ok:
395
+ print(f' 抓到: {issues[0][:120]}')
396
+ else:
397
+ print(' 门禁未触发(数值核对形同虚设)')
398
+ return ok
399
+
400
+
401
+ def _pptx_notes_case() -> bool:
402
+ """N4:剥离演讲者备注 → dataTable=notes 的图表数据不可追溯,必须被 strict 抓住。"""
403
+ name = '2026-09-09-research-mckinsey'
404
+ src = ROOT / 'dist' / 'regression' / f'{name}.pptx'
405
+ model = ROOT / 'assets' / 'examples' / f'{name}.model.json'
406
+ if not src.exists() or not model.exists():
407
+ print(' [SKIP] N4 备注剥离(需先跑 regression 生成 PPTX)')
408
+ return True
409
+ stripped = OUT / 'N4-no-notes.pptx'
410
+ with zipfile.ZipFile(src) as zin, zipfile.ZipFile(stripped, 'w', zipfile.ZIP_DEFLATED) as zout:
411
+ for item in zin.infolist():
412
+ if item.filename.startswith('ppt/notesSlides/'):
413
+ continue
414
+ zout.writestr(item, zin.read(item.filename))
415
+ report = OUT / 'N4.json'
416
+ subprocess.run([PY, str(ROOT / 'scripts' / 'validate_pptx.py'), str(stripped),
417
+ '--strict', '--model=' + str(model), '--json-out', str(report)],
418
+ capture_output=True, text=True, encoding='utf-8', errors='replace')
419
+ try:
420
+ data = json.loads(report.read_text(encoding='utf-8'))
421
+ except (OSError, json.JSONDecodeError):
422
+ print(' [FAIL] N4 备注剥离:校验报告不可解析')
423
+ return False
424
+ codes = {i.get('code') for i in (data.get('errors') or []) + (data.get('warnings') or [])}
425
+ ok = 'MODEL_CHART_NOTES_MISSING' in codes
426
+ print(f' [{"OK" if ok else "FAIL"}] N4 演讲者备注被剥离')
427
+ if not ok:
428
+ print(f' 门禁未触发(期望 MODEL_CHART_NOTES_MISSING,实际 {sorted(codes)[:6]})')
429
+ return ok
430
+
431
+
432
+ if __name__ == '__main__':
433
+ sys.exit(main())