mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-15 04:51:57 +00:00
测试夹具:表助手和导入导出测试里虚构订单表的号码列改叫 buyer_phone(和仓库里其他虚构夹具一致)
This commit is contained in:
@@ -101,7 +101,7 @@ def _shop_db(path) -> str:
|
||||
conn.executescript("""
|
||||
CREATE TABLE members (id INTEGER PRIMARY KEY, nick TEXT);
|
||||
CREATE TABLE orders (id INTEGER PRIMARY KEY, order_no TEXT NOT NULL, status INTEGER NOT NULL,
|
||||
amount REAL, contact_phone TEXT, created_at TEXT,
|
||||
amount REAL, buyer_phone TEXT, created_at TEXT,
|
||||
member_id INTEGER REFERENCES members(id));
|
||||
""")
|
||||
conn.executemany("INSERT INTO members VALUES (?, ?)", [(i, f"会员{i}") for i in range(1, 6)])
|
||||
@@ -119,7 +119,7 @@ ORDERS_NOTES = {
|
||||
"kind": make_item("fact", "llm", "rejected"),
|
||||
"columns": {
|
||||
"status": {"codes": make_item({"1": "已支付"}, "profile", note="数据剖析:全表 30 行,2 个取值")},
|
||||
"contact_phone": {"label": make_item("联系电话", "llm"),
|
||||
"buyer_phone": {"label": make_item("联系电话", "llm"),
|
||||
"codes": make_item({PHONES[0]: "测试号"}, "human", "confirmed")},
|
||||
},
|
||||
}
|
||||
@@ -142,7 +142,7 @@ async def client():
|
||||
|
||||
async def _source(client, tmp_path, *, profile: bool = True, guidance: str | None = "金额一律按元",
|
||||
notes: dict | None = None) -> str:
|
||||
options: dict[str, Any] = {"mask_columns": "contact_phone"}
|
||||
options: dict[str, Any] = {"mask_columns": "buyer_phone"}
|
||||
if profile:
|
||||
options["catalog_profile"] = {"enabled": True}
|
||||
if guidance:
|
||||
@@ -346,7 +346,7 @@ async def test_background_has_structure_catalog_and_hides_masked_values(client,
|
||||
# 界面上还没保存的修改
|
||||
assert "columns.amount.unit" in system and "用户说:金额是元" in system
|
||||
# 遮罩列只给列名:码值、取值一个都不给
|
||||
assert "contact_phone" in system
|
||||
assert "buyer_phone" in system
|
||||
assert not any(p in system for p in PHONES) and "测试号" not in system
|
||||
# 没开剖析的源才写不能查数据;这里开了,给了查询工具
|
||||
assert model.tool_names() == ["run_query", "propose_changes"]
|
||||
@@ -422,7 +422,7 @@ async def test_proposals_are_checked_and_never_written(client, tmp_path, monkeyp
|
||||
{"path": "valid_filter", "value": "status <> 9", "reason": "用户说:统计时排除作废"},
|
||||
{"path": "columns.amount.meaning", "value": "实收=单价*数量", "reason": "x"}, # 公式:不收
|
||||
{"path": "columns.ghost.label", "value": "幽灵", "reason": "x"}, # 列不存在:不收
|
||||
{"path": "columns.contact_phone.codes", "value": {PHONES[1]: "客服"}, "reason": "x"}, # 遮罩列:不给码值
|
||||
{"path": "columns.buyer_phone.codes", "value": {PHONES[1]: "客服"}, "reason": "x"}, # 遮罩列:不给码值
|
||||
{"path": "grain", "value": "每笔订单一行", "reason": "x"}, # 已经是这个值:不用提
|
||||
]
|
||||
model = Scripted([Turn(text=["好的,"], calls=[("propose_changes", {"changes": changes})]),
|
||||
@@ -562,7 +562,7 @@ async def test_queries_are_read_only_masked_and_capped(client, tmp_path, monkeyp
|
||||
sid = await _source(client, tmp_path)
|
||||
queries = [
|
||||
("run_query", {"sql": "SELECT status, COUNT(*) AS n FROM orders GROUP BY status ORDER BY status"}),
|
||||
("run_query", {"sql": "SELECT id, contact_phone AS phone, amount FROM orders ORDER BY id"}),
|
||||
("run_query", {"sql": "SELECT id, buyer_phone AS phone, amount FROM orders ORDER BY id"}),
|
||||
("run_query", {"sql": "DELETE FROM orders"}),
|
||||
]
|
||||
model = Scripted([Turn(text=["我查一下。"], calls=queries),
|
||||
|
||||
@@ -49,7 +49,7 @@ def _tables(*, upper: bool = False) -> dict:
|
||||
n("orders"): {"qualified": n("orders"), "primary_key": [n("id")], "comment": None, "is_view": False,
|
||||
"foreign_keys": [], "unique": [],
|
||||
"columns": [_col(n("id")), _col(n("status")), _col(n("amount"), "REAL"), _col(n("member_id")),
|
||||
_col(n("contact_phone"), "TEXT")]},
|
||||
_col(n("buyer_phone"), "TEXT")]},
|
||||
n("members"): {"qualified": n("members"), "primary_key": [n("id")], "comment": None, "is_view": False,
|
||||
"foreign_keys": [], "unique": [], "columns": members_cols},
|
||||
n("refunds"): {"qualified": n("refunds"), "primary_key": [n("id")], "comment": None, "is_view": False,
|
||||
@@ -75,7 +75,7 @@ SOURCE_ORDERS = {
|
||||
"status": {"codes": make_item({"1": "已支付", "9": "作废"}, "human", "confirmed", complete=True),
|
||||
"label": make_item("状态", "llm")},
|
||||
"amount": {"unit": make_item("元", "human", "confirmed"), "measure": make_item("flow", "llm")},
|
||||
"contact_phone": {"codes": make_item({"13900000001": "测试号"}, "human", "confirmed"),
|
||||
"buyer_phone": {"codes": make_item({"13900000001": "测试号"}, "human", "confirmed"),
|
||||
"label": make_item("联系电话", "human", "confirmed")},
|
||||
# 目标表结构里没有这一列
|
||||
"gift_flag": {"label": make_item("赠品标记", "human", "confirmed")},
|
||||
@@ -139,7 +139,7 @@ async def _pair() -> tuple[str, str]:
|
||||
{"orders": SOURCE_ORDERS, "members": SOURCE_MEMBERS, "ghost_table": SOURCE_GHOST},
|
||||
options={CATALOG_DRAFT_GUIDANCE_OPTION: "金额一律按元"})
|
||||
remote = await _source(f"deploy_{uuid.uuid4().hex[:6]}", _tables(upper=True), {"ORDERS": TARGET_ORDERS},
|
||||
options={"mask_columns": "contact_phone"})
|
||||
options={"mask_columns": "buyer_phone"})
|
||||
return local, remote
|
||||
|
||||
|
||||
@@ -212,7 +212,7 @@ async def test_preview_reports_and_writes_nothing(client):
|
||||
assert "保留" in label["why"]
|
||||
skipped = {s["path"]: s["why"] for s in orders["skipped"]}
|
||||
assert "columns.gift_flag.label" in skipped and "表结构里没有列 gift_flag" in skipped["columns.gift_flag.label"]
|
||||
assert "遮罩" in skipped["columns.contact_phone.codes"]
|
||||
assert "遮罩" in skipped["columns.buyer_phone.codes"]
|
||||
stores = next(p for p in skipped if p.startswith("relations."))
|
||||
assert "stores" in skipped[stores]
|
||||
# 新增:dedup(驳回的照带)、status 码值、amount 两项、联系电话的中文名、关联关系;更新:有效记录条件
|
||||
@@ -257,7 +257,7 @@ async def test_import_writes_by_the_rules_and_reports_versions(client):
|
||||
assert notes["columns"]["STATUS"]["label"]["value"] == "状态码"
|
||||
assert notes["columns"]["AMOUNT"]["measure"] == SOURCE_ORDERS["columns"]["amount"]["measure"]
|
||||
# 遮罩列:中文名照带,码值不导入
|
||||
assert notes["columns"]["CONTACT_PHONE"] == {"label": SOURCE_ORDERS["columns"]["contact_phone"]["label"]}
|
||||
assert notes["columns"]["BUYER_PHONE"] == {"label": SOURCE_ORDERS["columns"]["buyer_phone"]["label"]}
|
||||
assert "GIFT_FLAG" not in notes["columns"] and "gift_flag" not in notes["columns"]
|
||||
[rel] = notes["relations"]
|
||||
assert rel["id"] == catalog.relation_id("ORDERS", ["MEMBER_ID"], "MEMBERS", ["ID"])
|
||||
@@ -380,7 +380,7 @@ async def test_valid_filter_columns_must_be_in_the_target_table(client):
|
||||
assert why and "子查询" in why
|
||||
why, _ = await outcome("status <> 9; DELETE FROM orders")
|
||||
assert why and "条件" in why
|
||||
for fine in ("orders.status <> 9", "ORDERS.STATUS <> 9 AND ABS(amount) > 0", "contact_phone IS NOT NULL"):
|
||||
for fine in ("orders.status <> 9", "ORDERS.STATUS <> 9 AND ABS(amount) > 0", "buyer_phone IS NOT NULL"):
|
||||
why, update = await outcome(fine)
|
||||
assert why is None and update == 1, fine
|
||||
|
||||
|
||||
Reference in New Issue
Block a user