refactor(pchome): extract backlog policy and evidence modules
This commit is contained in:
@@ -28,8 +28,8 @@ def test_inventory_generates_complete_prioritized_work_items():
|
||||
assert all(item["work_item_id"] for item in result["python_work_items"])
|
||||
by_path = {item["path"]: item for item in result["python_work_items"]}
|
||||
assert by_path["routes/openclaw_bot_routes.py"]["status"] == "in_progress"
|
||||
assert by_path["services/pchome_mapping_backlog_service.py"]["status"] == "not_started"
|
||||
assert summary["work_item_status_counts"]["in_progress"] == 3
|
||||
assert by_path["services/pchome_mapping_backlog_service.py"]["status"] == "in_progress"
|
||||
assert summary["work_item_status_counts"]["in_progress"] == 4
|
||||
assert sum(summary["work_item_status_counts"].values()) == (
|
||||
summary["large_python_module_count"] + summary["large_frontend_asset_count"]
|
||||
)
|
||||
|
||||
45
tests/test_pchome_mapping_backlog_modularization.py
Normal file
45
tests/test_pchome_mapping_backlog_modularization.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from pathlib import Path
|
||||
|
||||
from services import pchome_mapping_backlog_service as compatibility_facade
|
||||
from services.pchome_mapping_backlog import contracts, evidence, policies
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def test_policy_registry_is_extracted_without_changing_legacy_exports():
|
||||
assert len(policies.__all__) == 96
|
||||
assert compatibility_facade.BACKLOG_POLICY == policies.BACKLOG_POLICY
|
||||
assert (
|
||||
compatibility_facade.AUTO_POLICY_DB_APPLY_CONTROLLED_DRY_RUN_PACKAGE_POLICY
|
||||
== policies.AUTO_POLICY_DB_APPLY_CONTROLLED_DRY_RUN_PACKAGE_POLICY
|
||||
)
|
||||
assert compatibility_facade.PCHOME_FETCH_ALLOWED_DOMAIN == "24h.pchome.com.tw"
|
||||
|
||||
|
||||
def test_evidence_and_contract_functions_keep_legacy_import_identity():
|
||||
assert (
|
||||
compatibility_facade.parse_pchome_product_page_evidence_html
|
||||
is evidence.parse_pchome_product_page_evidence_html
|
||||
)
|
||||
assert compatibility_facade.parse_unit_package_basis is evidence.parse_unit_package_basis
|
||||
assert (
|
||||
compatibility_facade._ai_exception_compatibility_fields
|
||||
is contracts._ai_exception_compatibility_fields
|
||||
)
|
||||
|
||||
|
||||
def test_extracted_unit_parser_preserves_ai_exception_and_no_write_contract():
|
||||
parsed = compatibility_facade.parse_unit_package_basis("理膚寶水 B5 40ml x2 超值組")
|
||||
|
||||
assert parsed["estimated_total_quantity"] == 80
|
||||
assert parsed["ai_exception_required"] is True
|
||||
assert parsed["primary_human_gate_count"] == 0
|
||||
assert parsed["writes_database"] is False
|
||||
assert parsed["fetches_external_sites"] is False
|
||||
|
||||
|
||||
def test_legacy_facade_is_smaller_after_first_p0_extraction():
|
||||
facade = ROOT / "services/pchome_mapping_backlog_service.py"
|
||||
|
||||
assert sum(1 for _ in facade.open(encoding="utf-8")) < 44_300
|
||||
Reference in New Issue
Block a user