v0.21 alpha add research brief and compressed findings

This commit is contained in:
kai
2026-05-06 19:23:30 +08:00
parent db626f1d58
commit 0644a68ecc
13 changed files with 539 additions and 27 deletions
+14
View File
@@ -11,10 +11,12 @@ if str(REPO_ROOT) not in sys.path:
from scripts.runtime.assembly import (
ChapterAssemblyWorker,
build_chapter_briefs,
build_compressed_findings,
build_chapter_user_prompt,
run_chapter_assembly_workers,
validate_chapter_markdown_citations,
validate_chapter_brief,
validate_compressed_finding,
)
from scripts.runtime.roles import resolve_runtime_profile
@@ -104,6 +106,17 @@ def test_build_chapter_briefs_aggregates_packets_by_chapter(tmp_path: Path) -> N
assert "src_002" in brief["source_ids"]
assert (project / "phase2/chapter_briefs/ch01.json").exists()
compressed = build_compressed_findings(project)
assert len(compressed) == 1
finding = compressed[0]
validate_compressed_finding(finding)
assert finding["chapter_id"] == "ch01"
assert "chapter_thesis" in finding
assert "evidence_landings" in finding
assert "src_001" in finding["source_ids"]
assert (project / "phase2/compressed_findings/ch01.json").exists()
def test_chapter_prompt_contains_brief_and_fragmentation_guard() -> None:
brief = {
@@ -122,6 +135,7 @@ def test_chapter_prompt_contains_brief_and_fragmentation_guard() -> None:
assert "临床证据正在重塑需求判断" in prompt
assert "避免碎片化" in prompt
assert "compressed finding" in prompt
assert "只输出 Markdown" in prompt
+11
View File
@@ -62,9 +62,20 @@ def test_framework_mentions_ingested_materials(tmp_path: Path) -> None:
render_framework(project, method_key="gmp_quality_operations_diagnosis")
framework = (project / "phase1/framework.md").read_text(encoding="utf-8")
research_brief_md = project / "phase1" / "research_brief.md"
research_brief_json = project / "phase1" / "research_brief.json"
brief = json.loads(research_brief_json.read_text(encoding="utf-8"))
assert "phase0/extracted/audit.md" in framework
assert "NMPA、FDA、EMA、ICH、WHO" in framework
assert "请先确认 `phase1/material_brief.md`" in framework
assert research_brief_md.exists()
assert "任务切分原则" in research_brief_md.read_text(encoding="utf-8")
assert brief["research_method"] == "gmp_quality_operations_diagnosis"
assert brief["work_language"] == "zh"
assert brief["task_planning"]["required_skills"]
assert brief["task_planning"]["search_routes_by_axis"]["counter"] == ["scholar", "general"]
assert brief["phase2_inputs"]["framework_path"] == "phase1/framework.md"
def test_pdf_requiring_ocr_uses_firered_and_records_result(tmp_path: Path, monkeypatch) -> None:
+19
View File
@@ -45,6 +45,23 @@ def test_orchestrator_reads_research_method_from_manifest(tmp_path: Path) -> Non
"## 第1章 GMP 体系差距需要按法规和风险双轴定位\n\n研究思路。",
encoding="utf-8",
)
(project / "phase1" / "research_brief.json").write_text(
json.dumps(
{
"research_method": "gmp_gap_assessment",
"work_language": "zh",
"task_planning": {
"required_skills": ["search-gateway", "evidence-table"],
"search_routes_by_axis": {"regulatory_gap": ["general", "news"]},
"axis_prompt_briefs": {"regulatory_gap": "逐条映射法规基线与审计差距。"},
"stop_conditions": ["证据不足则回炉补证。"],
},
"materials": [{"path": "phase0/extracted/audit.md"}],
},
ensure_ascii=False,
),
encoding="utf-8",
)
cards = create_phase2_task_cards(project, dry_run=True)
@@ -53,3 +70,5 @@ def test_orchestrator_reads_research_method_from_manifest(tmp_path: Path) -> Non
"risk_classification",
"capa_design",
]
assert cards[0]["prompt_brief"] == "逐条映射法规基线与审计差距。"
assert cards[0]["allowed_materials"] == ["phase0/extracted/audit.md"]
+42
View File
@@ -17,6 +17,7 @@ from scripts.runtime.tasks import (
TaskCard,
detect_dependency_cycles,
generate_task_cards,
generate_task_cards_from_research_brief,
validate_packet,
validate_task_cards,
)
@@ -77,6 +78,47 @@ def test_generate_task_cards_from_chinese_framework() -> None:
"ch02-regulatory",
]
assert cards[0].output_packet == "phase2/packets/ch01-clinical.json"
assert cards[0].research_goal
assert "search-gateway" in cards[0].required_skills
assert cards[0].expected_evidence["min_tier_1_2_sources"] == 2
assert cards[0].stop_conditions
def test_generate_task_cards_from_research_brief_carries_prompt_and_skills() -> None:
brief = {
"research_method": "gmp_quality_operations_diagnosis",
"work_language": "zh",
"tone": "面向管理层的事实型整改诊断",
"task_planning": {
"required_skills": ["search-gateway", "evidence-table", "source-quality"],
"search_routes_by_axis": {
"quality_system_gap": ["general", "news"],
"counter": ["scholar", "general"],
},
"axis_prompt_briefs": {
"quality_system_gap": "把现场发现映射到质量体系流程缺口和法规要求。",
"counter": "主动寻找能削弱或限定结论的反方证据。",
},
"stop_conditions": ["每张卡至少形成 3 条可追溯证据。"],
},
"materials": [{"path": "phase0/extracted/audit.md", "role": "site_evidence"}],
}
framework = "## 第1章 质量体系闭环能力决定整改可信度\n\n研究思路。"
cards = generate_task_cards_from_research_brief(
"baifan-test",
framework,
brief,
axes=["quality_system_gap", "counter"],
)
assert [card.task_id for card in cards] == ["ch01-quality_system_gap", "ch01-counter"]
assert cards[0].prompt_brief == "把现场发现映射到质量体系流程缺口和法规要求。"
assert cards[0].research_method == "gmp_quality_operations_diagnosis"
assert cards[0].allowed_materials == ["phase0/extracted/audit.md"]
assert cards[0].preferred_model_role == "dr_analyst"
assert cards[1].preferred_model_role == "dr_verifier"
assert "search-gateway" in cards[0].required_skills
def test_task_card_validation_rejects_duplicates_and_cycles() -> None: