| 1 | """The person-employee fixture: a person run for an ordinary employee. |
| 2 | |
| 3 | Dana Okafor works at Northwind Freight (northwind.example). The run resolves |
| 4 | her LinkedIn profile by lookup, reads her bio and own links from the |
| 5 | employer's team page, and reads her LinkedIn posts, some from before the |
| 6 | window. A web result about a different Dana Okafor, a chef in another city, |
| 7 | shares only the name. Everything here is hand-written and fictional. |
| 8 | """ |
| 9 | |
| 10 | from __future__ import annotations |
| 11 | |
| 12 | import os |
| 13 | from pathlib import Path |
| 14 | |
| 15 | import pytest |
| 16 | |
| 17 | from . import harness |
| 18 | |
| 19 | FIXTURE = "person-employee" |
| 20 | NAMESAKE_URL = "https://web.example.test/person-employee/tasting-counter" |
| 21 | OLDER_POST_URLS = ( |
| 22 | "https://www.linkedin.com/feed/update/urn:li:activity:7400000000000000103/", |
| 23 | "https://www.linkedin.com/feed/update/urn:li:activity:7400000000000000104/", |
| 24 | ) |
| 25 | # Older than the year the Person Profile looks back: shown nowhere. |
| 26 | EXPIRED_POST_URL = "https://www.linkedin.com/feed/update/urn:li:activity:7400000000000000105/" |
| 27 | |
| 28 | |
| 29 | @pytest.fixture(scope="module") |
| 30 | def run(): |
| 31 | from lib import render |
| 32 | |
| 33 | [fixture] = [f for f in harness.load_fixtures() if f.name == FIXTURE] |
| 34 | result = harness.evaluate_fixture(fixture) |
| 35 | text = render.render_compact(result.report) |
| 36 | start = text.index("## Person Profile") |
| 37 | end = text.index("\n## ", start + 1) |
| 38 | return result, text, text[start:end] |
| 39 | |
| 40 | |
| 41 | def _ranked_urls(report) -> set[str]: |
| 42 | urls = {candidate.url for candidate in report.ranked_candidates} |
| 43 | urls.update( |
| 44 | item.url for candidate in report.ranked_candidates for item in candidate.source_items |
| 45 | ) |
| 46 | return urls |
| 47 | |
| 48 | |
| 49 | def test_older_posts_stay_out_of_ranked_results(run): |
| 50 | result, _text, _profile = run |
| 51 | assert result.scores["recency_compliance"] == 1.0 |
| 52 | ranked = _ranked_urls(result.report) |
| 53 | linkedin = {item.url for item in result.report.items_by_source["linkedin_profile"]} |
| 54 | assert len(linkedin) == 2 |
| 55 | for url in (*OLDER_POST_URLS, EXPIRED_POST_URL): |
| 56 | assert url not in ranked |
| 57 | assert url not in linkedin |
| 58 | |
| 59 | |
| 60 | def test_namesake_is_kept_out_of_the_report(run): |
| 61 | result, text, profile = run |
| 62 | assert NAMESAKE_URL not in _ranked_urls(result.report) |
| 63 | assert NAMESAKE_URL not in {item.url for item in result.report.items_by_source["grounding"]} |
| 64 | assert NAMESAKE_URL not in text |
| 65 | assert "Lisbon" not in text |
| 66 | assert "Dropped as namesakes: 1 item" in profile |
| 67 | |
| 68 | |
| 69 | def test_person_profile_renders_what_the_person_lanes_found(run): |
| 70 | result, text, profile = run |
| 71 | assert text.count("## Person Profile") == 1 |
| 72 | assert "Current role: VP Operations at Northwind Freight" in profile |
| 73 | assert "profile current employer matches Northwind Freight" in profile |
| 74 | # The URL came from a lookup, so the profile must not claim the user gave it. |
| 75 | assert "given by the user" not in profile |
| 76 | assert "(source: [https://northwind.example/team]" in profile |
| 77 | person = result.report.artifacts["person_profile"] |
| 78 | assert person["bio"]["title"] == "VP Operations" |
| 79 | assert person["derived_handles"] == {"x": "nwf_dana_fx", "github": "dana-okafor-fixture"} |
| 80 | assert "LinkedIn posts in the window: 2." in profile |
| 81 | |
| 82 | |
| 83 | def test_older_posts_appear_only_under_the_person_profile(run): |
| 84 | _result, text, profile = run |
| 85 | for url in OLDER_POST_URLS: |
| 86 | assert url in profile |
| 87 | assert text.count(url) == profile.count(url) |
| 88 | assert EXPIRED_POST_URL not in text |
| 89 | |
| 90 | |
| 91 | def test_fixture_names_none_of_the_private_names(): |
| 92 | """Local only: names listed one per line in PERSON_FIXTURE_DENYLIST |
| 93 | must not appear in this fixture's files.""" |
| 94 | names_file = os.environ.get("PERSON_FIXTURE_DENYLIST") |
| 95 | if not names_file: |
| 96 | pytest.skip("PERSON_FIXTURE_DENYLIST is not set") |
| 97 | names = [ |
| 98 | line.strip() |
| 99 | for line in Path(names_file).expanduser().read_text(encoding="utf-8").splitlines() |
| 100 | if line.strip() |
| 101 | ] |
| 102 | fixture_dir = harness.FIXTURES_DIR / FIXTURE |
| 103 | found = [ |
| 104 | f"{path.name}: {name}" |
| 105 | for path in sorted(fixture_dir.iterdir()) |
| 106 | if path.is_file() |
| 107 | for name in names |
| 108 | if name.casefold() in path.read_text(encoding="utf-8").casefold() |
| 109 | ] |
| 110 | assert not found, "private names in the fixture:\n" + "\n".join(found) |
| 111 |