"""The `ats` plugin: each host's parser against a saved feed, the function classifier, and the fetch allow-list. No network — every fixture is a file under `tests/fixtures/ats/`.""" from __future__ import annotations import sys from pathlib import Path import pytest ROOT = Path(__file__).resolve().parents[1] if str(ROOT) not in sys.path: sys.path.insert(0, str(ROOT)) from plugins import ats # noqa: E402 FIXTURES = ROOT / "tests" / "fixtures" / "ats" def _rows(host: str, slug: str = "acme") -> list[ats.Row]: path = FIXTURES / f"{host}.{'xml' if host == 'personio' else 'json'}" body = path.read_bytes() return ats._PARSERS[host](body, slug) # ------------------------------------------------------------------ hosts def test_greenhouse_parses_titles_locations_and_html_description() -> None: rows = _rows("greenhouse") # The javascript: and data: rows are refused, same as the two real ones # are kept: a feed is external content, never trusted as a URL. assert [r["source_id"] for r in rows] == ["1001", "1002"] first = rows[0] assert first["title"] == "Senior Backend Engineer" # trimmed assert first["location"] == "Berlin, Germany" assert first["department"] == "Engineering" assert first["description"] == "Build our core platform." assert first["posted"] is not None and first["posted"].year == 2026 assert first["remote"] is None def test_greenhouse_reads_pay_input_ranges_and_skips_an_hourly_one() -> None: rows = _rows("greenhouse") assert (rows[0]["salary_min"], rows[0]["salary_max"], rows[0]["currency"]) == \ (65000, 85000, "EUR") # "SF Bay Area Hourly Rate" is skipped: a yearly figure invented from an # hourly one would be wrong. assert (rows[1]["salary_min"], rows[1]["salary_max"], rows[1]["currency"]) == \ (None, None, "") def test_lever_parses_categories_and_workplace_type() -> None: rows = _rows("lever") assert [r["source_id"] for r in rows] == ["2001", "2002"] first = rows[0] assert first["department"] == "Engineering" assert first["remote"] == "remote" assert first["description"] == "Own our platform reliability." # createdAt=0 means "no date", not epoch zero. assert rows[1]["posted"] is None def test_lever_reads_salary_range_and_skips_an_hourly_wage() -> None: rows = _rows("lever") assert (rows[0]["salary_min"], rows[0]["salary_max"], rows[0]["currency"]) == \ (90000, 120000, "EUR") assert (rows[1]["salary_min"], rows[1]["salary_max"], rows[1]["currency"]) == \ (None, None, "") def test_ashby_parses_is_remote_and_compensation() -> None: rows = _rows("ashby") assert [r["source_id"] for r in rows] == ["3001", "3002"] assert rows[0]["remote"] is False assert rows[0]["salary"] == "70,000-90,000 EUR" assert rows[1]["remote"] is True def test_ashby_reads_summary_components_only_with_includecompensation() -> None: # summaryComponents only appears with ?includeCompensation=true on the # feed URL (see _BOARDS); the second job has no compensation key at all. rows = _rows("ashby") assert (rows[0]["salary_min"], rows[0]["salary_max"], rows[0]["currency"]) == \ (70000, 90000, "EUR") assert (rows[1]["salary_min"], rows[1]["salary_max"], rows[1]["currency"]) == \ (None, None, "") def test_workable_builds_the_job_url_and_reads_location_and_remote() -> None: rows = _rows("workable", slug="huggingface") assert [r["source_id"] for r in rows] == ["6125026", "6125041"] assert rows[0]["url"] == "https://apply.workable.com/huggingface/j/DB4D7C0EC8/" assert rows[0]["location"] == "France" assert rows[0]["remote"] is True assert rows[0]["department"] == "Product" assert rows[1]["location"] == "Berlin, Germany" assert rows[1]["remote"] is False assert rows[0]["description"] == "" # the list endpoint carries no text def test_smartrecruiters_builds_the_job_url_from_id_and_slug() -> None: rows = _rows("smartrecruiters", slug="Acme") assert [r["source_id"] for r in rows] == ["744000151326819", "744000147485112"] assert rows[0]["url"] == "https://jobs.smartrecruiters.com/Acme/744000151326819" assert rows[0]["location"] == "Berlin, Germany" assert rows[1]["remote"] is True def test_recruitee_parses_salary_bounds_and_careers_url() -> None: rows = _rows("recruitee") assert [r["source_id"] for r in rows] == ["5001", "5002"] assert rows[0]["url"] == "https://acme.example/o/player-support-agent-german-1" assert rows[0]["salary"] == "35000-45000 EUR" assert rows[1]["salary"] == "" assert (rows[0]["salary_min"], rows[0]["salary_max"], rows[0]["currency"]) == \ (35000, 45000, "EUR") assert (rows[1]["salary_min"], rows[1]["salary_max"], rows[1]["currency"]) == \ (None, None, "") def test_personio_builds_the_job_url_and_reads_cdata_description() -> None: rows = _rows("personio", slug="acme") assert [r["source_id"] for r in rows] == ["6001", "6002"] assert rows[0]["url"] == "https://acme.jobs.personio.de/job/6001" assert rows[0]["description"] == "Grow our pipeline." assert rows[0]["remote"] is True # "Remote - Germany" assert rows[1]["remote"] is None # "Munich" def test_personio_reads_salary_information_when_present() -> None: rows = _rows("personio", slug="acme") assert (rows[0]["salary_min"], rows[0]["salary_max"], rows[0]["currency"]) == \ (42000, 55000, "EUR") assert (rows[1]["salary_min"], rows[1]["salary_max"], rows[1]["currency"]) == \ (None, None, "") # ------------------------------------------------------------ salary math def test_yearly_amount_converts_a_monthly_range_by_12() -> None: assert ats._yearly_amount(3000, 4000, "eur", "month", {"year": 1, "month": 12}) == \ (36000, 48000, "EUR") def test_yearly_amount_ignores_a_range_with_no_currency() -> None: assert ats._yearly_amount(3000, 4000, "", "year", {"year": 1, "month": 12}) == \ (None, None, "") def test_yearly_amount_skips_an_interval_outside_the_factor_table() -> None: # An hourly or a daily rate: a yearly figure invented from it would be # wrong, so it is left out rather than multiplied by a guess. assert ats._yearly_amount(20, 30, "usd", "hour", {"year": 1, "month": 12}) == \ (None, None, "") def test_greenhouse_salary_skips_more_than_one_range() -> None: # Several ranges (one per office/zone) give no way to tell which one the # role in hand is at, so all of them are left out rather than guessed. ranges = [ {"min_cents": 100000, "max_cents": 200000, "currency_type": "EUR", "title": "Zone 1"}, {"min_cents": 90000, "max_cents": 180000, "currency_type": "EUR", "title": "Zone 2"}, ] assert ats._greenhouse_salary(ranges) == (None, None, "") # --------------------------------------------------------------- classify def test_classify_matches_title_before_department() -> None: # A specific title beats a generic department (see classify's docstring # for the hand-checked sample this is based on). assert ats.classify("Engineering", "Marketing Lead") == "marketing" assert ats.classify("Operations", "Senior Backend Engineer") == "engineering" assert ats.classify("", "Product Manager, Payments") == "product" assert ats.classify("", "Data Product Manager") == "product" assert ats.classify("", "Machine Learning Engineer") == "data" assert ats.classify("", "Executive Assistant to the CEO") == "finance/legal/ops" # The department is still the fallback when the title matches nothing. assert ats.classify("Engineering", "") == "engineering" # Nothing matches either: '', not "other", which would claim a # knowledge the classifier does not have. assert ats.classify("", "") == "" assert ats.classify("", "Chief Bottle Washer") == "" def test_classify_matches_whole_words_not_substrings() -> None: # "it" used to match inside "Italy"/"Italia" ("IT" meant the department, # not the country), filing a sales role as engineering. assert ats.classify("Commercial Italy", "Account Manager - Liguria") == "sales" assert ats.classify("IT", "") == "engineering" assert ats.classify("", "Marketing Lead, Seoul") == "marketing" # A stem still matches its suffixed forms: "Engineering" the department, # not just "engineer" the exact word. assert ats.classify("Engineering", "") == "engineering" assert ats.classify("", "Software Developers") == "engineering" def test_classify_understands_a_modest_set_of_other_languages() -> None: assert ats.classify("", "Senior Entwickler (m/w/d)") == "engineering" assert ats.classify("", "Vertriebsmitarbeiter (m/w/d)") == "sales" assert ats.classify("", "Ontwikkelaar") == "engineering" assert ats.classify("", "Udvikler") == "engineering" assert ats.classify("", "Ingénieur logiciel") == "engineering" # ------------------------------------------------------------- allow-list def test_is_known_target_accepts_the_seven_hosts_and_refuses_others() -> None: for host in ("greenhouse", "lever", "ashby", "workable", "smartrecruiters", "recruitee", "personio"): assert ats.is_known_target(f"{host}:acme") assert not ats.is_known_target("linkedin:acme") assert not ats.is_known_target("workday:acme") assert not ats.is_known_target("greenhouse:") assert not ats.is_known_target("nohostnoseparator") def test_allowed_host_refuses_a_foreign_host_per_board() -> None: allow = ats._allowed_host("greenhouse", "acme") assert allow("boards-api.greenhouse.io") assert not allow("boards-api.greenhouse.io.evil.example") assert not allow("api.lever.co") # recruitee and personio key off the company's own subdomain, so one # company's slug must not pass for another's. allow_recruitee = ats._allowed_host("recruitee", "acme") assert allow_recruitee("acme.recruitee.com") assert not allow_recruitee("other.recruitee.com") def test_careers_url_is_filled_per_host_and_empty_for_unknown() -> None: assert ats.careers_url("greenhouse:acme") == "https://job-boards.greenhouse.io/acme" assert ats.careers_url("ashby:acme") == "https://jobs.ashbyhq.com/acme" assert ats.careers_url("recruitee:acme") == "https://acme.recruitee.com" assert ats.careers_url("workday:acme") == "" # --------------------------------------------------------------- body cap def test_max_bytes_is_96_mb() -> None: """Raised from openings.go's 8 MB: every URL here is on a fixed allow-list of ATS API hosts, not an arbitrary one, and the real run of 2026-09-23 refused boards up to 41 MB under it.""" assert ats.MAX_BYTES == 96 << 20 def test_fetch_rows_retries_greenhouse_without_content_on_a_too_large_body( monkeypatch: pytest.MonkeyPatch) -> None: calls = [] def fake_get(client, url, host, slug, *, method="GET"): calls.append(url) if "?content=true" in url: raise ats._TooLarge("response too large (100000000 bytes)") return (FIXTURES / "greenhouse.json").read_bytes() monkeypatch.setattr(ats, "_get", fake_get) rows = ats._fetch_rows(object(), "greenhouse:acme") # type: ignore[arg-type] assert calls == [ "https://boards-api.greenhouse.io/v1/boards/acme/jobs?content=true&pay_transparency=true", "https://boards-api.greenhouse.io/v1/boards/acme/jobs", ] assert [r["source_id"] for r in rows] == ["1001", "1002"] def test_fetch_rows_does_not_retry_a_too_large_body_on_other_hosts( monkeypatch: pytest.MonkeyPatch) -> None: def fake_get(client, url, host, slug, *, method="GET"): raise ats._TooLarge("response too large (100000000 bytes)") monkeypatch.setattr(ats, "_get", fake_get) with pytest.raises(ats._TooLarge): ats._fetch_rows(object(), "lever:acme") # type: ignore[arg-type]