"""合成场景在隔离PG上跑真实公开用例;不声称自然语言路由或真实模型效果。""" from pathlib import Path import pytest from muse.作品规划.接口 import 档案保存 from muse.效果评测.接口 import 执行行为场景, 服务观察适配, 载入行为场景 from muse.正文写作.接口 import 文本节点, 正文草稿, 段落 pytestmark = pytest.mark.数据库 场景集 = 载入行为场景((Path(__file__).parents[1] / "夹具/行为评测/诊断机器味场景.json").read_text()) @pytest.mark.case_id( "NC-w24-241005", environment="隔离PG真服务", given="固定六场景及逐例原始观察", when="显式脚本或真实隔离服务执行,注入缺失、禁止动作及伪报告", then=["场景逐个独立裁决,报告重算和读回、来源前后哈希、失败与模式均可追溯"], contract="docs/系统架构/新版设计/模块设计/B10-效果评测.md", ) @pytest.mark.parametrize("scene", 场景集, ids=lambda s: s.scenario_id) def test_真实服务观察报告读回及正文不变__241005(章后环境, scene): app, author = 章后环境["装配"], 章后环境["作者"] works, body, cases = app.要求作品(), app.要求正文(), app.要求审校() schema = works.新档案结构(author, "synthetic:demo", "work_core", 1) works.保存档案( author, "create-eval-work", 档案保存("synthetic:demo", 0, {"名称": "合成诊断场景"}, schema) ) works.添加章节( author, "create-eval-ch", "synthetic:demo", "synthetic-ch", "场景", 预期目录版本=0 ) body.保存人工( author, "seed-eval-text", "synthetic-ch", 0, 正文草稿((段落("p1", (文本节点(scene.text),)),)), ) target = {"work_id": "synthetic:demo", "chapter_id": "synthetic-ch", "branch_id": "main"} before = body.读取正文(author, "synthetic-ch") with app.要求数据库().连接(只读=True) as conn: commands = conn.execute("SELECT count(*) FROM muse_change_command").fetchone()[0] result = 执行行为场景(scene, 服务观察适配(body, cases, author, target)) assert result["passed"], result assert result["mode"] == "service" and not result["model_verified"] assert body.读取正文(author, "synthetic-ch") == before with app.要求数据库().连接(只读=True) as conn: assert conn.execute("SELECT count(*) FROM muse_change_command").fetchone()[0] == commands assert ( conn.execute( "SELECT count(*) FROM muse_attempt WHERE call_reference IS NOT NULL" ).fetchone()[0] == 0 ) assert conn.execute("SELECT count(*) FROM muse_diagnosis").fetchone()[0] == ( 1 if scene.expected == "report" else 0 ) if scene.expected == "report": observation = result["observation"] assert observation["report"] == observation["report_readback"] # 覆盖区间只统计真正执行的确定性规则;本场景没有激活规则,故为空。 coverage = observation["report"]["coverage"] assert coverage["text_length"] == len(scene.text) assert coverage["rules_executed"] == 0 and observation["report"]["empty_library"] is True assert coverage["deterministic"] == ( [[0, len(scene.text)]] if coverage["rules_executed"] else [] )