Keep a board's stated pay as salary_text, even when it does not normalise
Every ats parser now writes one human-readable pay line whether or not it
converts to yearly salary_min/salary_max/currency: hourly and daily rates,
Greenhouse's several pay zones, and a range with no currency all survive as
text instead of being dropped outright. Stored in roles.salary_text
(migration 12), replaced whole on every pull like title, so a board that
stops stating pay clears it rather than leaving a stale line. salary_state
is derived, not stored ('normalised', 'stated', or ''), and is what the
feed's new Pay filter and badge read; gates and scoring are unchanged, still
reading only the normalised columns.
Co-Authored-By: Claude Sonnet <noreply@anthropic.com>
This commit is contained in:
1 parent
706b127bc0
commit
fa4e1a657f
18 files changed
+528
-57
No files matched your search
+58
-2
@@ -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 == 11
|
||||
assert LATEST == 12
|
||||
# A second open finds it current and applies nothing.
|
||||
assert Store(path).migrations_applied == []
|
||||
|
||||
@@ -92,7 +92,7 @@ def test_a_v1_file_migrates_to_the_shape_a_new_file_has(tmp_path: Path) -> None:
|
||||
with sqlite3.connect(old) as conn:
|
||||
conn.execute("DROP INDEX idx_roles_posted") # v9: indexes posted_at
|
||||
for column in ("permit", "languages", "extract_tries", "summary", "summarised_at",
|
||||
"article_text", "article_at", "read_at", "posted_at"):
|
||||
"article_text", "article_at", "read_at", "posted_at", "salary_text"):
|
||||
conn.execute(f"ALTER TABLE roles DROP COLUMN {column}")
|
||||
for column in ("intent_key", "intent_vec", "limits"): # v3, v8
|
||||
conn.execute(f"ALTER TABLE agents DROP COLUMN {column}")
|
||||
@@ -119,6 +119,7 @@ def test_a_v8_file_gains_ats_slug_and_keeps_its_companies(tmp_path: Path) -> Non
|
||||
conn.execute("ALTER TABLE companies DROP COLUMN ats_slug")
|
||||
conn.execute("DROP INDEX idx_roles_posted") # v10, which follows
|
||||
conn.execute("ALTER TABLE roles DROP COLUMN posted_at")
|
||||
conn.execute("ALTER TABLE roles DROP COLUMN salary_text") # v12, which follows
|
||||
conn.execute("PRAGMA user_version = 8")
|
||||
|
||||
migrated = Store(path)
|
||||
@@ -136,6 +137,7 @@ def _downgrade_to_v4(path: Path) -> None:
|
||||
conn.execute("ALTER TABLE roles DROP COLUMN read_at")
|
||||
conn.execute("DROP INDEX idx_roles_posted") # v9: indexes posted_at
|
||||
conn.execute("ALTER TABLE roles DROP COLUMN posted_at") # v9
|
||||
conn.execute("ALTER TABLE roles DROP COLUMN salary_text") # v12
|
||||
conn.execute("DROP TABLE role_tags")
|
||||
conn.execute("ALTER TABLE roles ADD COLUMN vote INTEGER CHECK (vote IN (-1, 0, 1))")
|
||||
conn.execute("ALTER TABLE roles ADD COLUMN voted_at TEXT")
|
||||
@@ -245,6 +247,7 @@ def test_v10_backfills_posted_at_by_the_same_rule_upsert_uses(
|
||||
with sqlite3.connect(path) as conn:
|
||||
conn.execute("DROP INDEX idx_roles_posted")
|
||||
conn.execute("ALTER TABLE roles DROP COLUMN posted_at")
|
||||
conn.execute("ALTER TABLE roles DROP COLUMN salary_text") # v12
|
||||
conn.execute("PRAGMA user_version = 9")
|
||||
|
||||
migrated = Store(path)
|
||||
@@ -342,6 +345,40 @@ def test_upsert_unpacks_raw_and_keeps_filled_columns(store: Store) -> None:
|
||||
assert (role.place, role.remote, role.salary_min) == ("Berlin", "remote", 80000)
|
||||
|
||||
|
||||
def test_upsert_replaces_salary_text_including_with_empty(store: Store) -> None:
|
||||
"""`salary_text` behaves like `title` or `published_at`, not like the
|
||||
rest of `_RAW_TEXT`: a board's own pay line replaces what was stored on
|
||||
every pull, and a pull that states no pay at all clears it rather than
|
||||
leaving a stale line behind — the opposite of the keep-filled rule
|
||||
`test_upsert_unpacks_raw_and_keeps_filled_columns` checks just above."""
|
||||
store.upsert_role(posting(salary_text="EUR 70,000 to 90,000 per year"))
|
||||
role = store.role(posting().uid)
|
||||
assert role is not None and role.salary_text == "EUR 70,000 to 90,000 per year"
|
||||
|
||||
store.upsert_role(posting(salary_text="EUR 75,000 to 95,000 per year"))
|
||||
role = store.role(posting().uid)
|
||||
assert role is not None and role.salary_text == "EUR 75,000 to 95,000 per year"
|
||||
|
||||
# The board stops stating pay: the stored line is cleared, not kept.
|
||||
store.upsert_role(posting())
|
||||
role = store.role(posting().uid)
|
||||
assert role is not None and role.salary_text == ""
|
||||
|
||||
|
||||
def test_salary_state_is_derived_from_the_columns_and_the_text(store: Store) -> None:
|
||||
"""Not a stored column (docs/decisions.md): 'normalised' needs only
|
||||
`salary_min` or `salary_max`, whatever `salary_text` says beside it;
|
||||
'stated' is `salary_text` alone; neither is ''."""
|
||||
store.upsert_role(posting("1", salary_text="EUR 70,000 to 90,000 per year",
|
||||
salary_min=70000, salary_max=90000, currency="EUR"))
|
||||
store.upsert_role(posting("2", salary_text="USD 45 to 60 per hour"))
|
||||
store.upsert_role(posting("3"))
|
||||
by_id = {r.source_id: r for r in store.roles()}
|
||||
assert by_id["1"].salary_state == "normalised"
|
||||
assert by_id["2"].salary_state == "stated"
|
||||
assert by_id["3"].salary_state == ""
|
||||
|
||||
|
||||
def test_upsert_sets_posted_at_from_a_trusted_host_and_keeps_the_earliest(
|
||||
store: Store, clock: Clock) -> None:
|
||||
"""A board's first pull can carry a stale, too-recent published_at (a
|
||||
@@ -504,6 +541,25 @@ def test_roles_filters_q_function_remote_and_days(store: Store, clock: Clock) ->
|
||||
assert [r.source_id for r in store.roles(days=30)] == ["2", "1"]
|
||||
|
||||
|
||||
def test_roles_filters_by_pay_before_the_limit(store: Store, clock: Clock) -> None:
|
||||
"""`pay` filters in SQL, the same as the other filters `_roles_from`
|
||||
builds, so it narrows what a `limit` is taken from rather than the page
|
||||
already built (docs/decisions.md, "filtering before LIMIT")."""
|
||||
store.upsert_role(posting("normalised", salary_min=70000, salary_max=90000,
|
||||
currency="EUR", salary_text="EUR 70,000 to 90,000 per year"))
|
||||
clock.tick()
|
||||
store.upsert_role(posting("stated", salary_text="USD 45 to 60 per hour"))
|
||||
clock.tick()
|
||||
store.upsert_role(posting("none"))
|
||||
assert {r.source_id for r in store.roles(pay="stated")} == {"normalised", "stated"}
|
||||
assert [r.source_id for r in store.roles(pay="normalised")] == ["normalised"]
|
||||
assert [r.source_id for r in store.roles(pay="stated_only")] == ["stated"]
|
||||
assert {r.source_id for r in store.roles()} == {"normalised", "stated", "none"}
|
||||
assert store.count_roles(pay="stated") == 2
|
||||
with pytest.raises(ValueError, match="pay is"):
|
||||
store.roles(pay="bogus")
|
||||
|
||||
|
||||
def test_roles_hide_muted_excludes_before_the_limit(store: Store, clock: Clock) -> None:
|
||||
agent = store.save_agent("A")
|
||||
store.add_company("Acme", key="acme")
|
||||
|
||||
Reference in new issue
Block a user