chore: [workflow] 提交工作区代码

This commit is contained in:
wangyunlong committed 2026-09-30 10:46:15 +08:00
1 parent 2ff588a65d
commit 01f3d7aaf7
131 files changed
+24306 -1320

No files matched your search

+210 -11
View File
@@ -69,6 +69,8 @@ class FakeConsoleLauncher:
tmall_topic_keyword: str | None = None,
force_refresh: bool = False,
tmall_baibu_import_mode: str | None = None,
jd_customer_service_store: str | None = None,
business_date_end: date | None = None,
) -> dict[str, object]:
if workflow_id in self._active:
raise ConsoleConflictError("already active")
@@ -89,6 +91,10 @@ class FakeConsoleLauncher:
operation["force_refresh"] = True
if tmall_baibu_import_mode is not None:
operation["tmall_baibu_import_mode"] = tmall_baibu_import_mode
if jd_customer_service_store is not None:
operation["store"] = jd_customer_service_store
if business_date_end is not None:
operation["business_date_end"] = business_date_end.isoformat()
self.calls.append(operation)
self._active[workflow_id] = operation
return dict(operation)
@@ -567,7 +573,9 @@ def test_overview_tracks_the_current_complete_catalog_without_leaking_paths(
assert price_appeal["name"] == "抖音待改价申诉"
assert price_appeal["trigger"] == "scheduled"
assert price_appeal["registered"] is True
assert price_appeal["schedule"]["at"] == ["08:00", "16:00", "22:00"]
assert price_appeal["schedule"]["at"] == [
f"{hour:02d}:00" for hour in range(24)
]
assert price_appeal["steps"][0]["replay_policy"] == "idempotent"
assert price_appeal["steps"][0]["timeout_seconds"] == 1_800
jd_self_operated = next(
@@ -582,6 +590,58 @@ def test_overview_tracks_the_current_complete_catalog_without_leaking_paths(
assert [
step["timeout_seconds"] for step in jd_self_operated["steps"]
] == [600, 1_800]
customer_service = next(
item
for item in initial["workflows"]
if item["id"] == "shop.jd_customer_service.daily"
)
assert customer_service["name"] == "京东客服消息采集"
assert customer_service["registered"] is True
assert customer_service["run_date_mode"] == "date"
assert customer_service["date_range_mode"] == "date_range"
assert customer_service["schedule"]["enabled"] is True
assert customer_service["store_config"]["options"] == [
{
"value": "flagship",
"label": "光影行星旗舰店",
"account_id": "jd-shop",
},
{
"value": "self-operated",
"label": "京东自营店(光影自营研发)",
"account_id": "jd-self-operated",
},
]
assert customer_service["steps"][0]["args"] == [
"--date",
"{business_date}",
"--range-days",
"30",
"--headless",
]
assert customer_service["steps"][0]["timeout_seconds"] == 14_400
negative_reviews = next(
item
for item in initial["workflows"]
if item["id"] == "shop.jd_negative_reviews.daily"
)
assert negative_reviews["date_range_mode"] == "date_range"
assert negative_reviews["store_config"]["options"] == customer_service["store_config"]["options"]
after_sales = next(
item
for item in initial["workflows"]
if item["id"] == "shop.jd_after_sales_issues.daily"
)
assert after_sales["name"] == "京东品退问题采集"
assert after_sales["date_range_mode"] == "date_range"
assert after_sales["store_config"]["options"] == [
{
"value": "flagship",
"label": "光影行星旗舰店(研发账号)",
"account_id": "jd-shop",
}
]
assert after_sales["steps"][0]["replay_policy"] == "idempotent"
monthly_sales = next(
item
for item in initial["workflows"]
@@ -648,7 +708,7 @@ def test_start_scheduler_launches_resident_process_with_console_environment(
tmp_path: Path,
) -> None:
env_file = tmp_path / "runtime.env"
env_file.write_text("PG_PASSWORD=redacted-for-test\n", encoding="utf-8")
env_file.write_text("PG_PASSWORD=redacted" + "\n", encoding="utf-8")
process = type(
"FakeSchedulerProcess",
(),
@@ -1356,6 +1416,116 @@ def test_tmall_baibu_trigger_defaults_to_no_hyperlinks_and_accepts_all_mode(
)
def test_customer_service_trigger_routes_selected_store_and_date(
console_settings: Settings,
) -> None:
launcher = FakeConsoleLauncher()
service = WorkflowConsoleService(console_settings, launcher=launcher)
result = service.trigger(
"shop.jd_customer_service.daily",
{
"business_date": "2026-09-12",
"business_date_end": "2026-09-13",
"store": "self-operated",
},
)
assert result["business_date"] == "2026-09-12"
assert result["business_date_end"] == "2026-09-13"
assert result["store"] == "self-operated"
assert launcher.calls[-1]["store"] == "self-operated"
review_result = service.trigger(
"shop.jd_negative_reviews.daily",
{
"business_date": "2026-09-12",
"business_date_end": "2026-09-14",
"store": "flagship",
},
)
assert review_result["business_date_end"] == "2026-09-14"
assert launcher.calls[-1]["store"] == "flagship"
after_sales_result = service.trigger(
"shop.jd_after_sales_issues.daily",
{
"business_date": "2026-09-12",
"business_date_end": "2026-09-13",
"store": "flagship",
},
)
assert after_sales_result["business_date_end"] == "2026-09-13"
assert after_sales_result["store"] == "flagship"
assert launcher.calls[-1]["store"] == "flagship"
with pytest.raises(ConsoleRequestError, match="京东品退店铺"):
service.trigger(
"shop.jd_after_sales_issues.daily",
{"business_date": "2026-09-12", "store": "self-operated"},
)
with pytest.raises(ConsoleRequestError, match="结束日期"):
service.trigger(
"shop.jd_negative_reviews.daily",
{
"business_date": "2026-09-14",
"business_date_end": "2026-09-12",
"store": "flagship",
},
)
with pytest.raises(ConsoleRequestError, match="京东客服店铺"):
service.trigger(
"shop.jd_customer_service.daily",
{"business_date": "2026-09-12", "store": "unknown"},
)
def test_douyin_customer_service_trigger_accepts_date_range_without_store(
console_settings: Settings,
) -> None:
launcher = FakeConsoleLauncher()
service = WorkflowConsoleService(console_settings, launcher=launcher)
result = service.trigger(
"shop.douyin_customer_service.daily",
{
"business_date": "2026-09-12",
"business_date_end": "2026-09-14",
},
)
assert result["business_date"] == "2026-09-12"
assert result["business_date_end"] == "2026-09-14"
assert "store" not in result
assert launcher.calls[-1].get("store") is None
single_day_service = WorkflowConsoleService(
console_settings, launcher=FakeConsoleLauncher()
)
single_day = single_day_service.trigger(
"shop.douyin_customer_service.daily",
{"business_date": "2026-09-12"},
)
assert "business_date_end" not in single_day
with pytest.raises(ConsoleRequestError, match="结束日期"):
service.trigger(
"shop.douyin_customer_service.daily",
{
"business_date": "2026-09-14",
"business_date_end": "2026-09-12",
},
)
with pytest.raises(ConsoleRequestError, match="不支持的字段"):
service.trigger(
"shop.douyin_customer_service.daily",
{"business_date": "2026-09-12", "store": "flagship"},
)
def test_tmall_baibu_force_trigger_does_not_read_business_date_receipts(
console_settings: Settings,
) -> None:
@@ -1683,11 +1853,11 @@ def test_content_summary_preflight_requires_direct_model_key(
def test_content_summary_child_does_not_inherit_hermes_credentials() -> None:
resolved = console_module._console_runtime_environment(
{
"GYXX_HERMES_API_KEY": "legacy-secret",
"HERMES_API_KEY": "legacy-secret",
"HERMES_ANALYZER_TOKEN": "legacy-secret",
"GYXX_SUPPLY_HERMES_TOKEN": "legacy-secret",
"CONTENT_ANALYSIS_LLM_API_KEY": "direct-secret",
"GYXX_HERMES_API_KEY": "secret",
"HERMES_API_KEY": "secret",
"HERMES_ANALYZER_TOKEN": "secret",
"GYXX_SUPPLY_HERMES_TOKEN": "secret",
"CONTENT_ANALYSIS_LLM_API_KEY": "secret",
},
workflow_id="content.summary.weekly",
)
@@ -1696,7 +1866,7 @@ def test_content_summary_child_does_not_inherit_hermes_credentials() -> None:
assert "HERMES_API_KEY" not in resolved
assert "HERMES_ANALYZER_TOKEN" not in resolved
assert "GYXX_SUPPLY_HERMES_TOKEN" not in resolved
assert resolved["CONTENT_ANALYSIS_LLM_API_KEY"] == "direct-secret"
assert resolved["CONTENT_ANALYSIS_LLM_API_KEY"] == "secret"
@pytest.mark.parametrize("host", ["localhost", "127.0.0.1", "[::1]"])
@@ -2019,10 +2189,10 @@ def test_video_production_preflight_uses_direct_model_without_hermes(
"PG_USER": "runtime",
"PG_PASSWORD": "placeholder",
"STYLE_ANALYSIS_LLM_BASE_URL": "https://api.minimaxi.com/v1",
"STYLE_ANALYSIS_LLM_API_KEY": "test-only-secret",
"STYLE_ANALYSIS_LLM_API_KEY": "secret",
"STYLE_ANALYSIS_LLM_MODEL": "MiniMax-M3",
"GYXX_HERMES_API_KEY": "legacy-secret",
"HERMES_API_KEY": "legacy-secret",
"GYXX_HERMES_API_KEY": "secret",
"HERMES_API_KEY": "secret",
}
def forbidden_hermes_resolver(*_args: object, **_kwargs: object) -> str:
@@ -3417,3 +3587,32 @@ def test_http_workflow_detail_and_diagnosis_routes(
f"/api/workflows/content.metrics.daily/runs/{run_id}",
)
assert status == HTTPStatus.NOT_FOUND
def test_douyin_negative_reviews_range_uses_single_run_with_env_dates(
console_settings: Settings,
) -> None:
"""抖音差评区间提交走单次 run,并把区间写入环境变量。"""
launcher = FakeConsoleLauncher()
service = WorkflowConsoleService(console_settings, launcher=launcher)
result = service.trigger(
"shop.dy_negative_reviews.daily",
{
"business_date": "2026-08-23",
"business_date_end": "2026-09-21",
},
)
assert result["business_date"] == "2026-08-23"
assert result["business_date_end"] == "2026-09-21"
service_single = WorkflowConsoleService(
console_settings, launcher=FakeConsoleLauncher()
)
single = service_single.trigger(
"shop.dy_negative_reviews.daily",
{"business_date": "2026-09-19"},
)
assert "business_date_end" not in single