Merge branch 'main' into wp0-hosts
This commit is contained in:
commit
a7bb6c20ae
17 files changed
+1618
-313
No files matched your search
@@ -15,6 +15,7 @@ from fastapi.testclient import TestClient
|
||||
|
||||
from app.config import Config, ServerConfig
|
||||
from app.main import create_app
|
||||
from app.models import HAND_REASONS
|
||||
from app.storage import Store
|
||||
from desk.models import Item
|
||||
|
||||
@@ -96,6 +97,21 @@ def test_the_watchlist_is_the_third_tab_and_a_shell(client: TestClient) -> None:
|
||||
assert nav.count('aria-current="page"') == 1
|
||||
|
||||
|
||||
def test_the_watchlist_has_new_company_and_the_form_it_opens(client: TestClient) -> None:
|
||||
page = client.get("/watchlist").text
|
||||
assert '<button type="button" id="w-add">New company</button>' in page
|
||||
assert 'id="watchlist-answer"' in page
|
||||
template = page.split('<template id="company-form-template">', 1)[1].split("</template>", 1)[0]
|
||||
for part in ('id="company-form"', 'id="cf-name" required', 'type="url" id="cf-url"',
|
||||
'id="cf-reason"', 'id="cf-notes"', 'id="cf-cancel"', 'type="submit"'):
|
||||
assert part in template, part
|
||||
# The reason's options are the store's reasons, since a row's badge reads
|
||||
# its words off them and a PATCH sends their values.
|
||||
options = template.split('<select id="cf-reason">', 1)[1].split("</select>", 1)[0]
|
||||
values = [v.split('"', 1)[0] for v in options.split('<option value="')[1:]]
|
||||
assert sorted(values) == sorted(HAND_REASONS)
|
||||
|
||||
|
||||
def test_the_read_page_of_its_own_is_gone(client: TestClient) -> None:
|
||||
assert client.get("/static/role.js").status_code == 404
|
||||
other = client.get("/applications").text
|
||||
|
||||
+245
-4
@@ -83,6 +83,16 @@ def test_set_board_attaches_a_board_to_a_row_without_one(store: Store, boards: B
|
||||
"ashby", "acme", "acme.example", "met them", "https://acme.example/careers")
|
||||
|
||||
|
||||
def test_set_board_clears_the_reason_a_company_was_read_by_hand(
|
||||
store: Store, boards: Boards) -> None:
|
||||
store.add_company("Acme", careers_url="https://acme.example/careers", hand_reason="unread")
|
||||
sources.set_board(store, "acme", "ashby:acme")
|
||||
acme = store.company("acme")
|
||||
assert acme is not None
|
||||
# The link a person set stays; the reason goes with the board's arrival.
|
||||
assert (acme.hand_reason, acme.careers_url) == ("", "https://acme.example/careers")
|
||||
|
||||
|
||||
def test_set_board_replaces_a_board_and_closes_its_open_roles(
|
||||
store: Store, boards: Boards) -> None:
|
||||
old, _, _ = sources.set_board(store, "acme", "greenhouse:acme", name="Acme")
|
||||
@@ -110,7 +120,7 @@ def test_a_board_that_does_not_answer_or_is_unknown_is_refused(
|
||||
with pytest.raises(ValueError, match="did not answer"):
|
||||
sources.set_board(store, "", "greenhouse:gone", name="Gone")
|
||||
with pytest.raises(ValueError, match="host:slug"):
|
||||
sources.set_board(store, "", "workday:gone", name="Gone")
|
||||
sources.set_board(store, "", "taleo:gone", name="Gone")
|
||||
with pytest.raises(ValueError, match="needs a name"):
|
||||
sources.set_board(store, "nobody", "greenhouse:acme")
|
||||
with pytest.raises(ValueError, match="is not the company"):
|
||||
@@ -161,20 +171,34 @@ def test_add_discovered_records_an_unreadable_host_with_its_slug(
|
||||
careers_url="https://acme.example/careers")
|
||||
assert sources.add_discovered(store, "Acme", "acme.example", found) == ("acme", 0)
|
||||
store.update_company("acme", notes="keep")
|
||||
newer = Discovery(ats="workday", ats_slug="acme-inc",
|
||||
newer = Discovery(ats="taleo", ats_slug="acme-inc",
|
||||
careers_url="https://acme.example/jobs")
|
||||
assert sources.add_discovered(store, "Acme", "acme.example", newer) == ("acme", 0)
|
||||
acme = store.company("acme")
|
||||
assert acme is not None
|
||||
# The host and slug follow what discovery found last; the link, once
|
||||
# there, is kept, since a person may have typed it.
|
||||
assert (acme.ats, acme.ats_slug, acme.careers_url, acme.notes) == (
|
||||
"workday", "acme-inc", "https://acme.example/jobs", "keep")
|
||||
"taleo", "acme-inc", "https://acme.example/careers", "keep")
|
||||
|
||||
|
||||
def test_add_discovered_fills_a_link_only_where_there_is_none(
|
||||
store: Store, boards: Boards) -> None:
|
||||
store.add_company("Acme", ats="teamtailor")
|
||||
found = Discovery(ats="taleo", ats_slug="acme", careers_url="https://acme.example/jobs")
|
||||
sources.add_discovered(store, "Acme", "acme.example", found)
|
||||
assert store.company("acme").careers_url == "https://acme.example/jobs" # type: ignore[union-attr]
|
||||
|
||||
store.update_company("acme", careers_url="https://typed.example/by-hand")
|
||||
sources.add_discovered(store, "Acme", "acme.example", found)
|
||||
assert store.company("acme").careers_url == "https://typed.example/by-hand" # type: ignore[union-attr]
|
||||
|
||||
|
||||
def test_add_discovered_keeps_a_board_when_nothing_readable_was_found(
|
||||
store: Store, boards: Boards) -> None:
|
||||
sources.set_board(store, "", "greenhouse:acme", name="Acme")
|
||||
with pytest.raises(ValueError, match="nothing changed"):
|
||||
sources.add_discovered(store, "Acme", "acme.example", Discovery(ats="workday"))
|
||||
sources.add_discovered(store, "Acme", "acme.example", Discovery(ats="taleo"))
|
||||
acme = store.company("acme")
|
||||
assert acme is not None and acme.ats == "greenhouse"
|
||||
|
||||
@@ -240,6 +264,143 @@ def test_a_seed_board_that_clashes_still_lands_the_company(
|
||||
assert store.company_subscription("acme-two") is None
|
||||
|
||||
|
||||
def test_a_seed_rerun_fills_an_empty_link_and_reason_and_never_overwrites_one(
|
||||
store: Store, boards: Boards, tmp_path: Path) -> None:
|
||||
store.add_company("Bare", key="bare")
|
||||
store.add_company("Typed", key="typed", careers_url="https://typed.example/by-hand",
|
||||
hand_reason="blocked", notes="mine")
|
||||
seed = _seed(tmp_path,
|
||||
{"name": "Bare", "careers_url": "https://bare.example/jobs",
|
||||
"hand_reason": "unread"},
|
||||
{"name": "Typed", "careers_url": "https://seed.example/jobs",
|
||||
"hand_reason": "robots"},
|
||||
{"name": "Fresh", "careers_url": "https://fresh.example/jobs",
|
||||
"hand_reason": "key"})
|
||||
|
||||
result = sources.seed_companies(store, seed)
|
||||
|
||||
assert (result["added"], result["skipped"], result["problems"]) == (1, 2, [])
|
||||
got = {k: (c.careers_url, c.hand_reason, c.notes) for k in ("bare", "typed", "fresh")
|
||||
if (c := store.company(k)) is not None}
|
||||
assert got == {
|
||||
"bare": ("https://bare.example/jobs", "unread", ""),
|
||||
"typed": ("https://typed.example/by-hand", "blocked", "mine"),
|
||||
"fresh": ("https://fresh.example/jobs", "key", "")}
|
||||
# Run again, nothing moves.
|
||||
assert sources.seed_companies(store, seed)["added"] == 0
|
||||
assert store.company("bare").hand_reason == "unread" # type: ignore[union-attr]
|
||||
|
||||
|
||||
def test_a_seed_reason_outside_the_vocabulary_is_a_problem_not_a_row_value(
|
||||
store: Store, boards: Boards, tmp_path: Path) -> None:
|
||||
result = sources.seed_companies(
|
||||
store, _seed(tmp_path, {"name": "Odd", "hand_reason": "lazy"}))
|
||||
assert result["problems"] == ["odd: 'lazy' is not a hand_reason; kept without it"]
|
||||
assert store.company("odd").hand_reason == "" # type: ignore[union-attr]
|
||||
|
||||
|
||||
def test_a_seed_link_reaches_a_row_whose_board_clashes(
|
||||
store: Store, boards: Boards, tmp_path: Path) -> None:
|
||||
sources.set_board(store, "acme", "greenhouse:acme", name="Acme")
|
||||
store.add_company("Twin", key="twin")
|
||||
result = sources.seed_companies(store, _seed(
|
||||
tmp_path, {"name": "Twin", "board": "greenhouse:acme",
|
||||
"careers_url": "https://twin.example/jobs"}))
|
||||
assert len(result["problems"]) == 1
|
||||
assert store.company("twin").careers_url == "https://twin.example/jobs" # type: ignore[union-attr]
|
||||
|
||||
|
||||
# ------------------------------------------------------------- by hand
|
||||
|
||||
def test_a_company_added_by_hand_has_no_board_and_a_checked_link(store: Store) -> None:
|
||||
company = sources.add_by_hand(store, "Revolut Ltd", careers_url=" https://r.example/jobs ",
|
||||
notes="login wall")
|
||||
assert (company.key, company.hand_reason, company.careers_url, company.notes) == (
|
||||
"revolut", "added", "https://r.example/jobs", "login wall")
|
||||
assert store.company_subscription("revolut") is None
|
||||
with pytest.raises(sources.Conflict, match="on the list already"):
|
||||
sources.add_by_hand(store, "REVOLUT")
|
||||
for link in ("javascript:alert(1)", "r.example/jobs", "https://", "ftp://r.example"):
|
||||
with pytest.raises(ValueError, match="http"):
|
||||
sources.add_by_hand(store, "Other", careers_url=link)
|
||||
with pytest.raises(ValueError, match="hand_reason"):
|
||||
sources.add_by_hand(store, "Other", hand_reason="lazy")
|
||||
with pytest.raises(ValueError, match="needs a name"):
|
||||
sources.add_by_hand(store, " ")
|
||||
assert [c.key for c in store.companies()] == ["revolut"]
|
||||
|
||||
|
||||
def test_edit_company_changes_what_it_is_given_and_renames_only_without_a_board(
|
||||
store: Store, boards: Boards) -> None:
|
||||
sources.add_by_hand(store, "Acme", notes="old")
|
||||
edited = sources.edit_company(store, "acme", name="Acme GmbH", hand_reason="gone")
|
||||
assert (edited.key, edited.name, edited.notes, edited.hand_reason) == (
|
||||
"acme", "Acme GmbH", "old", "gone")
|
||||
with pytest.raises(ValueError, match="needs a name"):
|
||||
sources.edit_company(store, "acme", name=" ")
|
||||
with pytest.raises(ValueError, match="not a field"):
|
||||
sources.edit_company(store, "acme", ats="lever")
|
||||
with pytest.raises(KeyError):
|
||||
sources.edit_company(store, "nobody", notes="x")
|
||||
|
||||
sources.set_board(store, "acme", "greenhouse:acme")
|
||||
with pytest.raises(sources.Conflict, match="detach"):
|
||||
sources.edit_company(store, "acme", name="Acme Labs")
|
||||
# The name it has, and any other field, are no rename.
|
||||
assert sources.edit_company(store, "acme", name="Acme GmbH", notes="new").notes == "new"
|
||||
sources.detach_board(store, "acme")
|
||||
with pytest.raises(sources.Conflict):
|
||||
sources.edit_company(store, "acme", name="Acme Labs")
|
||||
|
||||
|
||||
def test_remove_company_refuses_a_board_shown_and_open_roles(
|
||||
store: Store, boards: Boards) -> None:
|
||||
agent = store.save_agent("A")
|
||||
sources.add_by_hand(store, "Hand")
|
||||
store.set_affinity(agent.id, "hand", 2)
|
||||
sources.remove_company(store, "hand")
|
||||
assert store.company("hand") is None
|
||||
assert store.company("hand", agent.id) is None
|
||||
with pytest.raises(KeyError):
|
||||
sources.remove_company(store, "hand")
|
||||
|
||||
sub, _found, _closed = sources.set_board(store, "acme", "greenhouse:acme", name="Acme")
|
||||
with pytest.raises(sources.Conflict, match="detach the board"):
|
||||
sources.remove_company(store, "acme")
|
||||
store.upsert_role(posting("1"), sub)
|
||||
sources.detach_board(store, "acme") # closes the role: no board, none open
|
||||
sources.remove_company(store, "acme")
|
||||
assert store.company("acme") is None
|
||||
# The detached subscription stays and is found again by a company of that name.
|
||||
assert store.company_subscription("acme") is not None
|
||||
|
||||
store.add_company("Open", key="open")
|
||||
other = store.add_subscription("search", "jobindex:x", label="x", board="jobindex")
|
||||
item = posting("2")
|
||||
item.raw = {"company": "Open"}
|
||||
store.upsert_role(item, other)
|
||||
with pytest.raises(ValueError, match="open roles"):
|
||||
sources.remove_company(store, "open")
|
||||
|
||||
|
||||
def test_by_hand_lists_the_unboarded_never_opened_first(
|
||||
store: Store, boards: Boards) -> None:
|
||||
sources.add_by_hand(store, "Zeta")
|
||||
sources.add_by_hand(store, "Beta")
|
||||
sources.add_by_hand(store, "Old")
|
||||
sources.add_by_hand(store, "Recent")
|
||||
store.update_company("old", careers_opened_at="2026-08-01T00:00:00+00:00")
|
||||
store.update_company("recent", careers_opened_at="2026-09-20T00:00:00+00:00")
|
||||
sources.set_board(store, "read", "greenhouse:acme", name="Read") # a board: not listed
|
||||
store.add_company("Pleo", key="pleo", ats="teamtailor") # unread, no reason: listed
|
||||
store.add_company("Quiet", key="quiet") # from a search only
|
||||
sources.set_board(store, "gone", "ashby:acme", name="Gone")
|
||||
sources.detach_board(store, "gone") # detached: listed
|
||||
|
||||
assert [c.key for c in sources.by_hand(store)] == [
|
||||
"beta", "gone", "pleo", "zeta", "old", "recent"]
|
||||
|
||||
|
||||
# -------------------------------------------------------------------- CLI
|
||||
|
||||
def _cli(tmp_path: Path, *argv: str) -> int:
|
||||
@@ -289,6 +450,86 @@ def test_cli_seed_prints_counts_and_problems(
|
||||
assert "companies seed: odd: 'nosuch:odd' is not a known board" in captured.err
|
||||
|
||||
|
||||
def test_cli_add_with_one_name_lists_a_company_by_hand_and_with_two_follows_a_board(
|
||||
store: Store, boards: Boards, tmp_path: Path,
|
||||
capsys: pytest.CaptureFixture[str]) -> None:
|
||||
assert _cli(tmp_path, "add", "Revolut", "--careers-url", "https://r.example/jobs",
|
||||
"--note", "login wall") == 0
|
||||
assert json.loads(capsys.readouterr().out) == {"key": "revolut", "hand_reason": "added"}
|
||||
revolut = store.company("revolut")
|
||||
assert revolut is not None
|
||||
assert (revolut.careers_url, revolut.notes, revolut.hand_reason) == (
|
||||
"https://r.example/jobs", "login wall", "added")
|
||||
assert _cli(tmp_path, "add", "Meta", "--reason", "blocked") == 0
|
||||
assert store.company("meta").hand_reason == "blocked" # type: ignore[union-attr]
|
||||
capsys.readouterr()
|
||||
|
||||
assert _cli(tmp_path, "add", "Revolut") == 1
|
||||
assert "on the list already" in capsys.readouterr().err
|
||||
assert _cli(tmp_path, "add", "Odd", "--careers-url", "javascript:alert(1)") == 1
|
||||
assert "http" in capsys.readouterr().err
|
||||
with pytest.raises(SystemExit): # argparse refuses the reason
|
||||
_cli(tmp_path, "add", "Odd", "--reason", "lazy")
|
||||
capsys.readouterr()
|
||||
assert store.company("odd") is None
|
||||
|
||||
# Two words are the board and the company, as before.
|
||||
assert _cli(tmp_path, "add", "greenhouse:acme", "Acme") == 0
|
||||
assert json.loads(capsys.readouterr().out) == {
|
||||
"key": "acme", "board": "greenhouse:acme", "roles": 3}
|
||||
|
||||
|
||||
def test_cli_edit_checked_and_remove_a_company_by_hand(
|
||||
store: Store, boards: Boards, tmp_path: Path,
|
||||
capsys: pytest.CaptureFixture[str]) -> None:
|
||||
store.add_company("Acme", key="acme", notes="keep", hand_reason="unread")
|
||||
assert _cli(tmp_path, "edit", "acme", "--careers-url", "https://acme.example/jobs",
|
||||
"--reason", "robots") == 0
|
||||
assert json.loads(capsys.readouterr().out) == {
|
||||
"key": "acme", "name": "Acme", "careers_url": "https://acme.example/jobs",
|
||||
"notes": "keep", "hand_reason": "robots"}
|
||||
assert _cli(tmp_path, "edit", "acme", "--note", "") == 0
|
||||
assert store.company("acme").notes == "" # type: ignore[union-attr]
|
||||
assert _cli(tmp_path, "edit", "acme", "--careers-url", "ftp://x") == 1
|
||||
assert "http" in capsys.readouterr().err
|
||||
assert _cli(tmp_path, "edit", "nobody", "--note", "x") == 1
|
||||
assert "no company 'nobody'" in capsys.readouterr().err
|
||||
|
||||
assert _cli(tmp_path, "checked", "acme") == 0
|
||||
stamp = json.loads(capsys.readouterr().out)["careers_opened_at"]
|
||||
assert stamp and store.company("acme").careers_opened_at == stamp # type: ignore[union-attr]
|
||||
assert _cli(tmp_path, "checked", "nobody") == 1
|
||||
capsys.readouterr()
|
||||
|
||||
sources.set_board(store, "read", "greenhouse:acme", name="Read")
|
||||
assert _cli(tmp_path, "remove", "read") == 1
|
||||
assert "detach the board first" in capsys.readouterr().err
|
||||
assert _cli(tmp_path, "remove", "acme") == 0
|
||||
assert store.company("acme") is None
|
||||
assert _cli(tmp_path, "remove", "acme") == 1
|
||||
|
||||
|
||||
def test_cli_by_hand_prints_never_opened_first_then_the_oldest_and_the_watch_rating(
|
||||
store: Store, boards: Boards, tmp_path: Path,
|
||||
capsys: pytest.CaptureFixture[str]) -> None:
|
||||
store.add_company("Recent", careers_url="https://recent.example/jobs",
|
||||
hand_reason="gone")
|
||||
store.add_company("Old", hand_reason="robots")
|
||||
store.add_company("Never", careers_url="https://never.example/jobs", hand_reason="added")
|
||||
store.update_company("recent", careers_opened_at="2026-09-20T08:00:00+00:00", watch=0)
|
||||
store.update_company("old", careers_opened_at="2026-08-01T08:00:00+00:00", watch=1)
|
||||
sources.set_board(store, "read", "greenhouse:acme", name="Read")
|
||||
|
||||
assert _cli(tmp_path, "by-hand") == 0
|
||||
lines = capsys.readouterr().out.splitlines()
|
||||
assert [ln.split()[0] for ln in lines[:-1]] == ["Never", "Old", "Recent"]
|
||||
assert lines[0].split() == ["Never", "added", "-", "never", "https://never.example/jobs"]
|
||||
assert lines[1].split() == ["Old", "robots", "yes", "2026-08-01"]
|
||||
assert lines[2].split() == ["Recent", "gone", "no", "2026-09-20",
|
||||
"https://recent.example/jobs"]
|
||||
assert lines[-1] == "3 by hand"
|
||||
|
||||
|
||||
def test_replacing_or_detaching_a_board_forgets_that_it_was_failing(
|
||||
store: Store, boards: Boards) -> None:
|
||||
from app.jobs.pull import FAILING, failing_boards
|
||||
|
||||
+61
-6
@@ -69,7 +69,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 == 15
|
||||
assert LATEST == 16
|
||||
# A second open finds it current and applies nothing.
|
||||
assert Store(path).migrations_applied == []
|
||||
|
||||
@@ -88,9 +88,16 @@ def _columns(path: Path, table: str) -> list[tuple[str, str, int, str]]:
|
||||
return [(r[1], r[2], r[3], r[4]) for r in conn.execute(f"PRAGMA table_info({table})")]
|
||||
|
||||
|
||||
def _undo_v16(conn: sqlite3.Connection) -> None:
|
||||
"""A fresh file put back to the v15 shape: no by-hand reason on a
|
||||
company."""
|
||||
conn.execute("ALTER TABLE companies DROP COLUMN hand_reason")
|
||||
|
||||
|
||||
def _undo_v15(conn: sqlite3.Connection) -> None:
|
||||
"""A fresh file put back to the v14 shape: no Watchlist columns on a
|
||||
company."""
|
||||
_undo_v16(conn)
|
||||
conn.execute("ALTER TABLE companies DROP COLUMN watch")
|
||||
conn.execute("ALTER TABLE companies DROP COLUMN careers_opened_at")
|
||||
|
||||
@@ -98,7 +105,7 @@ def _undo_v15(conn: sqlite3.Connection) -> None:
|
||||
def _undo_v14(conn: sqlite3.Connection) -> None:
|
||||
"""A fresh file put back to the v13 shape: an agent's intent and its
|
||||
cached vector on the agent row, no prompts, no prompt on a score. Every
|
||||
downgrade below starts here, after `_undo_v15`, since v15 is the last
|
||||
downgrade below starts here, after `_undo_v15`, since v16 is the last
|
||||
migration."""
|
||||
_undo_v15(conn)
|
||||
conn.execute("DROP TABLE agent_prompts")
|
||||
@@ -146,7 +153,7 @@ def test_a_v14_file_gains_the_watchlist_columns_and_leaves_companies_unrated(
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
assert migrated.migrations_applied == [15]
|
||||
assert migrated.migrations_applied == [15, 16]
|
||||
acme = migrated.company("acme")
|
||||
assert acme is not None
|
||||
assert (acme.ats, acme.careers_url) == ("teamtailor", "https://a.example")
|
||||
@@ -351,7 +358,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]
|
||||
assert migrated.migrations_applied == [14, 15, 16]
|
||||
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]
|
||||
@@ -365,6 +372,24 @@ def test_v14_makes_each_intent_the_agents_one_prompt_with_its_vector(tmp_path: P
|
||||
assert not {"intent", "intent_key", "intent_vec"} & columns
|
||||
|
||||
|
||||
def test_v16_gives_a_company_no_reason_and_keeps_its_row(tmp_path: Path) -> None:
|
||||
fresh, path = tmp_path / "fresh.db", tmp_path / "v15.db"
|
||||
Store(fresh)
|
||||
Store(path).add_company("Acme", careers_url="https://acme.example/jobs", notes="met them")
|
||||
with sqlite3.connect(path) as conn:
|
||||
_undo_v16(conn)
|
||||
conn.execute("PRAGMA user_version = 15")
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
assert migrated.migrations_applied == [16]
|
||||
acme = migrated.company("acme")
|
||||
assert acme is not None
|
||||
assert (acme.careers_url, acme.notes, acme.hand_reason) == (
|
||||
"https://acme.example/jobs", "met them", "")
|
||||
assert sorted(_columns(path, "companies")) == sorted(_columns(fresh, "companies"))
|
||||
|
||||
|
||||
def test_prompts_are_saved_replaced_reordered_and_deleted(store: Store) -> None:
|
||||
ai = Prompt(name="AI leadership", text="Head of AI")
|
||||
fde = Prompt(name="Forward deployed", text="FDE lead")
|
||||
@@ -450,13 +475,13 @@ def test_posted_host_reads_board_then_provider() -> None:
|
||||
|
||||
|
||||
def test_posted_at_trusts_only_a_known_host() -> None:
|
||||
assert "greenhouse" in TRUSTED_POSTED_HOSTS and "workday" not in TRUSTED_POSTED_HOSTS
|
||||
assert "greenhouse" in TRUSTED_POSTED_HOSTS and "taleo" not in TRUSTED_POSTED_HOSTS
|
||||
early = "2020-01-01T00:00:00+00:00"
|
||||
late = "2026-09-23T09:00:00+00:00"
|
||||
# A trusted host's earlier date wins over first_seen...
|
||||
assert posted_at(early, late, "greenhouse") == early
|
||||
# ...but an untrusted (or unknown) host never moves it off first_seen.
|
||||
assert posted_at(early, late, "workday") == late
|
||||
assert posted_at(early, late, "taleo") == late
|
||||
assert posted_at(early, late, "") == late
|
||||
|
||||
|
||||
@@ -1011,6 +1036,36 @@ def test_companies_crud(store: Store) -> None:
|
||||
assert store.company("acme") is None
|
||||
|
||||
|
||||
def test_a_company_takes_a_reason_from_the_vocabulary(store: Store) -> None:
|
||||
assert store.add_company("Acme", hand_reason="robots").hand_reason == "robots"
|
||||
assert store.add_company("Plain").hand_reason == ""
|
||||
with pytest.raises(ValueError, match="hand_reason is one of"):
|
||||
store.add_company("Odd", hand_reason="lazy")
|
||||
assert store.company("odd") is None
|
||||
assert store.update_company("acme", hand_reason="").hand_reason == ""
|
||||
with pytest.raises(ValueError, match="hand_reason is one of"):
|
||||
store.update_company("acme", hand_reason="lazy")
|
||||
assert store.company("acme").hand_reason == "" # type: ignore[union-attr]
|
||||
|
||||
|
||||
def test_removing_a_company_takes_every_agents_stance_on_it(store: Store) -> None:
|
||||
store.add_company("Acme")
|
||||
store.add_company("Other")
|
||||
one, two = store.save_agent("One"), store.save_agent("Two")
|
||||
store.set_affinity(one.id, "acme", 2)
|
||||
store.set_affinity(two.id, "acme", -1)
|
||||
store.set_affinity(one.id, "other", 1)
|
||||
|
||||
assert store.remove_company("acme") is True
|
||||
assert store.remove_company("acme") is False
|
||||
|
||||
# Added again under the same name, it starts neutral for everyone.
|
||||
store.add_company("Acme")
|
||||
assert store.company("acme", one.id).affinity == 0 # type: ignore[union-attr]
|
||||
assert store.company("acme", two.id).affinity == 0 # type: ignore[union-attr]
|
||||
assert store.company("other", one.id).affinity == 1 # type: ignore[union-attr]
|
||||
|
||||
|
||||
def test_affinity_is_per_agent(store: Store) -> None:
|
||||
store.add_company("Acme", key="acme")
|
||||
store.add_company("Other", key="other")
|
||||
|
||||
+159
-5
@@ -421,25 +421,27 @@ def test_companies_lists_board_and_open_role_count(
|
||||
store.add_company("Acme", key="acme", ats="greenhouse", country="DK")
|
||||
store.upsert_role(posting("1", company="Acme"), sub)
|
||||
store.add_company("Other", key="other", domain="other.example") # no board found
|
||||
store.add_company("Novo", key="novo", ats="successfactors", # followed, not readable
|
||||
store.add_company("Novo", key="novo", ats="taleo", # followed, not readable
|
||||
careers_url="https://novo.example/careers")
|
||||
|
||||
res = client.get("/api/companies")
|
||||
assert res.status_code == 200
|
||||
[row] = [c for c in res.json() if c["key"] == "acme"]
|
||||
assert row == {"key": "acme", "name": "Acme", "board": "greenhouse",
|
||||
assert row == {"key": "acme", "name": "Acme", "notes": "", "board": "greenhouse",
|
||||
"subscription_id": sub.id, "on": True, "affinity": 0, "open_roles": 1,
|
||||
"ats": "greenhouse", "ats_slug": "", "careers_url": "",
|
||||
"country": "DK", "city": "", "domain": "", "watch": None,
|
||||
"careers_opened_at": "", "failing_since": "", "failing_reason": "",
|
||||
"from_search": False}
|
||||
"from_search": False, "hand_reason": "", "by_hand": False}
|
||||
[other] = [c for c in res.json() if c["key"] == "other"]
|
||||
assert (other["board"], other["subscription_id"], other["on"], other["ats"]) == (
|
||||
"", None, None, "")
|
||||
[novo] = [c for c in res.json() if c["key"] == "novo"]
|
||||
assert (novo["board"], novo["subscription_id"], novo["ats"], novo["careers_url"]) == (
|
||||
"", None, "successfactors", "https://novo.example/careers")
|
||||
"", None, "taleo", "https://novo.example/careers")
|
||||
assert not any(c["from_search"] for c in res.json())
|
||||
# Companies with no board shown, unread or not, are the list checked by hand.
|
||||
assert {c["key"] for c in res.json() if c["by_hand"]} == {"other", "novo"}
|
||||
|
||||
|
||||
def test_judging_a_company_known_only_from_a_search_creates_its_row(
|
||||
@@ -1262,10 +1264,162 @@ def test_a_companys_board_is_set_replaced_and_detached(
|
||||
assert client.post("/api/companies/nope/board",
|
||||
json={"board": "lever:acme"}).status_code == 404
|
||||
assert client.delete("/api/companies/nope/board").status_code == 404
|
||||
bad = client.post("/api/companies/acme/board", json={"board": "workday:acme"})
|
||||
bad = client.post("/api/companies/acme/board", json={"board": "taleo:acme"})
|
||||
assert bad.status_code == 422 and "host:slug" in bad.json()["detail"]
|
||||
|
||||
|
||||
def test_a_company_is_added_by_hand_with_a_reason_and_a_link(
|
||||
client: TestClient, store: Store) -> None:
|
||||
res = client.post("/api/companies", json={
|
||||
"name": "Revolut Ltd", "careers_url": " https://revolut.example/careers ",
|
||||
"notes": "wants a login"})
|
||||
assert res.status_code == 201, res.text
|
||||
assert res.json() == {
|
||||
"key": "revolut", "name": "Revolut Ltd", "domain": "", "notes": "wants a login",
|
||||
"board": "", "subscription_id": None, "on": None, "affinity": 0, "open_roles": 0,
|
||||
"ats": "", "ats_slug": "", "careers_url": "https://revolut.example/careers",
|
||||
"country": "", "city": "", "watch": None, "careers_opened_at": "",
|
||||
"failing_since": "", "failing_reason": "", "from_search": False,
|
||||
"hand_reason": "added", "by_hand": True}
|
||||
assert store.company("revolut").hand_reason == "added" # type: ignore[union-attr]
|
||||
|
||||
other = client.post("/api/companies", json={"name": "Meta", "hand_reason": "blocked"})
|
||||
assert other.status_code == 201 and other.json()["hand_reason"] == "blocked"
|
||||
# The key comes from the name, so a legal suffix or case is the same company.
|
||||
assert client.post("/api/companies", json={"name": "REVOLUT"}).status_code == 409
|
||||
assert store.company("revolut").notes == "wants a login" # type: ignore[union-attr]
|
||||
|
||||
|
||||
def test_adding_a_company_by_hand_refuses_a_bad_link_reason_or_name(
|
||||
client: TestClient, store: Store) -> None:
|
||||
for link in ("javascript:alert(1)", "ftp://x.example/jobs", "revolut.example/careers",
|
||||
"https://"):
|
||||
res = client.post("/api/companies", json={"name": "Revolut", "careers_url": link})
|
||||
assert res.status_code == 422, link
|
||||
assert client.post("/api/companies", json={"name": "Revolut", "careers_url": ""}
|
||||
).status_code == 201
|
||||
assert client.post("/api/companies", json={"name": "Meta", "hand_reason": "lazy"}
|
||||
).status_code == 422
|
||||
assert client.post("/api/companies", json={"name": " "}).status_code == 422
|
||||
assert client.post("/api/companies", json={}).status_code == 422
|
||||
assert [c.key for c in store.companies()] == ["revolut"]
|
||||
|
||||
|
||||
def test_a_company_from_a_search_only_is_no_longer_one_once_it_has_a_reason(
|
||||
client: TestClient, store: Store) -> None:
|
||||
store.save_agent("A")
|
||||
search = store.add_subscription("search", "jobindex:cph", label="cph", board="jobindex")
|
||||
item = posting("1", company="Novo")
|
||||
item.source = "search"
|
||||
store.upsert_role(item, search)
|
||||
client.post("/api/companies/novo/affinity", json={"affinity": 1})
|
||||
[row] = client.get("/api/companies").json()
|
||||
assert (row["from_search"], row["by_hand"]) == (True, False)
|
||||
|
||||
res = client.patch("/api/companies/novo", json={"hand_reason": "unread"})
|
||||
assert res.status_code == 200
|
||||
assert (res.json()["from_search"], res.json()["by_hand"]) == (False, True)
|
||||
|
||||
|
||||
def test_a_company_is_edited_and_only_the_fields_sent_change(
|
||||
client: TestClient, store: Store) -> None:
|
||||
store.add_company("Acme", key="acme", careers_url="https://acme.example/jobs",
|
||||
notes="old", hand_reason="unread")
|
||||
res = client.patch("/api/companies/acme", json={"notes": "new", "name": "Acme Labs"})
|
||||
assert res.status_code == 200, res.text
|
||||
body = res.json()
|
||||
assert (body["key"], body["name"], body["notes"], body["careers_url"],
|
||||
body["hand_reason"]) == ("acme", "Acme Labs", "new", "https://acme.example/jobs",
|
||||
"unread")
|
||||
# A link and a reason can be cleared, since "" is a value.
|
||||
res = client.patch("/api/companies/acme", json={"careers_url": "", "hand_reason": ""})
|
||||
assert (res.json()["careers_url"], res.json()["hand_reason"]) == ("", "")
|
||||
assert client.patch("/api/companies/acme", json={}).status_code == 200
|
||||
|
||||
assert client.patch("/api/companies/acme", json={"careers_url": "javascript:x"}
|
||||
).status_code == 422
|
||||
assert client.patch("/api/companies/acme", json={"hand_reason": "lazy"}).status_code == 422
|
||||
assert client.patch("/api/companies/acme", json={"name": " "}).status_code == 422
|
||||
assert client.patch("/api/companies/acme", json={"notes": None}).status_code == 422
|
||||
assert client.patch("/api/companies/nope", json={"notes": "x"}).status_code == 404
|
||||
assert store.company("acme").name == "Acme Labs" # type: ignore[union-attr]
|
||||
|
||||
|
||||
def test_a_company_with_a_board_keeps_its_name_and_takes_the_other_edits(
|
||||
client: TestClient, store: Store, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
import plugins.ats as ats
|
||||
|
||||
monkeypatch.setattr(ats, "fetch_board", lambda target: ([], True))
|
||||
store.add_company("Acme", key="acme")
|
||||
assert client.post("/api/companies/acme/board", json={"board": "greenhouse:acme"}
|
||||
).status_code == 200
|
||||
|
||||
res = client.patch("/api/companies/acme", json={"name": "Acme Labs"})
|
||||
assert res.status_code == 409 and "detach" in res.json()["detail"]
|
||||
assert client.patch("/api/companies/acme", json={"name": "Acme"}).status_code == 200
|
||||
assert client.patch("/api/companies/acme", json={"notes": "hi"}).status_code == 200
|
||||
# Detached, the subscription is still there and the name stays fixed.
|
||||
client.delete("/api/companies/acme/board")
|
||||
assert client.patch("/api/companies/acme", json={"name": "Acme Labs"}).status_code == 409
|
||||
assert store.company("acme").name == "Acme" # type: ignore[union-attr]
|
||||
|
||||
|
||||
def test_the_watchlists_careers_link_and_the_by_hand_edit_share_one_url_rule(
|
||||
client: TestClient, store: Store) -> None:
|
||||
store.add_company("Acme", key="acme")
|
||||
for bad in ("https://", "javascript:alert(1)"):
|
||||
posted = client.post("/api/companies/acme/careers", json={"careers_url": bad})
|
||||
patched = client.patch("/api/companies/acme", json={"careers_url": bad})
|
||||
assert posted.status_code == patched.status_code == 422
|
||||
assert posted.json() == patched.json()
|
||||
assert store.company("acme").careers_url == "" # type: ignore[union-attr]
|
||||
|
||||
|
||||
def test_opening_a_by_hand_company_shows_when_it_was_last_looked_at(
|
||||
client: TestClient, store: Store) -> None:
|
||||
clock = Clock()
|
||||
store.clock = clock
|
||||
store.add_company("Acme", key="acme", hand_reason="unread")
|
||||
assert client.post("/api/companies/acme/opened").status_code == 200
|
||||
[row] = client.get("/api/companies").json()
|
||||
assert (row["by_hand"], row["careers_opened_at"]) == (True, "2026-09-23T09:00:00+00:00")
|
||||
assert client.post("/api/companies/acme/checked").status_code in (404, 405)
|
||||
|
||||
|
||||
def test_a_company_is_deleted_unless_it_is_read(
|
||||
client: TestClient, store: Store, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
import plugins.ats as ats
|
||||
|
||||
monkeypatch.setattr(ats, "fetch_board", lambda target: ([], True))
|
||||
agent = store.save_agent("A")
|
||||
store.add_company("Meta", key="meta", hand_reason="blocked")
|
||||
store.set_affinity(agent.id, "meta", 1)
|
||||
res = client.delete("/api/companies/meta")
|
||||
assert res.status_code == 204 and res.content == b""
|
||||
assert store.company("meta") is None
|
||||
assert store.company("meta", agent.id) is None
|
||||
assert client.delete("/api/companies/meta").status_code == 404
|
||||
assert "meta" not in {c["key"] for c in client.get("/api/companies").json()}
|
||||
|
||||
# A board shown: refused until it is detached; a detached board is no board.
|
||||
store.add_company("Acme", key="acme")
|
||||
sub_id = client.post("/api/companies/acme/board", json={"board": "greenhouse:acme"}
|
||||
).json()["source"]["id"]
|
||||
res = client.delete("/api/companies/acme")
|
||||
assert res.status_code == 409 and "greenhouse:acme" in res.json()["detail"]
|
||||
store.upsert_role(posting("1", company="Acme"), store.subscription(sub_id))
|
||||
client.delete("/api/companies/acme/board")
|
||||
assert client.delete("/api/companies/acme").status_code == 204
|
||||
|
||||
# Open roles hold a company even where no board is on: they would be
|
||||
# orphaned from the list.
|
||||
store.add_company("Beta", key="beta")
|
||||
store.upsert_role(posting("2", company="Beta"))
|
||||
res = client.delete("/api/companies/beta")
|
||||
assert res.status_code == 409 and "open roles" in res.json()["detail"]
|
||||
assert store.company("beta") is not None
|
||||
|
||||
|
||||
def test_the_pull_a_source_switch_queues_is_refused_quietly_while_one_runs(
|
||||
app: FastAPI, store: Store) -> None:
|
||||
"""The four actions that queue a `pull` (switching a source on, following
|
||||
|
||||
Reference in new issue
Block a user