Files
workphone-sdk/sdk/tests/test_friend_add_api_contract.py
2026-07-23 23:40:57 +08:00

32 lines
1.2 KiB
Python

from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
SOURCE = (ROOT / "sdk/app/routers/unified.py").read_text(encoding="utf-8")
def test_friend_add_api_forces_wechat_hook():
block = SOURCE[SOURCE.index('async def add_friend(req: AddFriendRequest)'):]
block = block[:block.index('@router.post("/friend/accept"')]
assert "hook_only=req.platform == Platform.WECHAT" in block
assert '"source_type": req.source_type' in block
def test_friend_add_api_exposes_verification_fields():
helper = SOURCE[SOURCE.index("def _friend_add_response("):]
helper = helper[:helper.index("@router.get(")]
for field in (
"target_user_id", "already_friend", "verified", "request_sent",
"status", "error_code", "error_message", "retryable",
"retry_after_seconds", "feedback", "channel_used",
):
assert field in helper
def test_existing_friend_preflight_runs_before_antiban_wait():
block = SOURCE[SOURCE.index('async def add_friend(req: AddFriendRequest)'):]
block = block[:block.index('@router.post("/friend/accept"')]
assert block.index('"get_contact_info"') < block.index("_anti_ban_guard")
assert "avoid" not in block
assert '"method": "contact_db"' in block