From 730d3a8ff4a799235d6c81bc1a57483e833d6218 Mon Sep 17 00:00:00 2001 From: ThearchyHelios Date: Fri, 16 Oct 2026 14:06:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=84=E6=B5=8B=E6=9C=9F=E6=9C=9B=E7=9A=84?= =?UTF-8?q?=E9=81=AE=E7=BD=A9=E6=8B=92=E6=94=B6=E6=B5=8B=E8=AF=95=EF=BC=9A?= =?UTF-8?q?=E6=AF=8F=E7=A7=8D=E5=86=99=E6=B3=95=E7=9A=84=E6=9C=9F=E6=9C=9B?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E5=86=99=E5=9C=A8=E5=8F=82=E6=95=B0=E9=87=8C?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E5=86=8D=E7=94=A8=E5=B5=8C=E5=A5=97=E7=9A=84?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E8=A1=A8=E8=BE=BE=E5=BC=8F=E6=8B=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/tests/test_eval_gold.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/backend/tests/test_eval_gold.py b/backend/tests/test_eval_gold.py index 02a736f7..7366587b 100644 --- a/backend/tests/test_eval_gold.py +++ b/backend/tests/test_eval_gold.py @@ -133,17 +133,16 @@ async def test_the_read_only_guard_refuses_writes_before_anything_runs(source): assert db.execute("SELECT COUNT(*) FROM orders").fetchone()[0] == len(shop.ROWS) -@pytest.mark.parametrize("sql, refused", [ - ("SELECT status, COUNT(*) AS n FROM orders GROUP BY status", True), - ("SELECT status AS 状态 FROM orders", True), # 改了名字也认得出 - ("SELECT * FROM orders", True), - ("SELECT COUNT(*) AS n FROM orders WHERE status = 'paid'", False), # 结果里没有取自遮罩列的格 +@pytest.mark.parametrize("sql, expectation, refused", [ + ("SELECT status, COUNT(*) AS n FROM orders GROUP BY status", {"kind": "set", "column": "status"}, True), + ("SELECT status AS 状态 FROM orders", {"kind": "set", "column": "状态"}, True), # 改了名字也认得出 + ("SELECT * FROM orders", {"kind": "table", "keys": ["id"]}, True), + # 结果里没有取自遮罩列的格:条件里用到遮罩列不算 + ("SELECT COUNT(*) AS n FROM orders WHERE status = 'paid'", {"kind": "scalar", "column": "n"}, False), ]) -async def test_gold_that_uses_a_masked_column_is_refused(tmp_path, sql, refused): +async def test_gold_that_uses_a_masked_column_is_refused(tmp_path, sql, expectation, refused): name, sid = await shop.add_source(shop.build(tmp_path / "masked.db"), options={"mask_columns": ["status"]}) try: - expectation = {"kind": "scalar", "column": "n"} if not refused else {"kind": "table", "keys": ["id"]} \ - if sql.startswith("SELECT *") else {"kind": "set", "column": "状态" if "状态" in sql else "status"} outcome = await gold.compute_gold(sql_case(sid, sql, expectation), ctx()) if refused: assert outcome.status == "refused" and outcome.code == gold.GOLD_MASKED, outcome.reason