取数 SQL 不再把数据源名写成库名,试运行失败的蓝图不能发布:填关节的说明以前把表写成「数据源名.表名」,模型照抄进 SQL,数据库把数据源名当成库名(MySQL 报 Unknown database),应用每次出数都失败;说明改成只写数据源里的表名,并写明不要加数据源名。助手自查加 sql_source_prefix:表名前面写了数据源名就交回模型改(认列的检查找表时去掉前缀,拦不住它;数据源名恰好是库名、schema 的不报)。发布单遇到最近一次试运行失败改为挡住(plan.trial_failed,带出错的那一句),不再只是「还没有成功的试运行」的提醒

This commit is contained in:
ThearchyHelios
2026-10-15 15:25:15 +08:00
parent 1e707c43c5
commit 7fc3488b55
6 changed files with 86 additions and 4 deletions
+17
View File
@@ -292,3 +292,20 @@ async def test_upgrade_assist_checks_sql_like_the_publish_gate(scenic_source, mo
# 改不好:整个作废,原因写的是这条 SQL 检查
assert out["accepted"] is False and out["ok"] is False
assert "一对多" in (out["reason"] or ""), out["reason"]
def test_a_source_name_written_as_a_database_is_sent_back():
"""表名前面写了数据源名(scenic.orders):数据库把它当成库名,跑起来报库不存在;认列的检查找表时会去掉前缀,拦不住它,
这里单独交回模型改。数据源名恰好也是库名的不报。"""
from app.api.copilot import authored_issues
cache = {"schema": "main", "tables": {"orders": {"columns": [{"name": "id"}, {"name": "total_amount"}]}}}
source = SimpleNamespace(name="scenic", database="/data/scenic.db", schema_cache=cache)
sql = "SELECT SUM(o.total_amount) AS gmv FROM `scenic`.orders o WHERE o.id > '{{ input.since }}' -- from scenic.x"
spec = _spec(_node("start", "input"), _fetch(sql), _node("out", "output", fields=[]))
(issue,) = authored_issues(spec, [source])
assert (issue["code"], issue["level"], issue["node_id"]) == ("sql_source_prefix", "error", "fetch")
assert "scenic.orders" in issue["message"] and "去掉「scenic.」" in issue["for_model"]
# 数据源名就是库名:照写,不报
same = SimpleNamespace(name="scenic", database="scenic", schema_cache=cache)
assert all(i["code"] != "sql_source_prefix" for i in authored_issues(spec, [same]))
+19
View File
@@ -167,6 +167,25 @@ async def test_preflight_blocks_and_nothing_is_written(client, tmp_path):
assert (await s.blueprint(bp["id"])).workflow_id is None
async def test_a_failed_trial_blocks_the_plan(client, tmp_path):
"""最近一次试运行失败了:挡住发布(用真数跑出了错,发布出去每次出数都是同一个错),写明出错的那一句;不再只是
「还没有成功的试运行」的提醒。"""
from sqlalchemy import update
bp = await _board_from_run(client, tmp_path)
async with SessionLocal() as session:
await session.execute(update(Run).where(Run.id == bp["last_trial_run_id"]).values(
status="failed", error="工具 db_query__shop 查询失败:(1049, \"Unknown database 'shop'\")\n第二行不要"))
await session.commit()
plan = (await client.post(f"/api/blueprints/{bp['id']}/publish-plan", json={"level": "published"})).json()
assert plan["ok"] is False
codes = {p["code"]: p for p in plan["problems"]}
failed = codes["plan.trial_failed"]
assert failed["level"] == "error" and failed["who"] == "you" and failed["plain"]["title"] == "最近一次试运行失败了"
assert failed["message"] == "最近一次试运行失败了:工具 db_query__shop 查询失败:(1049, \"Unknown database 'shop'\")"
assert "plan.untrialed" not in codes
async def test_a_process_with_an_unbound_step_stops_at_preflight(client):
wf_id = await s.published_workflow(s.expense_graph(), f"报销-{uuid.uuid4().hex[:4]}", description="报销审批")
bp = (await client.post("/api/blueprints", json={"source": {"kind": "workflow_version", "id": wf_id},