V10.606 正名 PChome 業績成長作戰系統
All checks were successful
CD Pipeline / deploy (push) Successful in 1m6s
All checks were successful
CD Pipeline / deploy (push) Successful in 1m6s
This commit is contained in:
@@ -379,13 +379,15 @@ def test_ai_intelligence_uses_v2_shell_and_real_runtime_apis():
|
||||
assert "{% block ewooo_content %}" in template
|
||||
assert "ai-intel-hero" in template
|
||||
assert "ai-status-badge" in template
|
||||
assert "PChome 競品比價監控" in template
|
||||
assert "AI 決策日誌" in template
|
||||
assert "PChome 業績成長自動化作戰系統" in template
|
||||
assert "MOMO 外部價格參考" in template
|
||||
assert "/api/ai/pchome-growth/opportunities" in template
|
||||
assert "作戰建議紀錄" in template
|
||||
assert "fetch('/api/ai/icaim/dashboard')" in template
|
||||
assert "fetch('/api/ai/product-picks/generate'" in template
|
||||
assert "fetch('/api/ai/pchome-match/backfill'" in template
|
||||
assert "JSON.stringify({ limit: 50 })" in template
|
||||
assert "僅顯示已通過身份比對的競品" in template
|
||||
assert "僅顯示已確認同款的商品" in template
|
||||
assert "tagMap[t] || ['bg-light text-dark', t]" not in template
|
||||
assert "\"match_type_exact\":[" not in template
|
||||
assert "'match_type_exact':[" in template
|
||||
@@ -684,8 +686,8 @@ def test_ai_product_pick_agent_uses_real_competitor_data_and_dashboard_action():
|
||||
assert "每日 10:30:pchome_match_backfill" in run_scheduler_source
|
||||
assert '"run_pchome_match_backfill_task"' in agent_actions_source
|
||||
|
||||
assert "產生挑品清單" in template
|
||||
assert "補抓未搜尋" in template
|
||||
assert "產生作戰商品" in template
|
||||
assert "補商品對應" in template
|
||||
assert "generatePickList" in template
|
||||
assert "backfillPchomeMatches" in template
|
||||
assert "/api/ai/product-picks/generate" in template
|
||||
|
||||
87
tests/test_pchome_revenue_growth_service.py
Normal file
87
tests/test_pchome_revenue_growth_service.py
Normal file
@@ -0,0 +1,87 @@
|
||||
from sqlalchemy import create_engine, text
|
||||
|
||||
|
||||
def _seed_growth_tables(engine):
|
||||
with engine.begin() as conn:
|
||||
conn.execute(text(
|
||||
'CREATE TABLE daily_sales_snapshot ('
|
||||
'"商品ID" TEXT, "商品名稱" TEXT, snapshot_date TEXT, "總業績" REAL, "數量" REAL, "商品館" TEXT)'
|
||||
))
|
||||
conn.execute(text(
|
||||
"CREATE TABLE competitor_prices ("
|
||||
"sku TEXT, source TEXT, competitor_product_id TEXT, competitor_product_name TEXT, "
|
||||
"price REAL, match_score REAL, tags TEXT, crawled_at TEXT, expires_at TEXT)"
|
||||
))
|
||||
conn.execute(text(
|
||||
"CREATE TABLE products ("
|
||||
"id INTEGER PRIMARY KEY, i_code TEXT, name TEXT, status TEXT)"
|
||||
))
|
||||
conn.execute(text(
|
||||
"CREATE TABLE price_records ("
|
||||
"id INTEGER PRIMARY KEY, product_id INTEGER, price REAL, timestamp TEXT)"
|
||||
))
|
||||
conn.execute(text("""
|
||||
INSERT INTO daily_sales_snapshot
|
||||
("商品ID", "商品名稱", snapshot_date, "總業績", "數量", "商品館")
|
||||
VALUES
|
||||
('PCH-1', '高業績商品', '2026-06-14', 120000, 36, '保養'),
|
||||
('PCH-1', '高業績商品', '2026-06-08', 180000, 50, '保養'),
|
||||
('PCH-2', '待補對應商品', '2026-06-14', 90000, 18, '彩妝'),
|
||||
('PCH-2', '待補對應商品', '2026-06-08', 30000, 8, '彩妝')
|
||||
"""))
|
||||
conn.execute(text(
|
||||
"INSERT INTO products (id, i_code, name, status) "
|
||||
"VALUES (1, 'MOMO-1', 'MOMO 參考商品', 'ACTIVE')"
|
||||
))
|
||||
conn.execute(text(
|
||||
"INSERT INTO price_records (product_id, price, timestamp) "
|
||||
"VALUES (1, 900, '2026-06-14 10:00:00')"
|
||||
))
|
||||
conn.execute(text("""
|
||||
INSERT INTO competitor_prices
|
||||
(sku, source, competitor_product_id, competitor_product_name,
|
||||
price, match_score, tags, crawled_at, expires_at)
|
||||
VALUES
|
||||
('MOMO-1', 'pchome', 'PCH-1', '高業績商品',
|
||||
1000, 0.91, '["identity_v2","match_type_exact"]', '2026-06-14 11:00:00', NULL)
|
||||
"""))
|
||||
|
||||
|
||||
def test_pchome_growth_opportunities_use_plain_language_and_pause_shopee_coupang():
|
||||
from services.pchome_revenue_growth_service import build_pchome_growth_opportunities
|
||||
|
||||
engine = create_engine("sqlite:///:memory:")
|
||||
_seed_growth_tables(engine)
|
||||
|
||||
payload = build_pchome_growth_opportunities(engine, limit=5)
|
||||
|
||||
assert payload["success"] is True
|
||||
assert payload["system_name"] == "PChome 業績成長自動化作戰系統"
|
||||
assert payload["source_scope"]["active_external_sources"] == ["MOMO 外部價格參考"]
|
||||
assert payload["source_scope"]["paused_external_sources"] == ["蝦皮", "酷澎"]
|
||||
assert payload["stats"]["candidate_count"] == 2
|
||||
assert payload["stats"]["mapped_count"] == 1
|
||||
assert payload["stats"]["needs_mapping_count"] == 1
|
||||
|
||||
actions = {item["pchome_product_id"]: item["recommended_action"]["label"] for item in payload["opportunities"]}
|
||||
assert actions["PCH-1"] == "檢查售價與活動"
|
||||
assert actions["PCH-2"] == "先補商品對應"
|
||||
assert all("identity" not in " ".join(item["reason_lines"]).lower() for item in payload["opportunities"])
|
||||
|
||||
|
||||
def test_ai_product_pick_sales_join_by_sku_disabled_by_default(monkeypatch):
|
||||
from services.ai_product_pick_agent import _sales_join_by_momo_sku_enabled
|
||||
|
||||
monkeypatch.delenv("PCHOME_SALES_JOIN_BY_MOMO_SKU_ENABLED", raising=False)
|
||||
|
||||
assert _sales_join_by_momo_sku_enabled() is False
|
||||
|
||||
|
||||
def test_ai_intelligence_template_uses_pchome_growth_name_and_endpoint():
|
||||
from pathlib import Path
|
||||
|
||||
template = Path("templates/ai_intelligence.html").read_text(encoding="utf-8")
|
||||
|
||||
assert "PChome 業績成長自動化作戰系統" in template
|
||||
assert "/api/ai/pchome-growth/opportunities" in template
|
||||
assert "待補對應" in template
|
||||
Reference in New Issue
Block a user