"""固定真实方法、反馈和B10实验;跨用途及owner提交后登记中断可恢复。""" import json import os import subprocess import sys from dataclasses import asdict, replace from uuid import uuid4 import pytest import test_方法启用凭据 as 启用测试 import test_正文候选与作者决定 as 正文测试 from muse.作者经验.接口 import 反馈版本, 反馈请求, 改进定位, 改进请求 from muse.共享.调用身份 import 用途 from muse.共享.错误 import Muse错误 from muse.正文写作.接口 import 读取候选依据 pytestmark = pytest.mark.数据库 方法环境 = 启用测试.方法环境 执行环境 = 启用测试.执行环境 def _提案(env): app, author = env["business"], env["owner"] service = app.要求作者经验() body = app.要求正文() body.保存人工(author, "before", "mw-1", 0, 正文测试.草稿()) candidate = body.创建人工候选(author, "after", "mw-1", 1, 正文测试.草稿("改过的一句。"))[ "results" ][0] original = body.读取正文(author, "mw-1") with env["pools"][用途.生产].连接(只读=True) as conn: updated = 读取候选依据(conn, author.作者, candidate["candidate_id"], 1) feedback = service.记录反馈( author, "improvement-feedback", 反馈请求( "method-work", 反馈版本("document", "mw-1", 1, original["document_hash"]), 反馈版本("candidate", candidate["candidate_id"], 1, updated["document_hash"]), "回收前文物件,不再临时添加解释。", "revise", ), ) request = 改进请求( str(uuid4()), 0, "检验物件回收方法", "依据本次修改保留回收时机。", str(env["version"]["version_id"]), (str(feedback["feedback_id"]),), ) row = service.提出改进(author, request) return service, request, 改进定位(request.improvement_id, row["revision"], row["content_hash"]) @pytest.mark.case_id( "NC-w26-26c002", environment="隔离PG、实际B10/S01/B04与合成HTTP;不认证外部文学效果", given="确切方法版本、真实反馈和同作者用途配置", when="登记具体改进、实际验证和owner启停并恢复已提交结果;记录分版本观察", then=["无真实反馈或异目标不能登记改进实验"], contract="docs/系统架构/新版设计/模块设计/B07-作者经验.md", ) @pytest.mark.parametrize("执行环境", [启用测试.参数], indirect=True) def test_无真实反馈或异目标不能登记改进实验__26c002(执行环境, 方法环境): env = 启用测试._确认方法(执行环境, 方法环境) service, request, point = _提案(env) with pytest.raises(Muse错误): service.提出改进( env["owner"], replace(request, improvement_id=str(uuid4()), feedback_ids=(str(uuid4()),)), ) with pytest.raises(Muse错误, match="非空"): replace(request, feedback_ids=()) with pytest.raises(Muse错误, match="同一具体改进"): service.申请验证( env["owner"], "wrong-target", point, env["app"].要求评测(), env["actor"], env["request"] ) assert service.读取改进(env["owner"], request.improvement_id)["actions"] == [] stranger = replace(env["owner"], 作者="stranger") with pytest.raises(Muse错误): service.读取改进(stranger, request.improvement_id) assert env["methods"].读取方法详情(env["owner"], env["method_id"])["state"] == "confirmed" assert env["received"] == [] @pytest.mark.case_id( "NC-w26-26c003", environment="隔离PG、实际B10/S01/B04与合成HTTP;不认证外部文学效果", given="确切方法版本、真实反馈和同作者用途配置", when="登记具体改进、实际验证和owner启停并恢复已提交结果;记录分版本观察", then=["具体改进CLI与作者HTTP引用同一版本"], contract="docs/系统架构/新版设计/模块设计/B07-作者经验.md", ) def test_具体改进CLI与作者HTTP引用同一版本__26c003(方法环境, tmp_path): import test_偏好实际消费 as 作者测试 import test_生产评测权限隔离 as 接入测试 from fastapi.testclient import TestClient from muse.接入.http.应用 import 创建应用 from muse.配置 import 读取配置 env = 启用测试._确认方法({"actor": 方法环境[1]}, 方法环境) service, request, point = _提案(env) config = 接入测试._配置文件(env["pools"][用途.生产], tmp_path) config.write_text(config.read_text().replace("eval-author", env["owner"].作者)) changed = replace(request, improvement_id=str(uuid4()), title="CLI具体改进") file = tmp_path / "improvement.json" file.write_text(json.dumps({"proposal": asdict(changed)}, ensure_ascii=False)) process = subprocess.run( [sys.executable, "-m", "muse", "经验", str(config), "提出改进", str(file)], cwd=tmp_path, text=True, capture_output=True, timeout=30, ) assert process.returncode == 0, process.stderr created = json.loads(process.stdout) assert created["improvement_id"] == changed.improvement_id process = subprocess.run( [sys.executable, "-m", "muse", "经验", str(config), "读取改进", changed.improvement_id], cwd=tmp_path, text=True, capture_output=True, timeout=30, ) assert process.returncode == 0, process.stderr assert json.loads(process.stdout)["target_state"] == "confirmed" with TestClient(创建应用(读取配置(config)), headers={"origin": "http://testserver"}) as client: assert ( client.post( "/api/v1/session", json={"password": "synthetic-evaluation-only"} ).status_code == 200 ) detail = client.get("/api/v1/improvements/" + point.improvement_id) assert detail.status_code == 200 and detail.json()["content_hash"] == point.content_hash assert detail.json()["consumption"] == [] invalid = client.post( "/api/v1/improvements", json={"proposal": {**asdict(changed), "expected_revision": True}}, ) assert invalid.status_code == 422 denied = client.post( "/api/v1/improvements/enable", json={"command_id": "bad-proof", "selection": asdict(point), "proof_id": str(uuid4())}, ) assert denied.status_code >= 400, denied.text assert client.get("/api/v1/improvements/" + point.improvement_id).json()["actions"] == [] if os.environ.get("MUSE_RUN_BROWSER") == "1": output = 作者测试._浏览器偏好( 读取配置(config), request.feedback_ids[0], tmp_path, "具体改进.spec.ts" ) files = list(output.rglob("实际改进.json")) assert len(files) == 1 saved = json.loads(files[0].read_text()) actual = service.读取改进(env["owner"], saved["improvement_id"]) assert actual["content_hash"] == saved["content_hash"] assert actual["target_state"] == "confirmed" and actual["actions"] == [] report = service.读取观察(env["owner"], saved["improvement_id"]) assert report["groups"][0]["metrics"]["review_seconds"]["total"] == 0 assert report["groups"][0]["metrics"]["cost_usd"]["total"] is None