feat: schedule growth momo backfill
All checks were successful
CD Pipeline / deploy (push) Successful in 1m11s

This commit is contained in:
OoO
2026-06-19 00:18:53 +08:00
parent 9ca8d4e43c
commit 4c59b74ced
11 changed files with 315 additions and 156 deletions

View File

@@ -385,5 +385,9 @@ def test_external_offer_sync_is_registered_in_scheduler():
assert "def run_external_offer_sync_task" in scheduler_source
assert "sync_legacy_momo_reference_offers" in scheduler_source
assert "def run_pchome_growth_momo_backfill_task" in scheduler_source
assert "run_pchome_growth_momo_backfill" in scheduler_source
assert "run_external_offer_sync_task" in run_scheduler_source
assert "run_pchome_growth_momo_backfill_task" in run_scheduler_source
assert "external_offer_sync" in run_scheduler_source
assert "pchome_growth_momo_backfill" in run_scheduler_source

View File

@@ -899,11 +899,16 @@ def test_ai_product_pick_agent_uses_real_competitor_data_and_dashboard_action():
run_scheduler_source = (ROOT / "run_scheduler.py").read_text(encoding="utf-8")
agent_actions_source = (ROOT / "services/agent_actions.py").read_text(encoding="utf-8")
assert "def run_pchome_match_backfill_task" in scheduler_source
assert "def run_pchome_growth_momo_backfill_task" in scheduler_source
assert "_save_stats('pchome_match_backfill'" in scheduler_source
assert "_save_stats('pchome_growth_momo_backfill'" in scheduler_source
assert "retryable_candidate_revalidation_total" in scheduler_source
assert "run_pchome_match_backfill_task" in run_scheduler_source
assert "run_pchome_growth_momo_backfill_task" in run_scheduler_source
assert "每日 10:30pchome_match_backfill" in run_scheduler_source
assert "每日 10:45pchome_growth_momo_backfill" in run_scheduler_source
assert '"run_pchome_match_backfill_task"' in agent_actions_source
assert '"run_pchome_growth_momo_backfill_task"' in agent_actions_source
assert "產生今日清單" in template
assert "補齊比價資料" in template
@@ -917,6 +922,7 @@ def test_ai_product_pick_agent_uses_real_competitor_data_and_dashboard_action():
assert "PChome 比價補強" in dashboard_template
assert "data-pchome-growth-backfill-trigger" in dashboard_template
assert "data-pchome-growth-backfill-status" in dashboard_template
assert "每日 10:45 自動補對應" in dashboard_template
assert "PCHOME MATCH BACKFILL" not in dashboard_template
assert ">ACTIVE<" not in dashboard_template
assert "目前 ACTIVE 商品" not in dashboard_template

View File

@@ -225,15 +225,13 @@ def test_pchome_growth_route_cache_respects_shared_invalidation_epoch(monkeypatc
assert routes._get_cached_pchome_growth_payload() is None
def test_pchome_growth_momo_backfill_route_targets_unmapped_high_sales_items(monkeypatch):
from flask import Flask
from routes import ai_routes as routes
def test_pchome_growth_momo_backfill_service_targets_unmapped_high_sales_items():
from services.pchome_growth_momo_backfill_service import run_pchome_growth_momo_backfill
captured = {}
class FakeEngine:
def dispose(self):
captured["disposed"] = True
pass
before_payload = {
"success": True,
@@ -309,20 +307,14 @@ def test_pchome_growth_momo_backfill_route_targets_unmapped_high_sales_items(mon
"unit_price_count": 1,
}
monkeypatch.setattr(routes, "_create_icaim_dashboard_engine", lambda database_path: FakeEngine())
monkeypatch.setattr(routes, "_build_pchome_growth_payload", fake_build_payload)
monkeypatch.setattr(routes, "_search_growth_momo_candidates", fake_search)
monkeypatch.setattr(routes, "_sync_growth_momo_candidates", fake_sync)
payload = run_pchome_growth_momo_backfill(
FakeEngine(),
limit=2,
build_payload_func=fake_build_payload,
search_func=fake_search,
sync_func=fake_sync,
)
app = Flask(__name__)
with app.test_request_context(
"/api/ai/pchome-growth/backfill-momo-candidates",
method="POST",
json={"limit": 2},
):
response = routes.api_pchome_growth_backfill_momo_candidates.__wrapped__()
payload = response.get_json()
assert payload["success"] is True
assert payload["data"]["scanned_products"] == 2
assert payload["data"]["candidate_count"] == 3
@@ -334,6 +326,47 @@ def test_pchome_growth_momo_backfill_route_targets_unmapped_high_sales_items(mon
assert [item["price"] for item in captured["targets"]] == [920, 760]
assert [item["product_id"] for item in captured["sync_candidates"]] == ["MOMO-AUTO", "MOMO-UNIT"]
assert captured["search_limit"] == 2
def test_pchome_growth_momo_backfill_route_calls_shared_service(monkeypatch):
from flask import Flask
from routes import ai_routes as routes
captured = {}
class FakeEngine:
def dispose(self):
captured["disposed"] = True
def fake_run(engine, limit):
captured["limit"] = limit
return {
"success": True,
"message": "已完成",
"data": {
"scanned_products": 2,
"candidate_count": 3,
"auto_compare_count": 2,
"review_count": 1,
"external_offer_sync": {"written_count": 2},
},
}
monkeypatch.setattr(routes, "_create_icaim_dashboard_engine", lambda database_path: FakeEngine())
monkeypatch.setattr(routes, "_run_pchome_growth_momo_backfill", fake_run)
app = Flask(__name__)
with app.test_request_context(
"/api/ai/pchome-growth/backfill-momo-candidates",
method="POST",
json={"limit": 2},
):
response = routes.api_pchome_growth_backfill_momo_candidates.__wrapped__()
payload = response.get_json()
assert payload["success"] is True
assert payload["data"]["external_offer_sync"]["written_count"] == 2
assert captured["limit"] == 2
assert captured["disposed"] is True

View File

@@ -226,6 +226,8 @@ def test_roi_ai_smoke_and_daily_report_schedules_stay_staggered():
assert 'schedule.every().day.at("09:00").do(run_daily_report_task)' in source
assert 'schedule.every().day.at("09:05").do(run_roi_monthly_report_if_new_month)' in source
assert 'schedule.every().day.at("09:10").do(run_ai_smoke_daily_summary_task)' in source
assert 'schedule.every().day.at("10:30").do(run_pchome_match_backfill_task)' in source
assert 'schedule.every().day.at("10:45").do(run_pchome_growth_momo_backfill_task)' in source
assert "schedule.every(6).hours.do(run_action_plan_hygiene_task)" in source
assert "schedule.every(15).minutes.do(run_ollama_111_usage_guard_check)" in source