test(cma): clear 10 pre-existing baseline failures (cma-baseline-tests-cleanup-20260915)
No production code changed. Root causes were all test-side staleness: - test_cash TestVoucherImport: fixture filename contained 'test' -> rejected by the intentional import guard (d71c7fe); renamed, and missing-columns case now asserts the column check is what returns 400 - test_budget_tech_improve TestP1ValueCollect: seeded voucher_details source rows; collector deliberately skips empty aggregates sinced71c7fe(no more implicit 0), and preview call now passes an explicit period - test_roadmap_r2r5 / test_budget / test_ai_suggestions: seeds hardcoded 2026-08 (authoring month) while detectors/rule engine use the current month -> replaced with current-period seeds pytest tests/ -q -rf: 1094 passed, 1 xfailed, 0 failed (baseline was 10 failed, 1084 passed, 1 xfailed)
This commit is contained in:
@@ -16,6 +16,15 @@ from scripts.opportunity_detector import (
|
||||
from scripts.closed_loop_check import check_entity, build_report
|
||||
|
||||
|
||||
def _cur_period() -> str:
|
||||
"""当前月字符串。
|
||||
|
||||
detect_budget_headroom 的口径是「当月预算执行率<70%」(实现内取 datetime.now()),
|
||||
用例里硬编码月份会在跨月后与实现错配、恒判 0 条(2026-09 跨月实证:原写死 2026-08)。
|
||||
"""
|
||||
return datetime.now().strftime("%Y-%m")
|
||||
|
||||
|
||||
def _kpi(db, code, target=100.0, **kw):
|
||||
return create_test_kpi(db, kpi_code=code, target_value=target, **kw)
|
||||
|
||||
@@ -68,9 +77,10 @@ class TestOpportunityR2:
|
||||
|
||||
def test_budget_headroom(self, db):
|
||||
"""当月预算执行率<70% → 预算余量机会"""
|
||||
p = _cur_period()
|
||||
kpi = _kpi(db, "OPP_04", target=1000.0)
|
||||
_value(db, kpi.id, "2026-08", 300.0)
|
||||
_budget(db, kpi.id, "2026-08", 1000.0)
|
||||
_value(db, kpi.id, p, 300.0)
|
||||
_budget(db, kpi.id, p, 1000.0)
|
||||
db.commit()
|
||||
out = detect_budget_headroom(db, 1)
|
||||
assert len(out) == 1
|
||||
@@ -78,18 +88,20 @@ class TestOpportunityR2:
|
||||
|
||||
def test_budget_headroom_negative_skip(self, db):
|
||||
"""实际值为负(现金流异常)不误判为余量"""
|
||||
p = _cur_period()
|
||||
kpi = _kpi(db, "OPP_05", target=1000.0)
|
||||
_value(db, kpi.id, "2026-08", -500.0)
|
||||
_budget(db, kpi.id, "2026-08", 1000.0)
|
||||
_value(db, kpi.id, p, -500.0)
|
||||
_budget(db, kpi.id, p, 1000.0)
|
||||
db.commit()
|
||||
assert detect_budget_headroom(db, 1) == []
|
||||
|
||||
def test_budget_headroom_dedup(self, db):
|
||||
"""同KPI同期间多版本预算只取一条"""
|
||||
p = _cur_period()
|
||||
kpi = _kpi(db, "OPP_06", target=1000.0)
|
||||
_value(db, kpi.id, "2026-08", 300.0)
|
||||
_budget(db, kpi.id, "2026-08", 1000.0)
|
||||
b2 = _budget(db, kpi.id, "2026-08", 2000.0)
|
||||
_value(db, kpi.id, p, 300.0)
|
||||
_budget(db, kpi.id, p, 1000.0)
|
||||
b2 = _budget(db, kpi.id, p, 2000.0)
|
||||
b2.version = "v2.0"
|
||||
db.commit()
|
||||
assert len(detect_budget_headroom(db, 1)) == 1
|
||||
|
||||
Reference in New Issue
Block a user