Title levels on the ladder: principal, senior manager, distinguished, lead split (WP A)

from_title matches a title twice, for the highest people level and the
highest individual grade. A people level wins on its own rung; a grade
above that rung lifts it one rung (Principal Engineering Manager is a
senior manager). Senior Staff is principal, Senior Principal, Distinguished
and Technical Fellow are distinguished; Associate Director, AVP and Senior
Manager are senior managers. lead is now a team lead only (Team Lead, Shift
Lead, Supervisor, Teamleiter); Tech Lead, Lead X and X Lead(er) are staff.
A slash names two levels, so Senior/Staff is staff.

- Jobylon "lead" maps to staff; Recruitee maps student_college, manager,
  senior_manager and executive.
- extract's prompt describes the ladder and its two tracks; enum from LEVELS.
- prep VERSION 2, so the next prep maps every open role again.
- Migration 25 clears seniority_model where it is staff, lead, manager or
  director, so extract reads those roles again, and sets roles.seniority to
  the first filled of model, stated and title.
- The coverage test of tests/test_seniority.py passes; its xfail is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-30 13:11:26 +02:00
1 parent ae978594b4
commit 322db49773
16 files changed
+308 -117

No files matched your search

+22 -10
View File
@@ -72,16 +72,28 @@ Fields:
("Berlin", "Greater London"). '' if none is named. ("Berlin", "Greater London"). '' if none is named.
- country: ISO 3166-1 alpha-2 code of that place ("DE", "GB"), or ''. - country: ISO 3166-1 alpha-2 code of that place ("DE", "GB"), or ''.
- remote: "remote", "hybrid" or "onsite" only when the posting says so, else ''. - remote: "remote", "hybrid" or "onsite" only when the posting says so, else ''.
- seniority: exactly one of {", ".join(s for s in SENIORITIES if s)}, for every - seniority: exactly one of {", ".join(LEVELS)}, for every posting; never ''.
posting; never ''. This is the one field where you decide rather than This is the one field where you decide rather than extract. The levels are
extract. Judge the level of the person hired from the title and the text (or one ladder; from staff up each rung has an individual-contributor level and
the short teaser when there is no text), weighing years of experience, a people-lead level of equal weight:
scope and who the role reports to. `stated` is the level the job board intern, junior, mid, senior: no track.
itself gave and `title_level` the one a word in the title suggests. Both staff (Staff, Tech Lead, "Lead Engineer", "Marketing Lead") |
are hints: boards use different vocabularies and many state nothing, so lead (Team Lead, Supervisor) or manager (manages a team).
overrule them when the posting says otherwise. When nothing says, choose the principal (Principal, Senior Staff) |
likeliest level for that kind of title; most postings are for individual senior_manager (Senior Manager, manages managers, Associate Director).
contributors, not managers. distinguished (Senior Principal, Distinguished, Technical Fellow) |
director (Director, Head of a function).
exec (VP, C-level, Managing Director).
Choose a people level only when the hire manages people; a Product,
Account or Project Manager is an individual contributor. Judge the level of
the person hired from the title and the text (or the short teaser when
there is no text), weighing years of experience, scope and who the role
reports to. `stated` is the level the job board itself gave and
`title_level` the one a word in the title suggests. Both are hints: boards
use different vocabularies and many state nothing, so overrule them when
the posting says otherwise. When nothing says, choose the likeliest level
for that kind of title; most postings are for individual contributors, not
managers.
- salary_min, salary_max: yearly gross amounts as integers, or null. A stated - salary_min, salary_max: yearly gross amounts as integers, or null. A stated
monthly figure is multiplied by 12; an hourly or daily rate is null. A single monthly figure is multiplied by 12; an hourly or daily rate is null. A single
figure is both min and max. figure is both min and max.
+3 -2
View File
@@ -2,12 +2,13 @@
#: The embed's `experience`. Only the coarse levels are mapped; "Experienced" #: The embed's `experience`. Only the coarse levels are mapped; "Experienced"
#: sits between "Mid level" and the managerial levels and says too little to #: sits between "Mid level" and the managerial levels and says too little to
#: place, so it stays unmapped. #: place, so it stays unmapped. "Lead" is a senior individual ("Lead
#: Engineer"), `staff`, beside the managerial "Manager".
SENIORITY: dict[str, str] = { SENIORITY: dict[str, str] = {
"student": "intern", "internship": "intern", "trainee": "intern", "student": "intern", "internship": "intern", "trainee": "intern",
"entry level": "junior", "entry-level": "junior", "junior": "junior", "entry level": "junior", "entry-level": "junior", "junior": "junior",
"graduate": "junior", "mid level": "mid", "mid-level": "mid", "mid": "mid", "graduate": "junior", "mid level": "mid", "mid-level": "mid", "mid": "mid",
"senior": "senior", "lead": "lead", "manager": "manager", "director": "director", "senior": "senior", "lead": "staff", "manager": "manager", "director": "director",
"executive": "exec", "not applicable": ""} "executive": "exec", "not applicable": ""}
#: The embed's `employment_type`. #: The embed's `employment_type`.
+4 -3
View File
@@ -1,9 +1,10 @@
"""Recruitee's words, for prep.""" """Recruitee's words, for prep."""
#: `experience_code`. `experienced` names no level and is known, so it maps #: `experience_code`. `experienced` names no level and is known, so it maps
#: to none. #: to none. A college student is an intern as a school one is.
SENIORITY = {"student_school": "intern", "entry_level": "junior", "mid_level": "mid", SENIORITY = {"student_school": "intern", "student_college": "intern",
"experienced": ""} "entry_level": "junior", "mid_level": "mid", "experienced": "",
"manager": "manager", "senior_manager": "senior_manager", "executive": "exec"}
#: The words of `employment_type_code` (`fulltime_permanent`), which is #: The words of `employment_type_code` (`fulltime_permanent`), which is
#: lowercased and split at "_" and "-"; the first entry found among its words #: lowercased and split at "_" and "-"; the first entry found among its words
+1 -1
View File
@@ -29,7 +29,7 @@ from app.storage import Store
#: Raised when the rules in this package change the way a stored word maps, #: Raised when the rules in this package change the way a stored word maps,
#: so every open role is mapped again as it is after a table changes. #: so every open role is mapped again as it is after a table changes.
VERSION = 1 VERSION = 2
#: The state key the last run's `fingerprint` is kept under. #: The state key the last run's `fingerprint` is kept under.
STATE = "prep:tables" STATE = "prep:tables"
+137 -60
View File
@@ -13,38 +13,58 @@ pattern is a word-bounded regex against that. Patterns are therefore written
folded: `direktör` is `direktor`, `chef d'équipe` is `chef d equipe`; `ø` and folded: `direktör` is `direktor`, `chef d'équipe` is `chef d equipe`; `ø` and
`æ` stay as they are, since NFKD does not decompose them. `æ` stay as they are, since NFKD does not decompose them.
The highest level named wins, checked from `exec` down: "Senior Director" is The levels are the ladder of `app.models.LADDER`: from `staff` up, a rung has
a director, "Managing Director" an exec, "Lead Project Manager" a lead. The an individual-contributor level and a people-lead level. A title is matched
one exception is `intern`, tried first: a title that says internship or twice, for the highest people level it names (`_PEOPLE`: a head, a manager,
thesis is one whatever it names after ("Praktikum ... Assistenz des Senior a team lead) and for the highest individual grade (`_GRADES`: Principal,
Vice Presidents"). A C-level or head named as the boss of the person hired Staff, Senior). A people level wins over a grade on its own rung or below:
("Executive Assistant to the CEO", "Office of the Head of ...") is cut out "Staff Engineering Manager" is a manager, "Senior Director" a director. A
before matching (`_NOISE`). Rules that decide the doubtful cases: grade above the people level's rung lifts it one rung, and one only:
"Principal Engineering Manager" is a senior manager. Without a people level
the grade decides: "Principal Product Manager" is principal, since a product
manager is an individual contributor. A slash names two levels (`_OR`):
"Senior/Staff Engineer" is staff, not a Senior Staff. The one exception is `intern`, tried
first: a title that says internship or thesis is one whatever it names after
("Praktikum ... Assistenz des Senior Vice Presidents"). A C-level or head
named as the boss of the person hired ("Executive Assistant to the CEO",
"Office of the Head of ...") is cut out before matching (`_NOISE`). Rules
that decide the doubtful cases:
- **exec** is C-level ("Chief ... Officer", CTO), "VP" and above (a bank's VP
is mid-level, but a tech company's is not, and the filter is the reader's:
exec), "Managing Director", Geschäftsführer, Vorstand and VD.
- **director** is the word in English, Danish, Swedish, German, French,
Spanish and Italian, "Head of" and a title's own first word "Head", and the
German "Leiter" alone or of a whole department (Bereichsleiter,
Abteilungsleiter). "Senior Director" and "Executive Director" are directors.
- **senior_manager** is "Senior Manager", a senior people manager ("Sr.
Engineering Manager"), "Associate Director", "Assistant Director" and a
bank's "Assistant Vice President" (AVP, Associate VP).
- **manager** is a level only where the word means someone who runs a team: - **manager** is a level only where the word means someone who runs a team:
a bare "Manager", "Senior Manager", "Manager, Data Science" (the word a bare "Manager", "Manager, Data Science" (the word first, as a level), and
first, as a level), an "Assistant Store Manager" as a lead, and the compounds whose department or place is what is the compounds whose department or place is what is managed
managed (`_PEOPLE_MANAGER`: engineering, team, store, general ...). Every (`_PEOPLE_MANAGER`: engineering, team, store, general ...), and a "Tech
other "X Manager" is an individual contributor by function (Account, Lead Manager". Every other "X
Product, Project, Customer Success, Office, Marketing, Sales ...) and says Manager" is an individual contributor by function (Account, Product,
nothing, so "Senior Product Manager" is senior. An unlisted compound stays Project, Customer Success, Office, Marketing, Sales ...) and says nothing,
unknown, which costs a recall the filter's "and no level" makes up. so "Senior Product Manager" is senior. An unlisted compound stays unknown,
- **director** is the word in English, Danish, Swedish, German, French, Spanish which costs a recall the filter's "and no level" makes up. **manager** is
and Italian, "Head of" and a title's own first word "Head", and the German also the head of a shop, site or office: "Store Leader", the Danish,
"Leiter" alone or of a whole department (Bereichsleiter, Abteilungsleiter). Swedish, German and Dutch -chef, -leder, Filialleiter, Kontorchef, French
"Associate Director" and "Executive Director" are directors. **manager** is "responsable" and "gérant", Spanish "jefe" and "gerente".
also the Danish, Swedish, German and Dutch head of a shop, site or office - **lead** is a team lead: "Team Lead", "Team Leader", the floor-sized leads
(-chef, -leder, Filialleiter, Kontorchef), French "responsable" and "gérant", (`_TEAM_SIZED_LEAD`: shift, crew, kitchen ...), a "People Leader",
Spanish "jefe" and "gerente". **exec** is C-level ("Chief ... Officer", CTO), "VP" and above "Supervisor", an "Assistant Store Manager" or "Associate Store Leader", and
(a bank's VP is mid-level, but a tech company's is not, and the filter is the team-sized German, Danish, Dutch, Swedish and French forms (Teamleiter,
the reader's: exec), "Managing Director", Geschäftsführer, Vorstand and VD. Teamleider, teamledare, chef d'équipe).
A bank's "Assistant Vice President" is a director. - **distinguished** is "Senior Principal", "Distinguished", "Technical
- **lead** is "Lead" as a noun at either end ("Tech Lead", "Lead Engineer"; Fellow", "Engineering Fellow" and SAP's "Chief Expert". "Fellow" alone is
not "Lead Generation"), "Leader", "Supervisor", and the team-sized German, academic ("Research Fellow", "Postdoctoral Fellow") and says nothing.
Danish, Dutch and French forms (Teamleiter, Teamleider, chef d'équipe). - **principal** is "Principal" and "Senior Staff".
- **staff** is "Staff" and "Principal". "Staff Nurse", "Staff Accountant" - **staff** is "Staff", and "Lead" or "Leader" as a noun at either end that
and their kind are left out; "Principal Investigator" and a is not a team lead ("Tech Lead", "Lead Engineer", "Marketing Lead", "Sales
"Staff Scientist" at a lab are taken as staff and are not. Leader"; not "Lead Generation"). "Staff Nurse", "Staff Accountant" and their
kind are left out.
- **project managers stay unknown** in every language (Projektleiter, - **project managers stay unknown** in every language (Projektleiter,
Bauleiter, chef de projet, projektleder, prosjektleder): they are Project Bauleiter, chef de projet, projektleder, prosjektleder): they are Project
Managers. Halbleiter and the other -leiter words for things are cut out too. Managers. Halbleiter and the other -leiter words for things are cut out too.
@@ -55,9 +75,12 @@ before matching (`_NOISE`). Rules that decide the doubtful cases:
"Mid-level", "Intermediate", "II", "Medior". "Mid-level", "Intermediate", "II", "Medior".
Known wrong, and left so: "Senior Care Assistant" and other "senior" that Known wrong, and left so: "Senior Care Assistant" and other "senior" that
means elderly; "Level II" outside a role level; "Principal Investigator"; means elderly; "Level II" outside a role level; "Principal Investigator" and
"Staff" on a title with an unlisted staff noun; "Field CTO" taken as unknown; a "Staff Scientist" at a lab as principal and staff; "Staff" on a title with
"Chief of Staff" as unknown; "Assistant Manager" as unknown; French "responsable" is an unlisted staff noun; a retail "Lead Store Advisor" and a "Sales Leader"
who runs a team as staff; "Distinguished Engineer, Team Lead" as a senior
manager, one rung above the lead; "Field CTO" taken as unknown; "Chief of
Staff" as unknown; "Assistant Manager" as unknown; French "responsable" is
taken as a manager wherever it stands, and "Directeur" of a small firm as a taken as a manager wherever it stands, and "Directeur" of a small firm as a
director; "VP" as exec at a bank. director; "VP" as exec at a bank.
""" """
@@ -66,7 +89,7 @@ from __future__ import annotations
import re import re
from app.models import title_key from app.models import LADDER, title_key
#: A C-level title or abbreviation, for `_NOISE`. #: A C-level title or abbreviation, for `_NOISE`.
_C_LEVEL = (r"(?:ceo|cto|cfo|coo|cio|ciso|cpo|cdo|chro|caio" _C_LEVEL = (r"(?:ceo|cto|cfo|coo|cio|ciso|cpo|cdo|chro|caio"
@@ -96,6 +119,7 @@ _NOISE = re.compile(
rf"|office|support|referent\w*|advisor|adviser) (?:\w+ ){{0,3}}?{_C_LEVEL}" rf"|office|support|referent\w*|advisor|adviser) (?:\w+ ){{0,3}}?{_C_LEVEL}"
rf"|{_C_LEVEL} (?:assistant|assistenz|office|team|support|founder associate)" rf"|{_C_LEVEL} (?:assistant|assistenz|office|team|support|founder associate)"
r"|field (?:cto|cio|ciso)" r"|field (?:cto|cio|ciso)"
r"|(?:technical|engineering|technology) fellows? office"
r"|\w*(?:halb|nicht|supra|strom|blitzab)leiter" r"|\w*(?:halb|nicht|supra|strom|blitzab)leiter"
r"|\w*(?:projekt|prosjekt|project|bau|bygge|produkt)(?:leiter|leitung|leder|ledare|leider)(?:in)?" r"|\w*(?:projekt|prosjekt|project|bau|bygge|produkt)(?:leiter|leitung|leder|ledare|leider)(?:in)?"
r"|zugchef\w*)\b" r"|zugchef\w*)\b"
@@ -118,12 +142,14 @@ _HEAD_JOBS = (r"(?:chef|cook|barista|nurse|coach|waiter|bartender|mechanic|garde
r"|teacher|cashier|housekeeper|receptionist|technician|butcher|baker" r"|teacher|cashier|housekeeper|receptionist|technician|butcher|baker"
r"|stylist|of)") r"|stylist|of)")
#: `(level, patterns)`, in the order they are tried: `intern` first, since a #: Floor-sized leads, which run a shift or a crew: "Shift Lead" and "Crew
#: title that says internship is one whatever it names after ("Internship, Office #: Leader" are team leads where "Marketing Lead" is an individual.
#: of the Head of Product"); then the rest from `exec` down. A title takes the _TEAM_SIZED_LEAD = r"(?:team|shift|crew|group|kitchen|warehouse|floor)"
#: first level with a match, so a rule need not exclude what a later rule claims.
_RULES: tuple[tuple[str, tuple[str, ...]], ...] = ( #: What says the person is still studying or training, tried before
("intern", ( #: anything else: a title that says internship is one whatever it names
#: after ("Internship, Office of the Head of Product").
_INTERN: tuple[str, ...] = (
r"\binterns?\b", r"\binternship\w*", r"\bwerkstudent\w*", r"\bworking students?\b", r"\binterns?\b", r"\binternship\w*", r"\bwerkstudent\w*", r"\bworking students?\b",
r"\bstudent (?:assistant|worker|helper|aide|job|position|trainee|employee)s?\b", r"\bstudent (?:assistant|worker|helper|aide|job|position|trainee|employee)s?\b",
r"\bstudentische\w*", r"\bstudent(?:er)?med(?:hj|arb)\w*", r"\bstudentische\w*", r"\bstudent(?:er)?med(?:hj|arb)\w*",
@@ -144,7 +170,12 @@ _RULES: tuple[tuple[str, tuple[str, ...]], ...] = (
r"(?<!early )(?<!late )(?<!growth )(?<!seed )(?<!mid )(?<!next )(?<!final )" r"(?<!early )(?<!late )(?<!growth )(?<!seed )(?<!mid )(?<!next )(?<!final )"
r"(?<!pre )(?<!first )(?<!phase )\bstage$", r"(?<!pre )(?<!first )(?<!phase )\bstage$",
r"\bstage (?:\d+ )?(?:mois|mesi|maanden|months)\b", r"\bstage (?:\d+ )?(?:mois|mesi|maanden|months)\b",
)), )
#: `(level, patterns)` of the people track, from `exec` down. A title takes
#: the first level with a match, so a rule need not exclude what a later rule
#: claims.
_PEOPLE: tuple[tuple[str, tuple[str, ...]], ...] = (
("exec", ( ("exec", (
r"\b(?:ceo|cto|cfo|coo|cio|ciso|cpo|cdo|chro|caio)\b", r"\b(?:ceo|cto|cfo|coo|cio|ciso|cpo|cdo|chro|caio)\b",
r"\bchief(?: \w+){0,4}? officer\b", r"\bchief executive\b", r"\bchief(?: \w+){0,4}? officer\b", r"\bchief executive\b",
@@ -156,9 +187,9 @@ _RULES: tuple[tuple[str, tuple[str, ...]], ...] = (
r"\bgeschaftsfuhr\w*", r"\bgeschaftsleit\w*", r"\bvorstand\b", r"\bgeschaftsfuhr\w*", r"\bgeschaftsleit\w*", r"\bvorstand\b",
)), )),
("director", ( ("director", (
r"(?<!associate )(?<!assoc )(?<!assistant )(?<!asst )"
r"\b(?:director(?:a|s|es|in)?|directeur|directrice|direktor(?:in|er)?" r"\b(?:director(?:a|s|es|in)?|directeur|directrice|direktor(?:in|er)?"
r"|direktør(?:er)?|direttore|direttrice)\b", r"|direktør(?:er)?|direttore|direttrice)\b",
r"\bavp\b", r"\b(?:assistant|associate|assoc) (?:vice president|vp)\b",
r"\bhead of\b", r"\b(?:department|division|unit|practice|group|team|country|regional) head\b", r"\bhead of\b", r"\b(?:department|division|unit|practice|group|team|country|regional) head\b",
rf"^head (?!{_HEAD_JOBS}\b)", r"\bhead$", rf"^head (?!{_HEAD_JOBS}\b)", r"\bhead$",
# Leiter(in) alone or of a whole unit (Bereichsleiter), and a title that # Leiter(in) alone or of a whole unit (Bereichsleiter), and a title that
@@ -168,10 +199,15 @@ _RULES: tuple[tuple[str, tuple[str, ...]], ...] = (
r"|entwicklungs|werks)leit(?:er|erin|ung)\b", r"|entwicklungs|werks)leit(?:er|erin|ung)\b",
r"\bhoofd\b", r"\bhoofd\b",
)), )),
("senior_manager", (
r"\b(?:associate|assoc|assistant|asst) director\b",
r"\bavp\b", r"\b(?:assistant|associate|assoc) (?:vice president|vp)\b",
rf"\b(?:senior|sr|snr) (?:{_PEOPLE_MANAGER} )?manager\b",
)),
("manager", ( ("manager", (
r"^(?:(?:senior|sr|global|regional|group|executive) )*manager\b", r"^(?:(?:global|regional|group|executive) )*manager\b",
r"\b(?:senior|sr) manager\b",
rf"(?<!assistant )(?<!deputy )(?<!asst )\b{_PEOPLE_MANAGER} manager\b", rf"(?<!assistant )(?<!deputy )(?<!asst )\b{_PEOPLE_MANAGER} manager\b",
r"\btech lead manager\b", r"(?<!associate )\bstore lead(?:er)?\b",
# -leiter / -leder / -leider of a shop, site or department: Filialleiter, # -leiter / -leder / -leider of a shop, site or department: Filialleiter,
# Afdelingsleder. The team-sized ones are lead (below), and project ones # Afdelingsleder. The team-sized ones are lead (below), and project ones
# are cut out by _NOISE. A -leitung is only these, since "Rohrleitung" # are cut out by _NOISE. A -leitung is only these, since "Rohrleitung"
@@ -192,18 +228,33 @@ _RULES: tuple[tuple[str, tuple[str, ...]], ...] = (
r"\bresponsabile\b", r"\bresponsabile\b",
)), )),
("lead", ( ("lead", (
r"\b(?:team|tech|squad)?lead\b", r"\b(?:team|shift)?leader\b", rf"\b{_TEAM_SIZED_LEAD} ?lead(?:er)?s?\b",
r"\bsupervisor\b", r"\bsuperviseur\b", r"\bsupervisor\b", r"\bsuperviseur\b",
rf"\b(?:assistant|deputy|asst) {_PEOPLE_MANAGER} manager\b", rf"\b(?:assistant|deputy|asst) {_PEOPLE_MANAGER} manager\b",
r"\bassociate store leader\b", r"\bpeople leader\b",
r"\b(?:team|gruppen?|schicht|hold|vagt)(?:leit(?:er|erin|ung)|leder|leider)\b", r"\b(?:team|gruppen?|schicht|hold|vagt)(?:leit(?:er|erin|ung)|leder|leider)\b",
r"\b(?:team|grupp)?ledare\b", r"\bchef(?: fe)? d equipe\b", r"\blider\b", r"\b(?:team|grupp)?ledare\b", r"\bchef(?: fe)? d equipe\b",
r"\bjef[ea] de equipo\b", r"\blider de equip[oe]\b", r"\bjef[ea] de equipo\b",
)), )),
("staff", ( )
r"\bstaff\b", r"\bprincipal\b", r"\bdistinguished\b",
#: `(level, patterns)` of the individual grades, from the highest down, as
#: `_PEOPLE`: "Senior Principal" is tried before "Principal".
_GRADES: tuple[tuple[str, tuple[str, ...]], ...] = (
("distinguished", (
r"\b(?:senior|sr|snr) principal\b", r"\bdistinguished\b",
r"\b(?:technical|engineering|technology) fellow\b",
# SAP's top individual-contributor grade. # SAP's top individual-contributor grade.
r"\bchief expert\b", r"\bchief expert\b",
)), )),
("principal", (
r"\b(?:senior|sr|snr) staff\b", r"\bprincipal\b",
)),
("staff", (
r"\bstaff\b",
# "Lead" the noun at either end; the team leads are `_PEOPLE`'s.
r"\b(?:tech)?lead\b", r"\bleader\b", r"\blider\b",
)),
("senior", ( ("senior", (
r"\b(?:senior|sr|snr|iii)\b", r"\b(?:senior|sr|snr|iii)\b",
)), )),
@@ -218,19 +269,45 @@ _RULES: tuple[tuple[str, tuple[str, ...]], ...] = (
)), )),
) )
#: `_RULES`, compiled once, in the same order.
_COMPILED: tuple[tuple[str, tuple[re.Pattern[str], ...]], ...] = tuple( def _compile(rules: tuple[tuple[str, tuple[str, ...]], ...]
(level, tuple(re.compile(pattern) for pattern in patterns)) ) -> tuple[tuple[str, re.Pattern[str]], ...]:
for level, patterns in _RULES) """Each level's patterns as one alternation, in the same order."""
return tuple((level, re.compile("|".join(f"(?:{p})" for p in patterns)))
for level, patterns in rules)
_INTERN_RE = re.compile("|".join(f"(?:{p})" for p in _INTERN))
_PEOPLE_RE = _compile(_PEOPLE)
_GRADES_RE = _compile(_GRADES)
#: The people level one rung above each people level, for a grade that lifts it.
_LIFT: dict[str, str] = {
level: next((up for up, (r, t) in LADDER.items() if t == "people" and r == rung + 1), level)
for level, (rung, track) in LADDER.items() if track == "people"}
#: A slash between two words, which `title_key` would fold to a space:
#: "Senior/Principal" names two grades, not a Senior Principal. The gender
#: marker's single letters (m/w/d) are left to `title_key`.
_OR = re.compile(r"(?<=\w\w|\w\.)\s*/\s*(?=\w\w)")
def _first(rules: tuple[tuple[str, re.Pattern[str]], ...], folded: str) -> str:
return next((level for level, pattern in rules if pattern.search(folded)), "")
def from_title(title: str) -> str: def from_title(title: str) -> str:
"""The highest level `title` names, one of `SENIORITIES`, or `''` when it """The level `title` names, one of `SENIORITIES`, or `''` when it names
names none. See the module docstring for what counts.""" none. See the module docstring for what counts."""
folded = " ".join(_NOISE.sub(" ", title_key(title)).split()) folded = " ".join(_NOISE.sub(" ", title_key(_OR.sub(" or ", title or ""))).split())
if not folded: if not folded:
return "" return ""
for level, patterns in _COMPILED: if _INTERN_RE.search(folded):
if any(pattern.search(folded) for pattern in patterns): return "intern"
return level people, grade = _first(_PEOPLE_RE, folded), _first(_GRADES_RE, folded)
return "" if not people:
return grade
if grade and LADDER[grade][0] > LADDER[people][0]:
return _LIFT[people]
return people
+12
View File
@@ -611,6 +611,18 @@ ALTER TABLE companies ADD COLUMN hand_reason TEXT NOT NULL DEFAULT '';
(24, "companies.all_countries takes over the All roles tag, and companies.all_roles " (24, "companies.all_countries takes over the All roles tag, and companies.all_roles "
"means no role narrowing; a board's {\"terms\": false} becomes its company's " "means no role narrowing; a board's {\"terms\": false} becomes its company's "
"all_roles", lambda conn: _split_all_roles(conn)), "all_roles", lambda conn: _split_all_roles(conn)),
# Seniority became a ladder of two tracks (models.LADDER): staff, lead,
# manager and director each split, so a model level in one of them is
# emptied for extract to read the role again. The level shown is then
# the first filled of the three, as Store.write_prep writes it; the
# title's is mapped again by the next prep (app.prep.stage.VERSION 2).
(25, "roles.seniority_model cleared where it is staff, lead, manager or director, "
"which the ladder splits; roles.seniority from the model, stated and title levels", """
UPDATE roles SET seniority_model = ''
WHERE seniority_model IN ('staff', 'lead', 'manager', 'director');
UPDATE roles SET seniority = COALESCE(NULLIF(seniority_model, ''),
NULLIF(seniority_stated, ''), seniority_title);
"""),
) )
#: What a file created from `SCHEMA` today is already at. #: What a file created from `SCHEMA` today is already at.
+2 -2
View File
@@ -148,7 +148,7 @@ def test_migration_20_seeds_an_old_file_and_leaves_collisions(tmp_path: Path) ->
"VALUES (?, ?, '', '')", (key, name)) "VALUES (?, ?, '', '')", (key, name))
conn.execute("PRAGMA user_version = 19") conn.execute("PRAGMA user_version = 19")
reopened = Store(path) reopened = Store(path)
assert reopened.migrations_applied == [20, 21, 22, 23, 24] assert reopened.migrations_applied == [20, 21, 22, 23, 24, 25]
assert reopened.duplicate_companies() == [("orsted", ["orsted", "ørsted"])] assert reopened.duplicate_companies() == [("orsted", ["orsted", "ørsted"])]
assert len(reopened.companies()) == 3 assert len(reopened.companies()) == 3
@@ -186,7 +186,7 @@ def test_migration_21_tags_the_favourites_and_the_boards_that_read_all_roles(tmp
conn.execute("ALTER TABLE companies DROP COLUMN all_countries") conn.execute("ALTER TABLE companies DROP COLUMN all_countries")
conn.execute("PRAGMA user_version = 20") conn.execute("PRAGMA user_version = 20")
reopened = Store(path) reopened = Store(path)
assert reopened.migrations_applied == [21, 22, 23, 24] assert reopened.migrations_applied == [21, 22, 23, 24, 25]
# The tag of 21 is All countries and All roles since 24. # The tag of 21 is All countries and All roles since 24.
tagged = {"mistral-ai": 1, "acme": 0, "black-forest-labs": 1, "liked": 0} tagged = {"mistral-ai": 1, "acme": 0, "black-forest-labs": 1, "liked": 0}
assert {c.key: c.all_roles for c in reopened.companies()} == tagged assert {c.key: c.all_roles for c in reopened.companies()} == tagged
+1 -1
View File
@@ -246,7 +246,7 @@ def test_a_v17_file_gains_dup_of_with_its_first_rebuild(tmp_path: Path) -> None:
migrated = Store(path) migrated = Store(path)
assert migrated.migrations_applied == [18, 19, 20, 21, 22, 23, 24] assert migrated.migrations_applied == [18, 19, 20, 21, 22, 23, 24, 25]
assert dup_of(migrated) == {first.uid: None, second.uid: first.uid} assert dup_of(migrated) == {first.uid: None, second.uid: first.uid}
with sqlite3.connect(path) as conn: with sqlite3.connect(path) as conn:
assert conn.execute("SELECT 1 FROM sqlite_master WHERE name = 'idx_roles_dup_of'" assert conn.execute("SELECT 1 FROM sqlite_master WHERE name = 'idx_roles_dup_of'"
+9 -1
View File
@@ -3,6 +3,7 @@ answer writes, and what it may not touch. Nothing here reaches a model."""
from __future__ import annotations from __future__ import annotations
import re
from datetime import UTC, datetime from datetime import UTC, datetime
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any
@@ -14,7 +15,7 @@ from desk.models import Item
from desk.tools import agent from desk.tools import agent
from app.config import Config from app.config import Config
from app.jobs import extract from app.jobs import extract
from app.models import Limits from app.models import LEVELS, Limits
from app.storage import Store from app.storage import Store
from prepped import upsert from prepped import upsert
@@ -263,6 +264,13 @@ def test_the_prompt_carries_the_hints_and_the_teaser_when_there_is_no_text(
assert "" not in schema["enum"], "the afterburner must pick a level" assert "" not in schema["enum"], "the afterburner must pick a level"
def test_the_prompt_names_every_level_of_the_ladder() -> None:
schema = extract.SCHEMA["properties"]["roles"]["items"]["properties"]["seniority"]
assert schema["enum"] == list(LEVELS)
section = extract.SYSTEM.split("- seniority:")[1].split("- salary_min")[0]
assert all(re.search(rf"\b{level}\b", section) for level in LEVELS)
def test_an_answer_with_no_level_is_charged_until_given_up( def test_an_answer_with_no_level_is_charged_until_given_up(
store: Store, config: Config, monkeypatch: pytest.MonkeyPatch) -> None: store: Store, config: Config, monkeypatch: pytest.MonkeyPatch) -> None:
item = posting("1") item = posting("1")
+1 -1
View File
@@ -437,7 +437,7 @@ def test_migration_23_gives_every_agent_no_terms(tmp_path: Path) -> None:
conn.execute("ALTER TABLE agents DROP COLUMN fetch_terms") conn.execute("ALTER TABLE agents DROP COLUMN fetch_terms")
conn.execute("PRAGMA user_version = 22") conn.execute("PRAGMA user_version = 22")
migrated = Store(path) migrated = Store(path)
assert migrated.migrations_applied == [23, 24] assert migrated.migrations_applied == [23, 24, 25]
assert migrated.agents()[0].fetch_terms == [] assert migrated.agents()[0].fetch_terms == []
+1 -1
View File
@@ -120,7 +120,7 @@ def test_migration_24_splits_the_tag_and_moves_terms_off(tmp_path: Path) -> None
conn.execute("UPDATE companies SET all_roles=1 WHERE key='mistral-ai'") conn.execute("UPDATE companies SET all_roles=1 WHERE key='mistral-ai'")
conn.execute("PRAGMA user_version = 23") conn.execute("PRAGMA user_version = 23")
migrated = Store(path) migrated = Store(path)
assert migrated.migrations_applied == [24] assert migrated.migrations_applied == [24, 25]
flags = {c.key: (c.all_countries, c.all_roles) for c in migrated.companies()} flags = {c.key: (c.all_countries, c.all_roles) for c in migrated.companies()}
assert flags == {"mistral-ai": (1, 1), "acme": (0, 1), "plain": (0, 0)} assert flags == {"mistral-ai": (1, 1), "acme": (0, 1), "plain": (0, 0)}
params = {s.target: s.params for s in migrated.subscriptions(source="ats")} params = {s.target: s.params for s in migrated.subscriptions(source="ats")}
+1 -1
View File
@@ -299,7 +299,7 @@ def test_migration_22_fills_the_host_words_from_raw(tmp_path: Path) -> None:
migrated = Store(path) migrated = Store(path)
assert migrated.migrations_applied == [22, 23, 24] assert migrated.migrations_applied == [22, 23, 24, 25]
one = row(migrated, "1") one = row(migrated, "1")
assert (one["seniority_host"], one["employment_host"], one["remote_host"], assert (one["seniority_host"], one["employment_host"], one["remote_host"],
one["country_host"]) == ("senior", "full_time", "true", "DK") one["country_host"]) == ("senior", "full_time", "true", "DK")
+1 -1
View File
@@ -27,7 +27,7 @@ def test_the_table_keys_are_lowercase_and_the_values_in_the_vocabulary(table: st
assert set(words.values()) <= {*VOCABULARY[table], ""} assert set(words.values()) <= {*VOCABULARY[table], ""}
@pytest.mark.parametrize(("word", "value"), [('mid level', 'mid'), ('student', 'intern'), ('entry level', 'junior'), ('executive', 'exec'), ('not applicable', '')]) @pytest.mark.parametrize(("word", "value"), [('mid level', 'mid'), ('student', 'intern'), ('entry level', 'junior'), ('executive', 'exec'), ('not applicable', ''), ('lead', 'staff'), ('manager', 'manager')])
def test_seniority_words(word: str, value: str) -> None: def test_seniority_words(word: str, value: str) -> None:
assert hosts.SENIORITY[word] == value assert hosts.SENIORITY[word] == value
+2
View File
@@ -18,6 +18,8 @@ def test_experience_codes_read() -> None:
assert [seniority[w] for w in ("student_school", "entry_level", "mid_level")] == [ assert [seniority[w] for w in ("student_school", "entry_level", "mid_level")] == [
"intern", "junior", "mid"] "intern", "junior", "mid"]
assert seniority["experienced"] == "" assert seniority["experienced"] == ""
assert [seniority[w] for w in ("student_college", "manager", "senior_manager",
"executive")] == ["intern", "manager", "senior_manager", "exec"]
assert "senior_level" not in seniority assert "senior_level" not in seniority
+67 -24
View File
@@ -42,9 +42,6 @@ TITLES: list[tuple[str, str]] = [
("Sr. Director, Enterprise Data", "director"), ("Sr. Director, Enterprise Data", "director"),
("Director of Engineering (Data Infrastructure)", "director"), ("Director of Engineering (Data Infrastructure)", "director"),
("Director, Pricing", "director"), ("Director, Pricing", "director"),
("Associate Director, AI Strategy", "director"),
("Assoc Director, Oral Sema", "director"),
("Associate VP, Drug Product Manufacturing US Quality", "director"),
("Head of Data & AI Platforms", "director"), ("Head of Data & AI Platforms", "director"),
("Head, Logistics Performance", "director"), ("Head, Logistics Performance", "director"),
("Head ASP Management", "director"), ("Head ASP Management", "director"),
@@ -60,12 +57,19 @@ TITLES: list[tuple[str, str]] = [
# "Head Chef"-like titles and a duty that is only mentioned are not heads. # "Head Chef"-like titles and a duty that is only mentioned are not heads.
("Augenoptikermeister mit technischer Leitung (m/w/d) in Berlin WILMA", ""), ("Augenoptikermeister mit technischer Leitung (m/w/d) in Berlin WILMA", ""),
("Sous Chef", ""), ("Sous Chef", ""),
# ---- senior_manager
("Associate Director, AI Strategy", "senior_manager"),
("Assoc Director, Oral Sema", "senior_manager"),
("Associate Director/Director in Investment Banking - Infrastructure Leveraged Finance", "director"),
("Associate VP, Drug Product Manufacturing US Quality", "senior_manager"),
("Sr. Engineering Manager - Notebook Dataplane", "senior_manager"),
("Senior Engineering Manager - Enterprise Trust & Reliability", "senior_manager"),
("Senior Manager, Strategic Planning", "senior_manager"),
("Sr. Manager, Technical Delivery", "senior_manager"),
("Business Development Sr. Manager", "senior_manager"),
# ---- manager # ---- manager
("Engineering Manager - Security Engineering", "manager"), ("Engineering Manager - Security Engineering", "manager"),
("Sr. Engineering Manager - Notebook Dataplane", "manager"), ("Store Leader, Shopping Leblon", "manager"),
("Senior Manager, Strategic Planning", "manager"),
("Sr. Manager, Technical Delivery", "manager"),
("Business Development Sr. Manager", "manager"),
("Data Science Manager, Finance Analytics", "manager"), ("Data Science Manager, Finance Analytics", "manager"),
("Manager, Bid Management", "manager"), ("Manager, Bid Management", "manager"),
("Manager Sales Enablement", "manager"), ("Manager Sales Enablement", "manager"),
@@ -94,20 +98,25 @@ TITLES: list[tuple[str, str]] = [
("Office Manager - 9 month fixed term contract", ""), ("Office Manager - 9 month fixed term contract", ""),
("Sales Manager (m/w/d) – Photovoltaik, Wärmepumpe & intelligente Energiesysteme - 1KOMMA5° Kiel", ""), ("Sales Manager (m/w/d) – Photovoltaik, Wärmepumpe & intelligente Energiesysteme - 1KOMMA5° Kiel", ""),
("Technical Program Manager, Data Centers", ""), ("Technical Program Manager, Data Centers", ""),
("Lead Project Manager (German speaker)", "lead"), ("Lead Project Manager (German speaker)", "staff"),
("Assistant Store Manager (efood market) - Θεσσαλονίκη", "lead"),
("Responsable de projets - Expériences Fever Originals", ""), ("Responsable de projets - Expériences Fever Originals", ""),
("Chef de projet SEO et Marketing Digital H/F", ""), ("Chef de projet SEO et Marketing Digital H/F", ""),
("Bauleiter AC (m/w/d) für Photovoltaik - 1KOMMA5° Handwerk - Region Bayern", ""), ("Bauleiter AC (m/w/d) für Photovoltaik - 1KOMMA5° Handwerk - Region Bayern", ""),
("Projektleder til produktion af færdigretter", ""), ("Projektleder til produktion af færdigretter", ""),
("Prosjektleder DTO", ""), ("Prosjektleder DTO", ""),
("Technologie-Forschungsingenieur für Leistungshalbleiter (w/m/div.)", ""), ("Technologie-Forschungsingenieur für Leistungshalbleiter (w/m/div.)", ""),
# ---- lead # ---- lead: a team lead
("Tech Lead, Deployment & Operations — Custom Infrastructure", "lead"),
("Lead Data Engineer", "lead"),
("Lead Engineer", "lead"),
("Technical Lead- AI Cockpit", "lead"),
("Engineering Team Lead - GateManager Platform", "lead"), ("Engineering Team Lead - GateManager Platform", "lead"),
("Team Lead - Technical Support", "lead"),
("Team Leader, Operations", "lead"),
("Delivery Station Supervisor", "lead"),
("Warehouse Lead", "lead"),
("[US-DC] Kitchen Lead", "lead"),
("Assistant Store Manager (efood market) - Θεσσαλονίκη", "lead"),
("Augenoptiker (m/w/d) als Assistant Store Manager in Dresden", "lead"),
("Associate Store Leader, Tyson's Corner", "lead"),
("People Leader - Model Design, LEGO® Design", "lead"),
("Chef d'Equipe Mecanique (H/F)", "lead"),
("Teamlead Winkel Schoten (36u)", "lead"), ("Teamlead Winkel Schoten (36u)", "lead"),
("Complaints Team Leader - Claims", "lead"), ("Complaints Team Leader - Claims", "lead"),
("Supervisor, Wind Site - Sunzia, NM", "lead"), ("Supervisor, Wind Site - Sunzia, NM", "lead"),
@@ -118,15 +127,29 @@ TITLES: list[tuple[str, str]] = [
("Chef d'équipe Entrepôt Magasin", "lead"), ("Chef d'équipe Entrepôt Magasin", "lead"),
("Chef·fe d’équipe - Modélisation (Unreal)", "lead"), ("Chef·fe d’équipe - Modélisation (Unreal)", "lead"),
("Superviseur magasin", "lead"), ("Superviseur magasin", "lead"),
# "Lead" the noun is a level, "lead" the sales lead is not.
("B2B Demand Generation Specialist", ""), ("B2B Demand Generation Specialist", ""),
# ---- staff # ---- distinguished
("Senior Principal Engineer, Central Ops & Systems", "distinguished"),
("Principal/Senior Principal Investment Accounting Solution Consultant – IAS Value Team", "distinguished"),
("Distinguished Engineer, Core DevOps", "distinguished"),
("Business Process Chief Expert CIS", "distinguished"),
# "Fellow" alone is academic; the Technical Fellow's office is not the grade.
("Postdoctoral Fellow in Robotics and Computer Vision", ""),
("Principal Engineer, Enterprise AI — Technical Fellow Office", "principal"),
# ---- principal
("Senior Staff Software Engineer- Search Quality", "principal"),
("Senior Staff Applications Engineer", "principal"),
("Principal Software Engineer - Platform Engineering", "principal"),
("Principal Product Manager - Audio and Media Playback", "principal"),
# ---- staff: Staff, and "Lead" the noun that is not a team lead
("Staff Software Engineer - Money Movement", "staff"), ("Staff Software Engineer - Money Movement", "staff"),
("Senior Staff Software Engineer- Search Quality", "staff"),
("Staff+ Software Engineer, Safeguards", "staff"), ("Staff+ Software Engineer, Safeguards", "staff"),
("Principal Software Engineer - Platform Engineering", "staff"), ("Tech Lead, Deployment & Operations — Custom Infrastructure", "staff"),
("Principal/Senior Principal Investment Accounting Solution Consultant – IAS Value Team", "staff"), ("Lead Data Engineer", "staff"),
("Business Process Chief Expert CIS", "staff"), ("Lead Engineer", "staff"),
("Technical Lead- AI Cockpit", "staff"),
("Product Marketing Lead, Experience", "staff"),
("Payroll Lead", "staff"),
("Member of Technical Staff - Research Infrastructure Engineer", ""), ("Member of Technical Staff - Research Infrastructure Engineer", ""),
("Chief of Staff (m/w/d)", ""), ("Chief of Staff (m/w/d)", ""),
("Staff Accountant", ""), ("Staff Accountant", ""),
@@ -213,6 +236,27 @@ SYNTHETIC: list[tuple[str, str]] = [
("Projectleider Logistiek", ""), ("Projectleider Logistiek", ""),
("Software Engineer III, Platform", "senior"), ("Software Engineer III, Platform", "senior"),
("Manager, Data Science", "manager"), ("Manager, Data Science", "manager"),
# A grade on a people title lifts it one rung only when it is above the
# title's own rung.
("Staff Engineering Manager", "manager"),
("Principal Engineering Manager", "senior_manager"),
("Senior Staff Engineering Manager", "senior_manager"),
("Senior Principal Engineering Manager", "senior_manager"),
("Principal Team Lead", "senior_manager"),
("Staff Tech Lead Manager, Machine Learning, Vision Models", "manager"),
# A slash names two levels, the higher of which wins.
("Senior/Principal Unity Developer | New Games", "principal"),
("Senior/Staff Backend Engineer", "staff"),
("Lead/Principal Cloud Engineer – Data Platform", "principal"),
("Assistant Vice President, Credit Risk", "senior_manager"),
("AVP, Operations", "senior_manager"),
("Assistant Director of Finance", "senior_manager"),
("Research Fellow in Economics", ""),
("Fellow", ""),
("Technical Fellow", "distinguished"),
("Engineering Fellow, Silicon", "distinguished"),
("Shift Leader", "lead"),
("Supervisor", "lead"),
] ]
@@ -221,8 +265,6 @@ def test_title(title: str, level: str) -> None:
assert from_title(title) == level assert from_title(title) == level
@pytest.mark.xfail(strict=True, reason="WP A of docs/plan-seniority.md adds the title rules "
"for principal, senior_manager and distinguished, and drops this marker")
def test_table_covers_every_level_and_at_least_eighty_titles() -> None: def test_table_covers_every_level_and_at_least_eighty_titles() -> None:
assert len(TITLES) >= 80 assert len(TITLES) >= 80
assert {level for _, level in TITLES} == set(SENIORITIES) assert {level for _, level in TITLES} == set(SENIORITIES)
@@ -239,8 +281,9 @@ def test_gender_marker_and_case_do_not_matter() -> None:
def test_highest_level_named_wins() -> None: def test_highest_level_named_wins() -> None:
assert from_title("Senior Director of Engineering") == "director" assert from_title("Senior Director of Engineering") == "director"
assert from_title("Senior Lead Engineer") == "lead" assert from_title("Senior Lead Engineer") == "staff"
assert from_title("Junior Principal Engineer") == "staff" assert from_title("Junior Principal Engineer") == "principal"
assert from_title("Senior Director, Principal Engineering") == "director"
assert from_title("Vice President and Managing Director") == "exec" assert from_title("Vice President and Managing Director") == "exec"
+44 -9
View File
@@ -70,7 +70,7 @@ def test_schema_creates_on_an_empty_file(tmp_path: Path) -> None:
"application_events", "agents", "scores", "state"} <= tables "application_events", "agents", "scores", "state"} <= tables
assert "idx_roles_cluster" in indexes assert "idx_roles_cluster" in indexes
assert store.migrations_applied == [] assert store.migrations_applied == []
assert LATEST == 24 assert LATEST == 25
# A second open finds it current and applies nothing. # A second open finds it current and applies nothing.
assert Store(path).migrations_applied == [] assert Store(path).migrations_applied == []
@@ -187,7 +187,7 @@ def test_a_v14_file_gains_the_watchlist_columns_and_leaves_companies_unrated(
migrated = Store(path) migrated = Store(path)
assert migrated.migrations_applied == [15, 16, 17, 18, 19, 20, 21, 22, 23, 24] assert migrated.migrations_applied == [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
acme = migrated.company("acme") acme = migrated.company("acme")
assert acme is not None assert acme is not None
assert (acme.ats, acme.careers_url) == ("teamtailor", "https://a.example") assert (acme.ats, acme.careers_url) == ("teamtailor", "https://a.example")
@@ -392,7 +392,7 @@ def test_v14_makes_each_intent_the_agents_one_prompt_with_its_vector(tmp_path: P
migrated = Store(path) migrated = Store(path)
assert migrated.migrations_applied == [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] assert migrated.migrations_applied == [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
assert migrated.agent(backend.id).prompts == [ # type: ignore[union-attr] assert migrated.agent(backend.id).prompts == [ # type: ignore[union-attr]
Prompt(name="Backend", text="python backend")] Prompt(name="Backend", text="python backend")]
assert migrated.agent(blank.id).prompts == [] # type: ignore[union-attr] assert migrated.agent(blank.id).prompts == [] # type: ignore[union-attr]
@@ -416,7 +416,7 @@ def test_v16_gives_a_company_no_reason_and_keeps_its_row(tmp_path: Path) -> None
migrated = Store(path) migrated = Store(path)
assert migrated.migrations_applied == [16, 17, 18, 19, 20, 21, 22, 23, 24] assert migrated.migrations_applied == [16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
acme = migrated.company("acme") acme = migrated.company("acme")
assert acme is not None assert acme is not None
assert (acme.careers_url, acme.notes, acme.hand_reason) == ( assert (acme.careers_url, acme.notes, acme.hand_reason) == (
@@ -445,7 +445,7 @@ def test_v17_folds_every_place_and_levels_the_titles_extract_has_not_read(
migrated = Store(path) migrated = Store(path)
assert migrated.migrations_applied == [17, 18, 19, 20, 21, 22, 23, 24] assert migrated.migrations_applied == [17, 18, 19, 20, 21, 22, 23, 24, 25]
with sqlite3.connect(path) as conn: with sqlite3.connect(path) as conn:
rows = {uid: (fold, level) for uid, fold, level in conn.execute( rows = {uid: (fold, level) for uid, fold, level in conn.execute(
"SELECT uid, place_fold, seniority FROM roles")} "SELECT uid, place_fold, seniority FROM roles")}
@@ -681,13 +681,14 @@ def test_v19_gives_every_role_its_places_and_splits_its_level(tmp_path: Path) ->
_undo_v19(conn) _undo_v19(conn)
# A role whose own page was read is pulled with an empty place in raw. # A role whose own page was read is pulled with an empty place in raw.
conn.execute("UPDATE roles SET raw = '{}' WHERE uid = ?", (detailed.uid,)) conn.execute("UPDATE roles SET raw = '{}' WHERE uid = ?", (detailed.uid,))
conn.execute("UPDATE roles SET extracted_at = '2026-09-23', seniority = 'staff' " # A level 25 does not clear, so the split is what is checked here.
conn.execute("UPDATE roles SET extracted_at = '2026-09-23', seniority = 'mid' "
"WHERE uid = ?", (extracted.uid,)) "WHERE uid = ?", (extracted.uid,))
conn.execute("PRAGMA user_version = 18") conn.execute("PRAGMA user_version = 18")
migrated = Store(path) migrated = Store(path)
assert migrated.migrations_applied == [19, 20, 21, 22, 23, 24] assert migrated.migrations_applied == [19, 20, 21, 22, 23, 24, 25]
assert [p.name for p in migrated.role_places(joined.uid)] == ["Copenhagen", "Malmö"] assert [p.name for p in migrated.role_places(joined.uid)] == ["Copenhagen", "Malmö"]
assert [p.name for p in migrated.role_places(detailed.uid)] == ["Aarhus"] assert [p.name for p in migrated.role_places(detailed.uid)] == ["Aarhus"]
assert migrated.role_places(stated.uid) == [] assert migrated.role_places(stated.uid) == []
@@ -699,10 +700,44 @@ def test_v19_gives_every_role_its_places_and_splits_its_level(tmp_path: Path) ->
joined.uid: ["senior", "", "", "senior", ""], joined.uid: ["senior", "", "", "senior", ""],
detailed.uid: ["senior", "", "", "senior", ""], detailed.uid: ["senior", "", "", "senior", ""],
stated.uid: ["lead", "", "lead", "senior", ""], stated.uid: ["lead", "", "lead", "senior", ""],
extracted.uid: ["staff", "staff", "", "senior", ""], extracted.uid: ["mid", "mid", "", "senior", ""],
} }
def test_v25_clears_the_model_levels_the_ladder_splits_and_sets_the_level(
tmp_path: Path) -> None:
path = tmp_path / "v24.db"
store = Store(path)
# (model, stated, title) before 25, and what 25 leaves: the model level
# of the four split words is emptied, and the level is the first filled.
cases = {
"staff": (("staff", "", "senior"), ("", "", "senior", "senior")),
"lead": (("lead", "mid", "senior"), ("", "mid", "senior", "mid")),
"manager": (("manager", "", ""), ("", "", "", "")),
"director": (("director", "", "director"), ("", "", "director", "director")),
"senior": (("senior", "junior", "lead"), ("senior", "junior", "lead", "senior")),
"exec": (("exec", "", ""), ("exec", "", "", "exec")),
"none": (("", "", "lead"), ("", "", "lead", "lead")),
}
for sid in cases:
upsert(store, posting(sid))
with sqlite3.connect(path) as conn:
for sid, ((model, stated, title), _) in cases.items():
conn.execute("UPDATE roles SET seniority_model = ?, seniority_stated = ?, "
"seniority_title = ?, seniority = 'stale', extracted_at = '2026-09-23' "
"WHERE source_id = ?", (model, stated, title, sid))
conn.execute("PRAGMA user_version = 24")
migrated = Store(path)
assert migrated.migrations_applied == [25]
with sqlite3.connect(path) as conn:
found = {sid: rest for sid, *rest in conn.execute(
"SELECT source_id, seniority_model, seniority_stated, seniority_title, seniority "
"FROM roles")}
assert found == {sid: list(after) for sid, (_, after) in cases.items()}
def test_upsert_unpacks_raw_and_keeps_filled_columns(store: Store) -> None: def test_upsert_unpacks_raw_and_keeps_filled_columns(store: Store) -> None:
upsert(store, posting(place="Berlin", remote=True, salary_min="80000", upsert(store, posting(place="Berlin", remote=True, salary_min="80000",
salary_max=95000, currency="EUR", department="Eng")) salary_max=95000, currency="EUR", department="Eng"))
@@ -1028,7 +1063,7 @@ def test_roles_filter_by_place_tokens_on_whole_words(store: Store) -> None:
def test_roles_filter_by_seniority_and_keep_the_unknown_unless_told(store: Store) -> None: def test_roles_filter_by_seniority_and_keep_the_unknown_unless_told(store: Store) -> None:
for sid, title in (("senior", "Senior Engineer"), ("junior", "Junior Engineer"), for sid, title in (("senior", "Senior Engineer"), ("junior", "Junior Engineer"),
("lead", "Tech Lead"), ("none", "Engineer")): ("lead", "Team Lead"), ("none", "Engineer")):
item = posting(sid) item = posting(sid)
item.title = title item.title = title
upsert(store, item) upsert(store, item)