from __future__ import annotations import importlib from pathlib import Path from gyxx_flow.adapters.native import DeferredModuleCommandStep from gyxx_flow.catalog import WorkflowCatalog from gyxx_flow.modules.product_commerce import ( PRODUCT_RESOURCE, PRODUCT_SCHEDULED_WORKFLOW_IDS, PRODUCT_TIMEOUT_SECONDS, PRODUCT_WORKFLOW_IDS, ProductCommerceModule, ) PROJECT_ROOT = Path(__file__).resolve().parents[1] def test_product_module_registers_only_scheduled_entries() -> None: module = ProductCommerceModule.from_catalog( WorkflowCatalog.load(PROJECT_ROOT / "config") ) assert tuple(item.workflow_id for item in module.workflow_definitions()) == PRODUCT_WORKFLOW_IDS assert len(PRODUCT_SCHEDULED_WORKFLOW_IDS) == 8 def test_product_workflows_use_project_owned_module_commands() -> None: module = ProductCommerceModule.from_catalog( WorkflowCatalog.load(PROJECT_ROOT / "config") ) for definition in module.workflow_definitions(): assert definition.steps for step in definition.steps: assert isinstance(step.action, DeferredModuleCommandStep) assert step.timeout_seconds == PRODUCT_TIMEOUT_SECONDS == 6 * 60 * 60 assert step.max_attempts == 1 if definition.workflow_id == "product.main_image.weekly": assert step.resources == (f"{PRODUCT_RESOURCE}:{step.step_id}",) else: assert step.resources == (PRODUCT_RESOURCE,) == ( "module:product_commerce", ) assert step.production_sink is True def test_combined_main_image_workflow_runs_platforms_independently() -> None: module = ProductCommerceModule.from_catalog( WorkflowCatalog.load(PROJECT_ROOT / "config") ) workflow = next( item for item in module.workflow_definitions() if item.workflow_id == "product.main_image.weekly" ) assert [step.step_id for step in workflow.steps] == ["jd", "tmall"] assert all(step.critical is True for step in workflow.steps) assert all(step.depends_on == () for step in workflow.steps) assert all(step.run_after_failure is False for step in workflow.steps) assert [step.resources for step in workflow.steps] == [ ("module:product_commerce:jd",), ("module:product_commerce:tmall",), ] def test_product_runtime_compatibility_package_points_to_flattened_module() -> None: module_root = ( PROJECT_ROOT / "src" / "gyxx_flow" / "modules" / "product_commerce" ).resolve() compatibility = importlib.import_module( "gyxx_flow.modules.product_commerce.runtime" ) legacy_module = importlib.import_module( "gyxx_flow.modules.product_commerce.runtime.market_rank_limits" ) canonical_module = importlib.import_module( "gyxx_flow.modules.product_commerce.market_rank_limits" ) assert tuple(Path(path).resolve() for path in compatibility.__path__) == ( module_root, ) assert Path(legacy_module.__file__).resolve() == Path( canonical_module.__file__ ).resolve()