diff --git a/backend/app/engine/nodes/analysis.py b/backend/app/engine/nodes/analysis.py index 80501458..3c622232 100644 --- a/backend/app/engine/nodes/analysis.py +++ b/backend/app/engine/nodes/analysis.py @@ -56,7 +56,12 @@ async def run_analysis(state: GraphState, ctx: NodeContext) -> dict[str, Any]: if errors := [i for i in analysis_issues(ctx.run.spec, ctx.node) if i.level == "error"]: raise NodeError(ctx.node.id, errors[0].message) items: list[dict[str, Any]] = ctx.config["items"] - settings = await settings_of(run_snapshot(ctx.run), ctx.config.get("overrides") or None) + overrides = ctx.config.get("overrides") or None + settings = await settings_of(run_snapshot(ctx.run), overrides) + # 画图时阈值覆盖只能对着缺省值校验;合并了这次运行的设置快照以后再核一遍(管理员把「超出常规波动」调到 3、卡上把「明显 + # 超出」覆盖成 2.5,就永远判不出超出)。这是配置错误,不是数据问题:让卡失败、说清冲突在哪 + if overrides and (problem := contract.settings_problem(settings)): + raise NodeError(ctx.node.id, f"阈值覆盖和这次运行的分析设置冲突:{problem}。请改分析卡上的阈值覆盖") queries = [e for e in state.get("evidence") or [] if isinstance(e, dict) and e.get("kind") == "query"] inputs: dict[str, InputSnapshot] = {} diff --git a/backend/tests/test_analysis_card_data.py b/backend/tests/test_analysis_card_data.py index 755df707..179ef740 100644 --- a/backend/tests/test_analysis_card_data.py +++ b/backend/tests/test_analysis_card_data.py @@ -68,3 +68,16 @@ async def test_a_structural_call_error_still_fails_the_card_and_names_the_item() assert row.status == "failed" assert "分析项「where」(变化拆解)" in row.error and "没有「channel」这一列" in row.error assert "请在分析卡中改正这一项" in row.error + + +async def test_overrides_that_conflict_with_the_run_settings_fail_the_card(): + # 画图时对着缺省值校验能过(缺省「超出常规波动」是 2);这次运行的设置把它调到 3,卡上覆盖的「明显超出」2.5 就永远判不出 + card = node("card", "analysis", items=[WHERE], overrides={"k_alert": 2.5}) + graph = chain(node("start", "input"), node("by_region", "tool", tool=TOOL, args={"sql": BY_REGION}), card) + run = await run_manager.start(graph=graph, input_payload={}, options={"analysis": {"k_warn": 3.0}}) + row = await wait(run.id) + assert row.status == "failed" + assert "阈值覆盖和这次运行的分析设置冲突:「明显超出」的倍数要大于「超出常规波动」的倍数" in row.error + assert await events(row.id, "analysis.end", "card") == [] + ok = await run_manager.start(graph=graph, input_payload={}, options={"analysis": {"k_warn": 2.0}}) + assert (await wait(ok.id)).status == "succeeded"