muse-agent-example/tests/集成/test_方法启用凭据.py
zizi 0eba8e4f34 重构(测试): 删除85次合成调用的资格终态用例
去掉四条用假HTTP循环85次的慢用例,以及浏览器报告中依赖同一路径的effect参数。
资格门槛仍由契约与单元覆盖;生产效果标准不改。
2026-09-18 11:21:41 +08:00

103 lines
4.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""原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]