|
|
@@ -1,57 +0,0 @@
|
|
|
-"""M9 修复:作者画像按作者缓存(同作者只拉一次)+ 本 run 画像调用上限(安全阀)。"""
|
|
|
-
|
|
|
-from content_agent.business_modules.progressive_screening import _ProgressiveContext
|
|
|
-
|
|
|
-
|
|
|
-class CountingPortraitClient:
|
|
|
- def __init__(self):
|
|
|
- self.calls = []
|
|
|
-
|
|
|
- def fetch_account_fans_portrait(self, account_id):
|
|
|
- self.calls.append(account_id)
|
|
|
- return {
|
|
|
- "fans": {
|
|
|
- "age": {
|
|
|
- "data": {
|
|
|
- "41-50": {"percentage": "31.73%", "preference": "210"},
|
|
|
- "50-": {"percentage": "29.76%", "preference": "130"},
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-def _ctx(client):
|
|
|
- return _ProgressiveContext(
|
|
|
- run_id="r", policy_run_id="p", source_context={}, policy_bundle={},
|
|
|
- platform_client=client, runtime=None, gemini_video_client=None,
|
|
|
- limiter=None, archive_dispatcher=None, platform="douyin", portrait_client=client,
|
|
|
- )
|
|
|
-
|
|
|
-
|
|
|
-def _bundle(author, q=80, p=70):
|
|
|
- return {
|
|
|
- "pattern_match_result": {"query_relevance_score": q},
|
|
|
- "content_engagement_metrics": {"platform_performance": {"platform_performance_score": p}},
|
|
|
- "content": {"author": {"platform_author_id": author}},
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-def test_portrait_cached_by_author():
|
|
|
- client = CountingPortraitClient()
|
|
|
- ctx = _ctx(client)
|
|
|
- bundles = [_bundle("a1"), _bundle("a1"), _bundle("a2")]
|
|
|
- ctx._inject_fifty_plus(bundles)
|
|
|
- assert client.calls == ["a1", "a2"] # 同作者只拉一次
|
|
|
- assert all(b["content_audience_50plus"]["status"] == "ok" for b in bundles)
|
|
|
-
|
|
|
-
|
|
|
-def test_portrait_cap_bounds_new_fetches(monkeypatch):
|
|
|
- monkeypatch.setenv("CONTENT_AGENT_PORTRAIT_CALLS_PER_RUN_CAP", "1")
|
|
|
- client = CountingPortraitClient()
|
|
|
- ctx = _ctx(client)
|
|
|
- bundles = [_bundle("a1"), _bundle("a2")] # 两个不同作者
|
|
|
- ctx._inject_fifty_plus(bundles)
|
|
|
- assert len(client.calls) == 1 # 上限 1,只拉第一个
|
|
|
- assert bundles[0]["content_audience_50plus"]["status"] == "ok"
|
|
|
- assert bundles[1]["content_audience_50plus"]["status"] == "not_attempted" # 超额不拉
|