@dsh-gis/dsh-video-studio-skill 0.9.1 → 1.0.4

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 (63) hide show
  1. package/CHANGELOG.md +473 -0
  2. package/README.md +263 -327
  3. package/THIRD_PARTY_NOTICES.md +2 -2
  4. package/package.json +9 -10
  5. package/schemas/design.schema.json +722 -0
  6. package/schemas/film.schema.json +31 -42
  7. package/schemas/proposal.schema.json +133 -0
  8. package/skills/video-studio/SKILL.md +1216 -1123
  9. package/skills/video-studio/assets/design_fixture.json +141 -0
  10. package/skills/video-studio/assets/film.json +2 -4
  11. package/skills/video-studio/assets/golden_frames.json +13 -10
  12. package/skills/video-studio/assets/scenes.py +153 -65
  13. package/skills/video-studio/assets/voice_loudness.json +16 -0
  14. package/skills/video-studio/references/appearance.md +123 -0
  15. package/skills/video-studio/references/audio-variation.md +74 -93
  16. package/skills/video-studio/references/audio.md +64 -66
  17. package/skills/video-studio/references/change-impact.md +5 -5
  18. package/skills/video-studio/references/{v08-quality.md → delivery-gates.md} +16 -18
  19. package/skills/video-studio/references/frame-qa.md +48 -16
  20. package/skills/video-studio/references/pipeline.md +4 -4
  21. package/skills/video-studio/references/pitfalls.md +22 -3
  22. package/skills/video-studio/references/proposal.md +160 -0
  23. package/skills/video-studio/references/quality-gates.md +11 -11
  24. package/skills/video-studio/references/scene-authoring.md +2 -2
  25. package/skills/video-studio/references/scene-grammar.md +40 -42
  26. package/skills/video-studio/references/sfx-design.md +8 -6
  27. package/skills/video-studio/references/web-engine.md +8 -8
  28. package/skills/video-studio/references/word-timeline.md +9 -9
  29. package/skills/video-studio/requirements.txt +9 -13
  30. package/skills/video-studio/scripts/designkit.py +2115 -0
  31. package/skills/video-studio/scripts/filmcheck.py +22 -48
  32. package/skills/video-studio/scripts/filmkit.py +2980 -2904
  33. package/skills/video-studio/scripts/gates.py +4 -4
  34. package/skills/video-studio/scripts/grammar.py +73 -13
  35. package/skills/video-studio/scripts/musicgen.py +2042 -0
  36. package/skills/video-studio/scripts/preflight.py +14 -7
  37. package/skills/video-studio/scripts/previewkit.py +848 -0
  38. package/skills/video-studio/scripts/propose.py +825 -0
  39. package/skills/video-studio/scripts/qa_frames.py +73 -39
  40. package/skills/video-studio/scripts/qaasr.py +26 -7
  41. package/skills/video-studio/scripts/qavmaf.py +89 -23
  42. package/skills/video-studio/scripts/render.py +545 -231
  43. package/skills/video-studio/scripts/scorekit.py +55 -1755
  44. package/skills/video-studio/scripts/selfcheck.py +815 -215
  45. package/skills/video-studio/scripts/sfxkit.py +27 -26
  46. package/skills/video-studio/scripts/stagewatch.py +24 -8
  47. package/skills/video-studio/scripts/stylekit.py +207 -888
  48. package/skills/video-studio/scripts/voicekit.py +508 -387
  49. package/skills/video-studio/scripts/webengine.py +71 -72
  50. package/tools/audio_similarity.py +64 -37
  51. package/tools/ci_check.py +20 -14
  52. package/tools/estimate.py +34 -29
  53. package/tools/golden_frames.py +72 -28
  54. package/tools/silhouette_qa.py +520 -168
  55. package/docs/demo-pil-sheet.png +0 -0
  56. package/docs/styles/demo-results.json +0 -76
  57. package/docs/styles/sheet-8-styles.png +0 -0
  58. package/docs/styles/sheet-ai.png +0 -0
  59. package/docs/styles/sheet-before-after.png +0 -0
  60. package/docs/styles/sheet-craft.png +0 -0
  61. package/docs/styles/sheet-night.png +0 -0
  62. package/skills/video-studio/assets/score_demo.json +0 -307
  63. package/skills/video-studio/references/style-packs.md +0 -283
@@ -3,12 +3,12 @@
3
3
 
4
4
  跑法:python selfcheck.py [-v]
5
5
 
6
- 检查的全是"曾经真的坏过"的点,不是泛泛的健康检查:
7
- 1 TTS 缓存必须校验文本(v0.1 只判文件存在 -> 改台词不生效)
8
- 2 sub_window 不能把长句字幕截断在 5.2s(v0.1 的硬钳)
9
- 3 loudness 必须能测到真峰(v0.1 的 ebur128 没开 peak -> 真峰门禁永不触发)
10
- 4 mux 默认不重编视频流(v0.1 二次编码)
11
- 5 FrameSink 尺寸不符必须报错(v0.1 静默 resize)
6
+ 检查的全是真实缺陷的回归点,不是泛泛的健康检查:
7
+ 1 TTS 缓存必须校验文本(只判文件存在 -> 改台词不生效)
8
+ 2 sub_window 不能把长句字幕截断在 5.2s(硬钳会让长句丢字)
9
+ 3 loudness 必须能测到真峰(ebur128 没开 peak -> 真峰门禁永不触发)
10
+ 4 mux 默认不重编视频流(二次编码会再压一遍画面)
11
+ 5 FrameSink 尺寸不符必须报错(静默 resize 会让成片与构图不符)
12
12
  6 字形自查能识别缺字(msyhbd 缺 ✓ 等)
13
13
  7 ASS 头必须声明 PlayRes,且 Format/Dialogue 字段数一致
14
14
  8 时间轴第一段 start 严格为 0
@@ -16,48 +16,63 @@
16
16
  10 qa_report 能查出字幕条数不匹配
17
17
  11 尾静音裁剪
18
18
  12 mux 音轨 48kHz
19
- 13 v0.1 调用签名兼容
19
+ 13 旧调用签名兼容
20
20
  14 qa 帧率校验
