Share the readers' place, table-lookup and country helpers, unify the employment vocabulary, and list the enrich switch with the stages

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-30 10:13:24 +02:00
1 parent ca80219bbb
commit 903b69b6d3
34 files changed
+290 -207

No files matched your search

+1 -1
View File
@@ -141,7 +141,7 @@ def test_the_experience_is_mapped_and_a_word_the_table_lacks_is_logged(
assert all(r.get("seniority", "mid") in app_models.SENIORITIES for r in rows.values())
rows = {r["source_id"]: r for r in jobylon.parse(
(FIXTURES / "jobylon-places.html").read_bytes(), "3143")}
assert rows["502"]["seniority"] == "intern" and rows["502"]["employment"] == "intern"
assert rows["502"]["seniority"] == "intern" and rows["502"]["employment"] == "internship"
def test_a_summary_is_the_teaser_unless_the_embed_says_none() -> None:
+1 -1
View File
@@ -56,7 +56,7 @@ def test_it_reads_title_company_town_date_and_teaser() -> None:
def test_it_reads_hybrid_and_remote_from_the_town_line() -> None:
from plugins.readers._words import remote_word
from plugins.readers._shared import remote_word
assert remote_word("Birkerød, Hybrid position") == "hybrid"
assert remote_word("Nordhavn og mulighed for hjemmearbejde") == "hybrid"
+85
View File
@@ -0,0 +1,85 @@
"""The helpers the host modules share, and the one employment vocabulary."""
from __future__ import annotations
import logging
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from plugins import readers # noqa: E402
from plugins.readers import _shared # noqa: E402
from plugins.readers._shared import ( # noqa: E402
EMPLOYMENTS,
add_place,
country_if_single,
place,
remote_word,
table_word,
)
#: The module-level names a reader keeps its employment words in.
_TABLES = ("_EMPLOYMENT", "_CONTRACT", "_SCHEDULE")
def test_every_employment_table_maps_into_the_shared_vocabulary() -> None:
found = 0
for name, module in readers.READERS.items():
for table_name in _TABLES:
table = getattr(module, table_name, None)
if table is None:
continue
found += 1
values = table.values() if isinstance(table, dict) else [v for _k, v in table]
# "" is a known word that names no employment ("permanent").
assert set(values) <= {*EMPLOYMENTS, ""}, (name, table_name)
assert found >= 15
def test_the_vocabulary_is_the_documented_one() -> None:
assert EMPLOYMENTS == ("full_time", "part_time", "contract", "temporary", "internship",
"freelance")
def test_place_is_remote_on_the_word_and_otherwise_as_stated() -> None:
assert place("Remote (DE)") == {"text": "Remote (DE)", "remote": True}
assert place("Berlin, remote") == {"text": "Berlin, remote", "remote": True}
assert place("Berlin") == {"text": "Berlin", "remote": None}
assert place("Berlin", False) == {"text": "Berlin", "remote": False}
assert place("Remote", False)["remote"] is True
assert place("Remotely", None)["remote"] is None
def test_add_place_skips_empty_and_repeated_texts_and_keeps_order() -> None:
found: list = []
for text in ("Berlin", "", "Oslo", "Berlin"):
add_place(found, place(text))
assert [p["text"] for p in found] == ["Berlin", "Oslo"]
def test_table_word_maps_ignores_case_and_logs_only_unknown_words(caplog) -> None:
table = {"full-time": "full_time", "permanent": ""}
log = logging.getLogger("plugins.readers.acme")
with caplog.at_level(logging.DEBUG, logger=log.name):
assert table_word(table, " Full-Time ", log, "type") == "full_time"
assert table_word(table, "Permanent", log, "type") is None
assert table_word(table, None, log, "type") is None
assert not caplog.records
assert table_word(table, "Odd", log, "type") is None
assert [r.getMessage() for r in caplog.records] == ["acme: unknown type 'Odd'"]
def test_country_if_single_needs_exactly_one_code() -> None:
assert country_if_single({"DE"}) == "DE"
assert country_if_single({"DE", "SE"}) is None
assert country_if_single(set()) is None
def test_remote_word_reads_danish_swedish_and_english() -> None:
assert remote_word("Remote, Danmark") == "remote"
assert remote_word("Birkerød, Hybrid position") == "hybrid"
assert remote_word("Hedehusene") is None
assert _shared.remote_word is remote_word
+17 -3
View File
@@ -143,7 +143,7 @@ def client(app: FastAPI) -> Iterator[TestClient]:
yield c
def test_get_stages_lists_both_with_their_source_model_and_who_answers(
def test_get_stages_lists_all_three_with_their_source_model_and_who_answers(
client: TestClient, monkeypatch: pytest.MonkeyPatch) -> None:
answered_by(monkeypatch, "api")
res = client.get("/api/stages")
@@ -156,6 +156,8 @@ def test_get_stages_lists_both_with_their_source_model_and_who_answers(
{"name": "summarise", "on": False, "source": "config",
"model": "claude-haiku-4-5-20251001", "backend": "api",
"answer": "answered by the Claude API"},
{"name": "enrich", "on": True, "source": "config", "model": "", "backend": "",
"answer": "reads role pages, asks no model"},
]
@@ -164,7 +166,7 @@ def test_who_answers_is_said_for_the_api_claude_code_and_nobody(
answers = {}
for backend in ("api", "claude_code", ""):
answered_by(monkeypatch, backend)
[first, second] = client.get("/api/stages").json()
[first, second, _enrich] = client.get("/api/stages").json()
assert first["backend"] == second["backend"] == backend
answers[backend] = first["answer"]
@@ -191,6 +193,18 @@ def test_put_stores_the_setting_returns_the_same_shape_and_starts_nothing(
assert res.json()["on"] is False and store.state["stage:summarise"] == "off"
def test_the_enrich_switch_is_listed_and_stored_like_the_others(
client: TestClient, store: Store) -> None:
res = client.put("/api/stages/enrich", json={"on": False})
assert res.status_code == 200
assert res.json()["name"] == "enrich" and res.json()["on"] is False
assert store.state["stage:enrich"] == "off"
listed = {stage["name"]: stage for stage in client.get("/api/stages").json()}
assert list(listed) == ["extract", "summarise", "enrich"]
assert listed["enrich"]["on"] is False and listed["enrich"]["source"] == "stored"
def test_an_unknown_stage_is_404_and_a_bad_body_is_422(client: TestClient) -> None:
assert client.put("/api/stages/embed", json={"on": True}).status_code == 404
assert client.put("/api/stages/extract", json={"on": "sometimes"}).status_code == 422
@@ -200,7 +214,7 @@ def test_an_unknown_stage_is_404_and_a_bad_body_is_422(client: TestClient) -> No
def test_agent_backend_off_is_named_rather_than_blamed_on_missing_keys(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, store: Store) -> None:
off = Config(database=str(tmp_path / "roledesk.db"), agent={"backend": "off"})
[first, _] = stages.describe(off, store)
[first, *_] = stages.describe(off, store)
assert first.backend == "" and "agent.backend" in first.answer