from types import SimpleNamespace from snooper_card_images import enrich_card_images, extract_card_image_keys def test_extract_card_image_keys_deduplicates_json_and_binary_properties(): key = b"img_v3_02ad_synthetic" data = { "imageKey": key.decode(), "richtext": {"elements": {"dictionary": {"1": {"property": key}}}}, } assert extract_card_image_keys(data) == [key.decode()] def test_enrich_card_images_uses_approved_vision_client(monkeypatch): key = b"img_v3_02ad_synthetic" client = SimpleNamespace( auth=SimpleNamespace(region=SimpleNamespace(file_host="https://example.com")), pull_history=lambda chat_id, positions, visible_only: [ { "content_data": { "richtext": { "elements": {"dictionary": {"1": {"property": key}}} } } } ], ) monkeypatch.setattr( "snooper_card_images.download", lambda auth, url: (b"synthetic-image", "image/png"), ) ai_client = SimpleNamespace( complete_with_image=lambda image, mime: "合成图片文字" ) row = SimpleNamespace( msg_type=14, position=1, chat_id="chat-a", msg_id="message-a", content="[卡片] [图片]", ) stats = enrich_card_images(client, ai_client, [row]) assert stats == {"candidates": 1, "enriched": 1, "failed": 0} assert "合成图片文字" in row.content