Merge the remote area: remote tokens, role_remote, remote_from, model wins for remote (wp-remote-a)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	app/models.py
This commit is contained in:
Wolf committed 2026-09-30 16:21:57 +02:00
commit e5572cab9d
21 files changed
+1250 -143

No files matched your search

+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))
conn.execute("PRAGMA user_version = 19")
reopened = Store(path)
assert reopened.migrations_applied == [20, 21, 22, 23, 24, 25, 26]
assert reopened.migrations_applied == [20, 21, 22, 23, 24, 25, 26, 27]
assert reopened.duplicate_companies() == [("orsted", ["orsted", "ørsted"])]
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("PRAGMA user_version = 20")
reopened = Store(path)
assert reopened.migrations_applied == [21, 22, 23, 24, 25, 26]
assert reopened.migrations_applied == [21, 22, 23, 24, 25, 26, 27]
# The tag of 21 is All countries and All roles since 24.
tagged = {"mistral-ai": 1, "acme": 0, "black-forest-labs": 1, "liked": 0}
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)
assert migrated.migrations_applied == [18, 19, 20, 21, 22, 23, 24, 25, 26]
assert migrated.migrations_applied == [18, 19, 20, 21, 22, 23, 24, 25, 26, 27]
assert dup_of(migrated) == {first.uid: None, second.uid: first.uid}
with sqlite3.connect(path) as conn:
assert conn.execute("SELECT 1 FROM sqlite_master WHERE name = 'idx_roles_dup_of'"
+2 -1
View File
@@ -139,7 +139,8 @@ def test_closed_and_answered_roles_are_not_offered(
conn.execute("UPDATE roles SET closed_at = '2026-09-22T00:00:00+00:00' "
"WHERE source_id = 'closed'")
conn.execute("UPDATE roles SET extracted_at = '2026-09-22T00:00:00+00:00', "
"seniority_model = 'senior' WHERE source_id = 'done'")
"seniority_model = 'senior', remote_where_model = '[]' "
"WHERE source_id = 'done'")
model = stub(monkeypatch, lambda roles: [answer(r["uid"]) for r in roles])
modeltask.run(extract.TASK, config, store)
+1 -1
View File
@@ -434,7 +434,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("PRAGMA user_version = 22")
migrated = Store(path)
assert migrated.migrations_applied == [23, 24, 25, 26]
assert migrated.migrations_applied == [23, 24, 25, 26, 27]
assert migrated.agents()[0].fetch_terms == []
+1 -1
View File
@@ -50,7 +50,7 @@ def names(text: str) -> list[str]:
def test_the_seed_holds_the_dictionaries_in_code() -> None:
seeds, includes = seed()
kinds = Counter(s.kind for s in seeds)
assert {s.key for s in seeds if s.kind == "continent"} == {"europe", "asia-pacific"}
assert {s.key for s in seeds if s.kind == "continent"} == {"europe", "asia-pacific", "world"}
assert kinds["country"] == sum(1 for line in _COUNTRY_NAMES.split("\n") if line)
keys = {(s.kind, s.key) for s in seeds}
assert {("region", key) for key in places.REGIONS} <= keys
+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("PRAGMA user_version = 23")
migrated = Store(path)
assert migrated.migrations_applied == [24, 25, 26]
assert migrated.migrations_applied == [24, 25, 26, 27]
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)}
params = {s.target: s.params for s in migrated.subscriptions(source="ats")}
+14 -12
View File
@@ -205,21 +205,23 @@ def test_a_prep_that_read_old_words_leaves_the_role_due(store: Store) -> None:
assert row(store, "1")["prep_due"] == 2
def test_the_model_level_wins_and_a_place_guess_never_overwrites_extract(
def test_the_model_level_and_remote_win_over_the_host_and_the_place_line(
store: Store) -> None:
store.upsert_role(item("1", title="Senior Engineer", place="Hybrid, Berlin"))
uid = row(store, "1")["uid"]
with store.transaction() as conn:
conn.execute("UPDATE roles SET seniority_model = 'lead', remote = 'remote' "
"WHERE uid = ?", (uid,))
prep.run(store, tables=TABLES)
mapped = row(store, "1")
assert (mapped["seniority_title"], mapped["seniority"], mapped["remote"]) == \
("senior", "lead", "remote")
# The host's own statement does overwrite.
store.upsert_role(item("1", title="Senior Engineer", place="Hybrid, Berlin", remote="2"))
prep.run(store, tables=TABLES)
assert row(store, "1")["remote"] == "hybrid"
# The host's own word wins over the line.
store.upsert_role(item("1", title="Senior Engineer", place="Hybrid, Berlin", remote="fully"))
prep.run(store, tables=TABLES)
assert row(store, "1")["remote"] == "remote"
uid = row(store, "1")["uid"]
with store.transaction() as conn:
conn.execute("UPDATE roles SET seniority_model = 'lead', remote_model = 'onsite' "
"WHERE uid = ?", (uid,))
prep.run(store, tables=TABLES, remap=True)
mapped = row(store, "1")
assert (mapped["seniority_title"], mapped["seniority"], mapped["remote"]) == \
("senior", "lead", "onsite")
def test_the_company_resolves_through_its_aliases(store: Store) -> None:
@@ -314,7 +316,7 @@ def test_migration_22_fills_the_host_words_from_raw(tmp_path: Path) -> None:
migrated = Store(path)
assert migrated.migrations_applied == [22, 23, 24, 25, 26]
assert migrated.migrations_applied == [22, 23, 24, 25, 26, 27]
one = row(migrated, "1")
assert (one["seniority_host"], one["employment_host"], one["remote_host"],
one["country_host"]) == ("senior", "full_time", "true", "DK")
+533
View File
@@ -0,0 +1,533 @@
"""Where a remote role may be worked from: the `remote:` tokens, a remote
role's area in prep, the chips and gates that read it, the model's answer and
migration 27. The place texts are the live boards' (docs/plan-remote.md)."""
from __future__ import annotations
import json
import sqlite3
from collections.abc import Iterator
from datetime import UTC, datetime
from pathlib import Path
from typing import Any
import pytest
from desk.models import Item
from app import places, prep
from app.jobs import extract, reach
from app.models import Agent, Gate
from app.places import Gazetteer, label, known, parse, seed, suggest
from app.prep import words
from app.storage import Store
#: The require gate on country of the owner's agent: the EU, the EEA, the
#: UK, Switzerland and `EU`.
EUROPE = ["AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", "HU", "IE",
"IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE", "IS",
"LI", "NO", "GB", "CH", "EU"]
def gazetteer() -> Gazetteer:
"""The seeded gazetteer, as a fresh file holds it."""
seeds, includes = seed()
ids = {(s.kind, s.key): n for n, s in enumerate(seeds, 1)}
return Gazetteer([(ids[(s.kind, s.key)], s.kind, s.key, s.name,
ids[s.parent] if s.parent else None) for s in seeds],
[(a, ids[(s.kind, s.key)]) for s in seeds for a in s.aliases],
[(ids[w], ids[p]) for w, p in includes])
GAZ = gazetteer()
def names(ids: Any) -> list[str]:
return [GAZ.places[p].name for p in ids]
# ------------------------------------------------------------------ tokens
@pytest.mark.parametrize(("token", "shown", "text"), [
("remote:country:DK", "Remote · Denmark", "remote:country:DK"),
("remote:country:dk", "Remote · Denmark", "remote:country:DK"),
("remote:country:EU", "Remote · Europe", "remote:country:EU"),
("remote:region:oresund", "Remote · Øresund", "remote:region:oresund"),
("remote:place:berlin", "Remote · Berlin", "remote:place:berlin"),
("remote:anywhere", "Remote · anywhere", "remote:anywhere"),
("remote:worldwide", "Remote · anywhere", "remote:anywhere"),
("remote:any", "Remote", "remote:any"),
])
def test_a_remote_token_reads_its_place_token(token: str, shown: str, text: str) -> None:
assert label(token) == shown
assert str(parse(token)) == text
assert known(token)
def test_a_remote_token_of_nothing_is_not_known() -> None:
for token in ("remote:", "remote:country:ZZ", "remote:region:atlantis",
"remote:remote:country:DK"):
assert not known(token), token
def test_a_remote_token_is_answered_by_the_areas_only() -> None:
assert places.match_sql("remote:country:DK") == ("0", [])
assert not places.matches("remote denmark", "DK", "remote:country:DK")
@pytest.mark.parametrize(("text", "expected"), [
("Sweden (Remote)", ["Sweden"]), # Grafana
("Remote - US", ["United States"]),
("Home Based - EMEA", ["Europe"]),
("Home Based - Worldwide", ["Anywhere"]), # Canonical
("Remote, Global", ["Anywhere"]),
("Distributed, Global", ["Anywhere"]),
("Cardiff, London or Remote (UK)", ["United Kingdom"]),
("Anywhere in France, Belgium, Spain", ["France", "Belgium", "Spain"]),
("Remote", []),
("Global HQ, Berlin", []),
("Berlin", []),
("Hybrid, Berlin", []),
])
def test_the_parts_that_say_remote_name_the_area(text: str, expected: list[str]) -> None:
assert names(GAZ.remote_places(text)) == expected
def test_anywhere_is_no_place_of_a_role() -> None:
assert GAZ.resolve("Worldwide") == () and GAZ.resolve("Anywhere") == ()
assert names(GAZ.resolve("Global HQ, Berlin")) == ["Berlin"]
assert GAZ.under((GAZ.anywhere,)) == {GAZ.anywhere}
def test_denmarks_overlap_is_what_lies_in_it_what_it_lies_in_and_anywhere() -> None:
denmark = GAZ.by_key[("country", "DK")]
found = GAZ.overlap((denmark,))
for key in (("continent", "europe"), ("region", "oresund"), ("region", "hovedstaden"),
("city", "copenhagen"), places.ANYWHERE):
assert GAZ.by_key[key] in found, key
for key in (("country", "US"), ("country", "SE"), ("region", "skane")):
assert GAZ.by_key[key] not in found, key
def test_a_remote_line_is_no_town() -> None:
lines = [("USA (Remote)", "US", 70), ("Remote US", "US", 60), ("Germany (Remote)", "DE", 61),
("Remote Germany", "DE", 14), ("Remote - Berlin", "DE", 3), ("Berlin", "DE", 80)]
for q in ("usa", "remote", "germ", "berl"):
assert [s.label for s in suggest(q, lines) if s.kind == "place"] \
== (["Berlin"] if q == "berl" else []), q
assert places.towns("USA (Remote)") == frozenset()
# ---------------------------------------------------------------- the words
def test_remote_sensing_in_a_title_is_no_remote_work() -> None:
for title in ("Senior Sea Ice Scientist with Experience on Remote Sensing",
"Remote Control Engineer", "Remote-controlled Systems Lead",
"Remote Monitoring Specialist"):
assert words.remote("jobindex", None, (), "København Ø", title=title) == "", title
assert words.remote("jobindex", None, (), "Aarhus", title="Developer - Remote") == "remote"
# ------------------------------------------------------------------ the area
@pytest.fixture
def store(tmp_path: Path) -> Iterator[Store]:
yield Store(tmp_path / "roledesk.db")
def posting(source_id: str, place: str = "", *, board: str = "greenhouse",
**raw: Any) -> Item:
item = Item(source_id=f"{board}:{source_id}", location=f"https://boards.example/{source_id}",
title="Backend Engineer", body="", published_at=datetime(2026, 9, 20, tzinfo=UTC),
raw={"board": board, "company": "Acme"} | ({"place": place} if place else {})
| raw)
item.source = "ats"
return item
def add(store: Store, source_id: str, place: str = "", **raw: Any) -> str:
item = posting(source_id, place, **raw)
store.upsert_role(item)
return item.uid
#: One role per case of the plan, by what it stands for.
LINES: dict[str, tuple[str, dict[str, Any]]] = {
"grafana": ("Sweden (Remote)", {}),
"canonical": ("Home Based - EMEA; Home Based - Worldwide", {}),
"databricks": ("Denmark", {"remote": True}),
"airtame": ("København, Hovedstaden, Denmark; Remote", {}),
"europe": ("Remote - Europe", {}),
"germany": ("Germany (Remote)", {}),
"us": ("Remote US", {}),
"plain": ("Remote", {}),
"berlin": ("Global HQ, Berlin", {"remote": True}),
"hybrid": ("Hybrid, Copenhagen", {}),
"office": ("Copenhagen", {}),
}
@pytest.fixture
def roles(store: Store) -> dict[str, str]:
found = {key: add(store, key, line, **raw) for key, (line, raw) in LINES.items()}
prep.run(store, dupes=False)
return found
def area(store: Store, uid: str) -> tuple[str, str]:
role = store.role(uid)
assert role is not None
return role.remote, role.remote_where
def test_each_remote_role_gets_the_area_its_places_say(store: Store,
roles: dict[str, str]) -> None:
assert {key: area(store, uid) for key, uid in roles.items()} == {
"grafana": ("remote", "Sweden"),
"canonical": ("remote", "anywhere"), # EMEA and worldwide is worldwide
"databricks": ("remote", "Denmark"), # the host's flag and the place
"airtame": ("remote", "Denmark"), # an office town, read as its country
"europe": ("remote", "Europe"),
"germany": ("remote", "Germany"),
"us": ("remote", "United States"),
"plain": ("remote", ""), # remote, area not stated
"berlin": ("remote", "Germany"),
"hybrid": ("hybrid", ""),
"office": ("", ""),
}
role = store.role(roles["berlin"])
assert role is not None and [p.name for p in role.places] == ["Berlin"]
def test_the_rows_carry_the_area(store: Store, roles: dict[str, str]) -> None:
rows = {r.uid: r.remote_where for r in store.roles_page(limit=100)}
assert rows[roles["canonical"]] == "anywhere" and rows[roles["plain"]] == ""
listed = {r.uid: r.remote_where for r in store.roles(limit=100, by_score=False)}
assert listed == rows
def test_many_places_read_as_their_countries(store: Store) -> None:
uid = add(store, "komma", "Bayern (Remote); Hessen (Remote); Sachsen (Remote); "
"Saarland (Remote); Dänemark (Remote)")
prep.run(store, dupes=False)
assert area(store, uid) == ("remote", "Germany, Denmark")
def uids(store: Store, *tokens: str, agent: int | None = None) -> set[str]:
return {r.uid for r in store.roles(limit=1000, places=list(tokens), agent=agent,
by_score=False)}
def pick(roles: dict[str, str], *keys: str) -> set[str]:
return {roles[k] for k in keys}
def test_remote_denmark_is_every_remote_role_open_to_someone_in_denmark(
store: Store, roles: dict[str, str]) -> None:
assert uids(store, "remote:country:DK") == pick(
roles, "canonical", "databricks", "airtame", "europe")
assert uids(store, "remote:region:hovedstaden") == uids(store, "remote:country:DK")
def test_remote_europe_is_every_remote_role_in_europe(store: Store,
roles: dict[str, str]) -> None:
assert uids(store, "remote:country:EU") == pick(
roles, "grafana", "canonical", "databricks", "airtame", "europe", "germany", "berlin")
assert uids(store, "remote:country:SE") == pick(
roles, "grafana", "canonical", "europe") # Sweden, anywhere, Europe
def test_remote_anywhere_is_only_anywhere(store: Store, roles: dict[str, str]) -> None:
assert uids(store, "remote:anywhere") == pick(roles, "canonical")
assert uids(store, "remote:country:US") == pick(roles, "canonical", "us")
def test_remote_chips_or_with_the_place_chips(store: Store, roles: dict[str, str]) -> None:
assert uids(store, "remote:anywhere", "place:copenhagen") == pick(
roles, "canonical", "airtame", "hybrid", "office")
def test_remote_any_keeps_the_agents_scope(store: Store, roles: dict[str, str]) -> None:
remote = pick(roles, "grafana", "canonical", "databricks", "airtame", "europe", "germany",
"us", "plain", "berlin")
assert uids(store, "remote:any") == remote
agent = store.save_agent("Europe", "python backend", [
Gate(field="country", values=EUROPE, mode="require")])
assert uids(store, "remote:any", agent=agent.id) == remote - pick(roles, "us")
wide = store.save_agent("Anywhere", "python backend", [
Gate(field="country", values=["DK", "SE"], mode="any")])
assert uids(store, "remote:any", agent=wide.id) == remote
def states(store: Store, *gates: Gate) -> dict[str, list[int]]:
agent = store.save_agent(f"gates {len(store.agents())}", "python backend", list(gates))
return {c.uid: c.gates for c in store.score_candidates(agent.id, list(gates))}
def test_remote_from_is_met_as_the_chip_is_and_empty_without_an_area(
store: Store, roles: dict[str, str]) -> None:
found = states(store, Gate(field="remote_from", values=["country:DK"], mode="any"),
Gate(field="remote_from", values=["anywhere"], mode="any"))
by_key = {key: found[uid] for key, uid in roles.items()}
assert by_key == {
"grafana": [0, 0], "canonical": [1, 1], "databricks": [1, 0], "airtame": [1, 0],
"europe": [1, 0], "germany": [0, 0], "us": [0, 0],
"plain": [-1, -1], # remote, area not stated: neither
"berlin": [0, 0],
"hybrid": [0, 0], # evidence: not remote
"office": [-1, -1], # remote unknown
}
def test_a_require_gate_on_europe_reads_a_remote_role_through_its_area(
store: Store, roles: dict[str, str]) -> None:
found = states(store, Gate(field="country", values=EUROPE, mode="require"))
by_key = {key: found[uid][0] for key, uid in roles.items()}
assert by_key["canonical"] == 1 # Home Based - Worldwide
assert by_key["germany"] == 1
assert by_key["europe"] == 1
assert by_key["plain"] == -1 # "Remote" alone: kept, extract reads it
assert by_key["us"] == 0 # Remote US
assert by_key["office"] == 1 and by_key["hybrid"] == 1
def test_anywhere_aliased_by_hand_is_no_place_for_the_country_gate(store: Store) -> None:
uid = add(store, "ww", "Hybrid, Worldwide")
anywhere = store.gazetteer().anywhere
assert anywhere is not None
store.add_place_alias("Worldwide", anywhere)
prep.run(store, dupes=False)
assert [p.name for p in store.role_places(uid)] == ["Anywhere"]
assert area(store, uid) == ("hybrid", "")
found = states(store, Gate(field="country", values=EUROPE, mode="require"))
assert found[uid] == [-1]
def test_the_owners_agent_keeps_remote_roles_open_to_europe_and_drops_remote_us(
store: Store, roles: dict[str, str]) -> None:
from app.jobs.score import failed_gates
gates = [Gate(field="country", values=EUROPE, mode="require"),
Gate(field="country", values=["DK", "SE"], mode="any"),
Gate(field="remote", values=["remote"], mode="any")]
agent = store.save_agent("Owner", "python backend", gates)
kept = {c.uid for c in store.score_candidates(agent.id, gates) if not failed_gates(c, gates)}
assert pick(roles, "canonical", "germany", "europe", "plain") <= kept
assert roles["us"] not in kept
# ------------------------------------------------------------ the model's say
def test_the_models_remote_wins_and_its_names_are_the_area(store: Store) -> None:
# Black Forest Labs: Ashby says OnSite, the text offers remote work with
# an office week a month.
uid = add(store, "bfl", "Freiburg, Germany", board="ashby", remote="OnSite")
prep.run(store, dupes=False)
assert area(store, uid) == ("onsite", "")
store.set_extracted(uid, {"remote": "remote", "remote_where": []})
prep.run_roles(store, [uid])
assert area(store, uid) == ("remote", "Germany")
store.set_extracted(uid, {"remote": "remote", "remote_where": ["Europe"]})
prep.run_roles(store, [uid])
assert area(store, uid) == ("remote", "Europe")
# A later pull leaves the model's answer standing.
store.upsert_role(posting("bfl", "Freiburg, Germany", board="ashby", remote="OnSite"))
prep.run(store, dupes=False)
assert area(store, uid) == ("remote", "Europe")
def test_set_extracted_writes_the_remote_answer_outright(store: Store) -> None:
uid = add(store, "1", "Berlin")
prep.run(store, dupes=False)
store.set_extracted(uid, {"remote": "remote", "remote_where": ["anywhere"]})
row = store._row("SELECT remote_model, remote_where_model, prep_due FROM roles WHERE uid=?",
(uid,))
assert row is not None
assert (row["remote_model"], json.loads(row["remote_where_model"]), row["prep_due"]) == \
("remote", ["anywhere"], 1)
store.set_extracted(uid, {})
row = store._row("SELECT remote_model, remote_where_model FROM roles WHERE uid=?", (uid,))
assert row is not None and (row["remote_model"], row["remote_where_model"]) == ("", "[]")
@pytest.fixture
def config(tmp_path: Path) -> Any:
from app.config import Config
return Config(database=str(tmp_path / "roledesk.db"), extract={"enabled": True})
def test_extract_reads_the_area_once_more_and_maps_the_role_before_the_rescore(
store: Store, config: Any, monkeypatch: pytest.MonkeyPatch) -> None:
from desk import modeltask
from desk.tools import agent as desk_agent
uid = add(store, "1", "Freiburg, Germany", board="ashby", remote="OnSite")
prep.run(store, dupes=False)
agent = store.save_agent("Backend", "python backend")
store.replace_scores(agent.id, [(uid, 1.0, "")])
with store.transaction() as conn:
conn.execute("UPDATE roles SET extracted_at = '2026-09-22T00:00:00+00:00', "
"seniority_model = 'senior' WHERE uid = ?", (uid,))
assert [r.uid for r in store.extract_waiting(10)] == [uid] # never asked where
def reply(settings: Any, **kwargs: Any) -> desk_agent.Reply:
[one] = kwargs["question"]["roles"]
return desk_agent.Reply(data={"roles": [{
"uid": one["uid"], "place": "", "country": "", "remote": "remote",
"remote_where": ["Denmark", "Sweden"], "seniority": "senior", "salary_min": None,
"salary_max": None, "currency": "", "function": "", "permit": "",
"languages_required": []}]}, backend="api")
monkeypatch.setattr(desk_agent, "backend", lambda settings: "api")
monkeypatch.setattr(desk_agent, "ask_json", reply)
modeltask.run(extract.TASK, config, store)
assert area(store, uid) == ("remote", "Denmark, Sweden")
assert store.extract_waiting(10) == []
def test_the_prompt_asks_where_a_remote_hire_may_live() -> None:
props = extract.SCHEMA["properties"]["roles"]["items"]
assert "remote_where" in props["required"]
assert props["properties"]["remote_where"]["type"] == "array"
assert "office week" in extract.SYSTEM and "remote_where" in extract.SYSTEM
got = extract.fields({"remote": "remote", "remote_where": [" Europe ", "", "Europe", 3]})
assert (got["remote"], got["remote_where"]) == ("remote", ["Europe", "3"])
# ------------------------------------------------------------- suggestions
def test_remote_is_suggested_after_remote_any_and_before_the_regions(
store: Store, roles: dict[str, str]) -> None:
gaz = store.gazetteer()
areas = store.open_remote_areas()
def shown(q: str) -> list[tuple[str, str, str, int]]:
return [(s.kind, s.token, s.label, s.count)
for s in suggest(q, store.open_places(), 20, remote=areas, gaz=gaz,
remote_any=lambda: 9)]
found = shown("remote")
assert found[0] == ("remote", "remote:any", "Remote", 9)
tokens = [t for _, t, _, _ in found]
assert "remote:country:EU" in tokens and "remote:country:US" in tokens
assert "remote:anywhere" not in tokens
assert all(kind == "remote" for kind, _, _, _ in found)
assert ("remote", "remote:country:EU", "Remote · Europe", 7) in found
found = shown("denm")
assert found[:2] == [("country", "country:DK", "Denmark", 4),
("remote", "remote:country:DK", "Remote · Denmark", 4)]
assert shown("remote den")[:2] == [("remote", "remote:any", "Remote", 9),
("remote", "remote:country:DK", "Remote · Denmark", 4)]
assert shown("re") == [t for t in shown("re") if t[1] != "remote:any"]
def test_a_suggested_remote_token_finds_the_roles_it_counted(
store: Store, roles: dict[str, str]) -> None:
gaz = store.gazetteer()
for s in suggest("remote", store.open_places(), 50, remote=store.open_remote_areas(),
gaz=gaz):
assert label(s.token) == s.label
assert len(uids(store, s.token)) == s.count, s.token
def test_the_api_suggests_labels_and_filters_the_remote_tokens(tmp_path: Path) -> None:
from fastapi.testclient import TestClient
from app.config import Config, ServerConfig
from app.main import create_app
app = create_app(Config(server=ServerConfig(host="127.0.0.1", port=0),
database=tmp_path / "roledesk.db"))
store: Store = app.state.store
for key in ("europe", "us", "plain"):
line, raw = LINES[key]
add(store, key, line, **raw)
prep.run(store, dupes=False)
agent = store.save_agent("Europe", "python backend", [
Gate(field="country", values=EUROPE, mode="require")])
with TestClient(app) as client:
found = client.get("/api/suggest/places", params={"q": "remote"}).json()
assert found[0] == {"token": "remote:any", "label": "Remote", "kind": "remote",
"count": 2}
assert {"token": "remote:country:EU", "label": "Remote · Europe", "kind": "remote",
"count": 1} in found
other = client.get("/api/suggest/places", params={"q": "remote", "agent": agent.id})
assert other.json()[0]["count"] == 2
labels = client.get("/api/places/labels", params=[
("tokens", "remote:country:DK"), ("tokens", "remote:anywhere"),
("tokens", "remote:country:ZZ")]).json()
assert labels == [{"token": "remote:country:DK", "label": "Remote · Denmark"},
{"token": "remote:anywhere", "label": "Remote · anywhere"}]
rows = client.get("/api/roles", params={"places": "remote:country:DK"}).json()
assert [r["remote_where"] for r in rows["items"]] == ["Europe"]
assert client.get("/api/roles", params={"places": "remote:country:ZZ"}).status_code \
== 422
# ------------------------------------------------------------------ reach
def test_remote_from_is_remote_reach_and_never_widens_the_require_reach() -> None:
gaz = GAZ
near = Gate(field="remote_from", values=["country:DK"], mode="any")
assert reach.gate_reach(near, gaz) == reach.Reach(remote=True)
owner = Agent(id=2, name="Owner", created_at="2026-09-30", gates=[
Gate(field="country", values=EUROPE, mode="require"),
Gate(field="country", values=["DK", "SE"], mode="any"), near,
Gate(field="remote_from", values=["country:DK"], mode="require")])
assert reach.any_reach(owner, gaz) == reach.Reach(frozenset({"DK", "SE"}), remote=True)
wide = reach.require_reach(owner, gaz)
assert not wide.everywhere and not wide.remote and "DE" in wide.countries
# --------------------------------------------------------------- migration
def test_migration_27_keeps_an_older_readers_remote_as_the_hosts_word(tmp_path: Path) -> None:
path = tmp_path / "old.db"
store = Store(path)
board = add(store, "board", "Ireland")
search = Item(source_id="jobindex:1", location="https://jobindex.example/1",
title="Scientist with Experience on Remote Sensing",
body="", published_at=datetime(2026, 9, 20, tzinfo=UTC),
raw={"provider": "jobindex", "place": "København Ø", "remote": None})
search.source = "search"
store.upsert_role(search)
with sqlite3.connect(path) as conn:
conn.execute("UPDATE roles SET remote = 'remote', remote_host = '' WHERE uid = ?",
(board,))
conn.execute("UPDATE roles SET remote = 'remote', remote_host = 'remote' "
"WHERE uid = ?", (search.uid,))
conn.execute("DROP INDEX idx_role_remote_place")
conn.execute("DROP TABLE role_remote")
conn.execute("ALTER TABLE roles DROP COLUMN remote_model")
conn.execute("ALTER TABLE roles DROP COLUMN remote_where_model")
conn.execute("DELETE FROM places WHERE kind = 'continent' AND key = 'world'")
conn.execute("PRAGMA user_version = 26")
migrated = Store(path)
assert migrated.migrations_applied == [27]
assert migrated.gazetteer().anywhere is not None
row = migrated._row("SELECT remote_host, remote_model, remote_where_model FROM roles "
"WHERE uid = ?", (board,))
assert row is not None and tuple(row) == ("remote", "", None)
prep.run(migrated, dupes=False)
assert area(migrated, board) == ("remote", "Ireland")
assert area(migrated, search.uid) == ("", "")
with sqlite3.connect(path) as conn:
conn.execute("PRAGMA user_version = 26")
assert Store(path).migrations_applied == [27]
def test_a_role_waits_for_extract_until_it_was_asked_where(store: Store) -> None:
uid = add(store, "1", "Berlin")
prep.run(store, dupes=False)
with store.transaction() as conn:
conn.execute("UPDATE roles SET extracted_at = '2026-09-22', seniority_model = 'mid' "
"WHERE uid = ?", (uid,))
assert [r.uid for r in store.extract_waiting(5, [uid])] == [uid]
store.set_extracted(uid, {"seniority": "mid"})
assert store.extract_waiting(5, [uid]) == []
+9 -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
assert "idx_roles_cluster" in indexes
assert store.migrations_applied == []
assert LATEST == 26
assert LATEST == 27
# A second open finds it current and applies nothing.
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)
assert migrated.migrations_applied == [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]
assert migrated.migrations_applied == [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27]
acme = migrated.company("acme")
assert acme is not None
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)
assert migrated.migrations_applied == [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]
assert migrated.migrations_applied == [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27]
assert migrated.agent(backend.id).prompts == [ # type: ignore[union-attr]
Prompt(name="Backend", text="python backend")]
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)
assert migrated.migrations_applied == [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]
assert migrated.migrations_applied == [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27]
acme = migrated.company("acme")
assert acme is not None
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)
assert migrated.migrations_applied == [17, 18, 19, 20, 21, 22, 23, 24, 25, 26]
assert migrated.migrations_applied == [17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27]
with sqlite3.connect(path) as conn:
rows = {uid: (fold, level) for uid, fold, level in conn.execute(
"SELECT uid, place_fold, seniority FROM roles")}
@@ -688,7 +688,7 @@ def test_v19_gives_every_role_its_places_and_splits_its_level(tmp_path: Path) ->
migrated = Store(path)
assert migrated.migrations_applied == [19, 20, 21, 22, 23, 24, 25, 26]
assert migrated.migrations_applied == [19, 20, 21, 22, 23, 24, 25, 26, 27]
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 migrated.role_places(stated.uid) == []
@@ -730,7 +730,7 @@ def test_v25_clears_the_model_levels_the_ladder_splits_and_sets_the_level(
migrated = Store(path)
assert migrated.migrations_applied == [25, 26]
assert migrated.migrations_applied == [25, 26, 27]
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 "
@@ -748,12 +748,12 @@ def test_v26_adds_posting_url_empty_and_runs_twice_without_harm(tmp_path: Path)
migrated = Store(path)
assert migrated.migrations_applied == [26]
assert migrated.migrations_applied == [26, 27]
role = migrated.role(posting("a").uid)
assert role is not None and role.posting_url == ""
with sqlite3.connect(path) as conn:
conn.execute("PRAGMA user_version = 25") # the column is there already
assert Store(path).migrations_applied == [26]
assert Store(path).migrations_applied == [26, 27]
def test_a_pull_keeps_the_posting_url(store: Store) -> None:
+1 -1
View File
@@ -1227,7 +1227,7 @@ def test_list_roles_serves_the_row_projection_and_not_the_big_columns(
"uid", "company_key", "company", "title", "place", "country", "remote", "function",
"seniority", "salary_min", "salary_max", "currency", "salary_text", "salary_state",
"original_url", "posting_url", "posted_at", "score", "gated_reason", "prompt", "vote",
"voted_at", "read_at", "tags", "excerpt", "copies",
"voted_at", "read_at", "tags", "excerpt", "copies", "remote_where",
}
assert row["uid"] == uid
assert row["company"] == "Acme" and row["place"] == "Berlin, Germany"