from __future__ import annotations from copy import deepcopy import pytest @pytest.fixture def current_bundle(): bundle = { "record": { "id": 88001, "status": "running", "script_direction": "解释一家工厂怎样通过柔性排产减少浪费。", "summary": None, "error_message": None, "agent_config": {"model_name": "test-model"}, "cost_usd": 1.2, "start_time": "2026-07-13T10:00:00", "end_time": None, }, "rounds": [ { "id": 1, "round_index": 1, "goal": "确定文章结构并补齐可靠行业事实", "multipath_plan": [ {"path_index": 1, "target": "文章结构"}, {"path_index": 2, "target": "行业事实"}, {"path_index": 3, "target": "结尾表达"}, ], "race_or_divide": "分工", "plan_note": "内容方案和领域信息方案并行推进。", "status": "done", }, { "id": 2, "round_index": 2, "goal": "补齐正文细节", "multipath_plan": [{"path_index": 1, "target": "正文"}], "race_or_divide": "赛马", "plan_note": None, "status": "open", }, ], "branches": [ _branch(1, 1, "内容", "形成三段式文章结构", "merged"), _branch(1, 2, "领域信息", "核实柔性排产数据", "discarded"), _branch(1, 3, "内容", "形成行动建议结尾", "parked"), _branch(2, 4, "内容", "补齐正文案例", "open"), ], "dataDecisions": [ _data_decision(11, 1, 1, "采用案例中的三段结构", "结构能解释因果关系"), _data_decision(12, 1, 2, "采用两条交叉印证的数据", "两类来源结论一致"), _data_decision(13, 1, 3, "采用行动建议写法", None), ], "multipathDecisions": [ { "id": 21, "script_build_id": 88001, "round_index": 1, "branch_ids": [1, 2], "decision": "采用方案 1;方案 2 的领域事实保留,但内容分支不采用。", "reasoning": "结构可直接进入主脚本,领域事实独立沉淀。", "created_at": "2026-07-13T10:03:00", }, { "id": 22, "script_build_id": 88001, "round_index": 1, "branch_ids": [3], "decision": "方案 3 暂存。", "reasoning": "方向可用,但与正文衔接仍需调整。", "created_at": "2026-07-13T10:04:00", }, ], "domainInfo": [ { "id": 31, "script_build_id": 88001, "round_index": 1, "branch_id": 2, "content": "柔性排产可降低小批量切换损耗。", "source": [{"type": "report", "id": "R-1", "loc": "p.4"}], "note": "两份报告交叉印证", "created_at": "2026-07-13T10:02:30", } ], "events": [ { "id": 39, "event_seq": 6, "event_type": "agent_invoke", "event_name": "script_multipath_evaluator", "round_index": 1, "status": "ok", "inputData": {"task": "比较 branch_id=1, branch_id=2"}, "agentOutputData": {"summary": "### 分支评估 branch_id=1\n**该支结论**:通过\n**目标推进**:结构清晰。\n\n### 分支评估 branch_id=2\n**该支结论**:部分通过\n**目标推进**:事实可靠。\n\n### 对比与建议\n**采纳建议**:优先采用 branch_id=1。"}, "started_at": "2026-07-13T10:02:40", "ended_at": "2026-07-13T10:02:50", }, { "id": 40, "event_seq": 7, "event_type": "agent_invoke", "event_name": "script_multipath_evaluator", "round_index": 1, "status": "ok", "inputData": {"task": "评审 branch_id=3"}, "agentOutputData": {"summary": "### 分支评估 branch_id=3\n**该支结论**:通过\n**目标推进**:结尾方向可用。\n\n### 对比与建议\n**采纳建议**:可以暂存后调整。"}, "started_at": "2026-07-13T10:03:30", "ended_at": "2026-07-13T10:03:40", }, { "id": 41, "event_seq": 8, "event_type": "agent_invoke", "event_name": "script_evaluator", "round_index": 1, "status": "ok", "title": "派发 script_evaluator (ok)", "input_preview": "请评估第1轮", "output_preview": "### 整体结论:部分通过\n仍需完善正文细节。", "agentOutputData": {"summary": "### 整体结论:部分通过\n仍需完善正文细节。"}, "started_at": "2026-07-13T10:05:00", "ended_at": "2026-07-13T10:05:10", }, { "id": 42, "event_seq": 9, "event_type": "agent_invoke", "event_name": "retrieve_data_knowledge", "status": "ok", "title": "无法归属的取数 Agent", "started_at": "2026-07-13T10:06:00", "ended_at": "2026-07-13T10:06:10", }, { "id": 50, "event_seq": 10, "event_type": "agent_invoke", "event_name": "script_implementer", "agent_role": "script_implementer", "round_index": 1, "branch_id": 1, "status": "ok", "started_at": "2026-07-13T10:00:00", "ended_at": "2026-07-13T10:02:00", }, { "id": 51, "event_seq": 11, "event_type": "tool_call", "event_name": "get_script_snapshot", "agent_role": "script_implementer", "scope_event_id": 50, "round_index": 1, "branch_id": 1, "status": "ok", "inputData": {}, "output_preview": "{\"count\": 1}", "started_at": "2026-07-13T10:00:05", "ended_at": "2026-07-13T10:00:06", }, { "id": 52, "event_seq": 12, "event_type": "agent_invoke", "event_name": "retrieve_data_decode_case", "parent_event_id": 50, "scope_event_id": 50, "round_index": 1, "branch_id": 1, "status": "ok", "inputData": {"task": "查找可说明因果结构的解构 Case"}, "agentOutputData": {"summary": "初筛出两个可用的三段式案例。"}, "started_at": "2026-07-13T10:00:10", "ended_at": "2026-07-13T10:00:40", }, { "id": 53, "event_seq": 13, "event_type": "tool_call", "event_name": "search_script_decode_case", "scope_event_id": 52, "parent_event_id": 52, "round_index": 1, "branch_id": 1, "status": "ok", "inputData": {"keyword": "因果结构"}, "output_preview": "{\"count\": 2}", "started_at": "2026-07-13T10:00:15", "ended_at": "2026-07-13T10:00:20", }, { "id": 54, "event_seq": 14, "event_type": "tool_call", "event_name": "search_script_decode_case", "scope_event_id": 52, "parent_event_id": 52, "round_index": 1, "branch_id": 1, "status": "ok", "inputData": {"keyword": "柔性排产"}, "output_preview": "{\"count\": 0}", "started_at": "2026-07-13T10:00:25", "ended_at": "2026-07-13T10:00:30", }, ], "ignoredLegacyDataDecisionCount": 2, "currentArtifact": { "paragraphs": [{"id": 1}, {"id": 2}, {"id": 3}], "elements": [{"id": 10}, {"id": 11}], "paragraphElements": [{"id": 100, "paragraph_id": 1, "element_id": 10}], "sourceOrigin": "database", }, } return deepcopy(bundle) def _branch(round_index: int, branch_id: int, path_type: str, task: str, status: str): snapshot = { "paragraphs": [{"id": branch_id * 100, "name": task}], "elements": [{"id": branch_id * 1000}], "paragraphElements": [], } return { "id": branch_id, "script_build_id": 88001, "branch_id": branch_id, "round_index": round_index, "path_type": path_type, "target": task, "impl_task": task, "self_assessment": f"已经完成:{task}", "status": status, "decision_reasoning": f"方案 {branch_id} 的当前处理理由", "candidate_snapshot": { "snapshot": snapshot if path_type == "内容" else None, "snapshotKind": "saved-at-disposition" if status in {"merged", "discarded"} else "current-overlay", "historicalAccuracy": "exact" if status in {"merged", "discarded"} else "unknown", "currentProjectionAccuracy": "exact" if status in {"open", "parked"} else "not-applicable", "note": "测试候选版本", }, } def _data_decision(record_id: int, round_index: int, branch_id: int, decision: str, reasoning: str | None): return { "id": record_id, "script_build_id": 88001, "round_index": round_index, "branch_id": branch_id, "sources": [{"data_type": "领域信息", "data_id": f"S-{record_id}", "data_content": "已核实材料"}], "decision": decision, "reasoning": reasoning, "created_at": "2026-07-13T10:02:00", }