Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(skillturbo): 适配现行pptx-craft普通分支契约并修复ppt注册校验失败问题

Kinsame367a89a2594
diff --git a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/ppt_page_gen.py b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/ppt_page_gen.py
index c00f420bfc..6bc2ca6b78 100644
--- a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/ppt_page_gen.py
+++ b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/ppt_page_gen.py
@@ -55,8 +55,9 @@ def _extract_designer_section(
return text[start:end].rstrip()
sections = [
+ # 只认现行 designer.md:预算为加粗正文 **E. …**,终点「阶段 4」。
_extract_bounded_section(
- "### 页面内容预算契约",
+ "**E. 页面内容预算契约",
("\n### 阶段 4:交付",),
),
_extract_bounded_section(
@@ -71,9 +72,10 @@ def _extract_designer_section(
"## 视觉设计规范",
("\n## 图表与数据可视化",),
),
+ # 只认现行终点「禁止事项」,避免吃到文末。
_extract_bounded_section(
"## 关键原则",
- ("\n## 质量控制清单",),
+ ("\n## 禁止事项",),
),
]
if include_charts:
@@ -657,6 +659,20 @@ def _build_content_template_fill_prompt(
f"{rewrite_hint}\n"
"⚠️ 仅修复上述不通过项,不要改动其他正常部分。\n"
)
+ # custom content-template:page-main 已是根容器,PAGE_CONTENT 须 ≥2 直接子块;
+ # 四预设仍用唯一首层根容器(与现行预设脚手架一致)。
+ if style_id == "custom":
+ page_content_rule = (
+ "5. `{{PAGE_CONTENT}}` 必须作为 `<main class=\"page-main\">` 的至少两个直接子块"
+ "(例如结论条/关键指标 + 主体图表或分栏);高度归属写在各直接子块上"
+ "(如 `flex-shrink-0` / `flex-1 min-h-0`);需要分栏时只在其中一个直接子块内部"
+ "使用 grid/flex-row,禁止再用唯一根容器包住全部内容\n"
+ )
+ else:
+ page_content_rule = (
+ "5. `{{PAGE_CONTENT}}` 必须替换为一个且仅一个首层根容器,"
+ "根容器必须带 `w-full flex-1 min-h-0`\n"
+ )
return (
f"{user_query_section}"
f"## 任务:填充第 {page_number} 页预设风格 content-template 官方模板\n"
@@ -667,7 +683,7 @@ def _build_content_template_fill_prompt(
"2. **只允许替换 3 类占位符**:`{{PAGE_TITLE}}`、`{{PAGE_CONTENT}}`、`{{PAGE_FOOTER}}`\n"
"3. `{{PAGE_TITLE}}` 只填写本页标题文字;不得改 `<h1>` 的 class、字号、字重、字体、装饰线、padding\n"
"4. `{{PAGE_FOOTER}}` 只填写来源/备注;不得追加运行页码\n"
- "5. `{{PAGE_CONTENT}}` 必须替换为一个且仅一个首层根容器,根容器必须带 `w-full flex-1 min-h-0`\n"
+ f"{page_content_rule}"
"6. 不得修改预铺模板 `<main>` 的 class;所有布局变化仅在 `{{PAGE_CONTENT}}` 内完成\n"
"7. 每个占位符必须填有意义内容;禁止空串、`—`/`–`/`-`、`N/A`、`TBD`、`暂无`、`待补充`、`待定`、`占位`\n"
"8. 图表候选页必须优先激活模板内 `CHART_SCAFFOLD`,按模板注释填充 option;禁止额外手写第二套图表初始化框架\n"
diff --git a/tests/unit_tests/server/runtime/skill_turbo/test_pptx_craft_compat_adapt.py b/tests/unit_tests/server/runtime/skill_turbo/test_pptx_craft_compat_adapt.py
new file mode 100644
index 0000000000..814867d763
--- /dev/null
+++ b/tests/unit_tests/server/runtime/skill_turbo/test_pptx_craft_compat_adapt.py
@@ -0,0 +1,121 @@
+# Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved.
+
+"""SkillTurbo × 现行 pptx-craft 普通分支兼容适配回归(内嵌 fixture,无本机绝对路径)。"""
+
+from __future__ import annotations
+
+import json
+
+import pytest
+
+from jiuwenswarm.server.runtime.skill_turbo.skill_codes.ppt.ppt_page_gen import (
+ _build_content_template_fill_prompt,
+ _extract_designer_section,
+)
+from jiuwenswarm.server.runtime.skill_turbo.skill_turbo_tools import skill_turbo
+
+# 模拟现行 designer.md 关键结构:预算为加粗正文;关键原则后接「禁止事项」(无质量控制清单)。
+_DESIGNER_MD_FIXTURE = """
+## 角色定位
+
+无关前言。
+
+**E. 页面内容预算契约(生成 HTML 前必须完成)**
+
+预算片段 MARKER_BUDGET_CONTRACT
+
+#### 3.2 版面计算
+
+版面计算片段仍属预算段。
+
+### 阶段 4:交付
+
+交付片段不应进入预算抽取 MARKER_STAGE4_LEAK
+
+## 弹性布局模式
+
+弹性布局片段 MARKER_FLEX
+
+## HTML 代码规范
+
+代码规范。
+
+## 页面布局规范
+
+布局规范片段 MARKER_LAYOUT
+
+## 视觉设计规范
+
+视觉规范片段 MARKER_VISUAL
+
+## 图表与数据可视化
+
+图表规范。
+
+## 图片使用规范
+
+图片规范。
+
+## 关键原则
+
+### 防溢出核心策略
+
+关键原则片段 MARKER_CRITICAL
+
+### 防空白核心策略
+
+防空白说明。
+
+## 禁止事项
+
+禁止事项片段 MARKER_FORBIDDEN_LEAK
+
+## 输出要求
+
+输出说明。
+""".strip()
+
+
+def _minimal_fill_prompt(*, style_id: str) -> str:
+ return _build_content_template_fill_prompt(
+ page_number=3,
+ style_id=style_id,
+ style_text="style stub",
+ outline_page="- type: content\n title: 测试页",
+ research_page="research stub",
+ outline_full="outline stub",
+ seed_html="<html><main>{{PAGE_CONTENT}}</main></html>",
+ )
+
+
+def test_extract_designer_section_matches_current_anchors():
+ extracted = _extract_designer_section(_DESIGNER_MD_FIXTURE)
+
+ assert "MARKER_BUDGET_CONTRACT" in extracted
+ assert "MARKER_CRITICAL" in extracted
+ assert "MARKER_FORBIDDEN_LEAK" not in extracted
+ assert "MARKER_STAGE4_LEAK" not in extracted
+ assert "## 禁止事项" not in extracted
+
+
+def test_content_fill_prompt_custom_vs_preset_page_content_rules():
+ custom_prompt = _minimal_fill_prompt(style_id="custom")
+ preset_prompt = _minimal_fill_prompt(style_id="business-classic")
+
+ assert "一个且仅一个首层根容器" not in custom_prompt
+ assert "至少两个直接子块" in custom_prompt
+ assert "一个且仅一个首层根容器" in preset_prompt
+ assert "至少两个直接子块" not in preset_prompt
+
+
+async def test_skill_turbo_template_path_bypass_hard_fails():
+ raw = await skill_turbo.invoke(
+ {"query": r"用模板目录:C:\templates\demo-pack 生成一份产品发布会 PPT"}
+ )
+ result = json.loads(raw) if isinstance(raw, str) else raw
+
+ assert result.get("success") is False
+ error = str(result.get("error") or "")
+ assert "自定义模板" in error or "模板包" in error
+ assert "skill_tool" in error