# ============================================================ # EX-07 / EX-08 分析视图黄金测试 # ============================================================ from __future__ import annotations from server.agent_core.intent import parse_fast from server.aps_domain.analytics import build_compare_table, build_kpi_dashboard from server.aps_domain.flex import run_flex_schedule from server.engines import get_engine from server.engines.base import EngineParams from server.state.seed import seed_world from server.timeutil import add_minutes, fmt_date, today0 class _MemStore: def __init__(self, data): self.data = data def next_id(self, kind: str) -> int: key = f"_c_{kind}" self.data[key] = self.data.get(key, 5000) + 1 return self.data[key] def save(self): pass def _run_fixed(world): start = fmt_date(add_minutes(today0(), 24 * 60)) params = EngineParams(orderIds=[], engineType="RULE", strategyTemplate="COMPREHENSIVE", planningHorizonDays=14, startDate=start) counters: dict[str, int] = {} def next_id(kind: str) -> int: counters[kind] = counters.get(kind, 0) + 1 return counters[kind] get_engine("RULE").solve(world, params, next_id) def test_kpi_dashboard_aggregates(): store = _MemStore(seed_world()) _run_fixed(store.data) run_flex_schedule(store, sort_mode="BOTTLENECK", actor="test") dash = build_kpi_dashboard(store.data) assert len(dash["cards"]) >= 5 assert dash["fixed"] and dash["fixed"].get("versionNo") assert dash["flex"] and dash["flex"].get("versionNo") assert "total" in dash["conflicts"] def test_compare_table_has_best_and_deltas(): store = _MemStore(seed_world()) table = build_compare_table(store.data, track="flex") assert table["sections"] sec = table["sections"][0] assert len(sec["columns"]) == 3 assert sec["recommendation"] row = next(r for r in sec["rows"] if r["metric"] == "totalTardiness") assert row["bestIdx"] is not None assert row["deltas"][row["bestIdx"]] in (0, 0.0) def test_intent_analytics_phrases(): world = seed_world() assert parse_fast("打开KPI仪表盘", world).intent == "query.kpi" assert parse_fast("方案对比表", world).intent == "scenario.compare"