"""跨章作者改稿同事务生成B05候选,逐章审阅和采纳仍归B05。""" from dataclasses import replace from uuid import uuid4 import pytest import test_定稿与导出 as 定稿测试 from muse.交付连载.接口 import 全书修订, 章节修订 from muse.共享.错误 import Muse错误 from muse.正文写作.接口 import 候选定位, 选段修改 pytestmark = pytest.mark.数据库 候选环境 = 定稿测试.候选环境 交付环境 = 定稿测试.交付环境 def _请求(face): chapters = [] for chapter in face["chapters"]: p = chapter["paragraph_locations"][0] chapters.append( 章节修订( chapter["chapter_id"], chapter["revision"], chapter["document_hash"], (选段修改(p["paragraph_id"], p["paragraph_hash"], 0, 2, p["text"][:2], "新稿"),), ) ) return 全书修订(str(uuid4()), face["work_id"], tuple(chapters)) @pytest.mark.case_id( "NC-w27-27c001", environment="隔离PG", given="本作者完整目录、确切正文版本与独立隔离数据", when="通过定稿、S02导出、跨章候选或连载反馈实际入口执行并检查失败恢复", then=["全书跨章候选原子保存且单章采纳不批准其他章"], contract="docs/系统架构/新版设计/模块设计/B08-交付连载.md", ) def test_全书跨章候选原子保存且单章采纳不批准其他章__27c001(交付环境): app, author, _, req = 交付环境 svc, body = app.要求交付(), app.要求正文() batch = _请求(svc.全书回看(author, req.work_id)) result = svc.提出跨章修订(author, "book-patches", batch) assert svc.提出跨章修订(author, "book-patches", batch) == result assert len(result["results"]) == 2 candidates = [body.列出候选(author, c.chapter_id)[0] for c in req.chapters] for c in candidates: row = body.读取候选(author, c["candidate_id"]) assert row["decision"] == "undecided" and row["visible_text"].startswith("新稿") first = body.读取候选(author, candidates[0]["candidate_id"]) point = 候选定位( first["candidate_id"], 1, first["candidate_hash"], first["document_id"], 1, ) review = body.打开候选审阅(author, point) 定稿测试.正文测试.决定(body, author, "one-adopt", point, review) assert body.读取正文(author, req.chapters[0].chapter_id)["revision"] == 2 assert body.读取正文(author, req.chapters[1].chapter_id)["revision"] == 1 assert body.读取候选(author, candidates[1]["candidate_id"])["decision"] == "undecided" @pytest.mark.case_id( "NC-w27-27c002", environment="隔离PG", given="本作者完整目录、确切正文版本与独立隔离数据", when="通过定稿、S02导出、跨章候选或连载反馈实际入口执行并检查失败恢复", then=["末章依据不符不留下前章候选且例外不能跨版本沿用"], contract="docs/系统架构/新版设计/模块设计/B08-交付连载.md", ) def test_末章依据不符不留下前章候选且例外不能跨版本沿用__27c002(交付环境): app, author, _, req = 交付环境 svc = app.要求交付() face = svc.全书回看(author, req.work_id, names={"原句": "新句"}) finding = face["copyedit"][0] assert finding["quote"] == "原句" and finding["start"] == 0 kept = svc.全书回看(author, req.work_id, names={"原句": "新句"}, exceptions=[finding["id"]]) assert kept["copyedit"][0]["disposition"] == "preserved" batch = _请求(face) bad = replace(batch.chapters[1], document_hash="0" * 64) with pytest.raises(Muse错误): svc.提出跨章修订(author, "bad-book", replace(batch, chapters=(batch.chapters[0], bad))) assert app.要求正文().列出候选(author, req.chapters[0].chapter_id) == [] app.要求正文().保存人工( author, "change-version", req.chapters[0].chapter_id, 1, 定稿测试.正文测试.草稿(尾句="改后"), ) changed = svc.全书回看( author, req.work_id, names={"原句": "新句"}, exceptions=[finding["id"]], ) assert changed["copyedit"][0]["disposition"] == "review" with pytest.raises(Muse错误): svc.提出跨章修订(author, "stale-book", batch)