from argparse import Namespace from datetime import date def test_daily_creator_scope_filters_styles_and_publish_window(): from gyxx_flow.modules.content_marketing.daily_creator_exposure_scope import ( DEFAULT_MAX_AGE_DAYS, DEFAULT_PUBLISHED_FROM, EXCLUDED_STYLE_NAMES, classify_publish_scope, select_daily_styles, ) styles = [ {"index": 1, "name": "保留款"}, {"index": 2, "name": "盖亚微单"}, {"index": 3, "name": "逐星GT"}, {"index": 4, "name": "晨星2"}, {"index": 5, "name": "觅光"}, ] assert [row["index"] for row in select_daily_styles(styles)] == [1] assert EXCLUDED_STYLE_NAMES == frozenset({"盖亚微单", "逐星GT", "晨星2", "觅光"}) assert DEFAULT_PUBLISHED_FROM == date(2026, 7, 1) assert DEFAULT_MAX_AGE_DAYS == 30 assert classify_publish_scope( date(2026, 7, 1), date(2026, 7, 31), published_from=DEFAULT_PUBLISHED_FROM, max_age_days=DEFAULT_MAX_AGE_DAYS, ) == "collection_window_complete" assert classify_publish_scope( date(2026, 7, 2), date(2026, 7, 31), published_from=DEFAULT_PUBLISHED_FROM, max_age_days=DEFAULT_MAX_AGE_DAYS, ) is None def test_run_all_propagates_daily_scope_and_no_retry_to_local_children(): from gyxx_flow.modules.content_marketing import run_all args = Namespace(dry_run=False, style=[1, 2], daily_scope=True, no_retry=False) command = run_all.build_process_command("pgy", args) assert command[0] assert str(run_all.BASE_DIR) in command[1] assert "--skip-field-prepare" in command assert command[command.index("--published-from") + 1] == "2026-07-01" assert command[command.index("--max-age-days") + 1] == "30" assert "--no-retry" in command assert run_all.styles_after_field_prepare( {2, 3, 31}, {31}, preserve_failed=True ) == [2, 3, 31] def test_market_rank_limits_are_per_platform_and_per_category(): from gyxx_flow.modules.product_commerce.market_rank_limits import ( category_rank_limit, remaining_category_rank_limit, ) assert category_rank_limit("tm", "旅行箱") == 200 assert category_rank_limit("dy", "电脑包") == 200 assert category_rank_limit("jd", "旅行箱") == 150 assert category_rank_limit("jd", "电脑包") == 100 assert remaining_category_rank_limit( "dy", "双肩包", category_count=20, total_count=490, global_limit=500 ) == 10 def test_market_rank_collectors_use_the_shared_category_limits(): from pathlib import Path module_root = ( Path(__file__).parents[1] / "src" / "gyxx_flow" / "modules" / "product_commerce" ) for name in ( "collect_sycm_market_rank.py", "collect_dy_market_rank.py", "collect_jd_market_rank.py", ): source = (module_root / name).read_text(encoding="utf-8") assert "remaining_category_rank_limit(" in source assert "category_rank_limits" in source