mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-24 20:12:15 +00:00
数据目录阶段 4A 术语:服务端上界面的目录校验报错改用界面的叫法,表类型写明细表、度量类型写可累加、关联关系两端写本表字段和目标表,给模型看的说法不变
This commit is contained in:
@@ -77,8 +77,8 @@ async def world(scenic_db):
|
||||
created.append(wf.id)
|
||||
return wf
|
||||
|
||||
direct = await template("入园日报", [_graph(_query("q", src, "SELECT COUNT(*) FROM main.VISITS v WHERE v.status = 1",
|
||||
"查询入园人数"))], published=1)
|
||||
counted = _query("q", src, "SELECT COUNT(*) FROM main.VISITS v WHERE v.status = 1", "查询入园人数")
|
||||
direct = await template("入园日报", [_graph(counted)], published=1)
|
||||
agent = await template("入园分析", [_graph(_node("ask", "agent", "分析入园", prompt="分析",
|
||||
tools=[f"db_query__{src}", f"db_schema__{src}"]))],
|
||||
published=1, level="governed")
|
||||
|
||||
@@ -61,7 +61,8 @@ async def test_plan_patch_reports_before_and_after(scenic_db):
|
||||
assert (measure.path, measure.before, measure.before_status, measure.after) == (
|
||||
"columns.visitor_count.measure", "flow", "confirmed", "stock")
|
||||
assert measure.state == "change" and measure.reason == "在园人数是存量,不能跨天相加"
|
||||
assert (kind.path, kind.before, kind.before_status, kind.after, kind.state) == ("kind", None, None, "fact", "change")
|
||||
assert (kind.path, kind.before, kind.before_status, kind.after, kind.state) == (
|
||||
"kind", None, None, "fact", "change")
|
||||
|
||||
|
||||
async def test_codes_are_supplemented_not_replaced(scenic_db):
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
"""服务端上界面的数据目录说法和界面一致(阶段 4A 术语对齐)。
|
||||
|
||||
界面以 frontend/src/lib/terms.ts 的 CATALOG_TERMS 一组为准:表类型的 fact 写「明细表」,度量类型的 flow 写「可累加」,
|
||||
关联关系两端写「本表字段 → 目标表的目标字段」。校验报错(CatalogInvalid,接口回 422 时原样上界面)以前写的是
|
||||
「事实表」「流量」「被指向的表」,和界面对不上。给模型看的提示词(render_table_notes、起草提示)照旧,不在这里管。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
from app.data import catalog
|
||||
from app.data.catalog import make_item
|
||||
|
||||
TERMS = Path(__file__).resolve().parents[2] / "frontend" / "src" / "lib" / "terms.ts"
|
||||
|
||||
|
||||
def _labels(name: str) -> list[str]:
|
||||
"""terms.ts 里一张对照表的中文值,按书写顺序。"""
|
||||
text = TERMS.read_text(encoding="utf-8")
|
||||
block = re.search(rf"export const {name}\b[^=]*=\s*\{{(.*?)\n\}}", text, re.S)
|
||||
assert block, f"terms.ts 里没有 {name}"
|
||||
return re.findall(r":\s*'([^']+)'", block.group(1))
|
||||
|
||||
|
||||
def _choices(labels: list[str]) -> str:
|
||||
return f"应为{'、'.join(labels[:-1])}或{labels[-1]}之一"
|
||||
|
||||
|
||||
def test_kind_and_measure_hints_follow_the_ui_labels():
|
||||
kinds = _labels("CATALOG_KIND_LABEL")
|
||||
measures = _labels("CATALOG_MEASURE_LABEL")
|
||||
assert kinds[0] == "明细表" and measures[0] == "可累加"
|
||||
[kind] = catalog.validate_notes({"kind": make_item("event", "human")})
|
||||
assert kind == f"表的表类型{_choices(kinds)}"
|
||||
[measure] = catalog.validate_notes({"columns": {"amount": {"measure": make_item("sum", "human")}}})
|
||||
assert measure == f"列 amount 的度量类型{_choices(measures)}"
|
||||
for problem in (kind, measure):
|
||||
assert "事实表" not in problem and "流量" not in problem
|
||||
|
||||
|
||||
def test_relation_problems_use_the_ui_words():
|
||||
rel = {"id": "r1", "columns": ["a", "b"], "to_table": "", "to_columns": ["id"], "cardinality": None,
|
||||
"coverage": None, "source": "human", "status": "confirmed"}
|
||||
problems = catalog.validate_notes({"relations": [rel]})
|
||||
assert "关联关系 r1 缺少目标表" in problems
|
||||
rel = {**rel, "to_table": "parks", "to_columns": "id"}
|
||||
assert "关联关系 r1 的目标字段应为列名的列表" in catalog.validate_notes({"relations": [rel]})
|
||||
rel = {**rel, "columns": "a", "to_columns": ["id"]}
|
||||
assert "关联关系 r1 的本表字段应为列名的列表" in catalog.validate_notes({"relations": [rel]})
|
||||
rel = {**rel, "columns": ["a", "b"]}
|
||||
assert "关联关系 r1 两端的字段数不一致" in catalog.validate_notes({"relations": [rel]})
|
||||
text = ";".join(catalog.validate_notes({"relations": [{**rel, "to_table": ""}]}))
|
||||
assert "被指向" not in text and "本表列" not in text
|
||||
|
||||
|
||||
async def test_api_422_uses_the_ui_labels():
|
||||
"""接口把校验报错原样交给界面:整份提交和提案保存都是这一句。"""
|
||||
from app.api.catalog import _invalid
|
||||
|
||||
try:
|
||||
catalog.apply_human_edit({}, {"kind": {"value": "event"}}, table="visits")
|
||||
except catalog.CatalogInvalid as e:
|
||||
detail = _invalid(e).detail
|
||||
assert "明细表" in detail and "事实表" not in detail
|
||||
# 给模型看的渲染照旧:模型认得「事实表」「流量,可跨期加总」
|
||||
text = catalog.render_table_notes({"kind": make_item("fact", "human"),
|
||||
"columns": {"n": {"measure": make_item("flow", "human")}}})
|
||||
assert "表类型:事实表" in text and "流量,可跨期加总" in text
|
||||
Reference in New Issue
Block a user