Per-agent ranking: votes, affinity and a taste term; settings are three sub-tabs
Votes on roles and company affinity move to role_votes and agent_companies, one row per search agent, so two agents rank the same roles differently. The score gains taste, the cosine to mean(liked) - mean(passed) of the agent's votes, as newsdesk ranks articles. The API takes agent on roles, votes and companies and falls back to the default agent, the enabled one with the lowest id. Settings become Search agents (a list again, with New and Delete), Sources (job boards, company boards and runs with the message log, one section per plugin) and Account. Old paths answer 301 to their section. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
515d2250fc
commit
a0772519b3
28 files changed
+1461
-668
No files matched your search
+86
-3
@@ -179,9 +179,10 @@ def test_a_prefer_gate_adds_its_weight_to_the_score(
|
||||
|
||||
def test_a_favourite_skips_the_gates_and_is_floored(
|
||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||
store.add_company("Fave", affinity=2)
|
||||
store.add_company("Fave")
|
||||
fave = role(store, "1", company="Fave", place="Munich")
|
||||
agent = store.save_agent("Berlin", "", [Gate(field="place", values=["Berlin"])])
|
||||
store.set_affinity(agent.id, "fave", 2)
|
||||
|
||||
run(config, store, score.run_score)
|
||||
|
||||
@@ -189,17 +190,21 @@ def test_a_favourite_skips_the_gates_and_is_floored(
|
||||
assert reason == "" and value >= 0.9
|
||||
|
||||
|
||||
def test_a_muted_company_is_never_scored(
|
||||
def test_a_hidden_company_is_never_scored_for_the_agent_that_hid_it(
|
||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||
store.add_company("Muted", affinity=-1)
|
||||
store.add_company("Muted")
|
||||
muted = role(store, "1", company="Muted")
|
||||
kept = role(store, "2")
|
||||
agent = store.save_agent("Any")
|
||||
other = store.save_agent("Other")
|
||||
store.set_affinity(agent.id, "muted", -1)
|
||||
|
||||
run(config, store, score.run_score)
|
||||
|
||||
assert set(store.scores(agent.id)) == {kept}
|
||||
assert muted not in {r.uid for r in store.roles(agent=agent.id, gated=True)}
|
||||
# The other agent did not hide it, so it is scored for that one.
|
||||
assert set(store.scores(other.id)) == {muted, kept}
|
||||
|
||||
|
||||
def test_an_older_role_scores_lower(
|
||||
@@ -235,6 +240,84 @@ def test_two_agents_rank_the_same_roles_the_other_way_round(
|
||||
assert store.scores(frontend.id)[back][0] == 0.0
|
||||
|
||||
|
||||
# ------------------------------------------------------------------ taste
|
||||
|
||||
def _unit(*words: str) -> np.ndarray:
|
||||
return FakeEmbedder().encode([" ".join(words)])[0]
|
||||
|
||||
|
||||
def test_taste_direction_is_liked_minus_passed_and_none_without_votes() -> None:
|
||||
vectors = {"a": _unit("backend"), "b": _unit("frontend"), "c": _unit("data")}
|
||||
|
||||
assert score.taste_direction(vectors, {}) is None
|
||||
assert score.taste_direction(vectors, {"a": 0}) is None # neutral says nothing
|
||||
assert score.taste_direction(vectors, {"gone": 1}) is None # no vector to point at
|
||||
|
||||
liked_only = score.taste_direction(vectors, {"a": 1, "c": 1})
|
||||
assert liked_only is not None
|
||||
assert liked_only == pytest.approx((vectors["a"] + vectors["c"]) / 2)
|
||||
|
||||
passed_only = score.taste_direction(vectors, {"b": -1})
|
||||
assert passed_only is not None
|
||||
assert passed_only == pytest.approx(-vectors["b"])
|
||||
|
||||
both = score.taste_direction(vectors, {"a": 1, "b": -1, "c": 0})
|
||||
assert both is not None
|
||||
assert both == pytest.approx(vectors["a"] - vectors["b"])
|
||||
|
||||
|
||||
def test_taste_ranks_a_role_near_the_liked_one_above_one_near_the_passed(
|
||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||
liked = role(store, "1", "Backend Engineer", body="Python backend")
|
||||
passed = role(store, "2", "Frontend Engineer", body="React frontend")
|
||||
near_liked = role(store, "3", "Platform Engineer", body="Python backend services")
|
||||
near_passed = role(store, "4", "Web Engineer", body="React frontend apps")
|
||||
# No intent: with taste alone weighted, the votes are all that orders them.
|
||||
agent = store.save_agent("Taste", "", weights=Weights(fit=0, recency=0, affinity=0,
|
||||
taste=1))
|
||||
store.set_vote(agent.id, liked, 1)
|
||||
store.set_vote(agent.id, passed, -1)
|
||||
|
||||
run(config, store, embed.run_embed)
|
||||
run(config, store, score.run_score)
|
||||
|
||||
scores = store.scores(agent.id)
|
||||
assert scores[near_liked][0] > scores[near_passed][0]
|
||||
assert scores[liked][0] == 1.0 and scores[passed][0] == 0.0
|
||||
assert all(reason == "" for _, reason in scores.values())
|
||||
|
||||
|
||||
def test_without_votes_taste_leaves_the_denominator(
|
||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||
uid = role(store, "1")
|
||||
agent = store.save_agent("Any", weights=Weights(fit=0, recency=0, affinity=0, taste=1))
|
||||
|
||||
run(config, store, embed.run_embed)
|
||||
run(config, store, score.run_score)
|
||||
|
||||
# Taste is the only weighted term and there is no taste, so no weights.
|
||||
assert store.scores(agent.id)[uid] == (0.0, "no weights")
|
||||
|
||||
|
||||
def test_a_closed_liked_role_still_shapes_the_taste(
|
||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||
liked = role(store, "1", "Backend Engineer", body="Python backend")
|
||||
near = role(store, "2", "Platform Engineer", body="Python backend")
|
||||
far = role(store, "3", "Web Engineer", body="React frontend")
|
||||
agent = store.save_agent("Taste", "", weights=Weights(fit=0, recency=0, affinity=0,
|
||||
taste=1))
|
||||
run(config, store, embed.run_embed)
|
||||
store.set_vote(agent.id, liked, 1)
|
||||
with store.transaction() as conn:
|
||||
conn.execute("UPDATE roles SET closed_at = ? WHERE uid = ?", (NOW.isoformat(), liked))
|
||||
|
||||
run(config, store, score.run_score)
|
||||
|
||||
scores = store.scores(agent.id)
|
||||
assert liked not in scores
|
||||
assert scores[near][0] == 1.0 and scores[far][0] == 0.0
|
||||
|
||||
|
||||
# ------------------------------------------------------------ fit scaling
|
||||
|
||||
def test_scale_maps_the_closest_to_one_and_the_farthest_to_zero() -> None:
|
||||
|
||||
+244
-39
@@ -85,20 +85,103 @@ def test_a_v1_file_migrates_to_the_shape_a_new_file_has(tmp_path: Path) -> None:
|
||||
Store(fresh)
|
||||
Store(old)
|
||||
with sqlite3.connect(old) as conn:
|
||||
for column in ("permit", "languages", "extract_tries", "vote", "voted_at",
|
||||
"summary", "summarised_at", "article_text", "article_at"):
|
||||
# v1 had no v2-v4 columns; the v4 vote columns that v5 drops again are
|
||||
# not in a fresh file, so there is nothing to drop for them.
|
||||
for column in ("permit", "languages", "extract_tries", "summary", "summarised_at",
|
||||
"article_text", "article_at"):
|
||||
conn.execute(f"ALTER TABLE roles DROP COLUMN {column}")
|
||||
for column in ("intent_key", "intent_vec"):
|
||||
conn.execute(f"ALTER TABLE agents DROP COLUMN {column}")
|
||||
conn.execute("DROP TABLE vectors")
|
||||
conn.execute("ALTER TABLE companies ADD COLUMN affinity INTEGER NOT NULL DEFAULT 0")
|
||||
for table in ("vectors", "agent_companies", "role_votes"):
|
||||
conn.execute(f"DROP TABLE {table}")
|
||||
conn.execute("PRAGMA user_version = 1")
|
||||
|
||||
assert Store(old).migrations_applied == list(range(2, LATEST + 1))
|
||||
# ALTER appends, so the order differs; every read is by column name.
|
||||
for table in ("roles", "agents", "vectors"):
|
||||
for table in ("roles", "agents", "vectors", "companies", "agent_companies", "role_votes"):
|
||||
assert sorted(_columns(old, table)) == sorted(_columns(fresh, table))
|
||||
|
||||
|
||||
def _downgrade_to_v4(path: Path) -> None:
|
||||
"""A fresh file put back to the v4 shape: votes on the role, affinity on
|
||||
the company, no per-agent tables."""
|
||||
with sqlite3.connect(path) as conn:
|
||||
conn.execute("ALTER TABLE roles ADD COLUMN vote INTEGER CHECK (vote IN (-1, 0, 1))")
|
||||
conn.execute("ALTER TABLE roles ADD COLUMN voted_at TEXT")
|
||||
conn.execute("ALTER TABLE companies ADD COLUMN affinity INTEGER NOT NULL DEFAULT 0")
|
||||
conn.execute("DROP TABLE agent_companies")
|
||||
conn.execute("DROP TABLE role_votes")
|
||||
conn.execute("PRAGMA user_version = 4")
|
||||
|
||||
|
||||
def test_v5_moves_the_votes_and_affinities_to_the_default_agent(tmp_path: Path) -> None:
|
||||
path = tmp_path / "v4.db"
|
||||
store = Store(path)
|
||||
store.upsert_role(posting("liked"))
|
||||
store.upsert_role(posting("passed"))
|
||||
store.upsert_role(posting("none"))
|
||||
store.add_company("Acme", key="acme")
|
||||
store.add_company("Other", key="other")
|
||||
# The disabled agent has the lower id; the enabled one is the default.
|
||||
second = store.save_agent("Second", enabled=False)
|
||||
first = store.save_agent("First")
|
||||
assert first.id > second.id and store.default_agent().id == first.id
|
||||
_downgrade_to_v4(path)
|
||||
with sqlite3.connect(path) as conn:
|
||||
conn.execute("UPDATE roles SET vote = 1, voted_at = 'then' WHERE uid = ?",
|
||||
(posting("liked").uid,))
|
||||
conn.execute("UPDATE roles SET vote = -1 WHERE uid = ?", (posting("passed").uid,))
|
||||
conn.execute("UPDATE companies SET affinity = -1 WHERE key = 'acme'")
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
assert migrated.migrations_applied == [5]
|
||||
assert [a.name for a in migrated.agents()] == ["First", "Second"] # none added
|
||||
assert migrated.votes(first.id) == {posting("liked").uid: 1, posting("passed").uid: -1}
|
||||
assert migrated.votes(second.id) == {}
|
||||
liked = migrated.role(posting("liked").uid, first.id)
|
||||
assert liked is not None and liked.voted_at == "then"
|
||||
passed = migrated.role(posting("passed").uid, first.id)
|
||||
assert passed is not None and passed.voted_at # stamped when v4 had none
|
||||
assert [c.affinity for c in migrated.companies(first.id)] == [-1, 0]
|
||||
assert [c.affinity for c in migrated.companies(second.id)] == [0, 0]
|
||||
with sqlite3.connect(path) as conn:
|
||||
columns = {r[1] for r in conn.execute("PRAGMA table_info(roles)")}
|
||||
assert not {"vote", "voted_at"} & columns
|
||||
assert "affinity" not in {r[1] for r in conn.execute("PRAGMA table_info(companies)")}
|
||||
|
||||
|
||||
def test_v5_makes_an_agent_when_there_is_something_to_move_and_none_to_take_it(
|
||||
tmp_path: Path) -> None:
|
||||
path = tmp_path / "v4.db"
|
||||
store = Store(path)
|
||||
store.upsert_role(posting("liked"))
|
||||
store.add_company("Acme", key="acme")
|
||||
_downgrade_to_v4(path)
|
||||
with sqlite3.connect(path) as conn:
|
||||
conn.execute("UPDATE companies SET affinity = 2 WHERE key = 'acme'")
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
[agent] = migrated.agents()
|
||||
assert (agent.name, agent.enabled, agent.gates) == ("My ranking", True, [])
|
||||
assert agent.created_at.endswith("+00:00")
|
||||
assert migrated.default_agent() == agent
|
||||
assert migrated.company("acme", agent.id).affinity == 2 # type: ignore[union-attr]
|
||||
|
||||
|
||||
def test_v5_makes_no_agent_when_there_is_nothing_to_move(tmp_path: Path) -> None:
|
||||
path = tmp_path / "v4.db"
|
||||
store = Store(path)
|
||||
store.upsert_role(posting("plain"))
|
||||
store.add_company("Acme", key="acme")
|
||||
_downgrade_to_v4(path)
|
||||
|
||||
assert Store(path).migrations_applied == [5]
|
||||
assert Store(path).agents() == []
|
||||
|
||||
|
||||
def test_state_is_a_mapping(store: Store) -> None:
|
||||
store.state["ats:last"] = "2026-09-23"
|
||||
assert store.state["ats:last"] == "2026-09-23"
|
||||
@@ -190,7 +273,9 @@ def test_roles_filters_q_function_remote_and_days(store: Store, clock: Clock) ->
|
||||
|
||||
|
||||
def test_roles_hide_muted_excludes_before_the_limit(store: Store, clock: Clock) -> None:
|
||||
store.add_company("Acme", key="acme", affinity=-1)
|
||||
agent = store.save_agent("A")
|
||||
store.add_company("Acme", key="acme")
|
||||
store.set_affinity(agent.id, "acme", -1)
|
||||
store.upsert_role(posting("other", company="Other"))
|
||||
clock.tick()
|
||||
for i in range(3):
|
||||
@@ -199,10 +284,15 @@ def test_roles_hide_muted_excludes_before_the_limit(store: Store, clock: Clock)
|
||||
# Acme's roles are the three newest, so a plain limit=1 shows only Acme;
|
||||
# hide_muted has to reach past all three to find "other" rather than
|
||||
# just dropping Acme's rows out of an already-limited page.
|
||||
assert [r.source_id for r in store.roles(limit=1)] == ["a2"]
|
||||
assert [r.source_id for r in store.roles(limit=1, hide_muted=True)] == ["other"]
|
||||
assert {r.source_id for r in store.roles(hide_muted=True)} == {"other"}
|
||||
assert {r.source_id for r in store.roles()} == {"a0", "a1", "a2", "other"}
|
||||
listing = {"agent": agent.id, "by_score": False}
|
||||
assert [r.source_id for r in store.roles(limit=1, **listing)] == ["a2"]
|
||||
assert [r.source_id for r in store.roles(limit=1, hide_muted=True, **listing)] == ["other"]
|
||||
assert {r.source_id for r in store.roles(hide_muted=True, **listing)} == {"other"}
|
||||
assert {r.source_id for r in store.roles(**listing)} == {"a0", "a1", "a2", "other"}
|
||||
# Hidden is per agent: another agent, or no agent, hides nothing.
|
||||
other = store.save_agent("B")
|
||||
assert store.count_roles(hide_muted=True, agent=other.id, by_score=False) == 4
|
||||
assert store.count_roles(hide_muted=True) == 4
|
||||
|
||||
|
||||
def test_roles_page_by_offset_and_count_the_same_filter(
|
||||
@@ -214,34 +304,94 @@ def test_roles_page_by_offset_and_count_the_same_filter(
|
||||
assert [r.source_id for r in store.roles(limit=2, offset=3)] == ["1"]
|
||||
assert store.count_roles() == 4
|
||||
assert store.count_roles(company="acme") == 3
|
||||
store.add_company("Other", key="other", affinity=-1)
|
||||
assert store.count_roles(hide_muted=True) == 3
|
||||
agent = store.save_agent("A")
|
||||
store.add_company("Other", key="other")
|
||||
store.set_affinity(agent.id, "other", -1)
|
||||
assert store.count_roles(hide_muted=True, agent=agent.id, by_score=False) == 3
|
||||
|
||||
|
||||
def test_a_vote_is_stamped_cleared_and_filtered(store: Store, clock: Clock) -> None:
|
||||
for sid in ("up", "down", "fine", "none"):
|
||||
store.upsert_role(posting(sid))
|
||||
uid = {r.source_id: r.uid for r in store.roles()}
|
||||
role = store.set_vote(uid["up"], 1)
|
||||
agent = store.save_agent("A")
|
||||
role = store.set_vote(agent.id, uid["up"], 1)
|
||||
assert (role.vote, role.voted_at) == (1, clock().isoformat(timespec="seconds"))
|
||||
store.set_vote(uid["down"], -1)
|
||||
store.set_vote(uid["fine"], 0)
|
||||
store.set_vote(agent.id, uid["down"], -1)
|
||||
store.set_vote(agent.id, uid["fine"], 0)
|
||||
assert store.votes(agent.id) == {uid["up"]: 1, uid["down"]: -1, uid["fine"]: 0}
|
||||
|
||||
assert [r.source_id for r in store.roles(judged="liked")] == ["up"]
|
||||
assert [r.source_id for r in store.roles(judged="passed")] == ["down"]
|
||||
assert [r.source_id for r in store.roles(judged="unjudged")] == ["none"]
|
||||
assert store.count_roles(judged="unjudged") == 1
|
||||
def listed(judged: str) -> list[str]:
|
||||
return [r.source_id for r in store.roles(agent=agent.id, by_score=False,
|
||||
judged=judged)]
|
||||
|
||||
assert listed("liked") == ["up"]
|
||||
assert listed("passed") == ["down"]
|
||||
assert listed("unjudged") == ["none"]
|
||||
assert store.count_roles(agent=agent.id, by_score=False, judged="unjudged") == 1
|
||||
with pytest.raises(ValueError, match="judged"):
|
||||
store.roles(judged="maybe")
|
||||
|
||||
cleared = store.set_vote(uid["up"], None)
|
||||
clock.tick()
|
||||
changed = store.set_vote(agent.id, uid["up"], -1)
|
||||
assert (changed.vote, changed.voted_at) == (-1, clock().isoformat(timespec="seconds"))
|
||||
cleared = store.set_vote(agent.id, uid["up"], None)
|
||||
assert (cleared.vote, cleared.voted_at) == (None, None)
|
||||
assert store.set_vote(agent.id, uid["up"], None).vote is None # clearing twice is fine
|
||||
with pytest.raises(ValueError):
|
||||
store.set_vote(uid["up"], 2)
|
||||
store.set_vote(agent.id, uid["up"], 2)
|
||||
with pytest.raises(ValueError):
|
||||
store.set_vote(uid["up"], True)
|
||||
store.set_vote(agent.id, uid["up"], True)
|
||||
with pytest.raises(KeyError):
|
||||
store.set_vote("nope", 1)
|
||||
store.set_vote(agent.id, "nope", 1)
|
||||
with pytest.raises(KeyError):
|
||||
store.set_vote(999, uid["up"], 1)
|
||||
|
||||
|
||||
def test_votes_are_per_agent(store: Store) -> None:
|
||||
store.upsert_role(posting("1"))
|
||||
uid = posting("1").uid
|
||||
one = store.save_agent("One")
|
||||
two = store.save_agent("Two")
|
||||
store.set_vote(one.id, uid, 1)
|
||||
|
||||
assert store.role(uid, one.id).vote == 1 # type: ignore[union-attr]
|
||||
assert store.role(uid, two.id).vote is None # type: ignore[union-attr]
|
||||
assert store.role(uid).vote is None # type: ignore[union-attr]
|
||||
assert store.votes(two.id) == {}
|
||||
assert [r.vote for r in store.roles(agent=two.id, by_score=False)] == [None]
|
||||
assert [r.vote for r in store.roles()] == [None]
|
||||
assert [r.source_id for r in store.roles(agent=two.id, by_score=False, judged="liked")] == []
|
||||
assert [r.source_id for r in store.roles(judged="liked")] == []
|
||||
assert [r.source_id for r in store.roles(judged="unjudged")] == ["1"]
|
||||
|
||||
store.set_vote(two.id, uid, -1)
|
||||
assert store.role(uid, one.id).vote == 1 # type: ignore[union-attr]
|
||||
assert store.role(uid, two.id).vote == -1 # type: ignore[union-attr]
|
||||
|
||||
# Deleting the agent takes its votes with it and leaves the other's.
|
||||
store.delete_agent(two.id)
|
||||
assert store.votes(one.id) == {uid: 1}
|
||||
with store.transaction() as conn:
|
||||
assert conn.execute("SELECT COUNT(*) FROM role_votes").fetchone()[0] == 1
|
||||
|
||||
|
||||
def test_roles_with_an_agent_but_not_by_score_are_newest_first_with_votes(
|
||||
store: Store, clock: Clock) -> None:
|
||||
for sid in ("1", "2", "3"):
|
||||
store.upsert_role(posting(sid))
|
||||
clock.tick()
|
||||
uid = {r.source_id: r.uid for r in store.roles()}
|
||||
agent = store.save_agent("A")
|
||||
store.replace_scores(agent.id, [(uid["1"], 0.9, ""), (uid["2"], 0.1, "")]) # 3 unscored
|
||||
store.set_vote(agent.id, uid["1"], 1)
|
||||
|
||||
newest = store.roles(agent=agent.id, by_score=False)
|
||||
assert [r.source_id for r in newest] == ["3", "2", "1"]
|
||||
assert [r.score for r in newest] == [None, None, None]
|
||||
assert [r.vote for r in newest] == [None, None, 1]
|
||||
assert store.count_roles(agent=agent.id, by_score=False) == 3
|
||||
assert [r.source_id for r in store.roles(agent=agent.id)] == ["1", "2"]
|
||||
|
||||
|
||||
def test_a_vote_moves_the_served_score_and_the_order(store: Store) -> None:
|
||||
@@ -249,15 +399,21 @@ def test_a_vote_moves_the_served_score_and_the_order(store: Store) -> None:
|
||||
store.upsert_role(posting(sid))
|
||||
uid = {r.source_id: r.uid for r in store.roles()}
|
||||
agent = store.save_agent("A")
|
||||
other = store.save_agent("B")
|
||||
store.replace_scores(agent.id, [(uid["a"], 0.9, ""), (uid["b"], 0.5, ""),
|
||||
(uid["c"], 0.4, "")])
|
||||
store.set_vote(uid["a"], -1) # 0.45
|
||||
store.set_vote(uid["c"], 1) # 0.48
|
||||
store.replace_scores(other.id, [(uid["a"], 0.9, ""), (uid["b"], 0.5, ""),
|
||||
(uid["c"], 0.4, "")])
|
||||
store.set_vote(agent.id, uid["a"], -1) # 0.45
|
||||
store.set_vote(agent.id, uid["c"], 1) # 0.48
|
||||
ranked = [(r.source_id, round(r.score or 0, 3)) for r in store.roles(agent=agent.id)]
|
||||
assert ranked == [("b", 0.5), ("c", 0.48), ("a", 0.45)]
|
||||
assert store.scores(agent.id)[uid["a"]][0] == 0.9 # the stored score is kept
|
||||
store.set_vote(uid["a"], 1)
|
||||
store.set_vote(agent.id, uid["a"], 1)
|
||||
assert store.roles(agent=agent.id, limit=1)[0].score == 1.0
|
||||
# The other agent's ranking is untouched by these votes.
|
||||
assert [(r.source_id, r.score) for r in store.roles(agent=other.id)] == \
|
||||
[("a", 0.9), ("b", 0.5), ("c", 0.4)]
|
||||
|
||||
|
||||
def test_mark_closed_closes_what_the_board_no_longer_lists(store: Store) -> None:
|
||||
@@ -288,10 +444,10 @@ def test_companies_crud(store: Store) -> None:
|
||||
assert acme.key == "acme" and acme.affinity == 0 and acme.status == "researching"
|
||||
with pytest.raises(ValueError, match="already exists"):
|
||||
store.add_company("Acme")
|
||||
updated = store.update_company("acme", affinity=2, status="contacted")
|
||||
assert (updated.affinity, updated.status) == (2, "contacted")
|
||||
with pytest.raises(ValueError, match="affinity"):
|
||||
store.update_company("acme", affinity=5)
|
||||
updated = store.update_company("acme", status="contacted")
|
||||
assert updated.status == "contacted"
|
||||
with pytest.raises(ValueError, match="not a company field"):
|
||||
store.update_company("acme", affinity=2)
|
||||
with pytest.raises(ValueError, match="not a company field"):
|
||||
store.update_company("acme", created_at="x")
|
||||
assert [c.key for c in store.companies()] == ["acme"]
|
||||
@@ -299,6 +455,56 @@ def test_companies_crud(store: Store) -> None:
|
||||
assert store.company("acme") is None
|
||||
|
||||
|
||||
def test_affinity_is_per_agent(store: Store) -> None:
|
||||
store.add_company("Acme", key="acme")
|
||||
store.add_company("Other", key="other")
|
||||
one = store.save_agent("One")
|
||||
two = store.save_agent("Two")
|
||||
|
||||
assert store.set_affinity(one.id, "acme", 2).affinity == 2
|
||||
assert store.company("acme", one.id).affinity == 2 # type: ignore[union-attr]
|
||||
assert store.company("acme", two.id).affinity == 0 # type: ignore[union-attr]
|
||||
assert store.company("acme").affinity == 0 # type: ignore[union-attr]
|
||||
assert [(c.key, c.affinity) for c in store.companies(one.id)] == [("acme", 2), ("other", 0)]
|
||||
assert [c.affinity for c in store.companies(two.id)] == [0, 0]
|
||||
assert [c.affinity for c in store.companies()] == [0, 0]
|
||||
|
||||
store.set_affinity(two.id, "acme", -1)
|
||||
assert store.company("acme", one.id).affinity == 2 # type: ignore[union-attr]
|
||||
assert store.company("acme", two.id).affinity == -1 # type: ignore[union-attr]
|
||||
|
||||
# 0 deletes the row rather than keeping a neutral one.
|
||||
assert store.set_affinity(one.id, "acme", 0).affinity == 0
|
||||
with store.transaction() as conn:
|
||||
rows = conn.execute("SELECT agent_id, company_key FROM agent_companies").fetchall()
|
||||
assert [tuple(r) for r in rows] == [(two.id, "acme")]
|
||||
|
||||
with pytest.raises(ValueError, match="affinity"):
|
||||
store.set_affinity(one.id, "acme", 5)
|
||||
with pytest.raises(ValueError, match="affinity"):
|
||||
store.set_affinity(one.id, "acme", True) # type: ignore[arg-type]
|
||||
with pytest.raises(KeyError):
|
||||
store.set_affinity(one.id, "nope", 1)
|
||||
with pytest.raises(KeyError):
|
||||
store.set_affinity(999, "acme", 1)
|
||||
|
||||
store.delete_agent(two.id)
|
||||
with store.transaction() as conn:
|
||||
assert conn.execute("SELECT COUNT(*) FROM agent_companies").fetchone()[0] == 0
|
||||
|
||||
|
||||
def test_the_default_agent_is_the_lowest_enabled_id(store: Store) -> None:
|
||||
assert store.default_agent() is None
|
||||
off = store.save_agent("Off", enabled=False)
|
||||
assert store.default_agent() == off
|
||||
on = store.save_agent("On")
|
||||
assert store.default_agent() == on
|
||||
later = store.save_agent("Later")
|
||||
assert store.default_agent() == on
|
||||
store.delete_agent(on.id)
|
||||
assert store.default_agent() == later
|
||||
|
||||
|
||||
def test_open_role_counts_and_company_boards(store: Store) -> None:
|
||||
sub = store.add_subscription("ats", "greenhouse:acme", company="Acme", board="greenhouse")
|
||||
store.add_company("Acme", key="acme")
|
||||
@@ -390,23 +596,22 @@ def test_a_summary_is_written_once(store: Store) -> None:
|
||||
|
||||
|
||||
def test_summarise_waits_on_the_top_of_each_enabled_agent(store: Store) -> None:
|
||||
"""Two agents each contribute their own top one; a closed role, a hidden
|
||||
company's role and a gated score are not in anybody's top."""
|
||||
for sid, company in (("a", "Acme"), ("b", "Acme"), ("c", "Hidden"), ("d", "Acme")):
|
||||
store.upsert_role(posting(sid, company=company))
|
||||
"""Two agents each contribute their own top one; a closed role and a
|
||||
gated score are not in anybody's top. A hidden company needs no case:
|
||||
`score` writes no rows for it under the agent that hid it."""
|
||||
for sid in "abcd":
|
||||
store.upsert_role(posting(sid))
|
||||
a, b, c, d = (posting(s).uid for s in "abcd")
|
||||
store.add_company("Hidden", key="hidden", affinity=-1)
|
||||
with store.transaction() as conn:
|
||||
conn.execute("UPDATE roles SET closed_at = ? WHERE uid = ?", (store.now(), d))
|
||||
one = store.save_agent("One")
|
||||
two = store.save_agent("Two")
|
||||
store.replace_scores(one.id, [(d, 0.99, ""), (a, 0.9, ""), (b, 0.5, "")])
|
||||
store.replace_scores(two.id, [(a, 0.95, "remote"), (c, 0.9, ""), (b, 0.8, "")])
|
||||
store.replace_scores(two.id, [(a, 0.95, "remote"), (c, 0.7, ""), (b, 0.8, "")])
|
||||
|
||||
waiting = {r.uid for r in store.summarise_waiting(10, per_agent=1)}
|
||||
|
||||
# `c` is agent two's best open ungated role but its company is hidden.
|
||||
assert waiting == {a}
|
||||
assert {r.uid for r in store.summarise_waiting(10, per_agent=2)} == {a, b}
|
||||
assert store.summarise_pending(per_agent=2) == 2
|
||||
assert waiting == {a, b}
|
||||
assert {r.uid for r in store.summarise_waiting(10, per_agent=2)} == {a, b, c}
|
||||
assert store.summarise_pending(per_agent=2) == 3
|
||||
assert [r.uid for r in store.summarise_waiting(10, 1, uids=[d])] == [d]
|
||||
+185
-50
@@ -98,13 +98,25 @@ def test_muted_roles_are_hidden_unless_show_muted(client: TestClient, store: Sto
|
||||
store.add_company("Acme", key="acme")
|
||||
store.upsert_role(posting("1", company="Acme"))
|
||||
store.upsert_role(posting("2", company="Other"))
|
||||
agent = store.save_agent("A")
|
||||
other = store.save_agent("B")
|
||||
|
||||
assert {r["source_id"] for r in client.get("/api/roles").json()["items"]} == {"1", "2"}
|
||||
def shown(**params: Any) -> set[str]:
|
||||
return {r["source_id"] for r in client.get("/api/roles", params=params).json()["items"]}
|
||||
|
||||
assert shown() == {"1", "2"}
|
||||
|
||||
# No agent in the body: the default agent's, which is also who a list
|
||||
# without `agent` hides for.
|
||||
assert client.post("/api/companies/acme/affinity", json={"affinity": -1}).status_code == 200
|
||||
assert {r["source_id"] for r in client.get("/api/roles").json()["items"]} == {"2"}
|
||||
assert {r["source_id"] for r in
|
||||
client.get("/api/roles", params={"show_muted": "true"}).json()["items"]} == {"1", "2"}
|
||||
assert shown() == {"2"}
|
||||
assert shown(show_muted="true") == {"1", "2"}
|
||||
assert shown(agent=agent.id, order="newest") == {"2"}
|
||||
# Hidden is per agent: the other agent still sees Acme.
|
||||
assert shown(agent=other.id, order="newest") == {"1", "2"}
|
||||
assert [c["affinity"] for c in client.get("/api/companies").json()] == [-1]
|
||||
assert [c["affinity"] for c in
|
||||
client.get("/api/companies", params={"agent": other.id}).json()] == [0]
|
||||
|
||||
|
||||
def test_muted_is_excluded_before_the_limit_not_after(
|
||||
@@ -115,7 +127,8 @@ def test_muted_is_excluded_before_the_limit_not_after(
|
||||
of roles, all freshly (re-)pulled at once, produces."""
|
||||
clock = Clock()
|
||||
store.clock = clock
|
||||
store.add_company("Acme", key="acme", affinity=-1)
|
||||
store.add_company("Acme", key="acme")
|
||||
store.set_affinity(store.save_agent("A").id, "acme", -1)
|
||||
store.upsert_role(posting("other", company="Other"))
|
||||
clock.tick()
|
||||
for i in range(3):
|
||||
@@ -149,32 +162,104 @@ def test_a_vote_is_set_cleared_and_filtered_on(client: TestClient, store: Store)
|
||||
for sid in ("liked", "passed", "fine", "open"):
|
||||
store.upsert_role(posting(sid))
|
||||
uid = {r.source_id: r.uid for r in store.roles()}
|
||||
agent = store.save_agent("A")
|
||||
|
||||
# No `agent` in the body: the default agent's vote.
|
||||
res = client.post(f"/api/roles/{uid['liked']}/vote", json={"value": 1})
|
||||
assert res.status_code == 200
|
||||
assert res.json()["vote"] == 1 and res.json()["voted_at"] is not None
|
||||
client.post(f"/api/roles/{uid['passed']}/vote", json={"value": -1})
|
||||
assert store.votes(agent.id) == {uid["liked"]: 1}
|
||||
client.post(f"/api/roles/{uid['passed']}/vote", json={"value": -1, "agent": agent.id})
|
||||
client.post(f"/api/roles/{uid['fine']}/vote", json={"value": 0})
|
||||
|
||||
def judged(value: str) -> set[str]:
|
||||
page = client.get("/api/roles", params={"judged": value}).json()
|
||||
def judged(value: str, **params: Any) -> set[str]:
|
||||
page = client.get("/api/roles", params={"judged": value, **params}).json()
|
||||
return {r["source_id"] for r in page["items"]}
|
||||
|
||||
assert judged("liked") == {"liked"}
|
||||
assert judged("passed") == {"passed"}
|
||||
assert judged("unjudged") == {"open"}
|
||||
assert judged("") == {"liked", "passed", "fine", "open"} # a pass is not hidden
|
||||
assert judged("liked", agent=agent.id, order="newest") == {"liked"}
|
||||
assert client.get("/api/roles", params={"judged": "maybe"}).status_code == 422
|
||||
assert client.get(f"/api/roles/{uid['liked']}").json()["vote"] == 1
|
||||
assert client.get(f"/api/roles/{uid['liked']}", params={"agent": agent.id}).json()["vote"] == 1
|
||||
|
||||
cleared = client.delete(f"/api/roles/{uid['liked']}/vote")
|
||||
assert cleared.status_code == 200
|
||||
assert cleared.json()["vote"] is None and cleared.json()["voted_at"] is None
|
||||
assert judged("unjudged") == {"open", "liked"}
|
||||
cleared = client.delete(f"/api/roles/{uid['passed']}/vote", params={"agent": agent.id})
|
||||
assert cleared.status_code == 200 and cleared.json()["vote"] is None
|
||||
|
||||
assert client.post(f"/api/roles/{uid['open']}/vote",
|
||||
json={"value": 2}).status_code == 422
|
||||
assert client.post("/api/roles/nope/vote", json={"value": 1}).status_code == 404
|
||||
assert client.delete("/api/roles/nope/vote").status_code == 404
|
||||
assert client.post(f"/api/roles/{uid['open']}/vote",
|
||||
json={"value": 1, "agent": 999}).status_code == 404
|
||||
assert client.delete(f"/api/roles/{uid['open']}/vote", params={"agent": 999}).status_code == 404
|
||||
|
||||
|
||||
def test_votes_are_per_agent_over_the_api(client: TestClient, store: Store) -> None:
|
||||
store.upsert_role(posting("1"))
|
||||
uid = posting("1").uid
|
||||
one = store.save_agent("One")
|
||||
two = store.save_agent("Two")
|
||||
|
||||
assert client.post(f"/api/roles/{uid}/vote", json={"value": 1, "agent": one.id}).json()["vote"] == 1
|
||||
assert client.post(f"/api/roles/{uid}/vote", json={"value": -1, "agent": two.id}).json()["vote"] == -1
|
||||
assert client.get(f"/api/roles/{uid}", params={"agent": one.id}).json()["vote"] == 1
|
||||
assert client.get(f"/api/roles/{uid}", params={"agent": two.id}).json()["vote"] == -1
|
||||
assert client.get(f"/api/roles/{uid}").json()["vote"] == 1 # the default's
|
||||
assert client.get(f"/api/roles/{uid}", params={"agent": 999}).status_code == 404
|
||||
|
||||
def listed(**params: Any) -> list[int | None]:
|
||||
return [r["vote"] for r in client.get("/api/roles", params=params).json()["items"]]
|
||||
|
||||
assert listed(agent=one.id, order="newest") == [1]
|
||||
assert listed(agent=two.id, order="newest") == [-1]
|
||||
assert listed() == [1]
|
||||
|
||||
|
||||
def test_a_vote_or_an_affinity_needs_an_agent_to_belong_to(
|
||||
client: TestClient, store: Store) -> None:
|
||||
"""Nothing to vote as: a 422 with a sentence, not a vote that lands
|
||||
nowhere. Reading is fine, everything is simply unjudged and neutral."""
|
||||
store.upsert_role(posting("1"))
|
||||
store.add_company("Acme", key="acme")
|
||||
uid = posting("1").uid
|
||||
|
||||
res = client.post(f"/api/roles/{uid}/vote", json={"value": 1})
|
||||
assert res.status_code == 422 and "Settings" in res.json()["detail"]
|
||||
assert client.delete(f"/api/roles/{uid}/vote").status_code == 422
|
||||
assert client.post("/api/companies/acme/affinity", json={"affinity": 1}).status_code == 422
|
||||
assert client.get(f"/api/roles/{uid}").json()["vote"] is None
|
||||
assert client.get("/api/roles").json()["items"][0]["vote"] is None
|
||||
assert client.get("/api/companies").json()[0]["affinity"] == 0
|
||||
|
||||
|
||||
def test_roles_with_an_agent_can_be_ordered_newest_and_keep_the_votes(
|
||||
client: TestClient, store: Store) -> None:
|
||||
clock = Clock()
|
||||
store.clock = clock
|
||||
for sid in ("1", "2", "3"):
|
||||
store.upsert_role(posting(sid))
|
||||
clock.tick()
|
||||
uid = {r.source_id: r.uid for r in store.roles()}
|
||||
agent = store.save_agent("A")
|
||||
store.replace_scores(agent.id, [(uid["1"], 0.9, ""), (uid["2"], 0.1, "")]) # 3 unscored
|
||||
store.set_vote(agent.id, uid["1"], 1)
|
||||
|
||||
page = client.get("/api/roles", params={"agent": agent.id, "order": "newest"}).json()
|
||||
assert [r["source_id"] for r in page["items"]] == ["3", "2", "1"]
|
||||
assert [r["score"] for r in page["items"]] == [None, None, None]
|
||||
assert [r["vote"] for r in page["items"]] == [None, None, 1]
|
||||
assert page["total"] == 3
|
||||
scored = client.get("/api/roles", params={"agent": agent.id, "order": "score"}).json()
|
||||
assert [r["source_id"] for r in scored["items"]] == ["1", "2"]
|
||||
assert client.get("/api/roles", params={"agent": agent.id,
|
||||
"order": "best"}).status_code == 422
|
||||
|
||||
|
||||
def test_a_vote_moves_a_role_in_the_ranking_at_once(
|
||||
@@ -249,15 +334,27 @@ def test_companies_lists_board_and_open_role_count(
|
||||
def test_set_affinity_validates_updates_and_enqueues_a_score(
|
||||
client: TestClient, store: Store, queue: Any) -> None:
|
||||
store.add_company("Acme", key="acme")
|
||||
agent = store.save_agent("A")
|
||||
other = store.save_agent("B")
|
||||
|
||||
# No `agent` in the body: the default agent's affinity.
|
||||
res = client.post("/api/companies/acme/affinity", json={"affinity": 2})
|
||||
assert res.status_code == 200
|
||||
assert res.json()["affinity"] == 2
|
||||
assert store.company("acme").affinity == 2 # type: ignore[union-attr]
|
||||
assert store.company("acme", agent.id).affinity == 2 # type: ignore[union-attr]
|
||||
assert store.company("acme", other.id).affinity == 0 # type: ignore[union-attr]
|
||||
assert queue.jobs.last("score", states=("queued", "running", "done")) is not None
|
||||
|
||||
res = client.post("/api/companies/acme/affinity", json={"affinity": -1, "agent": other.id})
|
||||
assert res.status_code == 200 and res.json()["affinity"] == -1
|
||||
assert store.company("acme", agent.id).affinity == 2 # type: ignore[union-attr]
|
||||
assert [c["affinity"] for c in client.get("/api/companies", params={"agent": other.id}).json()] == [-1]
|
||||
|
||||
assert client.post("/api/companies/acme/affinity", json={"affinity": 9}).status_code == 422
|
||||
assert client.post("/api/companies/nope/affinity", json={"affinity": 1}).status_code == 404
|
||||
assert client.post("/api/companies/acme/affinity",
|
||||
json={"affinity": 1, "agent": 999}).status_code == 404
|
||||
assert client.get("/api/companies", params={"agent": 999}).status_code == 404
|
||||
|
||||
|
||||
# ----------------------------------------------------------- applications
|
||||
@@ -338,8 +435,7 @@ def test_the_applications_page_has_no_next_column(client: TestClient) -> None:
|
||||
|
||||
def test_every_page_renders_with_the_whole_nav(client: TestClient) -> None:
|
||||
assert [t.label for t in TABS] == ["Roles", "Applications"]
|
||||
assert [t.label for t in SETTINGS] == ["Ranking", "Searches", "Companies", "Pulls",
|
||||
"Messages", "Account"]
|
||||
assert [t.label for t in SETTINGS] == ["Search agents", "Sources", "Account"]
|
||||
assert all(t.path.startswith("/settings/") for t in SETTINGS)
|
||||
for tab in (*TABS, *SETTINGS):
|
||||
res = client.get(tab.path)
|
||||
@@ -352,80 +448,99 @@ def test_every_page_renders_with_the_whole_nav(client: TestClient) -> None:
|
||||
|
||||
|
||||
def test_the_cog_and_one_sub_tab_are_current_on_a_settings_page(client: TestClient) -> None:
|
||||
page = client.get("/settings/pulls").text
|
||||
page = client.get("/settings/sources").text
|
||||
assert 'class="icon active"' in page
|
||||
for tab in SETTINGS:
|
||||
assert f">{tab.label}</a>" in page
|
||||
assert page.count('aria-current="page"') == 1
|
||||
current = page.index('aria-current="page"')
|
||||
assert page.rindex('href="', 0, current) == page.index('href="/settings/pulls"')
|
||||
assert page.rindex('href="', 0, current) == page.index('href="/settings/sources"')
|
||||
assert 'class="icon active"' not in client.get("/").text
|
||||
|
||||
|
||||
def test_settings_is_ranking(client: TestClient) -> None:
|
||||
def test_settings_is_search_agents(client: TestClient) -> None:
|
||||
res = client.get("/settings", follow_redirects=False)
|
||||
assert res.status_code == 302 and res.headers["location"] == "/settings/ranking"
|
||||
assert res.status_code == 302 and res.headers["location"] == "/settings/agents"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("old", "new"), sorted(MOVED.items()))
|
||||
def test_an_old_tab_moves_permanently_and_keeps_its_query(
|
||||
client: TestClient, old: str, new: str) -> None:
|
||||
"""A merged page's old path lands on its section: the query goes before
|
||||
the anchor, or the browser would take `#runs?q=` as one fragment."""
|
||||
assert {"/agents", "/settings/ranking", "/companies", "/sources", "/jobs",
|
||||
"/schedules", "/messages", "/settings/searches", "/settings/companies",
|
||||
"/settings/pulls", "/settings/messages", "/account"} <= set(MOVED)
|
||||
path, _, anchor = new.partition("#")
|
||||
res = client.get(old, follow_redirects=False)
|
||||
assert res.status_code == 301 and res.headers["location"] == new
|
||||
res = client.get(f"{old}?agent=3&q=a+b", follow_redirects=False)
|
||||
assert res.status_code == 301 and res.headers["location"] == f"{new}?agent=3&q=a+b"
|
||||
assert res.status_code == 301
|
||||
assert res.headers["location"] == f"{path}?agent=3&q=a+b" + (f"#{anchor}" if anchor else "")
|
||||
assert client.get(old).status_code == 200
|
||||
|
||||
|
||||
def test_each_page_loads_only_its_own_script(client: TestClient) -> None:
|
||||
scripts = {"roles.js", "applications.js", "ranking.js", "companies.js", "sources.js",
|
||||
"""Sources is four sections' scripts on one page, each guarding on its own
|
||||
root element; every other page is one."""
|
||||
scripts = {"roles.js", "applications.js", "agents.js", "companies.js", "sources.js",
|
||||
"jobs.js", "messages.js"}
|
||||
for path, container, script in [
|
||||
("/", 'id="roles-list"', "roles.js"),
|
||||
("/applications", 'id="applications-list"', "applications.js"),
|
||||
("/settings/ranking", 'id="ranking-form"', "ranking.js"),
|
||||
("/settings/searches", 'id="searches-list"', "sources.js"),
|
||||
("/settings/companies", 'id="companies-list"', "companies.js"),
|
||||
("/settings/pulls", 'id="kinds"', "jobs.js"),
|
||||
("/settings/messages", 'id="notices"', "messages.js")]:
|
||||
for path, container, own in [
|
||||
("/", 'id="roles-list"', ["roles.js"]),
|
||||
("/applications", 'id="applications-list"', ["applications.js"]),
|
||||
("/settings/agents", 'id="agent-form"', ["agents.js"]),
|
||||
("/settings/sources", 'id="searches-list"',
|
||||
["sources.js", "companies.js", "jobs.js", "messages.js"])]:
|
||||
page = client.get(path).text
|
||||
assert container in page, path
|
||||
assert [s for s in scripts if f"/static/{s}" in page] == [script], path
|
||||
# toasts.js before app.js before the page's own script: `api()` needs
|
||||
assert sorted(s for s in scripts if f"/static/{s}" in page) == sorted(own), path
|
||||
# toasts.js before app.js before the page's own scripts: `api()` needs
|
||||
# `window.toast`, and every page script needs `api()` and the helpers.
|
||||
assert page.index("toasts.js") < page.index("app.js") < page.index(f"/static/{script}")
|
||||
assert client.get(f"/static/{script}").status_code == 200
|
||||
for script in own:
|
||||
assert page.index("toasts.js") < page.index("app.js") < page.index(f"/static/{script}")
|
||||
assert client.get(f"/static/{script}").status_code == 200
|
||||
assert "ROLEDESK_STATUSES" in client.get("/applications").text
|
||||
assert client.get("/static/ranking.js").status_code == 404
|
||||
|
||||
|
||||
def test_the_ranking_page_edits_one_ranking(client: TestClient) -> None:
|
||||
page = client.get("/settings/ranking").text
|
||||
def test_the_agents_page_lists_and_edits_search_agents(client: TestClient) -> None:
|
||||
page = client.get("/settings/agents").text
|
||||
assert 'id="agents-list"' in page and 'id="agents-count"' in page
|
||||
assert 'id="a-name"' in page and 'placeholder="My search"' in page
|
||||
assert 'id="a-intent"' in page and "<details" in page and 'id="a-gates"' in page
|
||||
assert 'id="a-delete"' not in page and 'id="a-new"' not in page
|
||||
assert 'id="agents-list"' not in page
|
||||
for weight in ("a-fit", "a-recency", "a-affinity", "a-taste"):
|
||||
assert f'id="{weight}"' in page
|
||||
assert 'id="a-taste" min="0" step="0.05" value="0.2"' in page
|
||||
assert 'id="a-new"' in page and 'id="a-delete"' in page
|
||||
assert "Save and score" in page
|
||||
|
||||
|
||||
def test_the_searches_page_offers_the_jobindex_areas(client: TestClient) -> None:
|
||||
page = client.get("/settings/searches").text
|
||||
assert 'id="searches-list"' in page
|
||||
assert 'value="1" selected>Region Hovedstaden' in page # from plugins.search
|
||||
# Boards and the prune tool moved to Companies; a search has no board.
|
||||
assert 'id="boards-list"' not in page and 'id="prune-form"' not in page
|
||||
assert 'id="pull-now"' not in page # moved to Pulls
|
||||
|
||||
|
||||
def test_the_companies_page_offers_the_follow_form_and_the_prune_tool(
|
||||
client: TestClient) -> None:
|
||||
page = client.get("/settings/companies").text
|
||||
assert 'id="companies-list"' in page
|
||||
def test_the_sources_page_has_a_section_per_plugin(client: TestClient) -> None:
|
||||
"""Job boards, company boards and the runs, in that order, with the
|
||||
message log at the end of the runs and a jump row to each section."""
|
||||
page = client.get("/settings/sources").text
|
||||
for anchor in ("job-boards", "company-boards", "runs"):
|
||||
assert f'href="#{anchor}"' in page and f'id="{anchor}"' in page
|
||||
assert page.index('id="job-boards"') < page.index('id="company-boards"') \
|
||||
< page.index('id="runs"') < page.index('id="messages"')
|
||||
# Job boards: the Jobindex areas and the Adzuna countries, from plugins.search.
|
||||
assert 'id="searches-list"' in page and 'id="search-form"' in page
|
||||
assert 'value="1" selected>Region Hovedstaden' in page
|
||||
assert "job board" in page.lower() and "saved search" not in page.lower()
|
||||
# Company boards: the follow form, the agent select, the list, the prune tool.
|
||||
assert 'id="companies-list"' in page and 'id="c-agent"' in page
|
||||
assert 'id="b-host"' in page and 'id="b-slug"' in page and 'id="b-name"' in page
|
||||
assert '<option value="greenhouse">' in page and '<option value="personio">' in page
|
||||
assert 'id="prune-form"' in page and "Switch off boards with no roles in a region" in page
|
||||
assert "hidden" in page.lower() and "mute" not in page.lower()
|
||||
boards = page[page.index('id="company-boards"'):page.index('id="runs"')].lower()
|
||||
assert "hidden" in boards and "mute" not in boards
|
||||
# Runs: Pull now, the queue's elements, one stage at a time, the log.
|
||||
assert 'id="pull-now"' in page and 'id="kinds"' in page
|
||||
assert 'id="notices"' in page and 'id="clear-all"' in page
|
||||
|
||||
|
||||
def test_the_modules_bring_their_own_elements(client: TestClient) -> None:
|
||||
pulls = client.get("/settings/pulls").text
|
||||
pulls = client.get("/settings/sources").text
|
||||
assert pulls.index("<desk-jobs>") < pulls.index("<desk-schedules>")
|
||||
assert "<auth-account>" in client.get("/settings/account").text
|
||||
|
||||
@@ -491,13 +606,14 @@ def test_agents_are_created_updated_listed_and_deleted(client: TestClient) -> No
|
||||
created = client.post("/api/agents", json=body)
|
||||
assert created.status_code == 200
|
||||
agent = created.json()
|
||||
assert agent["weights"] == {"fit": 0.6, "recency": 0.2, "affinity": 0.2}
|
||||
assert agent["weights"] == {"fit": 0.6, "recency": 0.2, "affinity": 0.2, "taste": 0.2}
|
||||
assert agent["gates"][0]["weight"] == 1.0
|
||||
|
||||
updated = client.post("/api/agents", json={**body, "id": agent["id"], "enabled": False,
|
||||
"weights": {"fit": 1, "recency": 0,
|
||||
"affinity": 0}})
|
||||
"affinity": 0, "taste": 0.5}})
|
||||
assert updated.json()["enabled"] is False and updated.json()["weights"]["fit"] == 1
|
||||
assert updated.json()["weights"]["taste"] == 0.5
|
||||
|
||||
assert [a["name"] for a in client.get("/api/agents").json()] == ["Berlin"]
|
||||
assert client.post("/api/agents", json=body).status_code == 409
|
||||
@@ -506,6 +622,25 @@ def test_agents_are_created_updated_listed_and_deleted(client: TestClient) -> No
|
||||
assert client.delete(f"/api/agents/{agent['id']}").status_code == 404
|
||||
|
||||
|
||||
def test_deleting_an_agent_takes_its_votes_and_affinities_with_it(
|
||||
client: TestClient, store: Store) -> None:
|
||||
store.upsert_role(posting("1"))
|
||||
store.add_company("Acme", key="acme")
|
||||
uid = posting("1").uid
|
||||
agent = client.post("/api/agents", json={"name": "A"}).json()
|
||||
kept = client.post("/api/agents", json={"name": "B"}).json()
|
||||
client.post(f"/api/roles/{uid}/vote", json={"value": 1, "agent": agent["id"]})
|
||||
client.post(f"/api/roles/{uid}/vote", json={"value": -1, "agent": kept["id"]})
|
||||
client.post("/api/companies/acme/affinity", json={"affinity": 2, "agent": agent["id"]})
|
||||
|
||||
assert client.delete(f"/api/agents/{agent['id']}").status_code == 204
|
||||
|
||||
with store.transaction() as conn:
|
||||
assert conn.execute("SELECT COUNT(*) FROM role_votes").fetchone()[0] == 1
|
||||
assert conn.execute("SELECT COUNT(*) FROM agent_companies").fetchone()[0] == 0
|
||||
assert client.get(f"/api/roles/{uid}", params={"agent": kept["id"]}).json()["vote"] == -1
|
||||
|
||||
|
||||
def test_a_gate_on_an_unknown_field_is_refused(client: TestClient) -> None:
|
||||
body = {"name": "Bad", "gates": [{"field": "salary", "values": [1]}]}
|
||||
assert client.post("/api/agents", json=body).status_code == 422
|
||||
|
||||
Reference in new issue
Block a user