Merge branch 'worktree-agent-afad54f12aef2cccf'

# Conflicts:
#	app/storage/schema.py
#	app/storage/store.py
#	tests/test_storage.py
This commit is contained in:
Wolf committed 2026-09-29 14:32:28 +02:00
commit 706b127bc0
10 files changed
+459 -37

No files matched your search

+7 -1
View File
@@ -11,7 +11,13 @@
"jobUrl": "https://ashby.example/1",
"applyUrl": "https://ashby.example/1/apply",
"descriptionHtml": "<p>Design our <strong>onboarding</strong> flow.</p>",
"compensation": {"compensationTierSummary": "70,000-90,000 EUR"}
"compensation": {
"compensationTierSummary": "70,000-90,000 EUR",
"summaryComponents": [
{"compensationType": "Salary", "interval": "1 YEAR", "currencyCode": "EUR",
"minValue": 70000, "maxValue": 90000}
]
}
},
{
"id": "3002",
+10 -2
View File
@@ -8,7 +8,11 @@
"updated_at": "2026-09-10T12:00:00-04:00",
"first_published": "2026-09-09T08:00:00-04:00",
"departments": [{"id": 1, "name": "Engineering"}],
"content": "&lt;p&gt;Build our &lt;strong&gt;core platform&lt;/strong&gt;.&lt;/p&gt;"
"content": "&lt;p&gt;Build our &lt;strong&gt;core platform&lt;/strong&gt;.&lt;/p&gt;",
"pay_input_ranges": [
{"min_cents": 6500000, "max_cents": 8500000, "currency_type": "EUR",
"title": "Base salary range:"}
]
},
{
"id": 1002,
@@ -17,7 +21,11 @@
"absolute_url": "https://gh.example/2",
"updated_at": "2026-09-11T12:00:00-04:00",
"departments": [{"id": 2, "name": "Sales"}],
"content": ""
"content": "",
"pay_input_ranges": [
{"min_cents": 3000, "max_cents": 4500, "currency_type": "USD",
"title": "SF Bay Area Hourly Rate"}
]
},
{
"id": 1003,
+4 -2
View File
@@ -6,7 +6,8 @@
"createdAt": 1789430400000,
"categories": {"location": "Remote", "department": "Engineering", "team": "Platform"},
"workplaceType": "remote",
"description": "<p>Own our <b>platform</b> reliability.</p>"
"description": "<p>Own our <b>platform</b> reliability.</p>",
"salaryRange": {"min": 90000, "max": 120000, "currency": "EUR", "interval": "per-year-salary"}
},
{
"id": "2002",
@@ -15,6 +16,7 @@
"createdAt": 0,
"categories": {"location": "New York", "department": "Customer Success"},
"workplaceType": "on-site",
"description": ""
"description": "",
"salaryRange": {"min": 25, "max": 35, "currency": "USD", "interval": "per-hour-wage"}
}
]
+7
View File
@@ -19,6 +19,13 @@
<seniority>entry-level</seniority>
<schedule>full-time</schedule>
<createdAt>2026-08-19T10:04:22+00:00</createdAt>
<salaryInformation>
<min>42000.00</min>
<max>55000.00</max>
<currencySymbol>€</currencySymbol>
<currencyCode>EUR</currencyCode>
<type>yearly</type>
</salaryInformation>
</position>
<position>
+101 -5
View File
@@ -43,6 +43,16 @@ def test_greenhouse_parses_titles_locations_and_html_description() -> None:
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"]
@@ -54,6 +64,14 @@ def test_lever_parses_categories_and_workplace_type() -> None:
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"]
@@ -62,6 +80,16 @@ def test_ashby_parses_is_remote_and_compensation() -> None:
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"]
@@ -88,6 +116,10 @@ def test_recruitee_parses_salary_bounds_and_careers_url() -> None:
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:
@@ -99,16 +131,80 @@ def test_personio_builds_the_job_url_and_reads_cdata_description() -> None:
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_department_before_title() -> None:
assert ats.classify("Engineering", "Marketing Lead") == "engineering"
assert ats.classify("", "Senior Backend Engineer") == "engineering"
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"
assert ats.classify("", "") == "other"
# 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
@@ -166,7 +262,7 @@ def test_fetch_rows_retries_greenhouse_without_content_on_a_too_large_body(
rows, complete = ats._fetch_rows(object(), "greenhouse:acme") # type: ignore[arg-type]
assert calls == [
"https://boards-api.greenhouse.io/v1/boards/acme/jobs?content=true",
"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"]
+44 -3
View File
@@ -66,7 +66,7 @@ def test_schema_creates_on_an_empty_file(tmp_path: Path) -> None:
"application_events", "agents", "scores", "state"} <= tables
assert "idx_roles_cluster" in indexes
assert store.migrations_applied == []
assert LATEST == 10
assert LATEST == 11
# A second open finds it current and applies nothing.
assert Store(path).migrations_applied == []
@@ -123,7 +123,7 @@ def test_a_v8_file_gains_ats_slug_and_keeps_its_companies(tmp_path: Path) -> Non
migrated = Store(path)
assert migrated.migrations_applied == [9, 10]
assert migrated.migrations_applied == list(range(9, LATEST + 1))
acme = migrated.company("acme")
assert acme is not None
assert (acme.ats, acme.country, acme.ats_slug) == ("teamtailor", "DK", "")
@@ -249,7 +249,7 @@ def test_v10_backfills_posted_at_by_the_same_rule_upsert_uses(
migrated = Store(path)
assert migrated.migrations_applied == [10]
assert migrated.migrations_applied == list(range(10, LATEST + 1))
after_trusted, after_untrusted = migrated.role(trusted.uid), migrated.role(untrusted.uid)
assert after_trusted is not None and after_untrusted is not None
# The backfill reproduces exactly what upsert_role would have written.
@@ -375,6 +375,47 @@ def test_upsert_without_a_trusted_host_keeps_posted_at_at_first_seen(store: Stor
assert role.posted_at == role.first_seen
def test_function_is_the_classifiers_guess_not_a_board_field(store: Store) -> None:
"""`function` behaves the opposite of every other raw field: a pull may
only set it before extract has run, and once extract has answered — even
with a different function than the pull's guess — no later pull may put
the guess back. The no-flip property across pull, extract, pull."""
store.upsert_role(posting(function="engineering"))
uid = posting().uid
assert store.role(uid).function == "engineering" # type: ignore[union-attr]
store.set_extracted(uid, {"function": "sales"})
assert store.role(uid).function == "sales" # type: ignore[union-attr]
# A later pull with the classifier's old (now wrong) guess must not flip
# it back — the "board wins" COALESCE that every other raw field gets
# would otherwise put "engineering" straight back on every pull.
store.upsert_role(posting(function="engineering"))
assert store.role(uid).function == "sales" # type: ignore[union-attr]
def test_function_is_frozen_once_extracted_even_with_no_answer(store: Store) -> None:
store.upsert_role(posting(function="engineering"))
uid = posting().uid
store.set_extracted(uid, {}) # extract answered this role, but not function
assert store.role(uid).extracted_at is not None # type: ignore[union-attr]
# extracted_at alone freezes it, whatever a later pull's guess says.
store.upsert_role(posting(function="sales"))
assert store.role(uid).function == "engineering" # type: ignore[union-attr]
def test_function_is_set_from_raw_before_extract_like_any_other_field(store: Store) -> None:
store.upsert_role(posting(function="engineering"))
role = store.role(posting().uid)
assert role is not None and role.function == "engineering"
# Before extract, a fresh guess still overwrites the old one, the same
# "board wins" behaviour as place, country and the rest.
store.upsert_role(posting(function="sales"))
role = store.role(posting().uid)
assert role is not None and role.function == "sales"
def test_company_falls_back_to_the_subscription(store: Store) -> None:
sub = store.add_subscription("ats", "greenhouse:acme", company="Acme", board="Greenhouse")
store.upsert_role(posting(), sub)