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): P2.2 改 page_count 后重算 total_pages,并清理 explicit 死代码

xukangd85c4d0ea23a
diff --git a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/requirement_collect.py b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/requirement_collect.py
index 3e5b24619f..f27d959ff2 100644
--- a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/requirement_collect.py
+++ b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/requirement_collect.py
@@ -502,10 +502,7 @@ def _sync_target_total_pages(inputs: dict[str, Any]) -> None:
return
mode = str(inputs.get("page_structure_mode") or "default").strip().lower()
if mode == "explicit_sequence":
- # 清单条目数应由上游槽位给出;已有合法值则保留
- existing = inputs.get("total_pages")
- if isinstance(existing, int) and existing > 0:
- return
+ # 清单条目数应由上游槽位给出;本函数不得替 explicit 推算
return
mid = PptCommon.resolve_mid_structural_page_count(
page_count,
@@ -1084,6 +1081,7 @@ def _apply_answer_item(
if count is not None:
inputs["page_count"] = count
inputs["page_count_user_specified"] = True
+ _sync_target_total_pages(inputs)
elif field == "audience":
inputs["audience"] = _audience_from_label(label, other_text)
elif field == "presentation_purpose":
@@ -1417,6 +1415,7 @@ async def _llm_default_batch_fields(
# 超时/空答兜底视为「页数收集已完成」,否则 HITL resume 会因
# page_count_user_specified=False 再次进入 P2.2,形成页数↔风格死循环。
inputs["page_count_user_specified"] = True
+ _sync_target_total_pages(inputs)
if "audience" in missing_fields:
audience = payload.get("audience")
inputs["audience"] = (
diff --git a/tests/unit_tests/server/runtime/skill_turbo/test_ppt_outline_contract_c.py b/tests/unit_tests/server/runtime/skill_turbo/test_ppt_outline_contract_c.py
index a7d712ae7c..eeb47a2b28 100644
--- a/tests/unit_tests/server/runtime/skill_turbo/test_ppt_outline_contract_c.py
+++ b/tests/unit_tests/server/runtime/skill_turbo/test_ppt_outline_contract_c.py
@@ -292,6 +292,35 @@ def test_merge_slot_explicit_preserves_total_pages():
assert inputs["total_pages"] == 4
+def test_p22_answer_resyncs_stale_total_pages_after_p21_guess():
+ """P2.1 预填 total 后,P2.2 用户改 page_count 必须重算 total_pages。"""
+ inputs: dict = {}
+ rc._merge_slot_payload(
+ inputs,
+ {
+ "topic": "主题",
+ "page_count": 8,
+ "page_count_basis": "content",
+ "page_count_user_specified": False,
+ "page_structure_mode": "default",
+ "exclude_cover_ending": False,
+ "structural_page_request": "none",
+ },
+ )
+ assert inputs["total_pages"] == 10
+
+ rc._apply_answer_item(
+ inputs,
+ {
+ "header": "页数",
+ "selected_options": ["5"],
+ },
+ )
+ assert inputs["page_count"] == 5
+ assert inputs["page_count_user_specified"] is True
+ assert inputs["total_pages"] == 7
+
+
def test_content_pages_from_total_respects_exclude():
from jiuwenswarm.server.runtime.skill_turbo.skill_codes.ppt.ppt_common import PptCommon