feat(dashboard): optimize cache and AI pick confidence
All checks were successful
CD Pipeline / deploy (push) Successful in 2m46s

This commit is contained in:
OoO
2026-05-01 16:01:52 +08:00
parent 0334051aa7
commit 3920701e1a
9 changed files with 198 additions and 27 deletions

View File

@@ -68,9 +68,13 @@ def test_set_sales_processed_cache_adds_timestamp_and_aliases():
assert cache_manager._SALES_PROCESSED_CACHE["realtime_sales_monthly"] is entry
def test_dashboard_cache_clear_restores_expected_shape():
def test_dashboard_cache_clear_restores_expected_shape(tmp_path, monkeypatch):
from services import cache_manager
shared_cache = tmp_path / "dashboard_full_cache.pkl"
shared_cache.write_bytes(b"stale")
monkeypatch.setattr(cache_manager, "_DASHBOARD_SHARED_CACHE_FILE", shared_cache)
cache_manager._DASHBOARD_DATA_CACHE["consolidated_data"] = ["stale"]
cache_manager._DASHBOARD_DATA_CACHE["full_data"] = ["stale"]
@@ -83,6 +87,7 @@ def test_dashboard_cache_clear_restores_expected_shape():
"full_data": None,
"full_timestamp": None,
}
assert not shared_cache.exists()
def test_cache_dicts_are_only_defined_in_cache_manager():

View File

@@ -47,6 +47,8 @@ def test_dashboard_v2_is_production_default_and_uses_real_dashboard_data():
assert "request.args.get('ui') == 'legacy'" in route_source
assert "template_name = 'dashboard.html' if request.args.get('ui') == 'legacy' else 'dashboard_v2.html'" in route_source
assert "get_full_dashboard_data()" in route_source
assert "_load_shared_full_dashboard_cache(now)" in route_source
assert "_write_shared_full_dashboard_cache(full_data)" in route_source
assert "_load_competitor_decision_overview(session)" in route_source
assert "ai_price_recommendations" in route_source
assert "pending_match_count" in route_source
@@ -187,6 +189,11 @@ def test_ai_product_pick_agent_uses_real_competitor_data_and_dashboard_action():
assert "PChome 價格優勢" in agent_source
assert "_daily_sales_columns" in agent_source
assert '"總業績"' in agent_source
assert '"毛利"' in agent_source
assert '"總成本"' in agent_source
assert "evidence_quality" in agent_source
assert "opportunity_score" in agent_source
assert "margin_rate" in agent_source
assert "{date_col}::date" in agent_source
assert "conn.rollback()" in agent_source