21
- 15 (v0.3)立体声总线:channels=2 形状正确、声像能量守恒
22
- 16 (v0.3)cue_time 三种写法都解析成绝对秒
23
- 17 (v0.3)CueBus 落盘 -> 读回 -> schema 正确(含未知类型不崩)
24
- 18 (v0.3)duck 真的压低了配乐(且不改变无音效处的电平)
25
- 19 (v0.3)mix_film 峰值不越界、时长精确、旁白优先
26
- 20 (v0.3)sfxkit 可用时:配方确定性 + 别名表能从 sfxkit 反查
27
- 21 (v0.3)scorekit 可用时:同 seed bit-identical + 时长精确
28
- 22 (v0.3)webengine 可用时:页面契约齐全(window.renderFrame/getCues/ready)
29
- 23 (v0.3)qa_frames 可用时:能检出注入的单帧闪烁
30
- 24 (v0.4.0)配乐来源:music.mode=off 不读上一轮 work/music.wav(模式判定回归)
31
- 25 (v0.5.0)风格层:8 套主题全部过对比度门禁,8 类题材能分出 >=6 种风格
32
- 26 (v0.5.0)legacy 兼容:没写 style 字段必须精确落回 Dm/120/seed7/单声线
33
- 27 (v0.5.0)内容指纹:同剧本稳定、改标点不换风格、换题材才换
34
- 28 (v0.5.0)声线计划:4 句样片 >=2 把声音,legacy 仍是单声线
35
- 29 (v0.5.0)字体族与主题字幕:换族换缓存键,浅色主题不画黑背板
36
- 30 (v0.6.0)门禁账本与签核:pass/fail/skipped 三档不许混,签核必须绑内容指纹
37
- 31 (v0.6.0)阶段新鲜度:改了输入必须报"过时",不许用旧产物静默出片
38
- 32 (v0.6.0)并行渲染主题序列化:JSON 往返后重解风格必须回到 tuple
39
- 33 (v0.7.0)音效跨片可区分:内容派生 seed 让跨片不同、legacy 逐样本不变
40
- 34 (v0.7.0)配乐/音效片内分离:duck 默认加深,配乐给音效让位
41
- 35 (v0.7.1)旁白优先:人声出现时背景必须再压、间隙恢复、人声电平不动
42
- 36 (v0.7.1)旁白优先默认值:配乐 -12 dB 基线 + 旁白侧链 6 dB(读 st_audio 源码)
43
- 37 (v0.7.1)旁白清晰度 SNR 兜底:背景天然太响时自动补压到 >=12 dB
44
- 38 (v0.7.1)无旁白时混音不受影响(voice_env/guard 不得空转改电平)
45
- 39 (v0.7.2)音频边界:极短旁白不崩、NaN/Inf 拒绝写盘、负起点与 seg=0 有守卫
46
- 40 (v0.7.2)QC 报告落点只有一个来源(--out 的目录,不许 accept 另算一套)
47
- 41 (v0.7.2)空门禁账本不许写成"通过"(没记录 != 通过)
48
- 42 (v0.7.2)单阶段产物归属:不许把别的 stage 写的文件算成自己的(假 stale)
49
- 43 (v0.7.2)theme_overrides 必须参与主题体检(否则能造出"看不清"的成片)
50
- 44 (v0.8.0)词级时间戳:规整(单调/裁剪/偏移)与 cue 词锚点解析
51
- 45 (v0.8.0)画幅规划:只允许 16:9 横屏下采样,竖屏/上采样/非法 fps 必须拒绝
52
- 46 (v0.8.0)金帧确定性:同一帧号两次渲染必须逐像素一致
53
- 47 (v0.8.0)依赖漂移体检:numpy/Pillow 主版本 + edge-tts 仍暴露 boundary 参数
54
- 48 (v0.8.0)批量清单解析:两种写法都认、上限卡死、坏条目在开跑前报错
55
- 49 (v0.8.0)TTS 后端可替换:注册/注销/未知后端的接口契约
56
- 50 (v0.8.0)web 风格载荷:style=None 时不得注入 __STYLE__(legacy 必须回落)
57
- 51 (v0.8.0)金帧回归:与 assets/golden_frames.json 的像素基线比对
21
+ 15 立体声总线:channels=2 形状正确、声像能量守恒
22
+ 16 cue_time 三种写法都解析成绝对秒
23
+ 17 CueBus 落盘 -> 读回 -> schema 正确(含未知类型不崩)
24
+ 18 duck 真的压低了配乐(且不改变无音效处的电平)
25
+ 19 mix_film 峰值不越界、时长精确、旁白优先
26
+ 20 sfxkit 可用时:配方确定性 + 别名表能从 sfxkit 反查
27
+ 21 scorekit 可用时:同 seed bit-identical + 时长精确
28
+ 22 webengine 可用时:页面契约齐全(window.renderFrame/getCues/ready)
29
+ 23 qa_frames 可用时:能检出注入的单帧闪烁
30
+ 24 配乐来源:music.mode=off 不读上一轮 work/music.wav(模式判定回归)
31
+ 25 风格层:每套采样主题全部过对比度门禁,8 类题材能分出 >=6 种风格
32
+ 26 legacy 已移除:不写 style 必须**报错并给迁移指引**(守的是"旧外观路径真的
33
+ 没了",而不是"精确落回某套老默认值")
34
+ 27 内容指纹:同剧本稳定、改标点不换风格、换题材才换
35
+ 28 声线计划:4 句样片 >=2 把声音,legacy 仍是单声线
36
+ 29 字体族与主题字幕:换族换缓存键,浅色主题不画黑背板
37
+ 30 门禁账本与签核:pass/fail/skipped 三档不许混,签核必须绑内容指纹
38
+ 31 阶段新鲜度:改了输入必须报"过时",不许用旧产物静默出片
39
+ 32 并行渲染主题序列化:JSON 往返后重解风格必须回到 tuple
40
+ 33 音效跨片可区分:内容派生 seed 让跨片不同、legacy 逐样本不变
41
+ 34 配乐/音效片内分离:duck 默认加深,配乐给音效让位
42
+ 35 旁白优先:人声出现时背景必须再压、间隙恢复、人声电平不动
43
+ 36 旁白优先默认值:配乐 -12 dB 基线 + 旁白侧链 6 dB(读 st_audio 源码)
44
+ 37 旁白清晰度 SNR 兜底:背景天然太响时自动补压到 >=12 dB
45
+ 38 无旁白时混音不受影响(voice_env/guard 不得空转改电平)
46
+ 39 音频边界:极短旁白不崩、NaN/Inf 拒绝写盘、负起点与 seg=0 有守卫
47
+ 40 QC 报告落点只有一个来源(--out 的目录,不许 accept 另算一套)
48
+ 41 空门禁账本不许写成"通过"(没记录 != 通过)
49
+ 42 单阶段产物归属:不许把别的 stage 写的文件算成自己的(假 stale)
50
+ 43 theme_overrides 必须参与主题体检(否则能造出"看不清"的成片)
51
+ 44 词级时间戳:规整(单调/裁剪/偏移)与 cue 词锚点解析
52
+ 45 画幅规划:只允许 16:9 横屏下采样,竖屏/上采样/非法 fps 必须拒绝
53
+ 46 金帧确定性:同一帧号两次渲染必须逐像素一致
54
+ 47 依赖漂移体检:numpy/Pillow 主版本 + edge-tts 仍暴露 boundary 参数
55
+ 48 批量清单解析:两种写法都认、上限卡死、坏条目在开跑前报错
56
+ 49 TTS 后端可替换:注册/注销/未知后端的接口契约
57
+ 50 web 风格载荷:style=None 时不得注入 __STYLE__(legacy 必须回落)
58
+ 51 金帧回归:与 assets/golden_frames.json 的像素基线比对
59
+ 52 场景语法:10 类构图分流、选型确定性、段长降级门
60
+ 53 视觉语言包:8 套结构签名齐全、过体检、彼此不是同一套
61
+ 54 场景类型单真值:grammar / filmcheck / scenes / schema 四处集合相等
62
+ 55 剪影可区分(G13):8 套风格两两之间构图骨架必须能区分
63
+ 56 设计 DSL:采样->校验->转计划全通;缺必填块必须报错(fail-closed);
64
+ 同 brief 两次采样一致;两两至少 2 维不同("伪多方案"门禁)
65
+ 57 零模板:仓库里不许存在 presets/ 与 presetkit.py;现场采样必须确定性、
66
+ 且换 brief 必须换结果(否则就是还在套模板)
67
+ 58 提案闸:absent / draft / broken 三档判定正确(confirmed 才放行出片)
68
+ 59 逐 stage 可单独跑:render 里每处 resolve_style 都必须拿得到 work
69
+ (只跑 --stage frames / --stage sfx 时缺参数会报"找不到设计",all 被缓存掩盖)
70
+ 60 brief 里的要求真的生效:自然语言要解析成 must_have/avoid,
71
+ 配色约束按色相窗口生效(早先整句被塞进 topic,"深蓝"采出来是橙色)
58
72
 
59
73
  说明:本文件里 CASES 的**实际条数**是唯一真理,上面的编号表要与它同步。
60
- v0.8.0 之前这张表停在 43 条而 CASES 已经有 51 条,属于"自检清单自己没被自检"。
74
+ 这张表落后过两次:停在 43 条而 CASES 已有 51 条、停在 51 条而 CASES 已有 58 条。
75
+ 改 CASES 时请同批改这张表,别让它再次落后。
61
76
  """
62
77
  import argparse
63
78
  import io
@@ -104,11 +119,37 @@ def run(name, fn):
104
119
  except AssertionError as e:
105
120
  RESULTS.append(("FAIL", name, str(e)))
106
121
  print(" FAIL %s -> %s" % (name, e))
122
+ except SystemExit as e:
123
+ # 被调代码用 SystemExit 报"用法错误"(例如 resolve_style 要求先提案)。
124
+ # 必须记 FAIL 而不是让自检直接退出 —— 早先 selfcheck 会在这里**静默中止**,
125
+ # 后面的用例一条都不跑,输出留在半截,很容易被当成"还在跑"。
126
+ RESULTS.append(("FAIL", name, "SystemExit: %s" % (e.code if str(e.code) != "None" else e)))
127
+ print(" FAIL %s -> SystemExit: %s" % (name, e))
107
128
  except Exception as e: # noqa: BLE001
108
129
  RESULTS.append(("FAIL", name, "%s: %s" % (type(e).__name__, e)))
109
130
  print(" FAIL %s -> %s: %s" % (name, type(e).__name__, e))
110
131
 
111
132
 
133
+ # 自检专用:造一份 design 计划。
134
+ # 删掉内置风格表后,"要一份 plan"这件事只能靠现场采样 + 转计划;
135
+ # 每个用例各写一遍既啰嗦又容易漂移,于是收到这里。
136
+ # 固定 seed 保证自检自身可复现(自检必须可复现,否则 CI 抖起来没法查)。
137
+ _PLAN_CACHE = {}
138
+
139
+
140
+ def _design_plan(topic="selfcheck 样例", seed=20260101):
141
+ key = (topic, seed)
142
+ if key not in _PLAN_CACHE:
143
+ import designkit as DK
144
+ d = DK.sample_designs({"topic": topic}, n=1, seed=seed)[0]
145
+ _PLAN_CACHE[key] = (d, DK.design_to_plan(d))
146
+ return _PLAN_CACHE[key]
147
+
148
+
149
+ def _sample_design(topic="selfcheck 样例", seed=20260101):
150
+ return _design_plan(topic, seed)[0]
151
+
152
+
112
153
  def _tone_wav(path, seconds=1.0, freq=440.0):
113
154
  import numpy as np
114
155
  n = int(seconds * K.SR)
@@ -297,7 +338,7 @@ def t_mux_48k():
297
338
 
298
339
 
299
340
  def t_compat():
300
- """v0.1 的调用签名必须还能用(升级不能把老项目直接炸掉)。"""
341
+ """旧调用签名必须还能用(升级不能把老项目直接炸掉)。"""
301
342
  a = K.tone(440, 0.2, kind="sine", harmonics=(1.0, 0.5))
302
343
  b = K.noise_burst(0.2, amp=0.1, lo=0.02, hi=0.35, decay=6.0, seed=7)
303
344
  assert len(a) > 0 and len(b) > 0, "兼容签名返回空"
@@ -309,7 +350,7 @@ def t_compat():
309
350
 
310
351
 
311
352
  def t_fps_check():
312
- """qa_report 必须能查出帧率不符(v0.2 之前只查宽高)。"""
353
+ """qa_report 必须能查出帧率不符(只查宽高会漏掉帧率写错)。"""
313
354
  with tempfile.TemporaryDirectory() as d:
314
355
  v = os.path.join(d, "v25.mp4")
315
356
  r = subprocess.run([K.FFMPEG, "-y", "-v", "error", "-f", "lavfi",
@@ -322,7 +363,7 @@ def t_fps_check():
322
363
  return "25fps 被检出"
323
364
 
324
365
 
325
- # ---------------------------------------------------------------- v0.3.0 新增
366
+ # ---------------------------------------------------------------- 立体声 / 配乐 / 音效
326
367
  def t_stereo_bus():
327
368
  """立体声总线:形状、声像、单声道来源自动展开。"""
328
369
  import numpy as np
@@ -411,9 +452,9 @@ def t_mix_film():
411
452
 
412
453
 
413
454
  def t_music_plan():
414
- """配乐来源判定:music.mode=off 不得读上一轮的 work/music.wav(v0.3.0 的回归)。
455
+ """配乐来源判定:music.mode=off 不得读上一轮的 work/music.wav。
415
456
 
416
- 背景:v0.3.0 的 st_audio 无条件读 work/music.wav,于是用户把 music.mode 改成 off
457
+ 背景:st_audio 若无条件读 work/music.wav,用户把 music.mode 改成 off
417
458
  之后,上一轮跑出来的旧配乐仍被混进成片(文档写的是 off = 不要配乐)。
418
459
  这里既测判定函数,也真的跑一次 st_audio 看输出电平。
419
460
  """
@@ -428,7 +469,7 @@ def t_music_plan():
428
469
  assert K.music_plan({"music": {"mode": "weird"}})[0] == "unknown-mode", "未知 mode 没报错(会静默当 auto)"
429
470
  assert K.music_plan({}, True)[0] == "file", "缺省时外部 music.wav 兼容链断了"
430
471
  assert K.music_plan({}, False)[0] == "none", "缺省且什么都没有时应判 none"
431
- assert K.music_plan({"music": {"chords": [[220.0, 261.6]]}}, False)[0] == "bed", "v0.2 和弦床兼容链断了"
472
+ assert K.music_plan({"music": {"chords": [[220.0, 261.6]]}}, False)[0] == "bed", "和弦床兼容链断了"
432
473
 
433
474
  # 2) 端到端:st_audio 在 mode=off 下不得混入 work/music.wav
434
475
  try:
@@ -451,13 +492,19 @@ def t_music_plan():
451
492
  K.wav_write(os.path.join(work, "music.wav"), np.stack([loud, loud], axis=1))
452
493
  buf = io.StringIO()
453
494
  with redirect_stdout(buf):
454
- off_out = render.st_audio(tl, work, {"music": {"mode": "off"}})
495
+ # D3 之后没有 design/style 的剧本会被拒(不再静默落 legacy),
496
+ # 这条用例测的是"off 不读旧配乐",与设计无关,显式给一个风格即可。
497
+ # D3 之后没有 design/style 的剧本会被拒(不再静默落 legacy),
498
+ # 这条用例测的是"off 不读旧配乐",与设计无关,给一份现场设计即可。
499
+ _d, _plan = _design_plan("配乐来源判定")
500
+ _script23 = {"title": "配乐来源", "_style": _plan}
501
+ off_out = render.st_audio(tl, work, dict(_script23, music={"mode": "off"}))
455
502
  off_peak = float(np.max(np.abs(K.wav_read(off_out)[0])))
456
- file_out = render.st_audio(tl, work, {"music": {"mode": "file"}})
503
+ file_out = render.st_audio(tl, work, dict(_script23, music={"mode": "file"}))
457
504
  file_peak = float(np.max(np.abs(K.wav_read(file_out)[0])))
458
505
  assert "music.mode=off" in buf.getvalue(), "off 没有打印说明(静默跳过也不行)"
459
506
  assert off_peak < 0.01, "music.mode=off 仍把旧 music.wav 混进来了(峰值 %.3f)" % off_peak
460
- # v0.7.1:断言改成"相对 off 明显变大"而不是绝对 0.3——
507
+ # 断言用"相对 off 明显变大"而不是绝对 0.3——
461
508
  # 配乐基线降到 -12 dB(旁白优先)后,0.8 幅度的外部配乐混出来约 0.2;
462
509
  # 绝对阈值会把"旁白优先调好了"判成"没读到外部配乐",这类断言会被调参牵着走。
463
510
  assert file_peak > 0.1 and file_peak > off_peak * 3.0, (
@@ -552,79 +599,89 @@ def t_qa_frames():
552
599
 
553
600
 
554
601
  def t_style_kits():
555
- """25 风格层:8 套主题过对比度门禁 + 自动选风格能把 8 类题材分开。"""
602
+ """25 连续配色空间:现场采样的每一套都必须过对比度门禁,
603
+ 且色相真的分散——这条是"没有模板"的硬证据。
604
+
605
+ 旧断言是"8 套内置主题全部过 lint + 自动选风格能分出 >=6 种"。模板删掉后那个断言
606
+ 失去对象,于是换成更强的:**连续空间采样 12 次,全部可读 + 色相覆盖 >= 180°**。
607
+ 只测"能采出来"不够 —— 全落在同一色相也能过,所以必须夹一条分布断言。
608
+ """
609
+ import designkit as DK
556
610
  import stylekit as ST
557
- bad = ST.lint_all()
558
- assert not bad, "内置主题没过对比度门禁: %s" % bad
559
- topics = {
560
- "tech": "AI 算法 模型 数据 架构 开源 编程 大模型 代码 系统",
561
- "report": "报告 复盘 年度 总结 研究 分析 调研 白皮书 趋势 发布",
562
- "craft": "手工 自然 历史 传统 木 田野 匠 古 茶 手艺 山河",
563
- "launch": "活动 上新 招募 挑战 年轻 潮流 种草 福利 开箱 限量",
564
- "truth": "观点 为什么 本质 真相 极简 反思 边界 定义 取舍",
565
- "story": "故事 记忆 城市 深夜 旅行 纪实 情绪 时代 变迁 命运",
566
- "night": "深夜 学习 效率 专注 写作 整理 笔记 书 日常 房间",
567
- "epic": "史诗 爆发 冲击 巅峰 决战 荣耀 震撼 传奇 极限 突破",
568
- }
569
- got = {}
570
- for key, text in topics.items():
571
- s = {"title": text, "style": "auto",
572
- "lines": [{"id": "l01", "kind": "hook", "text": text},
573
- {"id": "l02", "kind": "body", "text": text}]}
574
- got[key] = ST.resolve_script_style(s)["style"]
575
- assert len(set(got.values())) >= 6, "8 类题材只分出 %d 套风格: %s" % (len(set(got.values())), got)
576
- return "%d 套主题 + %d 类题材 -> %d 种风格" % (len(ST.STYLE_IDS), len(topics), len(set(got.values())))
611
+ designs = DK.sample_designs({"topic": "配色空间校验"}, n=12, seed=20260101)
612
+ assert len(designs) == 12, "采样返回 %d 套(要 12)" % len(designs)
613
+ hues, fails = [], []
614
+ for d in designs:
615
+ plan = DK.design_to_plan(d)
616
+ bad = ST.theme_lint(plan["theme"])
617
+ if bad:
618
+ fails.append("%s: %s" % (d["label"], bad[0][:50]))
619
+ h, _s, _v = ST.rgb_to_hsv(plan["theme"]["bg"])
620
+ hues.append(h)
621
+ assert not fails, "有设计过不了对比度门禁:%s" % ";".join(fails[:3])
622
+ span = max(hues) - min(hues)
623
+ if span < 180.0: # 跨 0° 的情况:取补集
624
+ span = 360.0 - span
625
+ assert span >= 180.0, ("12 套设计的底色谱相只覆盖 %.0f°(应 >=180°)——"
626
+ "说明配色并没有真的在连续空间里散开" % span)
627
+ # 配色必须是**连续**的,不是一份清单:断言"色相是连续量"而不是"落在 8 个点之一"。
628
+ # 做法:取 12 套的色相,检查它们不是某个固定集合的子集(容差 1°)。
629
+ # 早先这里断言的是 `len(PALETTE_FAMILIES) == len(_LEGACY_FAMILY_ANCHOR)` ——
630
+ # 而那两个名字是**同一个对象**,长度当然永远相等,等于什么也没验。
631
+ assert not DK.PALETTE_FAMILIES, "PALETTE_FAMILIES 必须为空(有内容=偷偷恢复了外观清单)"
632
+ rounded = sorted({round(h) for h in hues})
633
+ spread = len(rounded) / float(len(hues))
634
+ assert spread >= 0.8, ("12 套配色的色相只有 %d 个不同取值(%s)——"
635
+ "说明配色退化成了一份离散清单" % (len(rounded), rounded))
636
+ return "12 套现场配色全部过 lint;色相覆盖 %.0f°;%d/12 个不同色相" % (
637
+ span, len(rounded))
577
638
 
578
639
 
579
640
  def t_style_legacy():
580
- """26 legacy 兼容:没写 style 字段必须精确落回 v0.4 的配乐/旁白参数。"""
641
+ """26 legacy 已移除:不写 style 必须报错并给出迁移指引,而不是静默落老外观。
642
+
643
+ 这条盯的是"不写外观配置照样能出片"这条老思路真的没了:legacy 路径整个删掉,
644
+ 因为它是同质化的另一半根因(不写 style = 全片一套固定外观 + 120BPM/Dm)。
645
+ 断言分成两半:① 不给设计时必须**报错**且错误文本指得出下一步;
646
+ ② 显式给 style 也不可用(内置风格表已删,任何 style id 都必须落空报错)。
647
+ """
581
648
  import stylekit as ST
582
649
  s = {"title": "旧项目", "lines": [{"id": "a", "kind": "body", "text": "x"}]}
583
- p = ST.resolve_script_style(s)
584
- assert p["legacy"] is True, "没有 style 字段却没走 legacy"
585
- assert p["music"]["bpm"] == 120.0, "legacy BPM 应为 120,收到 %r" % (p["music"]["bpm"],)
586
- assert p["music"]["key"] == "Dm", "legacy 调性应为 Dm,收到 %r" % (p["music"]["key"],)
587
- assert p["music"]["seed_effective"] == 7, "legacy seed 应为 7(不做内容派生)"
588
- assert p["music"]["seed_from_content"] is False
589
- assert p["voice"]["map"] == {}, "legacy 不该有声线映射"
590
- assert p["voice"]["policy"]["jitter"] == 0.0 and p["voice"]["policy"]["auto"] is False
591
- # legacy 的节奏必须等于 render.py v0.4 的函数默认值,否则"没写 lead 的老剧本"会变节奏
592
- assert (p["pacing"]["lead"], p["pacing"]["tail"], p["pacing"]["min_dur"]) == (0.55, 0.85, 3.0), p["pacing"]
593
- # 显式 "legacy" 也必须是同一档
594
- s2 = dict(s, style="legacy")
595
- assert ST.resolve_script_style(s2)["legacy"] is True
596
- # 显式风格则必须真的换掉三件套
650
+ # ① 不给设计:必须报错,且错误文本指得出下一步
651
+ try:
652
+ ST.resolve_script_style(s)
653
+ except (ValueError, KeyError, SystemExit) as e:
654
+ msg = str(getattr(e, "code", None) or e)
655
+ assert "propose.py" in msg, "报错必须给出迁移指引(要提到 propose.py),实际:%r" % msg[:120]
656
+ assert "design" in msg.lower(), "报错要说清主路径是 design.json,实际:%r" % msg[:120]
657
+ else:
658
+ raise AssertionError("没有 style/design 却没报错:legacy 路径没有真的移除")
659
+ # ② 显式 style 也不可用——内置风格表整个删了,连带 STYLES 一起没了,
660
+ # 任何 style id 都必须落空并报错(否则就是"模板还在")。
597
661
  s3 = dict(s, style="cinema")
598
- p3 = ST.resolve_script_style(s3)
599
- assert p3["legacy"] is False and p3["music"]["bpm"] in ST.STYLES["cinema"]["music"]["bpm_ladder"]
600
- assert p3["music"]["key"] in ST.STYLES["cinema"]["music"]["keys"]
601
- return "bpm=%g key=%s seed=%d / cinema: bpm=%g key=%s" % (
602
- p["music"]["bpm"], p["music"]["key"], p["music"]["seed_effective"],
603
- p3["music"]["bpm"], p3["music"]["key"])
662
+ try:
663
+ ST.resolve_script_style(s3)
664
+ except (ValueError, KeyError, SystemExit) as e:
665
+ msg = str(getattr(e, "code", None) or e)
666
+ assert "模板" in msg or "design" in msg.lower() or "propose" in msg, "显式 style 报错也该给指引,实际:%r" % msg[:120]
667
+ else:
668
+ raise AssertionError("显式 style='cinema' 竟然还能解析出计划:内置风格表没删干净")
669
+ assert ST.STYLE_IDS == () and not ST.STYLES and not ST.THEMES, "内置风格/主题表必须为空,实际 STYLE_IDS=%r STYLES=%d THEMES=%d" % (
670
+ ST.STYLE_IDS, len(ST.STYLES), len(ST.THEMES))
671
+ return "无设计必报错并给迁移指引 / 显式 style 也被拒绝 / 三张模板表为空"
604
672
 
605
673
 
606
674
  def t_style_determinism():
607
675
  """27 指纹确定性:同剧本同结果;改错别字不换风格;改题材才换。"""
608
- import stylekit as ST
609
- base = {"title": "AI 大模型的三年", "style": "auto",
610
- "lines": [{"id": "l01", "kind": "hook", "text": "大模型改变了什么"},
611
- {"id": "l02", "kind": "body", "text": "算法和数据的规模一起上去了"}]}
612
- a = ST.resolve_script_style(base)
613
- b = ST.resolve_script_style(json.loads(json.dumps(base)))
614
- assert json.dumps(a, sort_keys=True, default=str) == json.dumps(b, sort_keys=True, default=str), \
615
- "同一剧本两次解析结果不同(不确定性)"
616
- typo = json.loads(json.dumps(base))
617
- typo["lines"][1]["text"] += "。"
618
- c = ST.resolve_script_style(typo)
619
- assert c["style"] == a["style"], "改一个标点就换了风格: %s -> %s" % (a["style"], c["style"])
620
- assert c["music"]["bpm"] == a["music"]["bpm"], "改一个标点就换了 BPM"
621
- assert c["fingerprint"]["full"] != a["fingerprint"]["full"], "full 指纹没变(内容派生失效)"
622
- other = {"title": "深夜学习指南", "style": "auto",
623
- "lines": [{"id": "l01", "kind": "hook", "text": "为什么深夜反而能专注"},
624
- {"id": "l02", "kind": "body", "text": "整理笔记,写作,阅读都更安静"}]}
625
- d = ST.resolve_script_style(other)
626
- assert d["style"] != a["style"], "换了一部片风格却相同: %s" % d["style"]
627
- return "%s -> %s(同一剧本稳定),换片 -> %s" % (a["style"], c["style"], d["style"])
676
+ import designkit as DK
677
+ # 没有"剧本 -> 自动选风格"了,这里验证"设计采样"的确定性与区分度。
678
+ # 固定 seed 才谈确定性:默认不给 seed 时每次都要不同(那是 56/57 条在守的事)。
679
+ a = DK.sample_designs({"topic": "AI 大模型的三年"}, n=1, seed=11)[0]
680
+ b = DK.sample_designs({"topic": "AI 大模型的三年"}, n=1, seed=11)[0]
681
+ assert DK.design_fingerprint(a) == DK.design_fingerprint(b), "同 seed 同 brief 采样不一致"
682
+ assert DK.design_fingerprint(a) != DK.design_fingerprint(
683
+ DK.sample_designs({"topic": "手工木作"}, n=1, seed=11)[0]), "换了题材设计却没变"
684
+ return "同 seed 可复现 + 换题材必变"
628
685
 
629
686
 
630
687
  def t_voice_plan():
@@ -633,44 +690,48 @@ def t_voice_plan():
633
690
  import voicekit as VK
634
691
  except Exception: # noqa: BLE001
635
692
  return "skip"
636
- import stylekit as ST
637
- s = {"title": "AI 大模型", "style": "auto",
693
+ import designkit as DK
694
+ s = {"title": "AI 大模型",
638
695
  "lines": [{"id": "l01", "kind": "hook", "text": "大模型改变了什么"},
639
696
  {"id": "l02", "kind": "body", "text": "算法和数据的规模一起上去了"},
640
697
  {"id": "l03", "kind": "quote", "text": "他说:这不可能"},
641
698
  {"id": "l04", "kind": "outro", "text": "它已经在我们身边了"}]}
642
- plan = ST.resolve_script_style(s)
699
+ # 声线计划同样只能从设计来(模板表已删)
700
+ plan = DK.design_to_plan(DK.sample_designs({"topic": "AI 大模型"}, n=1, seed=7)[0])
643
701
  vp = VK.voice_plan(s, plan)
644
702
  assert len(vp) == 4, "计划行数应为 4,收到 %d" % len(vp)
645
703
  assert json.dumps(vp, sort_keys=True, default=str) == json.dumps(
646
704
  VK.voice_plan(s, plan), sort_keys=True, default=str), "voice_plan 不确定"
647
- personas = {r["persona"] for r in vp}
648
- assert len(personas) >= 2, "4 句样片只用了一个声线: %s" % personas
705
+ # persona 身份表已删,声音身份的唯一表示是 edge voice id。
706
+ # 这里断言"至少 2 个不同的 voice id"——语义与旧 persona 表一致,字段换了。
707
+ voices = {r["voice"] for r in vp}
708
+ assert len(voices) >= 2, "4 句样片只用了一个声线: %s" % voices
649
709
  tones = {r["tone"] for r in vp}
650
710
  assert len(tones) >= 2, "语气档没有变化: %s" % tones
651
711
  for r in vp:
652
712
  for fld in ("voice", "rate", "pitch", "volume", "lead", "tail"):
653
713
  assert r.get(fld) not in (None, ""), "计划行缺 %s: %r" % (fld, r.get("id"))
654
- # legacy:单声线、body 语气、无抖动
655
- leg = {"title": "旧项目", "lines": [{"id": "a", "kind": "body", "text": "x"}]}
656
- lp = ST.resolve_script_style(leg)
657
- lvp = VK.voice_plan(leg, lp)
658
- assert len({r["voice"] for r in lvp}) == 1, "legacy 出现多声线"
659
- assert all(r["tone"] == "body" for r in lvp), "legacy 不该换语气档"
660
- return "%d 句 / %d 把声音 / %d 档语气" % (len(vp), len(personas), len(tones))
714
+ # 单句片:同样走 design(不再有 style="mono" 这种内置风格可选)
715
+ one = {"title": "单句片",
716
+ "lines": [{"id": "a", "kind": "body", "text": "一句话"}]}
717
+ op = DK.design_to_plan(DK.sample_designs({"topic": "单句片"}, n=1, seed=3)[0])
718
+ ovp = VK.voice_plan(one, op)
719
+ assert len(ovp) == 1, "单句片应只给一行计划,收到 %d" % len(ovp)
720
+ assert ovp[0]["voice"].endswith("Neural"), "声线应是 edge voice id:%r" % (ovp[0]["voice"],)
721
+ return "%d 句 / %d 把声音 / %d 档语气" % (len(vp), len(voices), len(tones))
661
722
 
662
723
 
663
724
  def t_font_family():
664
725
  """29 字体族 + 字幕主题:换族必须换缓存键,主题字幕不能是黑底白字。
665
726
 
666
727
  **别把"系统装了几族字体"当成产品缺陷**:CI 的 ubuntu 只装 fonts-noto-cjk,
667
- 四个族全回退到同一个 NotoSansCJK,宽度必然一样。v0.5.0 的第一版就在这里误报——
668
- 断言写成"宽度必须不同",于是 Linux CI 红、Windows 绿。
728
+ 四个族全回退到同一个 NotoSansCJK,宽度必然一样。断言若写成"宽度必须不同"就会误报——
729
+ Linux CI 红、Windows 绿。
669
730
  真正要保证的是**机制**:缓存按 family 分键(换族不会串味);
670
731
  宽度差异只在"系统确实解析出不同字体文件"时才有意义,单族系统跳过并说明。
671
732
  """
672
733
  fams = list(getattr(K, "FAMILY_IDS", ()))
673
- assert fams, "filmkit 没有 FONT_FAMILIES(v0.5 字体族没生效)"
734
+ assert fams, "filmkit 没有 FONT_FAMILIES(字体族没生效)"
674
735
  resolved = {}
675
736
  for fam in fams:
676
737
  f = K.font(40, "bold", fam)
@@ -704,11 +765,13 @@ def t_font_family():
704
765
  assert K.wrap_cn_cached("旧调用", 40, 500) is not None
705
766
  # 字幕主题:浅色主题不该画黑背板
706
767
  from PIL import Image
707
- try:
708
- import stylekit as ST
709
- th = ST.THEMES["magazine"]
710
- except Exception: # noqa: BLE001
711
- th = None
768
+ # 没有内置主题可借(THEMES 已清空),手写一份浅色主题。
769
+ # 这条断言测的是 draw_subtitle 的"浅底不画黑背板"逻辑,与主题从哪来无关。
770
+ th = {"bg": (247, 244, 238), "bg2": (233, 228, 218), "surface": (255, 255, 255),
771
+ "ink": (26, 24, 22), "muted": (110, 104, 96), "dim": (150, 146, 140),
772
+ "accent": (198, 96, 40), "accent2": (52, 96, 160),
773
+ "good": (46, 150, 92), "bad": (200, 60, 60), "rule": (208, 202, 192),
774
+ "id": "selfcheck-light", "label": "浅色测试"}
712
775
  if th is not None:
713
776
  img = Image.new("RGB", (K.W, K.H), th["bg"])
714
777
  K.draw_subtitle(img, "浅色主题字幕", theme=th)
@@ -722,7 +785,7 @@ def t_font_family():
722
785
  def t_gates():
723
786
  """30 门禁账本 / 签核 / QC 报告:三档状态必须能区分"没查"和"通过"。
724
787
 
725
- 这一条防的是 v0.6.0 自己最容易犯的错——把 skipped 混进 pass。
788
+ 这一条防的是最容易犯的错——把 skipped 混进 pass。
726
789
  用户看到的"质检通过"必须能区分"我查了 9 项"和"我只查了 3 项":
727
790
  前者是真知情,后者是假安全感。顺带验签核绑内容指纹:改了剧本旧签核必须失效。
728
791
  """
@@ -770,7 +833,7 @@ def t_gates():
770
833
  def t_stagewatch():
771
834
  """31 阶段新鲜度:改上游 -> 下游必须报过时;首跑不刷噪声;产物丢失要报。
772
835
 
773
- 这一条防的是 v0.6.0 前的老问题:frames 有分块指纹,其余 stage 全是裸奔
836
+ 这一条防的是:frames 有分块指纹,其余 stage 全是裸奔
774
837
  (改 style 后 audio 仍读旧 music.wav、改 hold 后 frames 仍用旧 cues.json,都不报错)。
775
838
  """
776
839
  import tempfile
@@ -806,7 +869,7 @@ def t_stagewatch():
806
869
  errs_strict, _ = SW.report(w, ["tts"], strict=True, write=lambda lv, m: None)
807
870
  assert errs_strict, "--strict-stale 没有让过时变成失败"
808
871
  # **源头输入**(剧本 / scenes.py)改了但没重跑 -> 必须报 source-changed。
809
- # 这条是 v0.6.0 补的洞:早期只跟踪 stage 之间的产物,"改了台词没重跑 tts" 查不出来,
872
+ # 这条守的是:只跟踪 stage 之间的产物时,"改了台词没重跑 tts" 查不出来,
810
873
  # 而那正是最需要报警的场景(旧 tts 配新剧本 = 配音字幕全错位)。
811
874
  w2 = tempfile.mkdtemp(prefix="sc_sw2_")
812
875
  film = os.path.join(w2, "film.json")
@@ -822,7 +885,7 @@ def t_stagewatch():
822
885
  open(film, "w", encoding="utf-8").write("{\"title\":\"b\"}") # 改剧本
823
886
  issues = [i for r in SW.explain(w2, ["tts"], src) for i in r["issues"]]
824
887
  assert any(i["kind"] == "source-changed" for i in issues), (
825
- "改了剧本却没报过时(这正是 v0.6.0 要堵的洞):%s" % issues)
888
+ "改了剧本却没报过时(这正是阶段新鲜度要堵的洞):%s" % issues)
826
889
  assert any("film.json" in i["reason"] for i in issues), issues
827
890
  # 坏 manifest 不许崩(用户手改坏一个 json 不该让整片跑不动)
828
891
  open(os.path.join(w, "manifest.json"), "w", encoding="utf-8").write("{broken")
@@ -831,7 +894,7 @@ def t_stagewatch():
831
894
 
832
895
 
833
896
  def t_parallel_frames():
834
- """32 --jobs >1 的并行路径能真的跑(v0.6.0 修的 pre-existing bug)。
897
+ """32 --jobs >1 的并行路径能真的跑(pre-existing bug 的回归)。
835
898
 
836
899
  bug 形状:worker 从 _script_snapshot.json 读剧本,JSON 把主题色元组变成 list,
837
900
  scenes._bg() 拿它当缓存键 -> TypeError: unhashable type: "list",
@@ -841,8 +904,9 @@ def t_parallel_frames():
841
904
  """
842
905
  import json as _json
843
906
  import tempfile
844
- import stylekit as ST
845
- th = dict(ST.THEMES["tech-deep"])
907
+ # 没有内置主题可借,用现场设计的主题(颜色同样是 (r,g,b) 元组)
908
+ _d, _plan0 = _design_plan("并行渲染主题序列化")
909
+ th = dict(_plan0["theme"])
846
910
  # ① 防御层:scenes._hashable 把 list 冻结成 tuple
847
911
  scenes = _load_scenes_mod()
848
912
  if scenes is not None and hasattr(scenes, "_hashable"):
@@ -854,18 +918,29 @@ def t_parallel_frames():
854
918
  assert isinstance(round_trip["bg"], list), "前提变了:JSON 居然保住了 tuple"
855
919
  w = tempfile.mkdtemp(prefix="sc_par_")
856
920
  snap = os.path.join(w, "snap.json")
857
- script = {"title": "t", "style": "tech-deep", "lines": [{"text": "x"}]}
858
- script["_style"] = ST.resolve_script_style(script)
921
+ script = {"title": "t", "lines": [{"text": "x"}]}
922
+ script["_style"] = _plan0
859
923
  with open(snap, "w", encoding="utf-8") as fh:
860
924
  _json.dump(script, fh, ensure_ascii=False)
861
925
  back = _json.load(open(snap, encoding="utf-8"))
862
926
  assert isinstance(back["_style"]["theme"]["bg"], list), "前提变了"
863
- # 重解风格(render.resolve_style 的纯函数部分):必须回到 tuple
864
- again = ST.resolve_script_style(back)
865
- assert isinstance(again["theme"]["bg"], tuple), (
866
- "--jobs >1 时主题色仍是 list,_bg() 会 TypeError(这正是被修的 bug):%r"
867
- % (again["theme"]["bg"],))
868
- return "主题标量可哈希 + 反序列化后重解回 tuple"
927
+ # 子进程路径(worker 必须从 work/design.json 重解设计,而不是回落 stylekit)。
928
+ # 现在直接验那条路径:把 design.json 放进 work/,resolve_style 必须解出**同一个**设计,
929
+ # 且颜色回到 tuple(list 会让 _bg() 的缓存键不可哈希)。
930
+ import designkit as DK
931
+ import render as R
932
+ dpath = os.path.join(w, "design.json")
933
+ with open(dpath, "w", encoding="utf-8") as fh:
934
+ _json.dump(_sample_design("并行渲染主题序列化"), fh, ensure_ascii=False)
935
+ sub_script = {"title": "t", "lines": [{"text": "x"}]}
936
+ got = R.resolve_style(sub_script, w, verbose=False)
937
+ assert got.get("style", "").startswith("design:"), \
938
+ "子进程重解没有走 design.json(会画出另一部片):%r" % (got.get("style"),)
939
+ assert isinstance(got["theme"]["bg"], tuple), (
940
+ "重解后主题色仍是 list,_bg() 会 TypeError(这正是被修的 bug):%r"
941
+ % (got["theme"]["bg"],))
942
+ assert got["theme"]["bg"] == th["bg"], "重解出的主题与父进程不一致(并行会画出不同的片)"
943
+ return "主题可哈希 + JSON 往返 + 按 design.json 重解一致"
869
944
 
870
945
 
871
946
  def _load_scenes_mod():
@@ -884,9 +959,9 @@ def _load_scenes_mod():
884
959
  return None
885
960
 
886
961
  def t_sfx_content_seed():
887
- """v0.7:音效 seed 必须随内容变化,但 legacy 路径必须逐样本不变。
962
+ """音效 seed 必须随内容变化,但 legacy 路径必须逐样本不变。
888
963
 
889
- - 不传 style/content_fp -> 两次渲染逐样本相同(v0.4 兼容,不破老片);
964
+ - 不传 style/content_fp -> 两次渲染逐样本相同(legacy 兼容,不破老片);
890
965
  - 传了不同 content_fp -> 必须不同(否则跨片音效还是"都一样");
891
966
  - 同一 content_fp -> 逐样本相同(可复现,是程序化视频的底线)。
892
967
  """
@@ -904,7 +979,7 @@ def t_sfx_content_seed():
904
979
  legacy_a, legacy_b = build(), build()
905
980
  except Exception: # noqa: BLE001
906
981
  return "skip" # sfxkit 不可用
907
- assert np.array_equal(legacy_a, legacy_b), "legacy 两次渲染不一致(v0.4 兼容被破坏)"
982
+ assert np.array_equal(legacy_a, legacy_b), "legacy 两次渲染不一致(逐样本兼容被破坏)"
908
983
  a = build(style="tech-deep", content_fp="aaaa1111", key="Dm")
909
984
  b = build(style="tech-deep", content_fp="bbbb2222", key="Dm")
910
985
  assert not np.array_equal(a, b), "不同内容指纹得到相同音效轨:跨片音效仍一模一样"
@@ -914,10 +989,10 @@ def t_sfx_content_seed():
914
989
 
915
990
 
916
991
  def t_audio_separation():
917
- """v0.7:混音侧 duck 默认必须加深(片内配乐给音效让位)。
992
+ """混音侧 duck 默认必须加深(片内配乐给音效让位)。
918
993
 
919
994
  直接读 render.py 的常量文本而不是跑全链:这条断言盯的是"默认值没被改回去"
920
- (v0.4 的 3.0 dB 在段落过门时配乐几乎和音效等高,是"听起来像同一套"的成因之一)。
995
+ (3.0 dB 这类浅值在段落过门时配乐几乎和音效等高,是"听起来像同一套"的成因之一)。
921
996
  """
922
997
  import re
923
998
  path = os.path.join(HERE, "render.py")
@@ -925,7 +1000,7 @@ def t_audio_separation():
925
1000
  m = re.search(r"duck_default\s*=\s*([0-9.]+)", src)
926
1001
  assert m, "render.py 里找不到 duck_default"
927
1002
  base = float(m.group(1))
928
- assert base >= 3.5, "duck_default=%.1f dB 太浅(v0.7 要求 >= 3.5)" % base
1003
+ assert base >= 3.5, "duck_default=%.1f dB 太浅(要求 >= 3.5)" % base
929
1004
  for sid, want in (("mono", 3.0), ("cinema", 5.5), ("epic", 5.5)):
930
1005
  mm = re.search(r'"%s"\s*:\s*([0-9.]+)' % sid, src)
931
1006
  assert mm, "render.py 里找不到风格 %s 的 duck 值" % sid
@@ -934,7 +1009,7 @@ def t_audio_separation():
934
1009
 
935
1010
 
936
1011
  def t_voice_priority():
937
- """v0.7.1 旁白优先:人声出现时背景必须再压,人声间隙背景恢复。
1012
+ """旁白优先:人声出现时背景必须再压,人声间隙背景恢复。
938
1013
 
939
1014
  以前配乐基线只比旁白低 1.5 dB,视频以旁白为主时观众要费力分辨字。
940
1015
  修法:`mix_film` 用旁白包络做侧链——人声处配乐 -6 dB、音效 -3 dB,间隙回原电平。
@@ -972,7 +1047,7 @@ def t_voice_priority():
972
1047
 
973
1048
 
974
1049
  def t_music_gain_default():
975
- """v0.7.1:配乐默认增益必须是 -12 dB(beside 人声),不是旧版的 -1.5。
1050
+ """配乐默认增益必须是 -12 dB(beside 人声),不是 -1.5。
976
1051
 
977
1052
  这条盯的是 `render.st_audio` 的默认值:`mus.get("gain_db", -12.0)`。
978
1053
  直接读源码文本,避免"跑全链才知道默认值"。
@@ -984,7 +1059,7 @@ def t_music_gain_default():
984
1059
 
985
1060
 
986
1061
  def t_snr_guard():
987
- """v0.7.1 SNR 兜底:背景天然太响时,混音后必须自己把它压到"人声听得清"。
1062
+ """SNR 兜底:背景天然太响时,混音后必须自己把它压到"人声听得清"。
988
1063
 
989
1064
  构造一段人声 + 一段刻意很响的配乐(比人声高 10 dB),不设侧链、只靠 guard:
990
1065
  `mix_film(guard_snr_db=12)` 后实测人声活跃区的 人声/背景 必须 >= 12 dB,
@@ -1021,11 +1096,11 @@ def t_mix_no_voice():
1021
1096
  assert abs(float(np.max(np.abs(out))) - 0.2) < 1e-5, "无旁白时配乐被改动了(峰值 %.3f)" % float(np.max(np.abs(out)))
1022
1097
  return "无旁白时背景不被压"
1023
1098
 
1024
- # ------------------------------------------------------------------ v0.7.2 新增(全项目深审)
1099
+ # ------------------------------------------------------------------ 音频入口边界
1025
1100
  def t_audio_edge_inputs():
1026
1101
  """39 音频入口的边界:极短旁白不能崩、NaN/Inf 必须拒绝、seg=0 不许死循环。
1027
1102
 
1028
- 这几条都是"真跑一次就会遇到"的输入。v0.7.1 及以前的行为:
1103
+ 这几条都是"真跑一次就会遇到"的输入。没有守卫时的行为:
1029
1104
  * voice_env 在极短音频上 np.convolve(mode="same") 返回核长 -> np.maximum 广播失败;
1030
1105
  * duck_voice 在"旁白比背景短"时包络与背景长度不同 -> 广播失败;
1031
1106
  * wav_write 对 NaN 做 clip 再 astype(int16),把 NaN 静默写成 0(写出损坏 WAV 却不报错);
@@ -1066,7 +1141,7 @@ def t_audio_edge_inputs():
1066
1141
  def t_report_single_source():
1067
1142
  """40 QC 报告落点只能有一个来源:--out 的目录。
1068
1143
 
1069
- v0.7.2 修的真 bug:all/mux/qa 用 dirname(abspath(out)),accept 用
1144
+ 真 bug:all/mux/qa 用 dirname(abspath(out)),accept 用
1070
1145
  dirname(abspath(work))/out。--out 指到 deliver/ 时,签核更新的是另一份没人
1071
1146
  交付的文件,交付出去的那份仍是"未签核"——正好打穿"报告是交付凭据"这条承诺。
1072
1147
  """
@@ -1108,7 +1183,7 @@ def t_empty_ledger_not_pass():
1108
1183
  def t_stage_io_no_phantom_output():
1109
1184
  """42 单阶段连跑不许报"自己的产物不见了"(假 stale)。
1110
1185
 
1111
- v0.7.2 修:stagewatch 的 STAGE_IO[style].outputs 里把 voice_plan.json 也算成
1186
+ stagewatch 的 STAGE_IO[style].outputs 里把 voice_plan.json 也算成
1112
1187
  style 的产物,而它其实是 tts 阶段写的(render.py 的 st_tts)。于是 --stage style
1113
1188
  连跑两次,第二次必然报"产物 voice_plan.json 不见了";打开 --strict-stale 就变成
1114
1189
  硬失败——SKILL.md 第 3 步(全新项目第一条生产命令)自己走不通。
@@ -1132,27 +1207,42 @@ def t_stage_io_no_phantom_output():
1132
1207
  def t_theme_overrides_linted():
1133
1208
  """43 theme_overrides 必须参与主题体检(否则用户能造出"看不清"的成片)。
1134
1209
 
1135
- v0.7.2 修的真 bug:render.resolve_style 以前只体检**基础主题**
1210
+ 真 bug:render.resolve_style 以前只体检**基础主题**
1136
1211
  (ST.THEMES[theme_id]),而 scenes 实际用的是 plan[theme](基础主题 + film.json 的
1137
1212
  visual.theme_overrides)。于是把 ink/bg 调成低对比度时体检照样 PASS,渲完才发现字幕看不清。
1138
1213
  实测 overrides ink=[30,30,30]/bg=[10,10,10]:基础主题 lint 为空,最终主题 lint 报对比度 1.09。
1139
1214
  """
1140
1215
  import stylekit as ST
1141
- base = {'title': 'x', 'style': 'auto',
1142
- 'lines': [{'id': 'l01', 'kind': 'body', 'text': 'y'}]}
1143
- p = ST.resolve_script_style(dict(base, visual={'theme_overrides': {
1144
- 'ink': [30, 30, 30], 'bg': [10, 10, 10]}}))
1145
- assert ST.theme_lint(ST.THEMES[p['theme_id']]) == [], \
1146
- "前提变了:基础主题本身就有 lint 问题,这条断言失去意义"
1147
- bad = ST.theme_lint(p['theme'])
1216
+ # 没有"基础主题 vs 最终主题"的区分了(内置主题表已删),
1217
+ # 但"overrides 之后必须重新 lint"这条规则仍然要守:
1218
+ # 直接把设计主题改成低对比度,theme_lint 必须抓到。
1219
+ _d, _plan43 = _design_plan("theme_overrides 体检")
1220
+ base_th = _plan43["theme"]
1221
+ assert ST.theme_lint(base_th) == [], \
1222
+ "前提变了:设计主题本身就有 lint 问题,这条断言失去意义"
1223
+ dirty = ST.apply_theme_overrides(base_th, {"ink": [30, 30, 30], "bg": [10, 10, 10]})
1224
+ bad = ST.theme_lint(dirty)
1148
1225
  assert bad, '低对比度的 theme_overrides 没被 lint 抓到(用户能造出看不清的字幕)'
1149
- src = open(os.path.join(HERE, "render.py"), encoding="utf-8").read()
1150
- assert "ST.theme_lint(plan.get('theme')" in src or 'ST.theme_lint(plan.get("theme")' in src, \
1151
- "render.resolve_style 仍在体检基础主题而不是最终主题"
1226
+ # 体检的位置在 designkit(design_to_plan 里就 lint,不过直接抛)。
1227
+ # 这里改查**真正干活的地方**——早先查 render.py 的源码文本,那只是"哪个文件里写了这行",
1228
+ # 一旦重构搬家就会误报(本次就是这样:lint 逻辑搬进 designkit 后断言还在查 render)。
1229
+ # 更硬的检查:直接把一份低对比度主题喂给 design_to_plan,必须抛。
1230
+ import designkit as DK
1231
+ dirty_design = json.loads(json.dumps(_sample_design("theme_overrides 体检")))
1232
+ dirty_design["visual"]["palette"]["ink"] = [30, 30, 30]
1233
+ dirty_design["visual"]["palette"]["bg"] = [10, 10, 10]
1234
+ try:
1235
+ DK.design_to_plan(dirty_design)
1236
+ except (ValueError, KeyError, SystemExit) as e:
1237
+ msg = str(getattr(e, "code", None) or e)
1238
+ assert "对比度" in msg or "lint" in msg.lower(), \
1239
+ "低对比度设计被拒了,但错误信息没说是对比度问题:%r" % msg[:120]
1240
+ else:
1241
+ raise AssertionError("低对比度主题竟然通过了 design_to_plan(体检失效,能造出看不清的字幕)")
1152
1242
  return "最终主题参与体检(%s)" % ";".join(bad)[:60]
1153
1243
 
1154
1244
 
1155
- # ------------------------------------------------------------------ v0.8.0 用例
1245
+ # ------------------------------------------------------------------ 词级时间戳 / 画幅 / 依赖 / 批量
1156
1246
  def t_word_events():
1157
1247
  """44 词级时间戳:规整/裁剪平移/单调兜底/词锚点解析(不联网)。
1158
1248
 
@@ -1227,12 +1317,9 @@ def t_golden_determinism():
1227
1317
  import hashlib
1228
1318
  sc = dict(id="l01", kind="hook", start=0.0, dur=4.0, chapter="01 · 测试",
1229
1319
  text="金帧确定性自检", sub="金帧确定性", big="金帧确定性")
1320
+ # 剧本必须显式给设计(内置风格表已删,没有"style": "mono" 这种写法了)。
1230
1321
  script = {"title": "selfcheck", "_total": 8.0}
1231
- try:
1232
- plan = __import__("stylekit").resolve_script_style(dict(script, lines=[sc]))
1233
- script["_style"] = plan
1234
- except Exception: # noqa: BLE001
1235
- pass
1322
+ script["_style"] = _design_plan("金帧确定性")[1]
1236
1323
  hs = []
1237
1324
  for _ in range(2):
1238
1325
  fr = mod.draw_frame(sc, 1.25, 4.0, 1.25, script, 37)
@@ -1268,7 +1355,7 @@ def t_dependency_drift():
1268
1355
  np.__version__, pil_ver, getattr(edge_tts, "__version__", "?"))
1269
1356
 
1270
1357
 
1271
- # ------------------------------------------------------------------ v0.8.0 用例(续)
1358
+ # ------------------------------------------------------------------ web 载荷 / 金帧
1272
1359
  def t_batch_manifest():
1273
1360
  """48 批量清单解析:两种写法都认、上限卡死、坏条目在**开跑前**报错。
1274
1361
 
@@ -1342,26 +1429,31 @@ def t_tts_backend():
1342
1429
  def t_web_style_payload():
1343
1430
  """50 web 引擎风格载荷:非 legacy 才注入、legacy 必须回落 None(逐字节兼容的前提)。
1344
1431
 
1345
- v0.8 给 web 引擎加了"跟随风格包",但兼容性要求是 style=None 时页面输出**逐字节**
1346
- 等于 v0.7。这条守住"什么时候该注入、什么时候必须不注入"这个开关。
1432
+ web 引擎会"跟随风格包",但兼容性要求是 style=None 时页面输出**逐字节**
1433
+ 等于不带载荷的旧输出。这条守住"什么时候该注入、什么时候必须不注入"这个开关。
1347
1434
  """
1348
1435
  import render as R
1349
1436
  try:
1350
1437
  import webengine as we
1351
1438
  except Exception as e: # noqa: BLE001
1352
1439
  return "skip(没有 webengine.py:%s)" % e
1353
- script = {"title": "x", "style": "cinema",
1354
- "lines": [{"id": "l01", "kind": "hook", "text": "y"}]}
1440
+ # 没有 legacy 概念了(legacy 入口已被拒绝),所以这里只验"设计项目必须注入载荷"。
1441
+ script = {"title": "x", "lines": [{"id": "l01", "kind": "hook", "text": "y"}]}
1442
+ script["_style"] = _design_plan("web 载荷")[1]
1355
1443
  tl = {"fps": 30, "video": {"out_w": 1280, "out_h": 720}}
1356
- payload = R._web_style_payload(we, script, tl)
1444
+ try:
1445
+ payload = R._web_style_payload(we, script, tl)
1446
+ except SystemExit as e:
1447
+ raise AssertionError("有 _style 却被当成没有设计:%s" % (e,)) from e
1357
1448
  assert payload is not None, "非 legacy 项目没有生成 style 载荷(页面不会跟随风格)"
1358
1449
  canvas = payload.get("canvas") or {}
1359
1450
  assert int(canvas.get("w") or 0) == 1280 and int(canvas.get("h") or 0) == 720, \
1360
1451
  "画布尺寸没跟着 video 块走:%r" % (canvas,)
1361
- legacy = {"title": "x", "lines": [{"id": "l01", "kind": "hook", "text": "y"}]}
1362
- assert R._web_style_payload(we, legacy, tl) is None, \
1363
- "legacy 项目也注入了 style(v0.7 的逐字节兼容会被打破)"
1364
- return "非 legacy 注入 %dx%d / legacy 回落 None" % (canvas["w"], canvas["h"])
1452
+ # 没有设计的剧本:必须回落 None(不是"随便注入一套默认风格")
1453
+ bare = {"title": "x", "lines": [{"id": "l01", "kind": "hook", "text": "y"}]}
1454
+ assert R._web_style_payload(we, bare, tl) is None, \
1455
+ "没有设计的剧本也注入了 style 载荷(等于凭空套一套外观)"
1456
+ return "有设计注入 %dx%d / 无设计回落 None" % (canvas["w"], canvas["h"])
1365
1457
 
1366
1458
 
1367
1459
  def t_golden_frames():
@@ -1408,7 +1500,7 @@ def t_golden_frames():
1408
1500
 
1409
1501
 
1410
1502
  # ============================================================================
1411
- # v0.9:场景语法 + 视觉语言
1503
+ # 场景语法 + 视觉语言
1412
1504
  # ============================================================================
1413
1505
 
1414
1506
  def _load_grammar():
@@ -1440,7 +1532,7 @@ def _fake_scenes(G, lines, per=6.0):
1440
1532
  def t_scene_grammar():
1441
1533
  """52 场景语法:10 类都能被选中、选型确定、段长门会降级。
1442
1534
 
1443
- 为什么要有这条:v0.9 之前 quote/emphasis/calm 三种 kind 全部落到 body 绘制器,
1535
+ 为什么要有这条:quote/emphasis/calm 三种 kind 全都落到 body 绘制器的话,
1444
1536
  画面永远只有一套骨架。这条断言盯的是"内容 -> 构图"这条链路真的在分流,
1445
1537
  而不是"代码里写了 10 个函数但没人调用"。
1446
1538
  """
@@ -1496,31 +1588,32 @@ def t_scene_grammar():
1496
1588
  def t_visual_languages():
1497
1589
  """53 视觉语言包:8 套结构签名齐全、过体检、且彼此不是同一套。
1498
1590
 
1499
- 为什么要有这条:v0.5 的"风格"只改配色,8 套风格骨架完全一样(用户抱怨的根因)。
1591
+ 为什么要有这条:只改配色的"风格"会让 8 套风格骨架完全一样(用户抱怨的根因)。
1500
1592
  这条盯的是"结构签名真的存在且互不相同"——母题/转场/重心偏移任一维度相同不算问题,
1501
1593
  但**五组签名全同**就说明这套语言只是复制粘贴。
1502
1594
  """
1595
+ import designkit as DK
1503
1596
  import stylekit as ST
1504
- if not hasattr(ST, "VISUAL_LANGUAGES"):
1505
- return "skip(stylekit 没有 VISUAL_LANGUAGES)"
1506
- bad = ST.visual_lint_all()
1507
- assert not bad, "内置视觉语言没过体检: %s" % bad
1508
- sigs = {}
1509
- for sid in ST.STYLE_IDS:
1510
- vl = ST.VISUAL_LANGUAGES[sid]
1597
+ # 没有 8 套内置语言了。验"现场生成的语言",而且断言更强:
1598
+ # 12 个设计的两两结构签名必须互不相同(以前只要求 8 套里 >=6 种母题)。
1599
+ sigs, motifs, transes = {}, set(), set()
1600
+ designs = DK.sample_designs({"topic": "视觉语言多样性"}, n=12, seed=20260202)
1601
+ for d in designs:
1602
+ plan = DK.design_to_plan(d)
1603
+ vl = plan["language"]
1604
+ bad = ST.visual_lint_language(vl)
1605
+ assert not bad, "%s 的语言包没过体检:%s" % (d["label"], bad[:2])
1511
1606
  key = (str((vl.get("motif") or {}).get("kind")),
1512
1607
  str((vl.get("transition") or {}).get("kind")),
1513
1608
  tuple(sorted((vl.get("bias") or {}).items())))
1514
- assert vl.get("motion") and vl.get("typography"), "%s 缺 motion/typography 签名" % sid
1515
- sigs.setdefault(key, []).append(sid)
1609
+ sigs.setdefault(key, []).append(d["label"])
1610
+ motifs.add(str((vl.get("motif") or {}).get("kind")))
1611
+ transes.add(str((vl.get("transition") or {}).get("kind")))
1516
1612
  dup = [v for v in sigs.values() if len(v) > 1]
1517
- assert not dup, "这些风格的母题/转场/重心完全相同(等于没做结构差异): %s" % (dup,)
1518
- motifs = {str((ST.VISUAL_LANGUAGES[s].get("motif") or {}).get("kind")) for s in ST.STYLE_IDS}
1519
- assert len(motifs) >= 6, "8 套风格只用了 %d 种装饰母题:%r" % (len(motifs), sorted(motifs))
1520
- return "8 套 / %d 种母题 / %d 种转场 / 无重复签名" % (
1521
- len(motifs),
1522
- len({str((ST.VISUAL_LANGUAGES[s].get("transition") or {}).get("kind"))
1523
- for s in ST.STYLE_IDS}))
1613
+ assert not dup, "这些设计语言签名完全相同(等于只在换色): %s" % (dup[:2],)
1614
+ assert len(motifs) >= 6, "12 个设计只用了 %d 种装饰母题:%r" % (len(motifs), sorted(motifs))
1615
+ return "12 个设计 / %d 种母题 / %d 种转场 / 无重复签名" % (
1616
+ len(motifs), len(transes))
1524
1617
 
1525
1618
 
1526
1619
  def t_scene_types_single_truth():
@@ -1569,7 +1662,7 @@ def t_scene_types_single_truth():
1569
1662
  def t_silhouette_gate():
1570
1663
  """55 剪影可区分(G13):8 套风格两两之间构图骨架必须能区分。
1571
1664
 
1572
- 这是 v0.9 的核心验收:如果这条挂了,说明"换风格只是换色"的毛病回来了。
1665
+ 这是核心验收:如果这条挂了,说明"换风格只是换色"的毛病回来了。
1573
1666
  工具在 tools/silhouette_qa.py(可选):缺了 skip,不阻塞 CI。
1574
1667
  """
1575
1668
  root = os.path.dirname(os.path.dirname(os.path.dirname(HERE)))
@@ -1612,6 +1705,499 @@ def t_silhouette_gate():
1612
1705
  len(pairs), same_ok if same_ok is not None else "?", same_n if same_n else "?")
1613
1706
 
1614
1707
 
1708
+ def t_design_dsl():
1709
+ """56 设计 DSL:采样 -> 校验 -> 转 plan,且 fail-closed(坏设计必须报错)。"""
1710
+ try:
1711
+ import designkit as DK
1712
+ except Exception: # noqa: BLE001
1713
+ return "skip(没有 designkit.py)"
1714
+ ds = DK.sample_designs({"topic": "selfcheck 设计 DSL"}, n=3)
1715
+ assert len(ds) == 3, "采样器只给了 %d 个候选" % len(ds)
1716
+ for d in ds:
1717
+ bad = DK.validate_design(d)
1718
+ assert not bad, "采样器吐出了不合格的设计 %r:%s" % (d.get("id"), bad)
1719
+ plan = DK.design_to_plan(d)
1720
+ assert plan["legacy"] is False, "design 计划不该标 legacy"
1721
+ assert str(plan["style"]).startswith("design:"), "style 应是 design:<id>:%r" % plan["style"]
1722
+ assert len(plan.get("theme") or {}) >= 30, "主题字段太少:%d" % len(plan.get("theme") or {})
1723
+ # 两两必须至少 2 个维度不同("伪多方案"门禁)
1724
+ for i in range(len(ds)):
1725
+ for j in range(i + 1, len(ds)):
1726
+ d = DK.design_distance(ds[i], ds[j])
1727
+ assert d["n"] >= 2, "候选 %s 与 %s 只差 %d 维" % (ds[i]["id"], ds[j]["id"], d["n"])
1728
+ # fail-closed:删掉必填块必须报错,不能静默回落
1729
+ broken = json.loads(json.dumps(ds[0]))
1730
+ broken["visual"].pop("motif", None)
1731
+ assert DK.validate_design(broken), "缺 motif 竟然通过校验(fail-closed 失效)"
1732
+ # 语义是**不给 seed = 每次都不一样**(需求是"每条视频都不同"),
1733
+ # 给 seed 才可复现。两条都要测,否则改错了任一边都发现不了。
1734
+ x1 = [d["id"] for d in DK.sample_designs({"topic": "selfcheck 设计 DSL"}, n=3)]
1735
+ x2 = [d["id"] for d in DK.sample_designs({"topic": "selfcheck 设计 DSL"}, n=3)]
1736
+ assert x1 != x2, "同一 brief 两次采样完全相同(那就是把模板藏进了哈希里)"
1737
+ y1 = [d["id"] for d in DK.sample_designs({"topic": "selfcheck 设计 DSL"}, n=3, seed=42)]
1738
+ y2 = [d["id"] for d in DK.sample_designs({"topic": "selfcheck 设计 DSL"}, n=3, seed=42)]
1739
+ assert y1 == y2, "给了 seed 竟然不可复现(回归/文档示例就不可信了)"
1740
+ return "3 候选 / 校验全过 / 两两 >=2 维 / 缺字段必报错 / 默认每次不同 + seed 可复现"
1741
+
1742
+
1743
+ def t_no_templates():
1744
+ """57 零模板:仓库里**不许再有**预设/模板文件(本技能只提供技术,不提供模板)。
1745
+
1746
+ 这条是反向断言:预设整个删掉后,
1747
+ 如果只是删掉这条检查,就再也拦不住"哪天有人又加一套预设进去"。
1748
+ 所以改成**禁止存在**——删掉模板是一次性动作,守住它是长期契约。
1749
+ """
1750
+ root = os.path.dirname(os.path.dirname(os.path.dirname(HERE)))
1751
+ skill = os.path.join(root, "skills", "video-studio")
1752
+ banned = []
1753
+ presets_dir = os.path.join(skill, "presets")
1754
+ if os.path.isdir(presets_dir):
1755
+ n = len([x for x in os.listdir(presets_dir) if x.endswith(".json")])
1756
+ banned.append("presets/ 目录还在(%d 个 json)" % n)
1757
+ for name in ("presetkit.py",):
1758
+ if os.path.exists(os.path.join(skill, "scripts", name)):
1759
+ banned.append("scripts/%s 还在" % name)
1760
+ assert not banned, ("本技能不提供模板,这些必须删掉:%s;"
1761
+ "要自定义请写 design.json(技术原语仍在,只是不再有现成目录)"
1762
+ % ";".join(banned))
1763
+ # 同时确认"现场采样"是唯一方式,且**每次都新**:
1764
+ # · 同一 brief 两次 -> 必须不同(否则等于模板藏在哈希里,用户要新片只能改措辞)
1765
+ # · 给 seed -> 必须可复现(回归与文档示例需要一个稳定值)
1766
+ try:
1767
+ import designkit as DK
1768
+ except Exception: # noqa: BLE001
1769
+ return "skip(没有 designkit.py)"
1770
+ a = [d["label"] for d in DK.sample_designs({"topic": "零模板校验 A"}, n=2)]
1771
+ b = [d["label"] for d in DK.sample_designs({"topic": "零模板校验 A"}, n=2)]
1772
+ c = [d["label"] for d in DK.sample_designs({"topic": "零模板校验 B"}, n=2)]
1773
+ s1 = [d["label"] for d in DK.sample_designs({"topic": "零模板校验 A"}, n=2, seed=7)]
1774
+ s2 = [d["label"] for d in DK.sample_designs({"topic": "零模板校验 A"}, n=2, seed=7)]
1775
+ assert a != b, "同一 brief 两次采样结果相同(等于把模板藏进了哈希)"
1776
+ assert a != c, "换 brief 采样结果没变(说明其实在套模板)"
1777
+ assert s1 == s2, "给了 seed 竟然不可复现"
1778
+ return "无模板文件;同 brief 两次必不同、换 brief 必变、seed 可复现"
1779
+
1780
+
1781
+ def t_brief_constraints():
1782
+ """60 brief 里的要求必须真的生效(自然语言 -> 约束 -> 采样结果)。
1783
+
1784
+ 这条防的是**需求被静默吃掉**:propose._brief_of 若把整句 --brief 塞进 topic,
1785
+ must_have/avoid 恒为空数组,于是"深蓝配色的科技解说"采出来是 h087 / h316(橙 / 紫)。
1786
+ 用户看到的需求和结果无关,而且没有任何提示——比报错更糟。
1787
+
1788
+ 三件事都要验:
1789
+ ① 自由文本能解析成 must_have / avoid(含否定词归到 avoid);
1790
+ ② 配色约束按**色相窗口**生效(不是按 8 个族名);
1791
+ ③ avoid 真的把色相排除掉。
1792
+ """
1793
+ import re
1794
+ try:
1795
+ import propose as PP
1796
+ import designkit as DK
1797
+ import stylekit as ST
1798
+ except Exception: # noqa: BLE001
1799
+ return "skip(缺 propose/designkit/stylekit)"
1800
+ # ① 解析
1801
+ b1 = PP._brief_of("要深蓝,不要放射线", {"title": "t"})
1802
+ assert b1["must_have"] and "深蓝" in b1["must_have"][0], "must_have 没解析出来:%r" % (b1["must_have"],)
1803
+ assert b1["avoid"] and "放射" in b1["avoid"][0], "avoid 没解析出来:%r" % (b1["avoid"],)
1804
+ b2 = PP._brief_of("随便做个片", {"title": "t"})
1805
+ assert b2["must_have"] == [] and b2["avoid"] == [], "认不出要求时不该硬凑约束"
1806
+ # ② 配色约束 -> 色相窗口
1807
+ ds = DK.sample_designs({"topic": "深蓝科技", "must_have": ["深蓝"]}, n=2, seed=7)
1808
+ for d in ds:
1809
+ h = DK._design_bg_hue(d)
1810
+ assert h is not None, "取不到底色色相"
1811
+ gap = DK._hue_gap(h, DK._PALETTE_ANCHOR["deep-blue"][0])
1812
+ assert gap <= DK._HUE_WINDOW + 1e-6, (
1813
+ "must_have『深蓝』没生效:底色色相 %.1f° 距 210° 有 %.1f°(窗口 %.0f°)"
1814
+ % (h, gap, DK._HUE_WINDOW))
1815
+ # ③ avoid 真的排除
1816
+ mint = DK._PALETTE_ANCHOR["cool-mint"][0]
1817
+ for i in range(3):
1818
+ d = DK.sample_designs({"topic": "避开薄荷 %d" % i, "avoid": ["薄荷"]}, n=1, seed=i)[0]
1819
+ h = DK._design_bg_hue(d)
1820
+ assert DK._hue_gap(h, mint) > DK._HUE_WINDOW, (
1821
+ "avoid『薄荷』没生效:底色色相 %.1f° 落在薄荷范围(%.0f°±%.0f°)"
1822
+ % (h, mint, DK._HUE_WINDOW))
1823
+ return "解析 2/2;深蓝落入窗口;薄荷 3/3 被排除"
1824
+
1825
+
1826
+ def t_stage_standalone():
1827
+ """59 逐 stage 可单独跑:render 里每处 resolve_style 都必须能拿到 work。
1828
+
1829
+ 这条守住一类**只在"单跑某个 stage"时才发作**的 bug:
1830
+ `--stage all` 时前面的 stage 已经把 script["_style"] 塞好了,后面全都命中缓存,
1831
+ 所以缺参数也看不出来;一旦用户只跑 `--stage frames` / `--stage sfx`,
1832
+ resolve_style 读不到 work/design.json 就报"找不到设计"(实测踩到:
1833
+ frames / sfx 两个 stage 单跑必挂,sfx 还是 NameError——函数里压根没有 work 这个名字)。
1834
+
1835
+ 为什么用 AST 而不是真的跑每个 stage:跑一遍 = 要 TTS 联网 + 全片渲染,几十秒起步,
1836
+ 不适合放进 20 秒的自检。静态检查能抓住"参数没传/名字不存在"这一整类问题,
1837
+ 而这正是本次的真实缺陷形态。
1838
+ """
1839
+ import ast
1840
+ src_path = os.path.join(HERE, "render.py")
1841
+ tree = ast.parse(open(src_path, encoding="utf-8").read())
1842
+ bad = []
1843
+ for node in ast.walk(tree):
1844
+ if not isinstance(node, ast.FunctionDef):
1845
+ continue
1846
+ args = [a.arg for a in node.args.args] + [a.arg for a in node.args.kwonlyargs]
1847
+ for sub in ast.walk(node):
1848
+ if not isinstance(sub, ast.Call):
1849
+ continue
1850
+ fn = sub.func
1851
+ name = getattr(fn, "id", None) or getattr(fn, "attr", None)
1852
+ if name != "resolve_style":
1853
+ continue
1854
+ # resolve_style(script, work) 的第二位必须是本函数能拿到的变量
1855
+ if len(sub.args) >= 2:
1856
+ second = sub.args[1]
1857
+ vname = getattr(second, "id", None)
1858
+ if vname and vname not in args and vname not in ("work",):
1859
+ # 明确允许 a.work 这类属性访问(不是 Name)
1860
+ bad.append("%s(): resolve_style 的 work 参数用了 %r,但该函数没有这个变量"
1861
+ % (node.name, vname))
1862
+ else:
1863
+ bad.append("%s(): resolve_style 没传 work(单跑该 stage 会读不到 design.json)"
1864
+ % node.name)
1865
+ assert not bad, ";".join(bad[:4])
1866
+ return "render 里 %d 处 resolve_style 全部带得上 work" % sum(
1867
+ 1 for n in ast.walk(tree) if isinstance(n, ast.Call)
1868
+ and (getattr(n.func, "id", None) or getattr(n.func, "attr", None)) == "resolve_style")
1869
+
1870
+
1871
+ def t_proposal_gate():
1872
+ """58 提案闸:没确认时必须判 draft/absent,确认后才放行;坏文件判 broken。"""
1873
+ try:
1874
+ import propose as PP
1875
+ except Exception: # noqa: BLE001
1876
+ return "skip(没有 propose.py)"
1877
+ with tempfile.TemporaryDirectory() as work:
1878
+ status, detail = PP.proposal_state(work)
1879
+ assert status == "absent", "空目录应判 absent,收到 %r" % status
1880
+ os.makedirs(work, exist_ok=True)
1881
+ with open(os.path.join(work, "proposal.json"), "w", encoding="utf-8") as fh:
1882
+ json.dump({"schema": 1, "rev": 1, "status": "draft",
1883
+ "candidates": [{"id": "A"}, {"id": "B"}]}, fh)
1884
+ status, _ = PP.proposal_state(work)
1885
+ assert status == "draft", "有草案但没确认应判 draft,收到 %r" % status
1886
+ with open(os.path.join(work, "proposal.json"), "w", encoding="utf-8") as fh:
1887
+ fh.write("{broken json")
1888
+ try:
1889
+ status, _ = PP.proposal_state(work)
1890
+ except SystemExit:
1891
+ status = "broken"
1892
+ assert status == "broken", "坏 JSON 应判 broken,收到 %r" % status
1893
+ return "absent / draft / broken 三档判定正确"
1894
+
1895
+
1896
+
1897
+
1898
+ def t_subtitle_style():
1899
+ """61 字幕样式可定制:design.visual.subtitle 必须真的改变像素,缺省逐像素不变。
1900
+
1901
+ 为什么必须有这条:字幕字号/位置/背板过去是 filmkit 的**模块常量**,任何两条片子
1902
+ 的字幕带都一模一样 —— 这正是用户说的"跨片大面积重复"。改成设计字段后,最容易
1903
+ 出现的退化是"字段读进来了但没传给 draw_subtitle"(写完不生效,实测踩过)。
1904
+ 所以这里验行为:同一个 theme、同一段文字,换字幕参数必须像素不同;
1905
+ 不传参数时必须与不传该字段的调用逐像素一致(老项目不漂)。
1906
+ """
1907
+ import numpy as _np
1908
+ import designkit as DK
1909
+ # 用一套现场采样设计里的主题,避免依赖内置主题表(已删)
1910
+ d = DK.sample_designs({"topic": "字幕样式自检"}, n=1, seed=3)[0]
1911
+ plan = DK.design_to_plan(d)
1912
+ theme = plan["theme"]
1913
+ text = "这是一句用来测试字幕样式是否真的生效的中文字幕"
1914
+ base = K.Image.new("RGB", (K.W, K.H), tuple(theme["bg"]))
1915
+ default_img = K.draw_subtitle(base.copy(), text, theme=theme)
1916
+ kw = K.subtitle_kwargs(plan)
1917
+ assert kw.get("size") and kw.get("align") in ("center", "left"), (
1918
+ "subtitle_kwargs 没把设计的字幕参数带出来:%r" % (kw,))
1919
+ styled = K.draw_subtitle(base.copy(), text, theme=theme, **kw)
1920
+ a = _np.asarray(default_img, dtype=_np.int16)
1921
+ b = _np.asarray(styled, dtype=_np.int16)
1922
+ assert int(_np.abs(a - b).max()) > 0, "字幕参数没有改变任何像素(字段写了不生效)"
1923
+ # 缺省必须等价于旧调用(老 design.json 逐像素不变)
1924
+ assert K.subtitle_kwargs({}) == {}, "没有 subtitle 的计划必须返回空 kw(保持旧像素)"
1925
+ assert K.subtitle_kwargs({"subtitle": {}}) == {}, "空 subtitle 也必须是空 kw"
1926
+ return "字幕参数改变像素;缺省等价旧调用(size=%s align=%s)" % (kw.get("size"), kw.get("align"))
1927
+
1928
+
1929
+ def t_layout_cycle():
1930
+ """62 片内版式轮换:layout_cycle 真的让不同章节换骨架,同章必须稳定。
1931
+
1932
+ 用户原则 5:同一部片不能"长时间一张版式"。design.visual.layout 是单值,
1933
+ grammar 把它当全片默认 → 8 段片子 8 屏同骨架。这条验三件事:
1934
+ ① 有 layout_cycle 时,不同 chapter 拿到不同版式;
1935
+ ② 同一个 chapter 内所有段版式一致(不能每句都跳);
1936
+ ③ 没有 layout_cycle 时行为与旧版一致(全用 layout_default)。
1937
+ """
1938
+ import grammar as G
1939
+ scenes = [
1940
+ {"id": "a1", "kind": "body", "chapter": "第一章", "start": 0.0, "end": 4.0, "dur": 4.0},
1941
+ {"id": "a2", "kind": "body", "chapter": "第一章", "start": 4.0, "end": 8.0, "dur": 4.0},
1942
+ {"id": "b1", "kind": "body", "chapter": "第二章", "start": 8.0, "end": 12.0, "dur": 4.0},
1943
+ {"id": "b2", "kind": "body", "chapter": "第二章", "start": 12.0, "end": 16.0, "dur": 4.0},
1944
+ ]
1945
+ plan = {"chapter_layout": {}, "layout_default": "left-stack",
1946
+ "layout_cycle": ["left-stack", "center-stack"]}
1947
+ scenes = [dict(s) for s in scenes]
1948
+ G.plan_scenes(scenes, {"lines": []}, plan)
1949
+ got = {s["id"]: s["scene_layout"] for s in scenes}
1950
+ assert got["a1"] == got["a2"], "同一章内版式必须稳定,实际 %s" % (got,)
1951
+ assert got["b1"] == got["b2"], "同一章内版式必须稳定,实际 %s" % (got,)
1952
+ assert got["a1"] != got["b1"], "不同章节应轮换版式,实际两章都是 %s" % (got["a1"],)
1953
+ # 没有 cycle 时回到旧行为
1954
+ scenes2 = [dict(s) for s in scenes]
1955
+ G.plan_scenes(scenes2, {"lines": []}, {"chapter_layout": {}, "layout_default": "split-right"})
1956
+ assert all(s["scene_layout"] == "split-right" for s in scenes2), \
1957
+ "没有 layout_cycle 时必须全用 layout_default(旧行为)"
1958
+ return "两章轮换 %s -> %s;同章稳定;无 cycle 时回落 layout_default" % (got["a1"], got["b1"])
1959
+
1960
+
1961
+ def t_brief_constraint_robustness():
1962
+ """63 带约束的 brief 不许高概率直接失败。
1963
+
1964
+ 实测过的真缺陷:配色候选去重按 24° 分桶,而 must_have「深蓝」把色相窗口压到 52°,
1965
+ n=3 时约一半概率抛 ValueError;「暖纸色 + 女声」20/20 全失败。用户第一步就撞墙。
1966
+ 修法改成"色相距离 + 结构差异"分档后,这里用 20 次独立采样守回归。
1967
+ """
1968
+ import propose as PP
1969
+ import designkit as DK
1970
+ briefs = ["深蓝", "纪录片,暖纸色,缓慢,女声", "科技发布会,深蓝,要遮幅"]
1971
+ for text in briefs:
1972
+ b = PP._brief_of(text, {"title": "t"})
1973
+ for _ in range(6):
1974
+ try:
1975
+ DK.sample_designs(b, n=3)
1976
+ except ValueError as e:
1977
+ raise AssertionError("brief %r 采样失败:%s" % (text, str(e)[:200])) from e
1978
+ return "3 种带约束 brief × 6 次 = 18 次 n=3 采样全部成功"
1979
+
1980
+
1981
+ def t_removed_apis_fail_closed():
1982
+ """64 已删除的 API 必须"明确报错/非零退出",不许 NameError、假绿或静默 fallback。
1983
+
1984
+ 删内置风格表时留下了一批**死路径**:stylekit 的 --list/--show NameError、
1985
+ --lint 空表 exit 0(假绿)、filmkit 的 resolve_theme/style_plan 吞异常回落到写死的
1986
+ 写死的主题(静默降级 = 用模板出片)。这三种都必须绝迹。
1987
+ """
1988
+ import subprocess as _sp
1989
+ import stylekit as ST
1990
+ import filmkit as FK
1991
+ # ① stylekit.resolve_script_style 必须 raise 且带指引
1992
+ try:
1993
+ ST.resolve_script_style({"title": "t", "lines": []})
1994
+ except (ValueError, KeyError, SystemExit) as e:
1995
+ msg = str(getattr(e, "code", None) or e)
1996
+ assert "propose.py" in msg, "报错必须给迁移指引(要提到 propose.py):%r" % msg[:120]
1997
+ else:
1998
+ raise AssertionError("没有设计的剧本竟然解析出了计划")
1999
+ # ② stylekit CLI 三个动作必须非零退出(不许假绿/NameError traceback)
2000
+ for flag in ("--list", "--lint"):
2001
+ p = _sp.run([sys.executable, os.path.join(HERE, "stylekit.py"), flag],
2002
+ capture_output=True, text=True, timeout=60)
2003
+ assert p.returncode == 2, "stylekit.py %s 应 exit 2(能力已移除),实际 %d" % (flag, p.returncode)
2004
+ assert "Traceback" not in (p.stderr or ""), "stylekit.py %s 不该抛 traceback" % flag
2005
+ # ③ filmkit 的静默回落必须改成明确报错
2006
+ for fn in (FK.resolve_theme, FK.style_plan):
2007
+ try:
2008
+ fn({"title": "t", "lines": []})
2009
+ except (ValueError, KeyError) as e:
2010
+ assert "propose" in str(e).lower() or "design" in str(e).lower(), \
2011
+ "%s 的报错要给迁移指引:%r" % (fn.__name__, str(e)[:120])
2012
+ else:
2013
+ raise AssertionError("%s 在无设计时静默返回了兜底主题(模板残留)" % fn.__name__)
2014
+ # ④ designkit 的配色采样示例不许崩(--list-palettes 曾 KeyError: family)
2015
+ p = _sp.run([sys.executable, os.path.join(HERE, "designkit.py"), "--list-palettes", "--json"],
2016
+ capture_output=True, text=True, timeout=120)
2017
+ assert p.returncode == 0, "designkit.py --list-palettes 崩了:%s" % (p.stderr or p.stdout)[:200]
2018
+ return "resolve_script_style/CLI/filmkit 全部 fail-closed;--list-palettes 可跑"
2019
+
2020
+
2021
+ def t_audio_overrides():
2022
+ """65 design.audio 的音量/音效参数必须真的落进 script。
2023
+
2024
+ 实测过的真缺陷:design.json 的 audio.music.gain_db / duck_db 与 audio.sfx.enabled
2025
+ / density / gain_db 一直被 validate_design 接受、却从来没有渲染代码读它们 ——
2026
+ 用户把 sfx.enabled 写成 false,成片照样出 8 条音效。
2027
+ 现在的契约:**film.json 显式写了的 > design 的值 > 模块默认**。
2028
+ """
2029
+ import designkit as DK
2030
+ d = DK.sample_designs({"topic": "声音参数自检"}, n=1, seed=5)[0]
2031
+ d = json.loads(json.dumps(d))
2032
+ d["audio"]["music"]["gain_db"] = -7.5
2033
+ d["audio"]["music"]["duck_db"] = 9.0
2034
+ d["audio"]["sfx"] = {"enabled": False, "density": "rich", "gain_db": -3}
2035
+ plan = DK.design_to_plan(d)
2036
+ ov = plan.get("audio_overrides") or {}
2037
+ assert abs(float(ov["music"]["gain_db"]) + 7.5) < 1e-9, "music.gain_db 没进计划"
2038
+ assert abs(float(ov["music"]["duck_db"]) - 9.0) < 1e-9, "music.duck_db 没进计划"
2039
+ assert ov["sfx"]["enabled"] is False, "sfx.enabled 没进计划"
2040
+ import render as R
2041
+ # 剧本里没写 -> 用 design 的值
2042
+ s1 = {"title": "t", "lines": []}
2043
+ R._apply_audio_overrides(s1, plan)
2044
+ assert s1["sfx"]["enabled"] is False and abs(s1["music"]["gain_db"] + 7.5) < 1e-9, \
2045
+ "design 的声音参数没有填进 script:%r" % (s1,)
2046
+ # 剧本显式写了 -> 以剧本为准(用户手里 film.json 是最终裁决权)
2047
+ s2 = {"title": "t", "lines": [], "music": {"gain_db": -1.0}, "sfx": {"enabled": True}}
2048
+ R._apply_audio_overrides(s2, plan)
2049
+ assert s2["music"]["gain_db"] == -1.0 and s2["sfx"]["enabled"] is True, \
2050
+ "film.json 的显式值被 design 覆盖了:%r" % (s2,)
2051
+ return "design.audio -> plan -> script 贯通;film.json 显式值优先"
2052
+
2053
+
2054
+ def t_design_ledger():
2055
+ """66 片间去重台账:确认过的设计要记住,下次提案主动避开;可关可查。
2056
+
2057
+ 用户原则 5:不同视频的整体风格不能大面积重复。只保证"同一 brief 两次采样不同"
2058
+ (nonce),但没有记忆——连拍同题材仍可能撞到相近设计。台账补上这一环。
2059
+ 这条验四件事:① confirm 后写台账;② 提案会读台账并报告距离;
2060
+ ③ 台账路径可被环境变量重定向(绝不污染用户真实台账);④ --no-ledger 可关闭。
2061
+ """
2062
+ import tempfile
2063
+ import subprocess as _sp
2064
+ tmp = tempfile.mkdtemp(prefix="vs_ledger_selfcheck_")
2065
+ ledger = os.path.join(tmp, "ledger.json")
2066
+ env = dict(os.environ, PYTHONIOENCODING="utf-8", VIDEO_STUDIO_LEDGER=ledger)
2067
+ script = {"title": "台账自检", "lines": [
2068
+ {"id": "l01", "kind": "hook", "text": "第一句话。"},
2069
+ {"id": "l02", "kind": "body", "text": "第二句话,讲一件具体的事。"},
2070
+ {"id": "l03", "kind": "outro", "text": "结束。"}]}
2071
+ film = os.path.join(tmp, "film.json")
2072
+ with open(film, "w", encoding="utf-8") as fh:
2073
+ json.dump(script, fh, ensure_ascii=False)
2074
+ pp = os.path.join(HERE, "propose.py")
2075
+
2076
+ def _run(args):
2077
+ r = _sp.run([sys.executable, pp] + args, cwd=tmp, capture_output=True,
2078
+ text=True, encoding="utf-8", errors="replace", env=env, timeout=300)
2079
+ assert r.returncode == 0, "propose.py %s 失败:%s" % (args[0], (r.stderr or r.stdout)[-300:])
2080
+ return r
2081
+
2082
+ _run(["--brief", "深蓝科技解说", "--script", film, "--n", "3"])
2083
+ assert not os.path.exists(ledger), "还没 confirm 就写台账了(草稿不该记)"
2084
+ _run(["--confirm", "--candidate", "A"])
2085
+ assert os.path.exists(ledger), "confirm 之后没有写台账:%s" % ledger
2086
+ data = json.load(open(ledger, encoding="utf-8"))
2087
+ assert len(data.get("designs") or []) == 1, "台账条数不对:%r" % (data,)
2088
+ row = data["designs"][0]
2089
+ assert row.get("fingerprint") and isinstance(row.get("design"), dict), "台账记录缺字段"
2090
+ # 第二次提案:必须能读到台账(人读输出里有一行"片间去重")
2091
+ r = _run(["--brief", "深蓝科技解说", "--script", film, "--n", "3"])
2092
+ assert "片间去重" in r.stdout, "提案没有报告台账状态:%s" % r.stdout[-400:]
2093
+ # --show-ledger 能查;--no-ledger 能关
2094
+ r = _run(["--show-ledger"])
2095
+ assert row["fingerprint"] in r.stdout, "--show-ledger 没列出刚记的指纹"
2096
+ r = _run(["--brief", "深蓝科技解说", "--script", film, "--n", "3", "--no-ledger"])
2097
+ assert "--no-ledger" in r.stdout, "--no-ledger 没有给出关闭提示"
2098
+ return "草稿不记 / confirm 记账 / 提案读取并报告 / --show-ledger 可查 / --no-ledger 可关"
2099
+
2100
+
2101
+ def t_duration_target():
2102
+ """67 时长要求真的被接住:brief 里的「2 分钟」要影响设计,渲染时对账。
2103
+
2104
+ 过去 `_brief_of` 把 duration_target 恒填 None —— 用户写「做个 2 分钟的片」等于没写,
2105
+ 成片永远按台词长度出(实测 23s / 30s)。这条守三件事:
2106
+ ① 中文/阿拉伯数字的常见时长说法都能解析;
2107
+ ② 解析出的时长进 design.structure.target_sec,并决定候选段落数;
2108
+ ③ 渲染时按"目标 vs 实测"对账(差 >15% 告警,但不截断旁白)。
2109
+ """
2110
+ import propose as PP
2111
+ import designkit as DK
2112
+ cases = {"2分钟": 120.0, "做个90秒的短视频": 90.0, "一分钟半": 90.0,
2113
+ "3分30秒": 210.0, "2.5分钟": 150.0, "两分钟": 120.0}
2114
+ for text, want in cases.items():
2115
+ got = PP.parse_duration(text)
2116
+ assert got is not None and abs(got - want) < 1e-6, \
2117
+ "时长解析 %r 得到 %r,期望 %r" % (text, got, want)
2118
+ assert PP.parse_duration("深蓝科技解说") is None, "没有时长时不该硬凑"
2119
+ assert PP.parse_duration("两小时") is None, "超出 3–1800s 契约范围应拒绝"
2120
+ b = PP._brief_of("深蓝,科技,2分钟,硬切", {"title": "t"})
2121
+ assert b.get("duration_target") == 120.0, "brief 没接住时长:%r" % (b,)
2122
+ d = DK.sample_designs(b, n=2, seed=9)[0]
2123
+ assert d["structure"].get("target_sec") == 120.0, \
2124
+ "目标时长没进设计:%r" % (d["structure"],)
2125
+ plan = DK.design_to_plan(d)
2126
+ assert plan.get("target_sec") == 120.0, "目标时长没进计划:%r" % (plan.get("target_sec"),)
2127
+ return "6 种时长说法解析正确;进 design/plan;超范围拒绝"
2128
+ def t_zoom_stability():
2129
+ """68 缩放取景的帧间稳定性(抖动回归)。
2130
+
2131
+ 为什么要有这条:底图把颗粒烘进去后用 NEAREST 逐帧直采,采样网格随 s 整体跳变,
2132
+ 颗粒图案跟着错位 1px —— 用户实测的原话是"生成的视频有明显的抖动感",
2133
+ 而单帧闪烁门禁(8x8 分块比较前后帧平均)对这类亚像素沸腾**完全不敏感**。
2134
+ 断言:同一主题从 s=1.0 缓推到 s=1+push 的过程中,相邻两帧最大差 <= 2 灰阶。
2135
+ 端点直采实测抖动 4~6,改成端点预烘 + blend 后 0~1。
2136
+ """
2137
+ mod = _load_scenes_mod()
2138
+ if mod is None:
2139
+ return "skip(没有 assets/scenes.py)"
2140
+ import numpy as np
2141
+ push = 0.12
2142
+ th = {"id": "zoom-stab", "bg": (28, 30, 36), "bg2": (18, 19, 24), "texture": "paper",
2143
+ "grain": 5.0, "grain_freq": 0.31, "vignette": 0.2, "vignette_tint": (0, 0, 0),
2144
+ "texture_alpha": 0.03, "push": push}
2145
+ frames = [np.asarray(mod._bg_plate(th, 1.0 + push * i / 19.0), dtype=np.int16)
2146
+ for i in range(20)]
2147
+ worst_max = 0
2148
+ worst_mean = 0.0
2149
+ for i in range(1, len(frames)):
2150
+ d = np.abs(frames[i] - frames[i - 1])
2151
+ worst_max = max(worst_max, int(d.max()))
2152
+ worst_mean = max(worst_mean, float(d.mean()))
2153
+ assert worst_max <= 2, ("缩放取景帧间跳变 %d 灰阶(>2):底图高频纹理被 NEAREST 重排,"
2154
+ "观感就是满屏噪点沸腾" % worst_max)
2155
+ # 均值守住 0.6:8-bit 输出下慢速缓推必然出现"整片 1 灰阶"的量化台阶,
2156
+ # 首帧端点与 s≈1.006 之间实测 mean≈0.44 —— 这是量化噪声,不是图案错位。
2157
+ # 真正能区分"错位沸腾"的是 max:旧实现 4~6,新实现 <=1。
2158
+ assert worst_mean <= 0.6, "缩放取景帧间平均差 %.3f(>0.6,疑似整屏跳变)" % worst_mean
2159
+ return ("20 帧缓推:最大帧间差 %d 灰阶 / 均值 %.3f(旧 NEAREST 直采为 4~6 灰阶)"
2160
+ % (worst_max, worst_mean))
2161
+
2162
+
2163
+ def t_asr_lost_diagnostics():
2164
+ """69 ASR 掉分可定位(低召回必须说清"掉在哪几个字")。
2165
+
2166
+ 为什么要有这条:实测 ASR 回读 0.813~0.844 是常态(中文专名 + 同音字),只报一个
2167
+ 百分比,agent 只能盲目放宽阈值。这条断言盯的是"低于 pass 线时,报告必须给出
2168
+ 没对上的字符(全局 + 最差段落)",且判分本身仍然是纯函数、不加载模型。
2169
+ """
2170
+ cand = os.path.join(HERE, "qaasr.py")
2171
+ if not os.path.exists(cand):
2172
+ return "skip(没有 qaasr.py)"
2173
+ import importlib.util
2174
+ spec = importlib.util.spec_from_file_location("sc_qaasr", cand)
2175
+ mod = importlib.util.module_from_spec(spec)
2176
+ spec.loader.exec_module(mod)
2177
+ scenes = [
2178
+ {"id": "a", "start": 0.0, "end": 3.0, "voice_start": 0.4,
2179
+ "text": "这是用 DeepSeek 生成的声音与画面。"},
2180
+ {"id": "b", "start": 3.0, "end": 6.0, "voice_start": 3.4,
2181
+ "text": "先定脚本,再定声音,最后才是画面。"},
2182
+ ]
2183
+ # ASR 把 DeepSeek 听成"迪普西克"、把"再定"听成"在订"——低召回但不丢句
2184
+ segments = [
2185
+ {"start": 0.4, "end": 3.0, "text": "这是用 迪普西克 生成的声音与画面"},
2186
+ {"start": 3.4, "end": 6.0, "text": "先定脚本,在订声音,最后才是画面"},
2187
+ ]
2188
+ rep = mod._judge(scenes, segments, recall_pass=0.99, recall_warn=0.5)
2189
+ assert rep["recall"] < 0.99, "构造样例没有触发低召回,断言前提不成立"
2190
+ assert rep.get("lost_top"), "低召回时没有输出 lost_top(掉分字符清单)"
2191
+ assert all("ch" in x and "n" in x for x in rep["lost_top"]), "lost_top 结构不对"
2192
+ lost_lines = [p for p in rep["per_line"] if p.get("lost")]
2193
+ assert lost_lines, "没有段落级 lost(最差段落无法定位)"
2194
+ warns = " ".join(rep.get("warnings") or [])
2195
+ assert "没对上的字" in warns, "低召回时警告里没有掉分字符清单"
2196
+ assert "最差段落" in warns, "低召回时警告里没有最差段落定位"
2197
+ return "lost_top %d 项 / 段落级 %d 段 / 警告 %d 条" % (
2198
+ len(rep["lost_top"]), len(lost_lines), len(rep.get("warnings") or []))
2199
+
2200
+
1615
2201
  CASES = [
1616
2202
  ("1 TTS 缓存校验文本", t_cache_key),
1617
2203
  ("2 sub_window 覆盖长句", t_sub_window),
@@ -1625,7 +2211,7 @@ CASES = [
1625
2211
  ("10 qa 字幕条数校验", t_qa_subs),
1626
2212
  ("11 尾静音裁剪", t_trim),
1627
2213
  ("12 mux 音轨 48kHz", t_mux_48k),
1628
- ("13 v0.1 调用签名兼容", t_compat),
2214
+ ("13 调用签名兼容", t_compat),
1629
2215
  ("14 qa 帧率校验", t_fps_check),
1630
2216
  ("15 立体声总线", t_stereo_bus),
1631
2217
  ("16 cue_time 三种写法", t_cue_time),
@@ -1645,9 +2231,9 @@ CASES = [
1645
2231
  ("30 门禁账本与签核", t_gates),
1646
2232
  ("31 阶段新鲜度守卫", t_stagewatch),
1647
2233
  ("32 并行渲染主题序列化", t_parallel_frames),
1648
- ("33 音效跨片可区分(v0.7 内容派生 seed)", t_sfx_content_seed),
1649
- ("34 配乐/音效片内分离(v0.7 duck 加深)", t_audio_separation),
1650
- ("35 旁白优先(v0.7.1 背景让位与恢复)", t_voice_priority),
2234
+ ("33 音效跨片可区分(内容派生 seed)", t_sfx_content_seed),
2235
+ ("34 配乐/音效片内分离(duck 加深)", t_audio_separation),
2236
+ ("35 旁白优先(背景让位与恢复)", t_voice_priority),
1651
2237
  ("36 旁白优先默认值(配乐 -12 dB + 侧链)", t_music_gain_default),
1652
2238
  ("37 旁白清晰度 SNR 兜底(背景太响时自动补压)", t_snr_guard),
1653
2239
  ("38 无旁白时混音不受影响", t_mix_no_voice),
@@ -1668,6 +2254,20 @@ CASES = [
1668
2254
  ("53 视觉语言包(结构签名互不相同)", t_visual_languages),
1669
2255
  ("54 场景类型单真值(4 处集合一致)", t_scene_types_single_truth),
1670
2256
  ("55 剪影可区分(G13:换风格不能只是换色)", t_silhouette_gate),
2257
+ ("56 设计 DSL(采样/校验/转计划/fail-closed)", t_design_dsl),
2258
+ ("57 零模板(仓库里不许有预设;采样确定性且随 brief 变化)", t_no_templates),
2259
+ ("58 提案闸(absent/draft/confirmed/broken)", t_proposal_gate),
2260
+ ("59 逐 stage 可单独跑(resolve_style 必须拿得到 work)", t_stage_standalone),
2261
+ ("60 brief 里的要求真的生效(自然语言 -> 约束 -> 采样)", t_brief_constraints),
2262
+ ("61 字幕样式可定制(design.visual.subtitle 真的生效)", t_subtitle_style),
2263
+ ("62 片内版式轮换(layout_cycle:换章即换骨架)", t_layout_cycle),
2264
+ ("63 带约束的 brief 不会高概率采样失败", t_brief_constraint_robustness),
2265
+ ("64 已删除 API 的 fail-closed(不许 NameError / 假绿 / 静默回落)", t_removed_apis_fail_closed),
2266
+ ("65 design.audio 的音量/音效参数真的落进 script", t_audio_overrides),
2267
+ ("66 片间去重台账(确认记账 / 提案避开 / 可关可查)", t_design_ledger),
2268
+ ("67 时长要求真的被接住(brief -> design -> 渲染对账)", t_duration_target),
2269
+ ("68 缩放取景的帧间稳定性(抖动回归)", t_zoom_stability),
2270
+ ("69 ASR 掉分可定位(lost_top / 最差段落)", t_asr_lost_diagnostics),
1671
2271
  ]
1672
2272
 
1673
2273