# retoor import pytest from devplacepy.services.community.extract import split_submitter from devplacepy.services.community.runtime import Collector from tests.conftest import run_async from tests.unit.services.community.dedupe import entry from tests.unit.services.community.fakes import FakeFetcher from tests.unit.services.community.generator import no_sleep @pytest.mark.parametrize( "raw,expected", [ ("lore.kernel.org via thang", "thang"), ("jakearchibald.com by jaffathecake", "jaffathecake"), ("decomp.dev via FedericoSchonborn", "FedericoSchonborn"), ("via rberger 2026-10-15 12:36:38", "rberger"), (" via spikewall", "spikewall"), ("plainname", "plainname"), ("two words", "two words"), ("", ""), ("site.org VIA Someone", "Someone"), ], ) def test_the_submitter_is_the_person_behind_by_or_via(raw, expected): assert split_submitter(raw) == expected def schema(): return { "community": "lobsters", "origin": "lobsters.test", "limits": {"delay_seconds": 0, "retries": 1}, "feeds": [ { "id": "front", "url": "https://lobsters.test/front", "type": "json_api", "list_path": "$.items", "post": {"fields": {"id": ["$.id"], "title": ["$.title"], "content": ["$.body"], "created_at": ["$.at"], "url": ["$.link"]}}, "author": {"fields": {"username": ["$.who"]}}, "comments": {"mode": "none"}, } ], } def test_one_person_sharing_from_many_sites_is_one_user_with_one_identity(): items = [ {**entry("S1", "https://decomp.dev/a", "First"), "who": "decomp.dev via FedericoSchonborn"}, {**entry("S2", "https://costa.jacobpalm.dk/b", "Second"), "who": "costa.jacobpalm.dk via FedericoSchonborn"}, {**entry("S3", "https://abner.page/c", "Third"), "who": "abner.page by abnercoimbre"}, ] result = run_async(Collector(FakeFetcher({"https://lobsters.test/front": {"items": items}}), schema(), None, sleep=no_sleep).run(None)) users = result["records"]["users"] assert sorted(user["username"] for user in users) == ["FedericoSchonborn", "abnercoimbre"] posts = {post["title"]: post["author_uid"] for post in result["records"]["posts"]} assert posts["First"] == posts["Second"] != posts["Third"]