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:
WolfandClaude Sonnet committed 2026-09-29 15:08:45 +02:00
1 parent 706b127bc0
commit fa4e1a657f
18 files changed
+528 -57

No files matched your search

+19 -1
View File
@@ -15,7 +15,7 @@ import re
import unicodedata
from typing import Annotated, Any, Literal, get_args
from pydantic import BeforeValidator, Field
from pydantic import BeforeValidator, Field, computed_field
from desk.models import JsonDict, Model, ModelTaskResult
@@ -337,6 +337,10 @@ class Role(Model):
salary_min: int | None = None
salary_max: int | None = None
currency: str = ""
#: The pay a board stated, as one human-readable line, whether or not it
#: could be normalised into `salary_min`/`salary_max`/`currency`
#: (`plugins.ats`'s per-host `_*_salary_text`; docs/decisions.md).
salary_text: str = ""
seniority: str = ""
function: str = ""
permit: Permit = ""
@@ -372,6 +376,20 @@ class Role(Model):
#: column: loaded from `role_tags` alongside the row, see `Store.role`.
tags: list[str] = []
@computed_field # type: ignore[prop-decorator]
@property
def salary_state(self) -> Literal["normalised", "stated", ""]:
"""Not a column: 'normalised' when `salary_min` or `salary_max` is
set, 'stated' when only `salary_text` is, '' otherwise. Gates and
scoring read `salary_min` alone and never this (docs/decisions.md);
it is what the feed's Pay filter and badge read instead
(`Store.PAY`, `static/roles.js`)."""
if self.salary_min is not None or self.salary_max is not None:
return "normalised"
if self.salary_text:
return "stated"
return ""
class ExtractResult(ModelTaskResult):
"""What one run of `extract` did. See app/jobs/extract.py."""
+44 -10
View File
@@ -84,7 +84,7 @@
function blankFilter() {
return {
sort: "score", agent: null, period: "all", tags: new Set(), showRead: true,
company: "", place: "", function: "", remote: "", judged: "",
company: "", place: "", function: "", remote: "", judged: "", pay: "",
showMuted: false, gated: false,
};
}
@@ -131,7 +131,7 @@
const p = new URLSearchParams();
if (state.q) p.set("q", state.q);
for (const key of ["company", "place"]) if (f[key].trim()) p.set(key, f[key].trim());
for (const key of ["function", "remote", "judged"]) if (f[key]) p.set(key, f[key]);
for (const key of ["function", "remote", "judged", "pay"]) if (f[key]) p.set(key, f[key]);
const days = PERIODS[f.period].days;
if (days) p.set("days", String(days));
if (f.showMuted) p.set("show_muted", "true");
@@ -154,7 +154,7 @@
const q = new URLSearchParams(location.search);
const f = state.filter;
state.q = q.get("q") || "";
for (const key of ["company", "place", "function", "remote", "judged"]) {
for (const key of ["company", "place", "function", "remote", "judged", "pay"]) {
f[key] = q.get(key) || "";
}
f.period = PERIOD_OF_DAYS[q.get("days")] || "all";
@@ -165,7 +165,8 @@
if (q.get("sort") === "time") f.sort = "time";
// Checked against the enabled agents once they are in (`chooseAgent`).
if (q.get("agent")) f.agent = Number(q.get("agent"));
if (f.company || f.place || f.function || f.remote || f.judged || f.showMuted || f.gated) {
if (f.company || f.place || f.function || f.remote || f.judged || f.pay
|| f.showMuted || f.gated) {
$("#f-more").open = true;
}
}
@@ -389,10 +390,11 @@
setValue("f-place", f.place);
setValue("f-function", f.function);
setValue("f-remote", f.remote);
setValue("f-pay", f.pay);
setValue("f-judged", f.judged);
setValue("f-show-muted", f.showMuted);
setValue("f-gated", f.gated);
const more = [f.company.trim(), f.place.trim(), f.function, f.remote, f.judged,
const more = [f.company.trim(), f.place.trim(), f.function, f.remote, f.pay, f.judged,
f.showMuted, ranked && f.gated].filter(Boolean).length;
$("#f-active").textContent = more ? ` · ${more}` : "";
@@ -435,7 +437,7 @@
function renderActive() {
const f = state.filter;
const on = [!f.showRead, f.period !== "all", f.company.trim(), f.place.trim(),
f.function, f.remote, f.judged, f.showMuted, sortShown() === "score" && f.gated]
f.function, f.remote, f.pay, f.judged, f.showMuted, sortShown() === "score" && f.gated]
.filter(Boolean).length + f.tags.size;
const count = on === 1 ? "1 filter" : `${on} filters`;
$(".rail-toggle-label").textContent = on ? count : "Menu";
@@ -490,9 +492,20 @@
aria-pressed="${state.filter.tags.has(tag)}">${esc(tag)}</button>`).join("");
}
/** The feed row's small pay badge: the range for 'normalised', "pay
stated" for 'stated', nothing for '' — `role.salary_state`, computed by
the API from `salary_min`/`salary_max`/`salary_text` (app/models.py). */
function payBadge(role) {
if (role.salary_state === "normalised") return salary(role);
if (role.salary_state === "stated") return "pay stated";
return "";
}
function badges(role, { seniority = false } = {}) {
const words = [role.remote, role.function, seniority ? role.seniority : ""].filter(Boolean);
const pay = payBadge(role);
return (role.closed_at ? `<span class="badge closed">closed</span>` : "")
+ (pay ? `<span class="badge">${esc(pay)}</span>` : "")
+ words.map((w) => `<span class="badge">${esc(w)}</span>`).join("");
}
@@ -575,7 +588,7 @@
if (!empty.hidden) {
const f = state.filter;
const filtered = state.q || f.tags.size || f.period !== "all" || !f.showRead
|| f.company.trim() || f.place.trim() || f.function || f.remote || f.judged;
|| f.company.trim() || f.place.trim() || f.function || f.remote || f.pay || f.judged;
empty.innerHTML = filtered
? `<h2>Nothing matches</h2>
<p>No open role fits these filters.
@@ -701,6 +714,25 @@
return "";
}
/* What the reader shows below the title for pay, or null when the role
states none: 'normalised' shows the range from the normalised columns,
plus the board's own text underneath when it says more than the range
does — a period, several zones — spotted by " per " or ";" in it, which
every conforming `salary_text` carries and the plain range never does
(`plugins.ats`'s `_pay_line`); 'stated' shows the text itself, with a
note that it was not normalised. */
function payDisplay(r) {
if (r.salary_state === "normalised") {
const range = salary(r);
const text = r.salary_text || "";
return { range, detail: /(;| per )/.test(text) && text !== range ? text : "", note: "" };
}
if (r.salary_state === "stated") {
return { range: r.salary_text, detail: "", note: "as stated, not normalised" };
}
return null;
}
function host(url) {
try { return new URL(url).host.replace(/^www\./, ""); } catch (e) { return ""; }
}
@@ -740,7 +772,7 @@
? `<p class="reader-note">Loading…</p>`
: text ? paragraphs(text)
: `<p class="reader-note">The board gave no description for this one.</p>`;
const pay = salary(r);
const pay = payDisplay(r);
const waiting = state.summarising === state.readingUid;
const teaser = r.uid && !r.article_text && out && (r.description || "").length < TEASER;
@@ -763,7 +795,9 @@
${tagChips(r.tags)}
</div>
<h1>${esc(r.title || "")}</h1>
${pay ? `<p class="reader-salary">${esc(pay)}</p>` : ""}
${pay ? `<p class="reader-salary">${esc(pay.range)}</p>
${pay.detail ? `<p class="muted small">${esc(pay.detail)}</p>` : ""}
${pay.note ? `<p class="muted small">${esc(pay.note)}</p>` : ""}` : ""}
${r.summary ? `<section class="reader-summary">
<h2 class="reader-label">Summary</h2><p>${esc(r.summary)}</p></section>` : ""}
<div class="reader-tools">
@@ -1030,7 +1064,7 @@
for (const key of ["company", "place"]) {
$(`#f-${key}`).addEventListener("input", (e) => { state.filter[key] = e.target.value; typed(); });
}
for (const key of ["function", "remote", "judged"]) {
for (const key of ["function", "remote", "pay", "judged"]) {
$(`#f-${key}`).addEventListener("change", (e) => setFilter({ [key]: e.target.value }));
}
$("#f-show-muted").addEventListener("change",
+6 -1
View File
@@ -86,7 +86,8 @@ CREATE TABLE IF NOT EXISTS roles (
-- whose description is only a teaser.
article_text TEXT NOT NULL DEFAULT '',
article_at TEXT,
created_at TEXT NOT NULL
created_at TEXT NOT NULL,
salary_text TEXT NOT NULL DEFAULT ''
);
-- The open vocabulary summarise reads off a posting: the role family, the
@@ -381,6 +382,10 @@ ALTER TABLE companies ADD COLUMN ats_slug TEXT NOT NULL DEFAULT '';
# its current rules is the whole point (see _recompute_function below).
(11, "roles.function recomputed for every not-yet-extracted role, word-boundary "
"classifier fix", lambda conn: _recompute_function(conn)),
(12, "roles.salary_text: the pay a board stated as one line, kept even when it "
"could not be normalised into salary_min/salary_max/currency", """
ALTER TABLE roles ADD COLUMN salary_text TEXT NOT NULL DEFAULT '';
"""),
)
#: What a file created from `SCHEMA` today is already at.
+31 -7
View File
@@ -60,6 +60,17 @@ JUDGED: dict[str, str] = {
"passed": "v.vote = -1",
}
#: The feed's Pay filter, `_roles_from`'s `pay`: the SQL that is true for
#: each choice, over `roles`. `salary_state` (`app.models.Role`) is derived,
#: not stored, so the filter spells the same rule out in SQL rather than
#: reading a column: 'normalised' is `salary_min` or `salary_max` set,
#: 'stated' is `salary_text` set and neither of those is.
PAY: dict[str, str] = {
"stated": "(salary_min IS NOT NULL OR salary_max IS NOT NULL OR salary_text != '')",
"normalised": "(salary_min IS NOT NULL OR salary_max IS NOT NULL)",
"stated_only": "(salary_text != '' AND salary_min IS NULL AND salary_max IS NULL)",
}
#: A ranking's score as `Store.roles` serves and orders it: halved by a pass,
#: lifted a fifth by a like, capped at 1. Applied at read time, so a vote
#: moves the role at once and the stored score stays what `score` computed.
@@ -313,6 +324,10 @@ class Store:
row["remote"] = row["remote"] or remote_of(place)
row |= {name: _int_or_none(raw.get(name)) for name in _RAW_INT}
row["function"] = str(raw.get("function") or "")
# A board's own pay line, one per pull like title or published_at —
# not kept-filled like _RAW_TEXT: a board that stops stating pay
# must be able to clear it, not leave a stale line behind.
row["salary_text"] = str(raw.get("salary_text") or "")
keep_filled = ("company", "company_key", "place_key", "remote", "description",
"feed_text", "original_url", *_RAW_TEXT)
@@ -320,7 +335,8 @@ class Store:
updates += [f"{c}=COALESCE(excluded.{c}, roles.{c})"
for c in (*_RAW_INT, "subscription_id")]
updates += [f"{c}=excluded.{c}"
for c in ("title", "title_key", "published_at", "raw", "last_seen")]
for c in ("title", "title_key", "published_at", "raw", "last_seen",
"salary_text")]
updates.append("posted_at=MIN(excluded.posted_at, roles.posted_at)")
# Not `keep_filled`'s COALESCE(NULLIF(...)): that would let a fresh
# pull's classifier guess overwrite what extract decided, which is
@@ -457,13 +473,15 @@ class Store:
hide_muted: bool = False, include_read: bool = True,
tags: Sequence[str] = (), tag_mode: str = "any",
agent: int | None = None, by_score: bool = True, gated: bool = False,
judged: str | None = None, offset: int = 0) -> list[ScoredRole]:
judged: str | None = None, pay: str | None = None,
offset: int = 0) -> list[ScoredRole]:
"""Newest first by `posted_at`. `company` and `place` are
case-insensitive substrings of the columns a board wrote — not the
key, so a search does not have to know the exact slug a company folds
to. `q` is matched word by word against `title`; a role must match
every word. `function` and `remote` match a gate column exactly.
`days` keeps only roles posted within that many days of now.
`days` keeps only roles posted within that many days of now. `pay`
(a key of `PAY`) filters on `salary_state`.
`agent` says whose votes, hidden companies and scores are meant. Each
row carries that agent's `vote` and `voted_at`; `judged` (a key of
@@ -498,7 +516,7 @@ class Store:
company=company, place=place, open_only=open_only, q=q, function=function,
remote=remote, days=days, hide_muted=hide_muted, include_read=include_read,
tags=tags, tag_mode=tag_mode, agent=agent, by_score=by_score, gated=gated,
judged=judged)
judged=judged, pay=pay)
select = "SELECT roles.*, v.vote, v.voted_at"
order = "roles.posted_at DESC, roles.uid"
scored = agent is not None and by_score
@@ -527,13 +545,14 @@ class Store:
days: int | None = None, hide_muted: bool = False,
include_read: bool = True, tags: Sequence[str] = (),
tag_mode: str = "any", agent: int | None = None, by_score: bool = True,
gated: bool = False, judged: str | None = None) -> int:
gated: bool = False, judged: str | None = None,
pay: str | None = None) -> int:
"""How many roles `roles` would list with the same filters and no limit."""
sql, params = self._roles_from(
company=company, place=place, open_only=open_only, q=q, function=function,
remote=remote, days=days, hide_muted=hide_muted, include_read=include_read,
tags=tags, tag_mode=tag_mode, agent=agent, by_score=by_score, gated=gated,
judged=judged)
judged=judged, pay=pay)
row = self._row(f"SELECT COUNT(*) AS n {sql}", params)
return int(row["n"]) if row else 0
@@ -541,7 +560,8 @@ class Store:
q: str | None, function: str | None, remote: str | None,
days: int | None, hide_muted: bool, include_read: bool,
tags: Sequence[str], tag_mode: str, agent: int | None,
by_score: bool, gated: bool, judged: str | None) -> tuple[str, list[Any]]:
by_score: bool, gated: bool, judged: str | None,
pay: str | None = None) -> tuple[str, list[Any]]:
"""The `FROM ... WHERE ...` that `roles` and `count_roles` share, with
its parameters in order. The agent's votes are always joined as `v`
(see `_WITH_VOTES`); its scores as `s` only when ordering by them."""
@@ -569,6 +589,10 @@ class Store:
if judged not in JUDGED:
raise ValueError(f"judged is {', '.join(JUDGED)}, not {judged!r}")
where.append(JUDGED[judged])
if pay:
if pay not in PAY:
raise ValueError(f"pay is {', '.join(PAY)}, not {pay!r}")
where.append(PAY[pay])
if open_only:
where.append("closed_at IS NULL")
if hide_muted and agent is not None:
+6
View File
@@ -84,6 +84,12 @@
<option value="{{ value }}">{{ label }}</option>
{% endfor %}
</select>
<select id="f-pay" aria-label="Pay">
<option value="">Any pay</option>
{% for value, label in pay_options %}
<option value="{{ value }}">{{ label }}</option>
{% endfor %}
</select>
<select id="f-judged" aria-label="Judged">
<option value="">Any vote</option>
<option value="liked">Liked</option>
+5 -2
View File
@@ -134,6 +134,7 @@ def list_roles(
order: Literal["score", "newest"] = "score",
gated: bool = False,
judged: Literal["", "liked", "unjudged", "passed"] = "",
pay: Literal["", "stated", "normalised", "stated_only"] = "",
offset: Annotated[int, Query(ge=0)] = 0,
limit: Annotated[int, Query(ge=1, le=1000)] = 60,
) -> RolesPage:
@@ -152,7 +153,9 @@ def list_roles(
`include_read` set false hides a role already marked read. `tags` is
`?tags=a&tags=b`, kept to a role with any of them or, with
`tag_mode=all`, every one."""
`tag_mode=all`, every one. `pay` keeps only roles whose `salary_state`
is stated or normalised, normalised only, or stated but not normalised
(`Store.PAY`)."""
agent_id = _agent_id(store, agent)
by_score = agent is not None and order == "score"
filters: dict[str, Any] = {
@@ -160,7 +163,7 @@ def list_roles(
"function": function or None, "remote": remote or None, "days": days,
"hide_muted": not show_muted, "include_read": include_read, "tags": tags,
"tag_mode": tag_mode, "agent": agent_id, "by_score": by_score,
"gated": gated, "judged": judged or None}
"gated": gated, "judged": judged or None, "pay": pay or None}
return RolesPage(items=store.roles(limit=limit, offset=offset, **filters),
total=store.count_roles(**filters))
+7 -2
View File
@@ -116,6 +116,10 @@ MOVED: dict[str, str] = {
#: role's `function` column holds; only the label is dressed up.
FUNCTION_OPTIONS = [(f, f.replace("/", " / ").capitalize()) for f in FUNCTIONS]
REMOTE_OPTIONS = [(r, r.capitalize()) for r in REMOTE if r]
#: The feed's Pay filter, in `Store.PAY`'s own keys — see its docstring for
#: what each one keeps.
PAY_OPTIONS = [("stated", "Stated or normalised"), ("normalised", "Normalised only"),
("stated_only", "Stated but not normalised")]
STATUS_OPTIONS = [(s, s.capitalize()) for s in STATUSES]
AREA_OPTIONS = list(JOBINDEX_AREAS.items())
COUNTRY_OPTIONS = [(c, c.upper()) for c in sorted(ADZUNA_COUNTRIES)]
@@ -151,7 +155,7 @@ def page(request: Request, name: str, **context: object) -> HTMLResponse:
@router.get("/", response_class=HTMLResponse)
def roles(request: Request) -> HTMLResponse:
return page(request, "roles.html", functions=FUNCTION_OPTIONS,
remote_options=REMOTE_OPTIONS, role=None)
remote_options=REMOTE_OPTIONS, pay_options=PAY_OPTIONS, role=None)
@router.get("/roles/{uid}", response_class=HTMLResponse)
@@ -165,7 +169,8 @@ def role(request: Request, uid: str, store: StoreDep) -> HTMLResponse:
if found is None:
raise HTTPException(404, f"no such role: {uid}")
return page(request, "roles.html", functions=FUNCTION_OPTIONS,
remote_options=REMOTE_OPTIONS, role=found, active_path="/")
remote_options=REMOTE_OPTIONS, pay_options=PAY_OPTIONS,
role=found, active_path="/")
@router.get("/applications", response_class=HTMLResponse)
+2
View File
@@ -30,6 +30,8 @@ What was decided for roledesk and the one reason for each. The longer reasoning
**Structured pay is unpacked the same as any other board field, except that Greenhouse and Ashby need an extra query parameter to get it.** Ashby sends it with `?includeCompensation=true`, Lever's `salaryRange` and Recruitee's `salary` are already on the plain list response, and Greenhouse needs `pay_transparency=true` on the same request it already makes (no per-role fetch); Personio's XML rarely carries a `salaryInformation` block, but reads the same way when it does. Workable and SmartRecruiters give neither, checked live against their real boards (2026-09-29). Every host converts to yearly `salary_min`/`salary_max`/`currency`: a monthly figure is multiplied by 12, an hourly or a daily one is left out rather than annualised into a number nobody stated, and a range with no currency is ignored. Greenhouse can give several ranges for one role (one per office or pay zone); with more than one there is no way to tell which office the role in hand is at, so all of them are skipped rather than one being picked at random.
**Pay that does not normalise is not dropped, only kept out of the gate columns.** `roles.salary_text` (migration 12) is one human-readable line per parser, written whether or not the board's pay conformed — an hourly or a daily rate, several Greenhouse pay zones, a range with no currency — so a person can read it and do their own sums; it is filled through `raw` like the other columns, but replaced whole on every pull, including with `''` when a board stops stating pay, since the usual keep-filled rule (`_RAW_TEXT`) would otherwise leave a stale line behind. `salary_state` (`app.models.Role`) is derived, not stored: 'normalised' when `salary_min` or `salary_max` is set, 'stated' when only `salary_text` is, `''` otherwise; it is what the feed's Pay filter and badge read, and gates and scoring keep reading only `salary_min`/`salary_max`/`currency`, unchanged.
**`extract` reads the board's location too.** The model gets title, the board's `place` text, and the first 3000 characters of the description. Greenhouse's location line ("Berlin, Germany") is often the only place a country is stated, and it is part of the posting, so the "only what the posting states" contract still holds.
**`country` is filled from `place` by a lookup, before `extract`.** `country_of` maps the folded location line to an ISO code from a table of European countries and cities, plus the non-European places that fill the seed boards, and returns nothing when a line names two countries. It resolves about 90% of the seed boards' roles for free, where `extract` would be a paid call per role for the same answer. `EU`, ISO's reserved code, stands for "Remote - Europe" and "EMEA", so a Europe gate is a list of codes that includes it. A US state after a comma counts only when no name matched, because DE and IN are countries too.
+156 -19
View File
@@ -279,6 +279,144 @@ def _ashby_salary(components: list[dict[str, Any]]) -> tuple[int | None, int | N
return None, None, ""
# ------------------------------------------------------------- salary_text
#
# `salary_min`/`salary_max`/`currency` above are yearly only, on purpose:
# hourly and daily rates, a Greenhouse role with several pay zones, and a
# range with no currency are all dropped from those columns rather than
# guessed into a wrong yearly figure. `salary_text` is where that dropped
# information survives — one human-readable line per parser, written
# whether or not the pay conformed, so a person can read it and do their own
# sums and a stricter analysis can find the roles the columns left out
# (`Role.salary_state`, `app/models.py`).
#: Formats a number the way a salary line writes it: no decimals for a whole
#: figure (the normal case for a yearly or monthly one), two for anything
#: else (an hourly or daily rate quoted with cents).
def _fmt_amount(value: float) -> str:
return f"{int(value):,}" if value == int(value) else f"{value:,.2f}"
def _bounds_words(lo: float | None, hi: float | None) -> str:
""""70,000 to 90,000", or "from 70,000"/"up to 90,000" with only one
bound stated, or "" with neither."""
if lo is not None and hi is not None:
return _fmt_amount(lo) if lo == hi else f"{_fmt_amount(lo)} to {_fmt_amount(hi)}"
if lo is not None:
return f"from {_fmt_amount(lo)}"
if hi is not None:
return f"up to {_fmt_amount(hi)}"
return ""
def _pay_line(lo: float | None, hi: float | None, currency: Any, period: str) -> str:
"""One statement of pay as a human-readable line — "EUR 70,000 to 90,000
per year" — or "" when there is no bound to report at all. A currency
that was not stated does not drop the line, unlike the normalised
columns: it is said plainly instead, "80,000 to 100,000 per year (no
currency stated)", so the figure is not lost along with the currency."""
bounds = _bounds_words(lo, hi)
if not bounds:
return ""
tail = f" per {period}" if period else ""
code = str(currency or "").strip().upper()
return f"{code} {bounds}{tail}" if code else f"{bounds}{tail} (no currency stated)"
def _greenhouse_salary_text(ranges: list[dict[str, Any]]) -> str:
"""One line per `pay_input_ranges` entry, joined with "; " — every range
Greenhouse states, not only the single one `_greenhouse_salary` accepts
for the columns. With more than one, each is labelled with the board's
own `title` ("Zone 1 Pay Range: ..."), since that is the only way to
tell the ranges apart; with just the one, the label adds nothing and is
left off. The hour/day check is the same one `_greenhouse_salary` uses
to keep those out of the yearly columns; here it only picks the word
that follows "per"."""
multi = len(ranges) > 1
lines = []
for entry in ranges:
title = str(entry.get("title") or "").strip()
low_title = title.lower()
period = ("hour" if any(w in low_title for w in ("hour", "/hr"))
else "day" if "day" in low_title else "year")
lo, hi = _num(entry.get("min_cents")), _num(entry.get("max_cents"))
line = _pay_line(lo / 100 if lo is not None else None,
hi / 100 if hi is not None else None,
entry.get("currency_type"), period)
if not line:
continue
if multi:
label = title.rstrip(":").strip() or "Range"
line = f"{label}: {line}"
lines.append(line)
return "; ".join(lines)
def _lever_salary_text(salary_range: dict[str, Any]) -> str:
"""One line from `salaryRange`, whatever its `interval` — including an
hourly or daily one, which `_yearly_amount` drops from the columns.
Lever's interval is "per-<period>-<kind>" ("per-year-salary",
"per-hour-wage"); the middle word is the period."""
interval = str(salary_range.get("interval") or "")
parts = interval.split("-")
period = parts[1] if len(parts) >= 3 else ""
return _pay_line(_num(salary_range.get("min")), _num(salary_range.get("max")),
salary_range.get("currency"), period)
def _ashby_salary_text(compensation: dict[str, Any]) -> str:
"""One line per `summaryComponents` entry that states a bound, labelled
by the board's own `compensationType` when more than one does (a salary
range beside a bonus range, say); with just the one, the label is left
off, the same as `_greenhouse_salary_text`. `interval` is "<n>
<PERIOD>" ("1 YEAR", "1 HOUR"); the last word, lowered, is the period.
With nothing to build a line from, Ashby's own prose summary
(`compensationTierSummary`, else `scrapeableCompensationSalarySummary`)
is what is left to show."""
components = compensation.get("summaryComponents") or []
stated = [c for c in components if _num(c.get("minValue")) is not None
or _num(c.get("maxValue")) is not None]
lines = []
for component in stated:
period = str(component.get("interval") or "").split(" ")[-1].lower()
line = _pay_line(_num(component.get("minValue")), _num(component.get("maxValue")),
component.get("currencyCode"), period)
if not line:
continue
if len(stated) > 1:
label = str(component.get("compensationType") or "").strip()
line = f"{label}: {line}" if label else line
lines.append(line)
if lines:
return "; ".join(lines)
return str(compensation.get("compensationTierSummary")
or compensation.get("scrapeableCompensationSalarySummary") or "")
def _recruitee_salary_text(salary: dict[str, Any]) -> str:
"""One line from Recruitee's `salary` object; `period` is already a
plain word ("year", "month")."""
period = str(salary.get("period") or "").strip().lower()
return _pay_line(_num(salary.get("min")), _num(salary.get("max")),
salary.get("currency"), period)
#: Personio's `salaryInformation/type` spellings, to the plain period word
#: `_pay_line` wants ("yearly" -> "year"). Anything else is passed through.
_PERSONIO_PERIODS = {"yearly": "year", "monthly": "month", "hourly": "hour",
"daily": "day", "weekly": "week"}
def _personio_salary_text(salary_info: ET.Element) -> str:
"""One line from a `<salaryInformation>` element, whatever its `type`,
including an hourly or daily one that `_yearly_amount` drops from the
columns."""
period_raw = (salary_info.findtext("type") or "").strip().lower()
period = _PERSONIO_PERIODS.get(period_raw, period_raw)
return _pay_line(_num(salary_info.findtext("min")), _num(salary_info.findtext("max")),
salary_info.findtext("currencyCode"), period)
def _parse_greenhouse(body: bytes) -> list[Row]:
data = json.loads(body)
rows = []
@@ -292,7 +430,8 @@ def _parse_greenhouse(body: bytes) -> list[Row]:
# JSON string (`&lt;p&gt;`), so it needs unescaping before the tags
# themselves can be stripped.
content = html.unescape(j.get("content") or "")
salary_min, salary_max, currency = _greenhouse_salary(j.get("pay_input_ranges") or [])
ranges = j.get("pay_input_ranges") or []
salary_min, salary_max, currency = _greenhouse_salary(ranges)
rows.append({
"source_id": str(j.get("id") or ""),
"title": title,
@@ -302,7 +441,7 @@ def _parse_greenhouse(body: bytes) -> list[Row]:
"department": (departments[0].get("name") if departments else "") or "",
"description": strip_html(content),
"remote": None, # Greenhouse's feed does not say
"salary": "",
"salary_text": _greenhouse_salary_text(ranges),
"salary_min": salary_min,
"salary_max": salary_max,
"currency": currency,
@@ -335,7 +474,7 @@ def _parse_lever(body: bytes) -> list[Row]:
"department": (categories.get("department") or categories.get("team") or "").strip(),
"description": strip_html(description),
"remote": (j.get("workplaceType") or "").strip() or None,
"salary": "",
"salary_text": _lever_salary_text(salary_range),
"salary_min": salary_min,
"salary_max": salary_max,
"currency": currency,
@@ -353,8 +492,6 @@ def _parse_ashby(body: bytes) -> list[Row]:
continue
description = j.get("descriptionHtml") or j.get("descriptionPlain") or ""
compensation = j.get("compensation") or {}
salary = (compensation.get("compensationTierSummary")
or compensation.get("scrapeableCompensationSalarySummary") or "")
salary_min, salary_max, currency = _ashby_salary(compensation.get("summaryComponents") or [])
rows.append({
"source_id": str(j.get("id") or ""),
@@ -365,7 +502,7 @@ def _parse_ashby(body: bytes) -> list[Row]:
"department": (j.get("department") or j.get("team") or "").strip(),
"description": strip_html(description),
"remote": j.get("isRemote"),
"salary": salary,
"salary_text": _ashby_salary_text(compensation),
"salary_min": salary_min,
"salary_max": salary_max,
"currency": currency,
@@ -408,7 +545,7 @@ def _workable_rows(data: dict[str, Any], slug: str) -> list[Row]:
"department": dept.strip(),
"description": "",
"remote": bool(j.get("remote")) or j.get("workplace") == "remote",
"salary": "",
"salary_text": "", # Workable's list endpoint states no pay at all
})
return rows
@@ -442,7 +579,7 @@ def _smartrecruiters_rows(data: dict[str, Any], slug: str) -> list[Row]:
"department": ((j.get("department") or {}).get("label") or "").strip(),
"description": "",
"remote": location.get("remote"),
"salary": "",
"salary_text": "", # SmartRecruiters' list endpoint states no pay at all
})
return rows
@@ -455,11 +592,7 @@ def _parse_recruitee(body: bytes) -> list[Row]:
url = (j.get("careers_url") or "").strip()
if not title or not _is_web_url(url):
continue
salary = j.get("salary") or {}
salary_text = ""
if isinstance(salary, dict) and (salary.get("min") or salary.get("max")):
bounds = "-".join(str(v) for v in (salary.get("min"), salary.get("max")) if v)
salary_text = f"{bounds} {salary.get('currency') or ''}".strip()
salary = j.get("salary") if isinstance(j.get("salary"), dict) else {}
salary_min, salary_max, currency = _yearly_amount(
salary.get("min"), salary.get("max"), salary.get("currency"),
salary.get("period"), {"year": 1, "month": 12})
@@ -472,7 +605,7 @@ def _parse_recruitee(body: bytes) -> list[Row]:
"department": (j.get("department") or "").strip(),
"description": strip_html(j.get("description") or ""),
"remote": j.get("remote"),
"salary": salary_text,
"salary_text": _recruitee_salary_text(salary),
"salary_min": salary_min,
"salary_max": salary_max,
"currency": currency,
@@ -496,11 +629,13 @@ def _parse_personio(body: bytes, slug: str) -> list[Row]:
salary_info = position.find("salaryInformation")
salary_min = salary_max = None
currency = ""
salary_text = ""
if salary_info is not None:
salary_min, salary_max, currency = _yearly_amount(
salary_info.findtext("min"), salary_info.findtext("max"),
salary_info.findtext("currencyCode"), salary_info.findtext("type"),
{"yearly": 1, "monthly": 12})
salary_text = _personio_salary_text(salary_info)
rows.append({
"source_id": job_id,
"title": title,
@@ -510,7 +645,7 @@ def _parse_personio(body: bytes, slug: str) -> list[Row]:
"department": (position.findtext("department") or "").strip(),
"description": strip_html(description),
"remote": "remote" in (position.findtext("office") or "").lower() or None,
"salary": "",
"salary_text": salary_text,
"salary_min": salary_min,
"salary_max": salary_max,
"currency": currency,
@@ -878,11 +1013,13 @@ class ATSSource(Source):
"department": row["department"],
"function": classify(row["department"], row["title"]),
"remote": row["remote"],
"salary": row["salary"],
# Only Ashby, Greenhouse, Lever, Recruitee and
# Personio's parsers set these (see "structured
# pay" above); the rest leave them at row.get's
# Every parser sets salary_text, empty or not (see
# "salary_text" above); only Ashby, Greenhouse,
# Lever, Recruitee and Personio's also set the
# normalised figures (see "structured pay"
# above), so the rest leave them at row.get's
# default of no figure.
"salary_text": row.get("salary_text", ""),
"salary_min": row.get("salary_min"),
"salary_max": row.get("salary_max"),
"currency": row.get("currency", ""),
+34
View File
@@ -29,6 +29,40 @@
"publishedAt": "2026-08-28T21:20:40.792+00:00",
"jobUrl": "https://ashby.example/2",
"descriptionHtml": ""
},
{
"id": "3003",
"title": "Sales Development Rep",
"department": "Sales",
"team": "Sales",
"location": "Remote",
"isRemote": true,
"publishedAt": "2026-08-20T00:00:00Z",
"jobUrl": "https://ashby.example/3",
"descriptionHtml": "",
"compensation": {
"compensationTierSummary": "Competitive OTE, details on request",
"summaryComponents": []
}
},
{
"id": "3004",
"title": "Support Engineer (Contract)",
"department": "Support",
"team": "Support",
"location": "Remote",
"isRemote": true,
"publishedAt": "2026-08-21T00:00:00Z",
"jobUrl": "https://ashby.example/4",
"descriptionHtml": "",
"compensation": {
"summaryComponents": [
{"compensationType": "Salary", "interval": "1 HOUR", "currencyCode": "USD",
"minValue": 45, "maxValue": 60},
{"compensationType": "Bonus", "interval": "1 YEAR", "currencyCode": "USD",
"minValue": 5000, "maxValue": 10000}
]
}
}
]
}
+28
View File
@@ -40,6 +40,34 @@
"location": {"name": "Anywhere"},
"absolute_url": "data:text/html,hi",
"departments": []
},
{
"id": 1005,
"title": "Regional Sales Manager",
"location": {"name": "Remote - US"},
"absolute_url": "https://gh.example/5",
"updated_at": "2026-09-12T12:00:00-04:00",
"departments": [{"id": 2, "name": "Sales"}],
"content": "",
"pay_input_ranges": [
{"min_cents": 18000000, "max_cents": 22000000, "currency_type": "USD",
"title": "Zone 1"},
{"min_cents": 16000000, "max_cents": 20000000, "currency_type": "USD",
"title": "Zone 2"}
]
},
{
"id": 1006,
"title": "Support Specialist",
"location": {"name": "Remote"},
"absolute_url": "https://gh.example/6",
"updated_at": "2026-09-13T12:00:00-04:00",
"departments": [{"id": 3, "name": "Support"}],
"content": "",
"pay_input_ranges": [
{"min_cents": 6500000, "max_cents": 8500000, "currency_type": "",
"title": "Base salary range:"}
]
}
]
}
+10
View File
@@ -18,5 +18,15 @@
"workplaceType": "on-site",
"description": "",
"salaryRange": {"min": 25, "max": 35, "currency": "USD", "interval": "per-hour-wage"}
},
{
"id": "2003",
"text": "Support Engineer",
"hostedUrl": "https://lever.example/3",
"createdAt": 1789430400000,
"categories": {"location": "Remote", "department": "Support"},
"workplaceType": "remote",
"description": "",
"salaryRange": {"min": 80000, "max": 100000, "currency": "", "interval": "per-year-salary"}
}
]
+18
View File
@@ -41,4 +41,22 @@
<createdAt>2026-09-21T14:53:35+00:00</createdAt>
</position>
<position>
<id>6003</id>
<subcompany>Acme AG</subcompany>
<office>Munich</office>
<department>Operations</department>
<name>Office Coordinator</name>
<jobDescriptions></jobDescriptions>
<employmentType>permanent</employmentType>
<seniority>entry-level</seniority>
<schedule>full-time</schedule>
<createdAt>2026-09-05T09:00:00+00:00</createdAt>
<salaryInformation>
<min>3000</min>
<max>3600</max>
<type>monthly</type>
</salaryInformation>
</position>
</workzag-jobs>
+13
View File
@@ -27,6 +27,19 @@
"published_at": "2026-09-01 00:00:00 UTC",
"description": "",
"salary": {"min": null, "max": null, "currency": null, "period": null}
},
{
"id": 5003,
"title": "Warehouse Coordinator",
"slug": "warehouse-coordinator",
"careers_url": "https://acme.example/o/warehouse-coordinator",
"department": "Operations",
"city": "Munich",
"location": "Munich",
"remote": false,
"published_at": "2026-09-05 00:00:00 UTC",
"description": "",
"salary": {"min": 18, "max": 24, "currency": null, "period": "hour"}
}
]
}
+65 -11
View File
@@ -31,9 +31,9 @@ def _rows(host: str, slug: str = "acme") -> list[ats.Row]:
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
# The javascript: and data: rows are refused, same as the four real ones
# are kept: a feed is external content, never trusted as a URL.
assert [r["source_id"] for r in rows] == ["1001", "1002"]
assert [r["source_id"] for r in rows] == ["1001", "1002", "1005", "1006"]
first = rows[0]
assert first["title"] == "Senior Backend Engineer" # trimmed
assert first["location"] == "Berlin, Germany"
@@ -53,9 +53,22 @@ def test_greenhouse_reads_pay_input_ranges_and_skips_an_hourly_one() -> None:
(None, None, "")
def test_greenhouse_salary_text_covers_the_single_hourly_and_zoned_cases() -> None:
"""`salary_text` is written whether or not the pay normalises: a single
yearly range reads plainly, the hourly one that the columns dropped
still reads as a line, several zones are joined and labelled with the
board's own titles, and a range with no currency says so."""
rows = _rows("greenhouse")
assert rows[0]["salary_text"] == "EUR 65,000 to 85,000 per year"
assert rows[1]["salary_text"] == "USD 30 to 45 per hour"
assert rows[2]["salary_text"] == ("Zone 1: USD 180,000 to 220,000 per year; "
"Zone 2: USD 160,000 to 200,000 per year")
assert rows[3]["salary_text"] == "65,000 to 85,000 per year (no currency stated)"
def test_lever_parses_categories_and_workplace_type() -> None:
rows = _rows("lever")
assert [r["source_id"] for r in rows] == ["2001", "2002"]
assert [r["source_id"] for r in rows] == ["2001", "2002", "2003"]
first = rows[0]
assert first["department"] == "Engineering"
assert first["remote"] == "remote"
@@ -72,11 +85,18 @@ def test_lever_reads_salary_range_and_skips_an_hourly_wage() -> None:
(None, None, "")
def test_lever_salary_text_covers_the_hourly_and_no_currency_cases() -> None:
rows = _rows("lever")
assert rows[0]["salary_text"] == "EUR 90,000 to 120,000 per year"
assert rows[1]["salary_text"] == "USD 25 to 35 per hour"
assert rows[2]["salary_text"] == "80,000 to 100,000 per year (no currency stated)"
def test_ashby_parses_is_remote_and_compensation() -> None:
rows = _rows("ashby")
assert [r["source_id"] for r in rows] == ["3001", "3002"]
assert [r["source_id"] for r in rows] == ["3001", "3002", "3003", "3004"]
assert rows[0]["remote"] is False
assert rows[0]["salary"] == "70,000-90,000 EUR"
assert rows[0]["salary_text"] == "EUR 70,000 to 90,000 per year"
assert rows[1]["remote"] is True
@@ -90,6 +110,20 @@ def test_ashby_reads_summary_components_only_with_includecompensation() -> None:
(None, None, "")
def test_ashby_salary_text_falls_back_to_prose_and_labels_several_components() -> None:
"""No component with a bound at all (job 3): Ashby's own prose summary is
what is left to show. An hourly Salary component beside a yearly Bonus
one (job 4): neither normalises (`_ashby_salary` only reads a yearly or
monthly `Salary` component), but both are stated, labelled since there
is more than one."""
rows = _rows("ashby")
assert rows[2]["salary_text"] == "Competitive OTE, details on request"
assert rows[3]["salary_text"] == \
"Salary: USD 45 to 60 per hour; Bonus: USD 5,000 to 10,000 per year"
assert (rows[3]["salary_min"], rows[3]["salary_max"], rows[3]["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"]
@@ -100,6 +134,7 @@ def test_workable_builds_the_job_url_and_reads_location_and_remote() -> None:
assert rows[1]["location"] == "Berlin, Germany"
assert rows[1]["remote"] is False
assert rows[0]["description"] == "" # the list endpoint carries no text
assert rows[0]["salary_text"] == "" # Workable's list endpoint states no pay at all
def test_smartrecruiters_builds_the_job_url_from_id_and_slug() -> None:
@@ -108,23 +143,31 @@ def test_smartrecruiters_builds_the_job_url_from_id_and_slug() -> None:
assert rows[0]["url"] == "https://jobs.smartrecruiters.com/Acme/744000151326819"
assert rows[0]["location"] == "Berlin, Germany"
assert rows[1]["remote"] is True
assert rows[0]["salary_text"] == "" # SmartRecruiters' list endpoint states no pay at all
def test_recruitee_parses_salary_bounds_and_careers_url() -> None:
rows = _rows("recruitee")
assert [r["source_id"] for r in rows] == ["5001", "5002"]
assert [r["source_id"] for r in rows] == ["5001", "5002", "5003"]
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_text"] == "EUR 35,000 to 45,000 per year"
assert rows[1]["salary_text"] == ""
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_recruitee_salary_text_states_an_hourly_rate_with_no_currency() -> None:
rows = _rows("recruitee")
assert rows[2]["salary_text"] == "18 to 24 per hour (no currency stated)"
assert (rows[2]["salary_min"], rows[2]["salary_max"], rows[2]["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 [r["source_id"] for r in rows] == ["6001", "6002", "6003"]
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"
@@ -137,6 +180,17 @@ def test_personio_reads_salary_information_when_present() -> None:
(42000, 55000, "EUR")
assert (rows[1]["salary_min"], rows[1]["salary_max"], rows[1]["currency"]) == \
(None, None, "")
assert rows[0]["salary_text"] == "EUR 42,000 to 55,000 per year"
assert rows[1]["salary_text"] == ""
def test_personio_salary_text_states_a_monthly_rate_with_no_currency() -> None:
rows = _rows("personio", slug="acme")
assert rows[2]["salary_text"] == "3,000 to 3,600 per month (no currency stated)"
# No currency: dropped from the columns like any other host's, even
# though the interval itself (monthly) is one _yearly_amount knows.
assert (rows[2]["salary_min"], rows[2]["salary_max"], rows[2]["currency"]) == \
(None, None, "")
# ------------------------------------------------------------ salary math
@@ -265,7 +319,7 @@ def test_fetch_rows_retries_greenhouse_without_content_on_a_too_large_body(
"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"]
assert [r["source_id"] for r in rows] == ["1001", "1002", "1005", "1006"]
assert complete # a host that does not page answers with the whole board
@@ -434,7 +488,7 @@ def test_an_answer_clears_the_failure_and_stamps_completeness(
source = _source(monkeypatch, (_rows("greenhouse"), False))
source.state["ats:failing:greenhouse:gone"] = json.dumps(
{"since": "2026-09-01T00:00:00+00:00", "reason": "404 Not Found"})
assert len(list(source.fetch())) == 2
assert len(list(source.fetch())) == 4
assert "ats:failing:greenhouse:gone" not in source.state
assert source.state["ats:ok:greenhouse:gone"] == "run-1"
assert source.state["ats:complete:greenhouse:gone"] == ""
+2 -2
View File
@@ -36,7 +36,7 @@ def _item(board: str, slug: str, job_id: str) -> Item:
source_id=f"{board}:{slug}:{job_id}", location=f"https://x.example/{job_id}",
title="Engineer", body="", published_at=datetime(2026, 9, 20, tzinfo=UTC),
raw={"company": "Acme", "place": "Berlin", "department": "",
"function": "engineering", "remote": None, "salary": "",
"function": "engineering", "remote": None, "salary_text": "",
"board": board, "slug": slug})
item.source = "ats"
return item
@@ -170,7 +170,7 @@ def test_close_boards_never_closes_a_board_stamped_by_an_earlier_run(
def _row(job_id: str) -> dict[str, object]:
return {"source_id": job_id, "title": f"Engineer {job_id}", "location": "Berlin",
"url": f"https://x.example/{job_id}", "posted": None, "department": "",
"description": "", "remote": None, "salary": ""}
"description": "", "remote": None, "salary_text": ""}
def _answer(monkeypatch: pytest.MonkeyPatch, answer: object) -> None:
+58 -2
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 == 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")
+24
View File
@@ -88,6 +88,30 @@ def test_list_roles_filters_by_query_place_and_function(
assert [r["source_id"] for r in res.json()["items"]] == ["3"]
def test_list_roles_exposes_and_filters_by_pay(client: TestClient, store: Store) -> None:
"""`salary_text` and `salary_state` (app/models.py) are on every role the
API serves, and `pay` (`Store.PAY`) filters the feed by it, in SQL before
`limit` like the other filters."""
store.upsert_role(posting("normalised", salary_min=70000, salary_max=90000,
currency="EUR", salary_text="EUR 70,000 to 90,000 per year"))
store.upsert_role(posting("stated", salary_text="USD 45 to 60 per hour"))
store.upsert_role(posting("none"))
items = {r["source_id"]: r for r in client.get("/api/roles").json()["items"]}
assert items["normalised"]["salary_text"] == "EUR 70,000 to 90,000 per year"
assert items["normalised"]["salary_state"] == "normalised"
assert items["stated"]["salary_state"] == "stated"
assert items["none"]["salary_state"] == ""
res = client.get("/api/roles", params={"pay": "stated"})
assert {r["source_id"] for r in res.json()["items"]} == {"normalised", "stated"}
res = client.get("/api/roles", params={"pay": "normalised"})
assert [r["source_id"] for r in res.json()["items"]] == ["normalised"]
res = client.get("/api/roles", params={"pay": "stated_only"})
assert [r["source_id"] for r in res.json()["items"]] == ["stated"]
assert client.get("/api/roles", params={"pay": "bogus"}).status_code == 422
def test_list_roles_limit_is_bounded(client: TestClient, store: Store) -> None:
for i in range(3):
store.upsert_role(posting(str(i)))