mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-18 17:01:58 +00:00
运行对比复核修正(第 1 轮):输入的出处追到合并查询的上游、Agent 引用的列和行段,没出处的数、数据没变数却变了的不再报成数据变化
出处判定(每个指标的分类靠它): - 合并查询:读合并结果的指标按别名一路追到喂它的每一份上游快照(嵌套的合并也追),上游 SQL 结构变了是 sql_changed, 不拆、不归因;合并节点多接、少接了输入也算结构变化 - 图里写死的字面量改了('paid' 改成 'refunded'、系数、LIMIT):执行的 SQL 只差字面量,但图里的 SQL 改过,算模板变化; 图里一字未改(定时运行代入的日期)才是参数。图里的 SQL 只改了空白、大小写的不算改过 - Agent 按出处交来的字段:还要引用同一列、同一行(段),两边都引用整份结果的不算换了;换了列、换了行段的说不清 (incomparable),不再把没引用的区域算成「数据没了」去归因 - 模型、人直接交出的值(Agent 没按出处交、模型调用、人工审批……):值变了说不清是数据还是模型本身,判 incomparable; 它自己查的库结构变了、配置变了照常标出 - 代码等确定性节点:上游的查询结果两次一模一样、交出的值却变了的,判 incomparable,不再说「变化来自上游数据」; 上游只有运行输入变了的算参数 - 图级变化落到节点上:连线有增删的终点节点、默认设置改了且没有自行设置这几项的模型类节点,都算改了配置; 「模板和取数的 SQL 都没有变化」只在整张图都没变时说 - 运行输入是列表、对象的,按还原出来的完整值比,长度不变、内容变了的是参数变化 - 同一节点按 SQL 配对时先配字面量也相同的:Agent 换了先后查东区、南区,两条各自配上自己,不再配成两条「只有参数不同」 - 一边记不出输入是哪个节点写的,说清是哪一边没记录(不再写出「None」) 口径与数值: - 口径变了的指标,喂它的取数也变了、说不清的照样写进说明(只在一边才有的输入是改表达式带来的,不重复说); 分类次序写进 compare() 的说明 - 千分位和不分组互换只影响显示,写进说明、不算口径变化;比率与否不同才算 - 升级前的口径卡没记小数位、显示格式:按那次运行图里的指标定义核对,定义也没有就不比,不再误报「小数位由 未设置 改为 1」 - 百分比:基准极小、这次很大时十进制量化放不下,退回浮点算,不再整个对比报 500 - 没设小数位的指标拆分:三个数按同一精度量化(最多 15 位有效数字),转成浮点交出去后两效应之和仍逐位等于总变化 - 维度归因标出用的是哪个输入、两边各自哪份快照(path、base_artifact、target_artifact) 接口:已经结束、只是没有封存清单的运行,409 说「没有封存清单,不能用于对比」,不再说「运行结束后才能对比」。 测试:补上复核指出的必测项(只一边对得上不给占比、只截断基准一侧、换了数据源、按旧口径小数位取整、写它的节点多查一次、 口径和 SQL 一起变不归因、小数位和比率变化、日期类型和常量列不当维度、合计行浮点误差、只改名称、结束过又接着运行的不当 基准),以及上面每一处修正的用例。32 处变异逐条打红验证,全部被测试抓到。
This commit is contained in:
+49
-13
@@ -12,6 +12,7 @@ from app.core.artifact_store import canonical_json, content_hash
|
||||
from app.engine import compare, recompute
|
||||
from app.engine.evidence import render_number
|
||||
from app.engine.expressions import parse_expression, substitute
|
||||
from app.engine.merge_query import MERGE_SOURCE
|
||||
|
||||
TOOL = "db_query__shop"
|
||||
WEEK36 = ("2026-08-31", "2026-09-06")
|
||||
@@ -110,15 +111,15 @@ class Fake:
|
||||
return artifact
|
||||
|
||||
def agent(self, node_id, sql, columns=COLUMNS, rows=BASE_ROWS, *, types=TYPES, truncated=False, masks=None,
|
||||
verify=()):
|
||||
"""Agent 节点自己查一次库,按出处交回数组字段 amounts(快照 gmv 列的全部行)。verify 是同一节点里核查类的
|
||||
查询(role: verify,不进台账)。"""
|
||||
verify=(), column="gmv", span=None):
|
||||
"""Agent 节点自己查一次库,按出处交回数组字段 amounts(默认是快照 gmv 列的全部行;column、span 改引用的列和
|
||||
行段)。verify 是同一节点里核查类的查询(role: verify,不进台账)。"""
|
||||
artifact = self.snapshot(sql, columns, rows, truncated=truncated, types=types, masks=masks)
|
||||
last = len(rows) - 1
|
||||
gmv = columns.index("gmv")
|
||||
data = {"amounts": [r[gmv] for r in rows]}
|
||||
evidence = {"amounts": {"ref": f"Q1.r0-{last}.gmv", "call": "Q1", "artifact": artifact,
|
||||
"locator": {"rows": [0, last], "column": "gmv"}, "status": "verified"}}
|
||||
first, last = span or (0, len(rows) - 1)
|
||||
at = columns.index(column)
|
||||
data = {"amounts": [r[at] for r in rows[first:last + 1]]}
|
||||
evidence = {"amounts": {"ref": f"Q1.r{first}-{last}.{column}", "call": "Q1", "artifact": artifact,
|
||||
"locator": {"rows": [first, last], "column": column}, "status": "verified"}}
|
||||
output = self.put({"text": "按区域列出了金额", "data": data, "data_evidence": evidence})
|
||||
self.add("node.started", node_id, {"node_type": "agent"})
|
||||
self.add("tool.start", node_id, {"tool": TOOL, "args": {"sql": sql}, "call_id": "c1"})
|
||||
@@ -130,6 +131,40 @@ class Fake:
|
||||
self.entry(node_id, artifact, columns, rows, call_id="c1", truncated=truncated)]})
|
||||
return artifact
|
||||
|
||||
def plain_agent(self, node_id, sqls, data, columns=COLUMNS, rows=BASE_ROWS, *, types=TYPES):
|
||||
"""没开按出处核对的 Agent:查几次库,交回的 data 没有出处(data_evidence),口径卡只知道是它写的。"""
|
||||
self.add("node.started", node_id, {"node_type": "agent"})
|
||||
entries = []
|
||||
for i, sql in enumerate(sqls):
|
||||
artifact = self.snapshot(sql, columns, rows, types=types)
|
||||
self.add("tool.start", node_id, {"tool": TOOL, "args": {"sql": sql}, "call_id": f"c{i}"})
|
||||
self.add("tool.end", node_id, {"tool": TOOL, "call_id": f"c{i}", "duration_ms": 5,
|
||||
"query_artifact": artifact})
|
||||
entries.append(self.entry(node_id, artifact, columns, rows, call_id=f"c{i}"))
|
||||
output = self.put({"text": "按区域分析了金额", "data": data})
|
||||
self.add("node.finished", node_id, {"duration_ms": 9, "attempt": 1, "artifact": output, "evidence": entries})
|
||||
|
||||
def merge(self, node_id, sql, inputs, columns, rows, *, types=None):
|
||||
"""合并查询:几份上游快照按别名落进内存库,再执行一条合并 SQL。快照里记着各个输入(别名、节点、快照),
|
||||
事件照合并节点的形状写(merge.end 加 node.finished 台账里的 query 条目,没有 tool.end)。
|
||||
inputs 是 [(别名, 上游节点, 上游快照)]。"""
|
||||
snap = {"columns": columns, "rows": rows, "row_count": len(rows), "truncated": False, "sql": sql,
|
||||
"source": MERGE_SOURCE, "sources": [self.source],
|
||||
"inputs": [{"alias": alias, "node_id": upstream, "artifact": artifact,
|
||||
"rows": len(self.store[artifact]["rows"]), "columns": self.store[artifact]["columns"],
|
||||
"source": self.store[artifact].get("source")} for alias, upstream, artifact in inputs],
|
||||
"warnings": [], **({"column_types": types} if types else {})}
|
||||
artifact = self.put(snap)
|
||||
self.queries.append(artifact)
|
||||
output = self.put({**snap, "artifact": artifact})
|
||||
view = [{k: v for k, v in item.items() if k != "columns"} for item in snap["inputs"]]
|
||||
self.add("node.started", node_id, {"node_type": "merge"})
|
||||
self.add("merge.end", node_id, {"inputs": view, "sql": sql, "rows": len(rows), "query_artifact": artifact})
|
||||
self.add("node.finished", node_id, {"duration_ms": 2, "attempt": 1, "artifact": output, "evidence": [
|
||||
{"kind": "query", "node_id": node_id, "exec": 1, "artifact": artifact, "source": MERGE_SOURCE,
|
||||
"columns": columns, "rows": len(rows), "truncated": False}]})
|
||||
return artifact
|
||||
|
||||
def code(self, node_id, value, var):
|
||||
"""沙箱代码节点算出一个数写进变量:它不查库,对不上具体的查询。"""
|
||||
output = self.put({var: value})
|
||||
@@ -169,11 +204,12 @@ def cell_in(row, column, value, artifact, node_id="fetch"):
|
||||
"eid": f"ev:cell:{artifact[:8]}:{row}:{column}", "status": "verified"}
|
||||
|
||||
|
||||
def amounts_in(artifact, rows):
|
||||
last = len(rows) - 1
|
||||
return {"path": "vars.kpi.amounts", "value": f"[{len(rows)} 项]", "node_id": "bot", "via": "agent_field",
|
||||
"field": "amounts", "ref": f"Q1.r0-{last}.gmv", "artifact": artifact,
|
||||
"locator": {"rows": [0, last], "column": "gmv"}, "eid": f"ev:rows:{artifact[:8]}", "status": "verified"}
|
||||
def amounts_in(artifact, rows, *, column="gmv", span=None):
|
||||
first, last = span or (0, len(rows) - 1)
|
||||
return {"path": "vars.kpi.amounts", "value": f"[{last - first + 1} 项]", "node_id": "bot", "via": "agent_field",
|
||||
"field": "amounts", "ref": f"Q1.r{first}-{last}.{column}", "artifact": artifact,
|
||||
"locator": {"rows": [first, last], "column": column}, "eid": f"ev:rows:{artifact[:8]}:{first}:{column}",
|
||||
"status": "verified"}
|
||||
|
||||
|
||||
def scalar_in(path, value, node_id, via):
|
||||
|
||||
@@ -149,12 +149,14 @@ async def test_unsealed_runs_are_refused(client):
|
||||
seal=False)
|
||||
body = await get(client, f"/api/runs/{target_id}/compare?base={base_id}", 409)
|
||||
assert body["code"] == "compare_unsealed" and body["detail"].startswith("这次运行")
|
||||
# 已经结束、只是没有封存清单的:说没有封存清单,不说「运行结束后才能对比」
|
||||
assert "没有封存清单" in body["detail"] and "尚未结束" not in body["detail"]
|
||||
body = await get(client, f"/api/runs/{base_id}/compare?base={target_id}", 409)
|
||||
assert body["code"] == "compare_unsealed" and body["detail"].startswith("作为基准的运行")
|
||||
# 封存过、又被接着运行(还在运行)的:封存范围之后还会变,同样不比
|
||||
running = await persist(week("r3", NEXT_ROWS, source=SOURCE), workflow, status="running")
|
||||
body = await get(client, f"/api/runs/{running}/compare?base={base_id}", 409)
|
||||
assert body["code"] == "compare_unsealed"
|
||||
assert body["code"] == "compare_unsealed" and "尚未结束" in body["detail"]
|
||||
|
||||
|
||||
async def test_a_broken_seal_is_refused(client):
|
||||
@@ -233,12 +235,15 @@ async def test_masked_columns_never_leave_the_server(client):
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
|
||||
async def bare(workflow_id, finished, *, status="succeeded", run_class="formal", schedule_id=None, sealed=True) -> str:
|
||||
"""只为挑基准用的运行记录:挑基准只看运行记录上的几列。"""
|
||||
async def bare(workflow_id, finished, *, status="succeeded", run_class="formal", schedule_id=None, sealed=True,
|
||||
resumed=False) -> str:
|
||||
"""只为挑基准用的运行记录:挑基准只看运行记录上的几列。resumed:结束、封存过又被接着运行(状态已回到运行中,
|
||||
结束时间和封存还没清掉),只能靠状态把它挡在外面。"""
|
||||
done = status in ("succeeded", "failed", "cancelled") or resumed
|
||||
async with SessionLocal() as session:
|
||||
run = Run(workflow_id=workflow_id, workflow_name="区域周报", status=status, run_class=run_class,
|
||||
schedule_id=schedule_id, started_at=finished - timedelta(minutes=2),
|
||||
finished_at=finished if status in ("succeeded", "failed", "cancelled") else None,
|
||||
finished_at=finished if done else None,
|
||||
manifest_hash="ab" * 32 if sealed else None, manifest_seq=1 if sealed else None)
|
||||
session.add(run)
|
||||
await session.commit()
|
||||
@@ -271,6 +276,7 @@ async def test_the_default_base_skips_what_cannot_be_compared(client):
|
||||
good = await bare(workflow, T0)
|
||||
await bare(workflow, T0 + day, sealed=False) # 没封存
|
||||
await bare(workflow, T0 + 2 * day, status="running") # 还在运行
|
||||
await bare(workflow, T0 + 2 * day, status="running", resumed=True) # 结束过、又被接着运行
|
||||
await bare(workflow, T0 + 3 * day, run_class="exploratory") # 别的运行类别
|
||||
await bare(await new_workflow("另一个周报"), T0 + 4 * day) # 别的工作流
|
||||
current = await bare(workflow, T0 + 5 * day)
|
||||
|
||||
@@ -9,9 +9,12 @@ SQL,Agent 节点 bot 自己再查一次、把各区域的金额作为数组字
|
||||
为 1;对不上时占比为空并说明;截断的快照不归因,照实写
|
||||
- 遮罩列的值绝不出现在结果里;用到遮罩列的指标不拆分
|
||||
- 模板对比:新增、删除的节点,配置有变化的节点和配置项名
|
||||
- 输入的出处:合并查询追到它的上游查询;Agent 按出处交的字段还要引用同一列、同一段行;没按出处交的数、上游数据
|
||||
没变数却变了的,说不清变化从哪来(incomparable);图里写死的字面量改了、默认设置和连线变了都算模板变化
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
import json
|
||||
from decimal import Decimal
|
||||
|
||||
@@ -19,13 +22,16 @@ from app.engine import compare
|
||||
from app.engine.merge_query import MERGE_SOURCE
|
||||
from tests.fixtures.compare_runs import (
|
||||
BASE_ROWS,
|
||||
COLUMNS,
|
||||
EAST,
|
||||
NEXT_ROWS,
|
||||
REFUND,
|
||||
TOOL,
|
||||
WEEK37,
|
||||
Fake,
|
||||
amounts_in,
|
||||
cell_in,
|
||||
chain,
|
||||
default_metrics,
|
||||
metric,
|
||||
node,
|
||||
@@ -167,14 +173,14 @@ def test_the_split_adds_up_exactly_with_awkward_decimals():
|
||||
return make
|
||||
|
||||
base_rows = [["东区", 1000.1, 0.3], *BASE_ROWS[1:]]
|
||||
next_rows = [["东区", 1000.7, 0.2], *NEXT_ROWS[1:]]
|
||||
next_rows = [["东区", 1000.75, 0.2], *NEXT_ROWS[1:]]
|
||||
base = week("r1", base_rows, metrics=build(f"{EAST} * 0.1 - {REFUND}", 2))
|
||||
target = week("r2", next_rows, metrics=build(f"{EAST} * 0.3 + {REFUND}", 3), version="v2")
|
||||
ratio = by_id(run_compare(base, target))["ratio"]
|
||||
split = ratio["decomposition"]
|
||||
assert split is not None, ratio["decomposition_note"]
|
||||
# f_old(x_new) 按旧口径的小数位取整:round(1000.7 * 0.1 - 0.2, 2) = 99.87
|
||||
assert exact(split["data_effect"]) == exact(99.87) - exact(ratio["base"])
|
||||
# f_old(x_new) 按旧口径的小数位取整:1000.75 * 0.1 - 0.2 = 99.875,取 2 位是 99.88(按新口径的 3 位是 99.875)
|
||||
assert exact(split["data_effect"]) == exact(99.88) - exact(ratio["base"])
|
||||
assert exact(split["caliber_effect"]) + exact(split["data_effect"]) == exact(ratio["delta"])
|
||||
assert exact(ratio["delta"]) == exact(ratio["target"]) - exact(ratio["base"])
|
||||
|
||||
@@ -204,6 +210,20 @@ def test_no_split_when_the_sql_changed_too():
|
||||
net = by_id(run_compare(base, target))["net"]
|
||||
assert net["classification"] == "caliber_and_data" and net["decomposition"] is None
|
||||
assert "SQL" in net["decomposition_note"]
|
||||
# 两条不同的查询的行不拿来按维度配对
|
||||
assert net["attribution"] is None
|
||||
|
||||
|
||||
def test_a_caliber_change_still_names_the_sql_change():
|
||||
"""口径变了、SQL 结构也变了、旧口径的叶子这次又没记录:分类按口径,SQL 的变化照样写进说明。"""
|
||||
base = week("r1", metrics=net_metrics(f"{EAST} - {REFUND}"), version="v1")
|
||||
paid = region_sql(extra=" AND status = 'paid'")
|
||||
target = week("r2", NEXT_ROWS, sql=paid, metrics=net_metrics(EAST), version="v2")
|
||||
net = by_id(run_compare(base, target))["net"]
|
||||
assert net["classification"] == "caliber_and_data" and net["decomposition"] is None
|
||||
assert any("区域取数" in r and "SQL" in r for r in net["reasons"]), net["reasons"]
|
||||
# 退款那一格只在旧口径里用到:改表达式带来的,不再另说一遍「只在一边有记录」
|
||||
assert not any("只在一边" in r for r in net["reasons"]), net["reasons"]
|
||||
|
||||
|
||||
def test_a_unit_change_is_not_subtracted():
|
||||
@@ -217,15 +237,102 @@ def test_a_unit_change_is_not_subtracted():
|
||||
assert "单位" in east["decomposition_note"]
|
||||
|
||||
|
||||
def test_display_settings_that_change_the_value_are_caliber_changes():
|
||||
def build(**kw):
|
||||
def make(fetch, bot, rows, bot_rows):
|
||||
return [metric("east", EAST, rows[0][1], [cell_in(0, "gmv", rows[0][1], fetch)], **kw)]
|
||||
return make
|
||||
|
||||
def east(before, after):
|
||||
return by_id(run_compare(week("r1", metrics=build(**before)), week("r2", NEXT_ROWS, metrics=build(**after))))
|
||||
|
||||
# 小数位改变取整
|
||||
found = east({"decimals": 1}, {"decimals": 0})
|
||||
assert found["east"]["classification"] == "caliber_and_data" and any("小数位" in r for r in found["east"]["reasons"])
|
||||
# 比率与否改变数值的含义
|
||||
found = east({"unit": "", "fmt": "plain"}, {"unit": "", "fmt": "percent_of_ratio"})
|
||||
assert found["east"]["classification"] == "caliber_and_data" and found["east"]["delta"] is None
|
||||
# 千分位和不分组只影响显示:分类照数据算,变化写进说明
|
||||
result = run_compare(week("r1", metrics=build(fmt="thousands")), week("r2", NEXT_ROWS, metrics=build(fmt="plain")))
|
||||
assert by_id(result)["east"]["classification"] == "data_only"
|
||||
assert any("显示格式" in n for n in result["notes"])
|
||||
|
||||
|
||||
def test_an_old_card_without_display_settings_is_not_a_caliber_change():
|
||||
"""升级前封存的运行:卡上的指标没记小数位、显示格式和输入(当时按定义里的小数位取过整)。"""
|
||||
def old(run_id, value, graph=None):
|
||||
run = Fake(run_id, graph=graph)
|
||||
run.tool("fetch", region_sql())
|
||||
run.agent("bot", region_sql())
|
||||
run.card([{"id": "east", "name": "东区金额", "unit": "元", "value": value, "expression": EAST}])
|
||||
return run
|
||||
|
||||
def new(run_id, value):
|
||||
run = Fake(run_id)
|
||||
fetch = run.tool("fetch", region_sql())
|
||||
run.agent("bot", region_sql())
|
||||
run.card([metric("east", EAST, value, [cell_in(0, "gmv", value, fetch)], name="东区金额")])
|
||||
return run
|
||||
|
||||
east = by_id(run_compare(old("r1", 1200.5), new("r2", 1200.5)))["east"]
|
||||
assert (east["classification"], east["reasons"]) == ("unchanged", [])
|
||||
east = by_id(run_compare(old("r1", 1200.5), new("r2", 1500.5)))["east"]
|
||||
assert east["classification"] == "incomparable" and east["reasons"] == [compare.NO_LINEAGE]
|
||||
# 那次运行的图里写着定义:按定义里的小数位核对
|
||||
graph = weekly_graph()
|
||||
graph["nodes"][3]["data"]["config"]["metrics"] = [{"id": "east", "expression": EAST, "decimals": 2}]
|
||||
east = by_id(run_compare(old("r1", 1200.5, graph), new("r2", 1200.5)))["east"]
|
||||
assert east["classification"] == "caliber_and_data" and any("小数位由 2 改为 1" in r for r in east["reasons"])
|
||||
|
||||
|
||||
def test_the_split_adds_up_in_json_without_fixed_decimals():
|
||||
"""没设小数位的指标:三个数各自转成浮点也要逐位相加(接口按 JSON 交回的就是浮点)。"""
|
||||
def build(expression):
|
||||
def make(fetch, bot, rows, bot_rows):
|
||||
gmv, refund = rows[0][1], rows[0][2]
|
||||
inputs = [cell_in(0, "gmv", gmv, fetch), cell_in(0, "refund", refund, fetch)]
|
||||
value = eval(expression.replace(EAST, repr(gmv)).replace(REFUND, repr(refund)))
|
||||
return [metric("m", expression, value, inputs, decimals=None, unit="")]
|
||||
return make
|
||||
|
||||
base_rows = [["东区", 0.1, 0.2], *BASE_ROWS[1:]]
|
||||
next_rows = [["东区", 0.7, 0.1], *NEXT_ROWS[1:]]
|
||||
base = week("r1", base_rows, metrics=build(f"{EAST} + {REFUND}")) # 0.30000000000000004
|
||||
target = week("r2", next_rows, metrics=build(f"{EAST} * 3 + {REFUND}"), version="v2") # 2.1999999999999997
|
||||
m = by_id(run_compare(base, target))["m"]
|
||||
split = m["decomposition"]
|
||||
assert split is not None, m["decomposition_note"]
|
||||
assert exact(split["caliber_effect"]) + exact(split["data_effect"]) == exact(m["delta"])
|
||||
assert abs(m["delta"] - (m["target"] - m["base"])) < 1e-12
|
||||
|
||||
|
||||
def test_a_tiny_base_does_not_break_the_percentage():
|
||||
"""基准是浮点误差那么小的数、这次很大:百分比写得出来(或者为空),对比不能整个失败。"""
|
||||
def build(value):
|
||||
def make(fetch, bot, rows, bot_rows):
|
||||
m = metric("diff", EAST, 1.0, [cell_in(0, "gmv", rows[0][1], fetch)], decimals=None)
|
||||
m["value"], m["rendered"] = value, "—"
|
||||
return [m]
|
||||
return make
|
||||
diff = by_id(run_compare(week("r1", metrics=build(0.30000000000000004 - 0.3)),
|
||||
week("r2", NEXT_ROWS, metrics=build(1e8))))["diff"]
|
||||
assert diff["delta"] == 1e8 - (0.30000000000000004 - 0.3)
|
||||
assert diff["delta_pct"] is not None and diff["delta_pct"] > 1e25
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# 维度归因
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_attribution_pairs_keys_and_shares_add_up_to_one():
|
||||
total = by_id(run_compare(week("r1"), week("r2", NEXT_ROWS)))["total"]
|
||||
base, target = week("r1"), week("r2", NEXT_ROWS)
|
||||
total = by_id(run_compare(base, target))["total"]
|
||||
attribution = total["attribution"]
|
||||
assert attribution["columns"] == ["region"] and attribution["measure"] == "gmv"
|
||||
# 归因用的是哪个输入、两边各自哪份快照
|
||||
assert (attribution["path"], attribution["base_artifact"], attribution["target_artifact"]) == (
|
||||
"vars.kpi.amounts", base.queries[1], target.queries[1])
|
||||
assert attribution["total_delta"] == 200.0
|
||||
rows = attribution["rows"]
|
||||
assert [(r["key"], r["base"], r["target"], r["delta"]) for r in rows] == [
|
||||
@@ -265,6 +372,49 @@ def test_no_share_when_the_measure_does_not_add_up_to_the_input():
|
||||
assert all(r["share"] is None for r in attribution["rows"]) and attribution["note"]
|
||||
|
||||
|
||||
def test_no_share_when_only_one_side_adds_up():
|
||||
"""基准运行里东区就是全部(各区域之和等于它),这次南区也有了:只有一边对得上,不给占比。"""
|
||||
base_rows = [["东区", 100.0, 0.0], ["南区", 0.0, 0.0], ["西区", 0.0, 0.0]]
|
||||
next_rows = [["东区", 150.0, 0.0], ["南区", 20.0, 0.0], ["西区", 0.0, 0.0]]
|
||||
east = by_id(run_compare(week("r1", base_rows), week("r2", next_rows)))["east"]
|
||||
attribution = east["attribution"]
|
||||
assert east["classification"] == "data_only" and len(attribution["rows"]) == 3
|
||||
assert all(r["share"] is None for r in attribution["rows"]) and compare.NO_SHARE in attribution["note"]
|
||||
|
||||
|
||||
def test_a_total_row_summed_in_floating_point_still_adds_up():
|
||||
"""合计行是库里按浮点加出来的(0.1 + 0.2 + 0.3 = 0.6000000000000001):差在最后几位也算相等,照给占比。"""
|
||||
base_rows = [["东区", 0.1, 0.0], ["南区", 0.2, 0.0], ["西区", 0.3, 0.0], ["合计", 0.1 + 0.2 + 0.3, 0.0]]
|
||||
next_rows = [["东区", 0.4, 0.0], ["南区", 0.2, 0.0], ["西区", 0.3, 0.0], ["合计", 0.4 + 0.2 + 0.3, 0.0]]
|
||||
|
||||
def build(fetch, bot, rows, bot_rows):
|
||||
return [metric("all", "cell(nodes.fetch, 3, 'gmv')", rows[3][1], [cell_in(3, "gmv", rows[3][1], fetch)],
|
||||
decimals=None)]
|
||||
found = by_id(run_compare(week("r1", base_rows, metrics=build), week("r2", next_rows, metrics=build)))["all"]
|
||||
rows = found["attribution"]["rows"]
|
||||
assert [r["key"] for r in rows] == [["东区"], ["南区"], ["西区"]]
|
||||
assert abs(sum(r["share"] for r in rows) - 1) < 1e-9
|
||||
|
||||
|
||||
def test_date_typed_and_constant_columns_are_not_dimensions():
|
||||
"""日期类型的列(两边有相同的日子也不算)和两边都只有一个值的列(币种)不当维度。"""
|
||||
columns = ["day", "region", "currency", "gmv"]
|
||||
types = {"day": "date", "region": "text", "currency": "text", "gmv": "number"}
|
||||
|
||||
def make(run_id, rows):
|
||||
run = Fake(run_id)
|
||||
sql = "SELECT day, region, currency, SUM(amount) AS gmv FROM orders GROUP BY day, region, currency"
|
||||
bot = run.agent("bot", sql, columns, rows, types=types)
|
||||
run.card([metric("total", "sum(vars.kpi.amounts)", sum(r[3] for r in rows), [amounts_in(bot, rows)])])
|
||||
return run
|
||||
|
||||
base_rows = [["2026-09-01", "东区", "CNY", 10.0], ["2026-09-02", "南区", "CNY", 20.0]]
|
||||
next_rows = [["2026-09-02", "东区", "CNY", 15.0], ["2026-09-03", "南区", "CNY", 18.0]]
|
||||
attribution = by_id(run_compare(make("r1", base_rows), make("r2", next_rows)))["total"]["attribution"]
|
||||
assert attribution["columns"] == ["region"]
|
||||
assert [(r["key"], r["delta"]) for r in attribution["rows"]] == [(["东区"], 5.0), (["南区"], -2.0)]
|
||||
|
||||
|
||||
def test_a_total_row_is_left_out_of_its_own_breakdown():
|
||||
"""合计行和各区域在同一份结果里:指标取合计那一格,按其余各行归因,占比之和为 1。"""
|
||||
base_rows = [*BASE_ROWS, ["合计", 2600.5, 150.0]]
|
||||
@@ -290,6 +440,16 @@ def test_a_truncated_snapshot_is_not_attributed():
|
||||
assert result_queries(run_compare(base, target), "bot")["target_truncated"] is True
|
||||
|
||||
|
||||
def test_a_truncated_base_snapshot_is_not_attributed_either():
|
||||
base = Fake("r1")
|
||||
fetch = base.tool("fetch", region_sql())
|
||||
bot = base.agent("bot", region_sql(), truncated=True)
|
||||
base.card(default_metrics(fetch, bot, BASE_ROWS, BASE_ROWS))
|
||||
total = by_id(run_compare(base, week("r2", NEXT_ROWS)))["total"]
|
||||
assert total["classification"] == "data_only"
|
||||
assert total["attribution"]["rows"] == [] and "基准运行" in total["attribution"]["note"]
|
||||
|
||||
|
||||
def result_queries(result, node_id):
|
||||
return next(q for q in result["queries"] if q["node_id"] == node_id)
|
||||
|
||||
@@ -412,10 +572,49 @@ def test_an_input_from_a_code_node_follows_its_upstream():
|
||||
# 上游什么都没变:变化来自数据
|
||||
calc = by_id(run_compare(make("r1", BASE_ROWS, 10), make("r2", NEXT_ROWS, 12)))["calc"]
|
||||
assert calc["classification"] == "data_only" and calc["delta"] == 4
|
||||
assert calc["reasons"] == [compare.DATA_FROM_UPSTREAM]
|
||||
# 上游的 SQL 结构变了:说不清它变没变,不能报成数据变化
|
||||
calc = by_id(run_compare(make("r1", BASE_ROWS, 10),
|
||||
make("r2", NEXT_ROWS, 12, sql=region_sql(extra=" AND status = 'paid'"))))["calc"]
|
||||
assert calc["classification"] == "incomparable" and any("调整" in r for r in calc["reasons"])
|
||||
# 上游查到的数据两次一模一样,它交的数却变了:变化不来自数据
|
||||
calc = by_id(run_compare(make("r1", BASE_ROWS, 10), make("r2", BASE_ROWS, 12)))["calc"]
|
||||
assert calc["classification"] == "incomparable" and any("调整" in r for r in calc["reasons"])
|
||||
assert compare.DATA_FROM_UPSTREAM not in calc["reasons"]
|
||||
|
||||
|
||||
def test_a_value_from_a_querying_node_that_moved_without_its_data_is_incomparable():
|
||||
"""调用工具节点整份交出的结果(不是 cell() 取的格):它查到的行两次一样,交出的值(这里是查询耗时)却变了,
|
||||
变化不来自数据;查到的行也变了的,照常是数据变化。"""
|
||||
def make(run_id, elapsed, rows=BASE_ROWS):
|
||||
run = Fake(run_id)
|
||||
run.tool("fetch", region_sql(), rows=rows)
|
||||
run.agent("bot", region_sql(), rows=rows)
|
||||
run.card([metric("cost", "vars.res.elapsed_ms", elapsed,
|
||||
[scalar_in("vars.res.elapsed_ms", elapsed, "fetch", "tool")], unit="毫秒", decimals=None)])
|
||||
return run
|
||||
cost = by_id(run_compare(make("r1", 3), make("r2", 5)))["cost"]
|
||||
assert cost["classification"] == "incomparable" and any("区域取数" in r for r in cost["reasons"])
|
||||
cost = by_id(run_compare(make("r1", 3), make("r2", 5, NEXT_ROWS)))["cost"]
|
||||
assert cost["classification"] == "data_only"
|
||||
|
||||
|
||||
def test_data_from_upstream_is_only_claimed_when_the_graph_is_the_same():
|
||||
"""改了它下游的节点(成果字段):它的上游没变,变化照样来自上游数据,但不能说「模板没有变化」。"""
|
||||
def make(run_id, rows, value, graph):
|
||||
run = Fake(run_id, graph=graph)
|
||||
run.tool("fetch", region_sql(), rows=rows)
|
||||
run.agent("bot", region_sql(), rows=rows)
|
||||
run.code("calc", value, "adj")
|
||||
run.card(code_metrics(value)(None, None, rows, rows))
|
||||
return run
|
||||
|
||||
base_graph = weekly_graph(between=(node("calc", "code", "调整", code="print(1)", assign_to="adj"),))
|
||||
target_graph = copy.deepcopy(base_graph)
|
||||
target_graph["nodes"][-1]["data"]["config"] = {"fields": [{"name": "周报", "value": "{{ nodes.write.text }}"}]}
|
||||
calc = by_id(run_compare(make("r1", BASE_ROWS, 10, base_graph), make("r2", NEXT_ROWS, 12, target_graph)))["calc"]
|
||||
assert calc["classification"] == "data_only"
|
||||
assert calc["reasons"] == [compare.DATA_FROM_UPSTREAM_SCOPED]
|
||||
|
||||
|
||||
def test_the_code_node_itself_changed_is_a_template_change():
|
||||
@@ -430,6 +629,133 @@ def test_the_code_node_itself_changed_is_a_template_change():
|
||||
assert calc["classification"] == "sql_changed" and any("调整" in r for r in calc["reasons"])
|
||||
|
||||
|
||||
def test_rewired_edges_are_a_template_change():
|
||||
"""调整节点改由取数节点接进来(各节点的配置都没动):它交的数变了算模板变化,不能说变化来自上游数据。"""
|
||||
calc_node = node("calc", "code", "调整", code="result = 1", assign_to="adj")
|
||||
base_graph = weekly_graph(between=(calc_node,))
|
||||
target_graph = copy.deepcopy(base_graph)
|
||||
target_graph["edges"] = [e for e in target_graph["edges"] if (e["source"], e["target"]) != ("bot", "calc")]
|
||||
target_graph["edges"].append({"source": "fetch", "target": "calc"})
|
||||
|
||||
def make(run_id, graph, value):
|
||||
run = Fake(run_id, graph=graph)
|
||||
run.tool("fetch", region_sql())
|
||||
run.agent("bot", region_sql())
|
||||
run.code("calc", value, "adj")
|
||||
run.card(code_metrics(value)(None, None, BASE_ROWS, BASE_ROWS))
|
||||
return run
|
||||
result = run_compare(make("r1", base_graph, 10), make("r2", target_graph, 12))
|
||||
calc = by_id(result)["calc"]
|
||||
assert calc["classification"] == "sql_changed" and any("连线" in r for r in calc["reasons"]), calc["reasons"]
|
||||
assert compare.EDGES_CHANGED in result["notes"]
|
||||
|
||||
|
||||
def uncited(run_id, share, *, graph=None, sqls=None):
|
||||
"""Agent 没开按出处核对,口径卡用了它交的占比 vars.kpi.share;东区金额照旧取取数节点的那一格。"""
|
||||
run = Fake(run_id, graph=graph)
|
||||
fetch = run.tool("fetch", region_sql())
|
||||
run.plain_agent("bot", sqls or [region_sql()], {"kpi": {"share": share}})
|
||||
run.card([metric("east", EAST, BASE_ROWS[0][1], [cell_in(0, "gmv", BASE_ROWS[0][1], fetch)], name="东区金额"),
|
||||
metric("share", "vars.kpi.share * 100", share * 100, [scalar_in("vars.kpi.share", share, "bot", "agent")],
|
||||
unit="%", fmt="plain")])
|
||||
return run
|
||||
|
||||
|
||||
def test_a_number_the_agent_gave_without_citing_is_incomparable():
|
||||
"""Agent 没按出处交的数:两次查到的数据一样,数却变了(模型本身的差异),不能说是数据变化。"""
|
||||
result = run_compare(uncited("r1", 0.46), uncited("r2", 0.52))
|
||||
share = by_id(result)["share"]
|
||||
assert share["classification"] == "incomparable" and share["attribution"] is None
|
||||
assert any("区域分析" in r and "查询快照" in r for r in share["reasons"]), share["reasons"]
|
||||
assert by_id(result)["east"]["classification"] == "unchanged"
|
||||
# 交的数一样:照常没变
|
||||
assert by_id(run_compare(uncited("r1", 0.46), uncited("r2", 0.46)))["share"]["classification"] == "unchanged"
|
||||
|
||||
|
||||
def test_an_extra_query_by_the_writer_is_a_sql_change():
|
||||
extra = "SELECT COUNT(*) AS n FROM refunds"
|
||||
share = by_id(run_compare(uncited("r1", 0.46), uncited("r2", 0.52, sqls=[region_sql(), extra])))["share"]
|
||||
assert share["classification"] == "sql_changed" and any("多了一次查询" in r for r in share["reasons"])
|
||||
|
||||
|
||||
def test_a_changed_default_model_is_a_template_change_for_agents_that_follow_it():
|
||||
base_graph = weekly_graph()
|
||||
base_graph["defaults"] = {"provider": "anthropic", "model": "model-a"}
|
||||
target_graph = copy.deepcopy(base_graph)
|
||||
target_graph["defaults"]["model"] = "model-b"
|
||||
result = run_compare(uncited("r1", 0.46, graph=base_graph), uncited("r2", 0.52, graph=target_graph))
|
||||
share = by_id(result)["share"]
|
||||
assert share["classification"] == "sql_changed" and any("默认设置" in r for r in share["reasons"]), share["reasons"]
|
||||
assert result["template"]["same_graph"] is False and compare.DEFAULTS_CHANGED in result["notes"]
|
||||
# 取数节点不用模型:东区金额不受影响
|
||||
assert by_id(result)["east"]["classification"] == "unchanged"
|
||||
# Agent 自己指定了模型:默认设置变了它不跟着变
|
||||
for graph in (base_graph, target_graph):
|
||||
graph["nodes"][2]["data"]["config"]["model"] = "model-x"
|
||||
share = by_id(run_compare(uncited("r1", 0.46, graph=base_graph), uncited("r2", 0.52, graph=target_graph)))["share"]
|
||||
assert share["classification"] == "incomparable"
|
||||
|
||||
|
||||
def cited(run_id, rows=BASE_ROWS, *, column="gmv", span=None):
|
||||
"""Agent 按出处交回数组字段:引用快照的哪一列、哪一段行由调用方定。"""
|
||||
run = Fake(run_id)
|
||||
run.tool("fetch", region_sql(), rows=rows)
|
||||
bot = run.agent("bot", region_sql(), rows=rows, column=column, span=span)
|
||||
first, last = span or (0, len(rows) - 1)
|
||||
values = [r[COLUMNS.index(column)] for r in rows[first:last + 1]]
|
||||
run.card([metric("total", "sum(vars.kpi.amounts)", sum(values),
|
||||
[amounts_in(bot, rows, column=column, span=span)])])
|
||||
return run
|
||||
|
||||
|
||||
def test_an_agent_citing_another_column_is_not_a_data_change():
|
||||
"""SQL 一字不差、数据一模一样,Agent 这次引用的是退款列:取的不是同一个数。"""
|
||||
total = by_id(run_compare(cited("r1"), cited("r2", column="refund")))["total"]
|
||||
assert total["classification"] == "incomparable" and total["attribution"] is None
|
||||
assert any("gmv" in r and "refund" in r for r in total["reasons"]), total["reasons"]
|
||||
|
||||
|
||||
def test_an_agent_citing_other_rows_is_not_a_data_change():
|
||||
"""Agent 这次只引用了后两行:东区的数还在快照里,不能把它算成「东区的数据没了」。"""
|
||||
total = by_id(run_compare(cited("r1"), cited("r2", span=(1, 2))))["total"]
|
||||
assert total["classification"] == "incomparable" and total["attribution"] is None
|
||||
assert any("行" in r for r in total["reasons"]), total["reasons"]
|
||||
# 两边引用的都是整份结果(这次多了一个区域):照常是数据变化
|
||||
total = by_id(run_compare(cited("r1"), cited("r2", [*NEXT_ROWS, ["北区", 90.0, 0.0]])))["total"]
|
||||
assert total["classification"] == "data_only" and total["attribution"]["rows"]
|
||||
|
||||
|
||||
def test_an_unknown_writer_on_one_side_is_named_plainly():
|
||||
"""一边记不出 vars.adj 是哪个节点写的:说清是哪一边没记录,不写「None」。"""
|
||||
def make(run_id, writer, value):
|
||||
run = Fake(run_id, graph=weekly_graph(between=(node("calc", "code", "调整", code="x", assign_to="adj"),)))
|
||||
run.tool("fetch", region_sql())
|
||||
run.agent("bot", region_sql())
|
||||
run.code("calc", value, "adj")
|
||||
item = scalar_in("vars.adj", value, writer, "code" if writer else "state")
|
||||
run.card([metric("calc", "vars.adj * 2", value * 2, [item])])
|
||||
return run
|
||||
calc = by_id(run_compare(make("r1", None, 10), make("r2", "calc", 12)))["calc"]
|
||||
assert calc["classification"] == "incomparable"
|
||||
assert not any("None" in r for r in calc["reasons"]) and any("基准运行" in r for r in calc["reasons"])
|
||||
|
||||
|
||||
def test_a_list_run_input_is_compared_by_its_content():
|
||||
"""运行输入是列表:卡上只记了「[2 项]」,按入口节点的产出还原出完整值再比。"""
|
||||
def make(run_id, targets):
|
||||
run = Fake(run_id, inputs={"targets": targets})
|
||||
run.add("node.started", "start", {"node_type": "input"})
|
||||
run.add("node.finished", "start", {"artifact": run.put({"targets": targets})})
|
||||
item = {"path": "input.targets", "value": f"[{len(targets)} 项]", "node_id": "start", "via": "input",
|
||||
"field": "targets", "status": "ok"}
|
||||
run.card([metric("goal", "sum(input.targets)", float(sum(targets)), [item])])
|
||||
return run
|
||||
goal = by_id(run_compare(make("r1", [100.0, 200.0]), make("r2", [100.0, 500.0])))["goal"]
|
||||
assert goal["classification"] == "params_only" and any("targets" in r for r in goal["reasons"]), goal["reasons"]
|
||||
goal = by_id(run_compare(make("r1", [100.0, 200.0]), make("r2", [100.0, 200.0])))["goal"]
|
||||
assert goal["classification"] == "unchanged"
|
||||
|
||||
|
||||
def test_a_run_input_change_is_a_parameter_change():
|
||||
def make(run_id, goal):
|
||||
run = Fake(run_id, inputs={"goal": goal})
|
||||
@@ -534,6 +860,107 @@ def test_an_agent_asking_in_another_order_is_paired_by_sql():
|
||||
assert pairs == [("params_only", by_day[:20]), ("params_only", by_region[:20])]
|
||||
|
||||
|
||||
def test_swapped_queries_with_the_same_literals_pair_up_exactly():
|
||||
"""Agent 两次都查了东区和南区,只是先后互换:先配字面量也相同的,两条都没变;下游的数照常是数据变化。"""
|
||||
def region(name):
|
||||
return f"SELECT SUM(amount) AS gmv FROM orders WHERE region = '{name}'"
|
||||
|
||||
def make(run_id, regions, value, gmv):
|
||||
run = Fake(run_id, graph=weekly_graph(between=(node("calc", "code", "调整", code="x", assign_to="adj"),)))
|
||||
run.plain_agent("bot", [region(r) for r in regions], {"text": "ok"}, ["gmv"], [[gmv]], types={"gmv": "number"})
|
||||
run.code("calc", value, "adj")
|
||||
run.card(code_metrics(value)(None, None, None, None))
|
||||
return run
|
||||
|
||||
result = run_compare(make("r1", ["东区", "南区"], 10, 1.0), make("r2", ["南区", "东区"], 12, 2.0))
|
||||
assert [(q["structure"], q["literals"]) for q in result["queries"]] == [("same", []), ("same", [])]
|
||||
assert by_id(result)["calc"]["classification"] == "data_only"
|
||||
|
||||
|
||||
def test_a_switched_data_source_is_a_structure_change():
|
||||
"""SQL 一字不差、换了数据源:查的不是同一份数据。"""
|
||||
result = run_compare(week("r1"), week("r2", NEXT_ROWS, source="shop_backup"))
|
||||
fetch = result_queries(result, "fetch")
|
||||
assert fetch["structure"] == "changed" and any("shop_backup" in d for d in fetch["differences"])
|
||||
assert by_id(result)["east"]["classification"] == "sql_changed"
|
||||
|
||||
|
||||
def test_a_literal_edited_in_the_workflow_is_a_template_change():
|
||||
"""图里写死的筛选值改了('paid' 改成 'refunded'):执行的 SQL 只差字面量,但这是改模板,不是运行时代入的参数。"""
|
||||
paid, refunded = region_sql(extra=" AND status = 'paid'"), region_sql(extra=" AND status = 'refunded'")
|
||||
result = run_compare(week("r1", sql=paid, graph=weekly_graph(paid)),
|
||||
week("r2", NEXT_ROWS, sql=refunded, graph=weekly_graph(refunded)))
|
||||
east = by_id(result)["east"]
|
||||
assert east["classification"] == "sql_changed", east["reasons"]
|
||||
assert any("区域取数" in r and "'paid'" in r for r in east["reasons"])
|
||||
assert east["decomposition"] is None and east["attribution"] is None
|
||||
# 查询表照实写:执行的 SQL 确实只差这一处字面量
|
||||
assert result_queries(result, "fetch")["structure"] == "params_only"
|
||||
|
||||
|
||||
def test_reformatting_the_workflow_sql_is_not_a_change():
|
||||
loose = region_sql().replace(" FROM ", "\n FROM ").lower()
|
||||
result = run_compare(week("r1"), week("r2", NEXT_ROWS, sql=loose, graph=weekly_graph(loose)))
|
||||
assert {m["classification"] for m in result["metrics"]} == {"data_only"}
|
||||
|
||||
|
||||
def test_renaming_a_node_is_not_a_change():
|
||||
graph = weekly_graph()
|
||||
graph["nodes"][2]["data"]["label"] = "区域分析(新)"
|
||||
result = run_compare(week("r1"), week("r2", NEXT_ROWS, graph=graph))
|
||||
assert {m["classification"] for m in result["metrics"]} == {"data_only"}
|
||||
[renamed] = result["template"]["nodes"]
|
||||
assert (renamed["node_id"], renamed["keys"]) == ("bot", ["label"])
|
||||
|
||||
|
||||
MERGE_SQL = "SELECT region, gmv FROM a ORDER BY region"
|
||||
OUTER_SQL = "SELECT region, gmv FROM m ORDER BY region"
|
||||
MERGED_TYPES = {"region": "text", "gmv": "number"}
|
||||
|
||||
|
||||
def merged(run_id, sql, rows, *, template=None, nested=False, twice=False):
|
||||
"""取数节点查一次,合并节点把它当输入 a 再执行一条合并 SQL(nested:再套一层合并;twice:这次多接一个输入 b),
|
||||
口径卡取合并结果的一格。"""
|
||||
nodes = [node("start", "input", "开始"), node("fetch", "tool", "区域取数", tool=TOOL, args={"sql": template or sql}),
|
||||
node("join", "merge", "合并", sql=MERGE_SQL, inputs={"a": "fetch", **({"b": "fetch"} if twice else {})})]
|
||||
if nested:
|
||||
nodes.append(node("outer", "merge", "再合并", sql=OUTER_SQL, inputs={"m": "join"}))
|
||||
nodes.append(node("card", "metrics", "口径卡", caliber="周报口径", caliber_version="v1"))
|
||||
run = Fake(run_id, graph=chain(*nodes))
|
||||
fetch = run.tool("fetch", sql, rows=rows)
|
||||
table = [[r[0], r[1]] for r in rows]
|
||||
inputs = [("a", "fetch", fetch)] + ([("b", "fetch", fetch)] if twice else [])
|
||||
top, owner = run.merge("join", MERGE_SQL, inputs, ["region", "gmv"], table, types=MERGED_TYPES), "join"
|
||||
if nested:
|
||||
top, owner = run.merge("outer", OUTER_SQL, [("m", "join", top)], ["region", "gmv"], table,
|
||||
types=MERGED_TYPES), "outer"
|
||||
run.card([metric("east", f"cell(nodes.{owner}, 0, 'gmv')", table[0][1],
|
||||
[cell_in(0, "gmv", table[0][1], top, node_id=owner)], name="东区金额")])
|
||||
return run
|
||||
|
||||
|
||||
def test_a_merged_cell_follows_the_queries_feeding_the_merge():
|
||||
"""合并 SQL 一字没改,喂它的取数 SQL 加了筛选:读合并结果的指标是 SQL 变了,不拆、不归因(嵌套的合并也追到底)。"""
|
||||
paid = region_sql(extra=" AND status = 'paid'")
|
||||
for nested in (False, True):
|
||||
east = by_id(run_compare(merged("r1", region_sql(), BASE_ROWS, nested=nested),
|
||||
merged("r2", paid, NEXT_ROWS, nested=nested)))["east"]
|
||||
assert east["classification"] == "sql_changed", (nested, east["reasons"])
|
||||
assert east["decomposition"] is None and east["attribution"] is None
|
||||
assert any("区域取数" in r and "SQL" in r for r in east["reasons"]), east["reasons"]
|
||||
# 上游只是代进去的日期不同:参数变化
|
||||
template = region_sql(("{{ input.start }}", "{{ input.end }}"))
|
||||
east = by_id(run_compare(merged("r1", region_sql(), BASE_ROWS, template=template),
|
||||
merged("r2", region_sql(WEEK37), NEXT_ROWS, template=template)))["east"]
|
||||
assert east["classification"] == "params_only", east["reasons"]
|
||||
# 合并 SQL 和上游都没变:数据变化
|
||||
east = by_id(run_compare(merged("r1", region_sql(), BASE_ROWS), merged("r2", region_sql(), NEXT_ROWS)))["east"]
|
||||
assert east["classification"] == "data_only", east["reasons"]
|
||||
# 合并节点这次多接了一个输入
|
||||
east = by_id(run_compare(merged("r1", region_sql(), BASE_ROWS), merged("r2", region_sql(), NEXT_ROWS, twice=True)))
|
||||
assert east["east"]["classification"] == "sql_changed" and any("「b」" in r for r in east["east"]["reasons"])
|
||||
|
||||
|
||||
def test_an_agent_reconfigured_with_the_same_sql_is_a_template_change():
|
||||
"""Agent 改了提示词、SQL 一字不差:它按出处交来的字段可能换了取法,不能报成数据变化。"""
|
||||
graph = weekly_graph()
|
||||
|
||||
Reference in New Issue
Block a user