refactor(pchome): extract controlled apply executor
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
from pathlib import Path
|
||||
|
||||
from services import pchome_mapping_backlog_service as compatibility_facade
|
||||
from services.pchome_mapping_backlog import contracts, evidence, policies
|
||||
from services.pchome_mapping_backlog import (
|
||||
artifacts,
|
||||
contracts,
|
||||
controlled_apply_executor,
|
||||
evidence,
|
||||
policies,
|
||||
)
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
@@ -39,7 +45,57 @@ def test_extracted_unit_parser_preserves_ai_exception_and_no_write_contract():
|
||||
assert parsed["fetches_external_sites"] is False
|
||||
|
||||
|
||||
def test_legacy_facade_is_smaller_after_first_p0_extraction():
|
||||
def test_controlled_apply_executor_helpers_keep_legacy_import_identity():
|
||||
assert (
|
||||
compatibility_facade._canonical_retry_exception_artifact_bytes
|
||||
is artifacts._canonical_retry_exception_artifact_bytes
|
||||
)
|
||||
assert (
|
||||
compatibility_facade._selector_to_pchome_match_params
|
||||
is controlled_apply_executor._selector_to_pchome_match_params
|
||||
)
|
||||
|
||||
|
||||
def test_controlled_apply_executor_core_is_no_write_without_apply_request(tmp_path):
|
||||
preflight = {
|
||||
"policy": "controlled_apply_preflight_fixture",
|
||||
"success": True,
|
||||
"generated_at": "2026-07-11T12:00:00+08:00",
|
||||
"stats": {},
|
||||
"backlog": {},
|
||||
"summary": {"mutation_plan_count": 1},
|
||||
"controlled_apply_preflight": {
|
||||
"preflight_id": "preflight-1",
|
||||
"run_id": "run-1",
|
||||
"ready_for_controlled_apply_executor": True,
|
||||
},
|
||||
"target_selectors": [
|
||||
{
|
||||
"selector_id": "selector-1",
|
||||
"momo_product_id": "MOMO-1",
|
||||
"momo_product_name": "Example 40ml",
|
||||
"target_pchome_product_id": "PCH-1",
|
||||
"target_pchome_product_name": "Example 40ml",
|
||||
"target_match_score": 0.91,
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
result = controlled_apply_executor.build_controlled_apply_executor_from_preflight(
|
||||
preflight,
|
||||
artifact_root=tmp_path,
|
||||
)
|
||||
|
||||
assert result["result"] == "DIRECT_MAPPING_RETRY_EXCEPTION_CONTROLLED_APPLY_EXECUTOR_READY"
|
||||
assert result["summary"]["target_selector_count"] == 1
|
||||
assert result["summary"]["applied_record_count"] == 0
|
||||
assert result["summary"]["rollback_step_count"] == 1
|
||||
assert result["safety"]["execute_apply"] is False
|
||||
assert result["safety"]["writes_database_count"] == 0
|
||||
assert result["safety"]["writes_artifact_count"] == 0
|
||||
|
||||
|
||||
def test_legacy_facade_is_smaller_after_second_p0_extraction():
|
||||
facade = ROOT / "services/pchome_mapping_backlog_service.py"
|
||||
|
||||
assert sum(1 for _ in facade.open(encoding="utf-8")) < 44_300
|
||||
assert sum(1 for _ in facade.open(encoding="utf-8")) < 44_000
|
||||
|
||||
Reference in New Issue
Block a user