103 lines
4.0 KiB
Python
103 lines
4.0 KiB
Python
"""原S02→合格判据→最小证明→作者启用;仅隔离PG/合成HTTP,不认证外部文学效果。
|
||
|
||
runtime配置验证由测试夹具模拟,用来走有证据的分支;它不是生产配置批准。
|
||
"""
|
||
|
||
import json
|
||
from dataclasses import replace
|
||
from uuid import uuid4
|
||
|
||
import psycopg
|
||
import pytest
|
||
import test_上下文快照与索引写入 as 方法测试
|
||
import test_实际效果判据 as 效果测试
|
||
import test_评测执行与失败收敛 as 运行测试
|
||
|
||
from muse.共享.调用身份 import 用途
|
||
from muse.共享.错误 import Muse错误
|
||
from muse.知识方法.接口 import 状态命令
|
||
|
||
pytestmark = pytest.mark.数据库
|
||
执行环境 = 运行测试.执行环境
|
||
方法环境 = 方法测试.方法环境
|
||
|
||
|
||
def _响应工厂():
|
||
config = 效果测试._响应工厂()
|
||
original = config["generator_output"]
|
||
|
||
def generate(request, script):
|
||
data = json.loads(request["input"])
|
||
if data["instruction"].startswith("渡口"):
|
||
text = "他迎着细雨走到门前。" if "方法材料" in data["context"] else "他站在山门旁等候。"
|
||
return {"paragraphs": [{"text": data["instruction"] + "。" + text}]}
|
||
return original(request, script)
|
||
|
||
return {**config, "generator_output": generate}
|
||
|
||
|
||
参数 = {
|
||
**效果测试.参数,
|
||
"output_factory": _响应工厂,
|
||
"runtime_validation_fixture": True,
|
||
}
|
||
|
||
|
||
def _确认方法(env, method_env):
|
||
app, author, methods, source, _, pools = method_env
|
||
req = 方法测试._提案(str(uuid4()), "启用桥接方法", str(source.source_id), owner=author.作者)
|
||
proposed = methods.提出方法(author, "enablement-method", req)
|
||
方法测试._确认(methods, author, proposed["target_ref"])
|
||
version = methods.读取方法详情(author, req.method_id)["versions"][0]
|
||
return {
|
||
**env,
|
||
"actor": replace(env["actor"], 作者=author.作者),
|
||
"business": app,
|
||
"owner": author,
|
||
"methods": methods,
|
||
"method_id": req.method_id,
|
||
"version": version,
|
||
"pools": pools,
|
||
}
|
||
|
||
|
||
@pytest.mark.case_id(
|
||
"NC-w25-25f902",
|
||
environment="隔离PG;无效凭据与角色权限,不发起合成评测循环",
|
||
given="确切方法确认版本和明确作者身份",
|
||
when="核对启用凭据并执行当前目标的作者状态操作",
|
||
then=["不存在或格式错误的凭据不能启用,生产和评测角色不能写凭据原表"],
|
||
contract="docs/系统架构/新版设计/模块设计/B10-效果评测.md",
|
||
)
|
||
def test_未有目标证明不能启用且公开表不可写__25f902(方法环境):
|
||
app, owner, methods, source, _, pools = 方法环境
|
||
request = 方法测试._提案(str(uuid4()), source_id=str(source.source_id), owner=owner.作者)
|
||
proposed = methods.提出方法(owner, "unverified-method", request)
|
||
方法测试._确认(methods, owner, proposed["target_ref"])
|
||
for proof in ("not-a-uuid", str(uuid4())):
|
||
with pytest.raises(Muse错误):
|
||
methods.变更方法状态(
|
||
owner,
|
||
proof,
|
||
状态命令(
|
||
request.method_id,
|
||
"enable",
|
||
expected_state_revision=1,
|
||
启用凭据=proof,
|
||
),
|
||
)
|
||
assert methods.读取方法详情(owner, request.method_id)["state"] == "confirmed"
|
||
with pools[用途.生产].连接() as conn, pytest.raises(psycopg.errors.InsufficientPrivilege):
|
||
conn.execute("SELECT * FROM evaluation.muse_effect_assessment")
|
||
for purpose in (用途.生产, 用途.评测):
|
||
with pools[purpose].连接(只读=True) as conn:
|
||
for privilege in ("INSERT", "UPDATE", "DELETE"):
|
||
assert not conn.execute(
|
||
"SELECT has_table_privilege(current_user,%s,%s)",
|
||
("public.muse_enablement_receipt", privilege),
|
||
).fetchone()[0]
|
||
assert conn.execute(
|
||
"SELECT has_table_privilege(current_user,%s,'SELECT')",
|
||
("public.muse_enablement_status",),
|
||
).fetchone()[0]
|