fix(scraper): voice body 加 departmentId/isRoom/时间窗 + sync 解析 root department_id

实测 queryWeChatVoiceList 必须带 callSource+departmentId+isRoom+startTime+endTime,
否则 200 但 data 空(0 数据)。WA callSource=4 / 微信 callSource=0,宽窗抓全量。
sync_*_voice_calls 照 sync_wechat_accounts 模式解析 _find_root_department_id。

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
浅念
2026-08-07 09:49:31 +08:00
parent 18620870c6
commit 79b89bc919
5 changed files with 210 additions and 21 deletions
@@ -205,7 +205,15 @@ async def test_scrape_wechat_voice_calls_null_oss_file_name_yields_none_record_f
@respx.mock
async def test_scrape_wechat_voice_calls_sends_pagination_body():
"""Outgoing request body carries pageNum/pageSize; advances per page."""
"""Body carries the full required filter set + advancing pageNum/pageSize.
Live diagnosis (2026-08-07) showed ``queryWeChatVoiceList`` REQUIRES
``callSource=0`` + ``departmentId`` + ``isRoom`` + ``startTime`` +
``endTime`` — omit any and the endpoint returns 200 with an empty
``data.data`` (0 rows). The WeChat variant uses ``callSource="0"``;
the wide time window ``2000-01-01 .. 2099-12-31`` pulls the full
history in one scrape.
"""
page1 = make_voice_list_response(
VOICE_RECORDS[:1], total=TOTAL, page_num=1, page_size=1
)
@@ -221,7 +229,12 @@ async def test_scrape_wechat_voice_calls_sends_pagination_body():
client = _primed_client()
try:
results = [r async for r in scrape_wechat_voice_calls(client, page_size=1)]
results = [
r
async for r in scrape_wechat_voice_calls(
client, department_id="DEPT_TEST", page_size=1
)
]
finally:
await client.aclose()
@@ -229,13 +242,30 @@ async def test_scrape_wechat_voice_calls_sends_pagination_body():
assert len(results) == 1
assert route.call_count == 2
# Page 1 body: full required filter set + standard pagination pair.
body1 = _json.loads(route.calls[0].request.content.decode())
assert body1["callSource"] == "0"
assert body1["departmentId"] == "DEPT_TEST"
assert body1["isRoom"] == "0"
assert body1["startTime"] == "2000-01-01 00:00:00"
assert body1["endTime"] == "2099-12-31 23:59:59"
assert body1["pageNum"] == 1
assert body1["pageSize"] == 1
# Blank-but-required keys are present (the live endpoint expects them
# in the body even when empty).
assert body1["userId"] == ""
assert body1["sort"] == ""
assert body1["ids"] == []
# Page 2 advances pageNum and keeps the same filter set verbatim.
body2 = _json.loads(route.calls[1].request.content.decode())
assert body2["pageNum"] == 2
assert body2["pageSize"] == 1
assert body2["callSource"] == "0"
assert body2["departmentId"] == "DEPT_TEST"
assert body2["isRoom"] == "0"
assert body2["startTime"] == "2000-01-01 00:00:00"
assert body2["endTime"] == "2099-12-31 23:59:59"
# ---------------------------------------------------------------------------