使用者的原始运行记录只给问数据的运行,对账运行经证据接口读(复核 M3)

复核发现:使用者(开登录后的 user 角色)发起的口径对账运行带 MASK_RESULTS、记在本人名下,run_events_readable 只看这两条,
于是他能经 /api/runs/{id}、/events、/graph 读到对账运行的原始图和事件,里面原样是口径取数节点的 SQL 模板。这一波正是以
「口径的 SQL 可能写着遮罩值」为由不让使用者在问数据里看口径、use_caliber,这条读法绕开了证据面板按遮罩换 SQL 的那一层。

做法:api/deps.run_events_readable 给 user 角色再加一条 origin_kind == "chat"——原始记录、事件、运行时的图、实时流只给他
自己的、查询结果在工具边界遮过的问数据运行(原来的说明里就写着「实际上满足的就是它自己的问数据运行」,这次照实收紧)。
对账运行他仍然能经账本和证据接口读(can_read_run 不变,那里展示的 SQL 按遮罩换过),对账的发起也不变。改了
api/deps.py 的这一个函数(没分给哪个包)和 ledger/reconcile 的模块说明。

测试:开账号密码登录,使用者对自己的问数据答案经接口发起对账,对账运行的 /api/runs/{id}、/events、/graph 都回 403,证据
接口 200;他自己的问数据运行这三样照旧 200。去掉这一条回跑,新用例失败;test_auth_access、test_personal_apps 照旧过。
This commit is contained in:
ThearchyHelios
2026-10-16 18:25:43 +08:00
parent 37d0f0abf1
commit 38d9082994
3 changed files with 46 additions and 7 deletions
+34
View File
@@ -214,3 +214,37 @@ async def test_users_reconcile_their_own_answers_read_only_and_masked(client, mo
assert run.options[MASK_RESULTS_OPTION] is True and run.options[READ_ONLY_OPTION] is True
done = await S.wait(run.id)
assert done.status == "succeeded", done.error
async def test_users_read_their_reconcile_runs_only_through_the_evidence(client, monkeypatch):
"""使用者发起的对账运行带 MASK_RESULTS、记在他名下,但派生图里有口径取数节点的 SQL 模板(口径的 SQL 可能写着遮罩值,
所以问数据里使用者不看口径、不能 use_caliber):运行的原始记录、事件、运行时的图(/api/runs/{id}、/events、/graph)只给
他自己的问数据运行,对账运行经证据接口读(那里按遮罩渲染)。"""
from app.tools.datasource import MASK_RESULTS_OPTION
from tests.fakes import auth_env
wf = await S.publish()
row = await S.explore(monkeypatch, S.WITH_REFUNDS, origin="chat")
# 当作开登录后使用者 carol 问的:问数据运行在工具边界遮
async with SessionLocal() as session:
source = await session.get(Run, row.id)
source.started_by, source.options = "carol", {MASK_RESULTS_OPTION: True}
await session.commit()
[action] = [a for a in (await ledger_of(client, row.id))["actions"] if a["kind"] == "reconcile"]
await auth_env.reset()
try:
admin = await auth_env.turn_on_local()
await auth_env.make_user("carol", "user")
assert (await admin.put("/api/auth/settings", json={"user_can_chat": True})).status_code == 200
carol = await auth_env.login("carol")
res = await carol.post(f"/api/ledger/answers/{row.id}/reconcile", json={
"query": action["query"], "workflow_id": wf, "version": 1, "inputs": CHECKED, "confirm": True})
assert res.status_code == 201, res.text
done = await S.wait(res.json()["run_id"])
assert done.status == "succeeded" and done.started_by == "carol" and done.options[MASK_RESULTS_OPTION] is True
for rest in ("", "/events", "/graph"):
assert (await carol.get(f"/api/runs/{done.id}{rest}")).status_code == 403, rest
assert (await carol.get(f"/api/runs/{row.id}{rest}")).status_code == 200, f"自己的问数据运行照旧:{rest}"
assert (await carol.get(f"/api/runs/{done.id}/evidence")).status_code == 200
finally:
await auth_env.reset()